]> git.ipfire.org Git - thirdparty/gcc.git/commit
modula2: new option -Wcase-enum and associated fixes
authorGaius Mulley <gaiusmod2@gmail.com>
Tue, 12 Sep 2023 09:50:44 +0000 (10:50 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Tue, 12 Sep 2023 09:50:44 +0000 (10:50 +0100)
commit89b5866742a17c38cc98edd9e434cff8e3a3c7ea
tree3bb85bb9a6fc8240c9449bac46ef7c4ea0a320ab
parent56004123ab74193d88ad297877fa4e2a0d7ef5b1
modula2: new option -Wcase-enum and associated fixes

This patch introduces -Wcase-enum which enumerates each missing
field in a case statement without an else clause providing the selector
expression type is an enum.

gcc/ChangeLog:

* doc/gm2.texi (Compiler options): Document new option
-Wcase-enum.

gcc/m2/ChangeLog:

* gm2-compiler/M2CaseList.def (PushCase): Rename parameters
r to rec and v to va.  Add expr parameter.
(MissingCaseStatementBounds): New procedure function.
* gm2-compiler/M2CaseList.mod (RangePair): Add expression.
(PushCase): Rename parameters r to rec and v to va.  Add
expr parameter.
(RemoveRange): New procedure function.
(SubBitRange): Detect the case when the range in the set matches
lo..hi.
(CheckLowHigh): New procedure.
(ExcludeCaseRanges): Rename parameter c to cd.  Rename local
variables q to cl and r to rp.
(High): Remove.
(Low): Remove.
(DoEnumValues): Remove.
(IncludeElement): New procedure.
(IncludeElements): New procedure.
(ErrorRangeEnum): New procedure.
(ErrorRange): Remove.
(ErrorRanges): Remove.
(appendEnum): New procedure.
(appendStr): New procedure.
(EnumerateErrors): New procedure.
(MissingCaseBounds): Re-implement.
(InRangeList): Remove.
(MissingCaseStatementBounds): New procedure function.
(checkTypes): Re-format.
(inRange): Re-format.
(TypeCaseBounds): Re-format.
* gm2-compiler/M2Error.mod (GetAnnounceScope): Add noscope to
case label list.
* gm2-compiler/M2GCCDeclare.mod: Replace ForeachFieldEnumerationDo
with ForeachLocalSymDo.
* gm2-compiler/M2Options.def (SetCaseEnumChecking): New procedure.
(CaseEnumChecking): New variable.
* gm2-compiler/M2Options.mod (SetCaseEnumChecking): New procedure.
(Module initialization): set CaseEnumChecking to FALSE.
* gm2-compiler/M2Quads.def (QuadOperator): Alphabetically ordered.
* gm2-compiler/M2Quads.mod (IsBackReferenceConditional): Add else
clause.
(BuildCaseStart): Pass selector expression to InitCaseBounds.
(CheckUninitializedVariablesAreUsed): Remove.
(IsInlineWithinBlock): Remove.
(AsmStatementsInBlock): Remove.
(CheckVariablesInBlock): Remove commented code.
(BeginVarient): Pass NulSym to InitCaseBounds.
* gm2-compiler/M2Range.mod (FoldCaseBounds): New local variable
errorGenerated.  Add call to MissingCaseStatementBounds.
* gm2-compiler/P3Build.bnf (CaseEndStatement): Call ElseCase.
* gm2-compiler/PCSymBuild.mod (InitDesExpr): Add else clause.
(InitFunction): Add else clause.
(InitConvert): Add else clause.
(InitLeaf): Add else clause.
(InitBinary): Add else clause.
(InitUnary): Add else clause.
* gm2-compiler/SymbolTable.def (GetNth): Re-write comment.
(ForeachFieldEnumerationDo): Re-write comment stating alphabetical
traversal.
* gm2-compiler/SymbolTable.mod (GetNth): Re-write comment.
Add case label for EnumerationSym and call GetItemFromList.
(ForeachFieldEnumerationDo): Re-write comment stating alphabetical
traversal.
(SymEnumeration): Add ListOfFields used for declaration order.
(MakeEnumeration): Initialize ListOfFields.
(PutFieldEnumeration): Include Field in ListOfFields.
* gm2-gcc/m2options.h (M2Options_SetCaseEnumChecking): New
function.
* gm2-lang.cc (gm2_langhook_handle_option): Add
OPT_Wcase_enum case and call M2Options_SetCaseEnumChecking.
* lang.opt (Wcase-enum): Add.

gcc/testsuite/ChangeLog:

* gm2/switches/case/fail/missingclause.mod: New test.
* gm2/switches/case/fail/switches-case-fail.exp: New test.
* gm2/switches/case/pass/enumcase.mod: New test.
* gm2/switches/case/pass/enumcase2.mod: New test.
* gm2/switches/case/pass/switches-case-pass.exp: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
22 files changed:
gcc/doc/gm2.texi
gcc/m2/gm2-compiler/M2CaseList.def
gcc/m2/gm2-compiler/M2CaseList.mod
gcc/m2/gm2-compiler/M2Error.mod
gcc/m2/gm2-compiler/M2GCCDeclare.mod
gcc/m2/gm2-compiler/M2Options.def
gcc/m2/gm2-compiler/M2Options.mod
gcc/m2/gm2-compiler/M2Quads.def
gcc/m2/gm2-compiler/M2Quads.mod
gcc/m2/gm2-compiler/M2Range.mod
gcc/m2/gm2-compiler/P3Build.bnf
gcc/m2/gm2-compiler/PCSymBuild.mod
gcc/m2/gm2-compiler/SymbolTable.def
gcc/m2/gm2-compiler/SymbolTable.mod
gcc/m2/gm2-gcc/m2options.h
gcc/m2/gm2-lang.cc
gcc/m2/lang.opt
gcc/testsuite/gm2/switches/case/fail/missingclause.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/case/fail/switches-case-fail.exp [new file with mode: 0644]
gcc/testsuite/gm2/switches/case/pass/enumcase.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/case/pass/enumcase2.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/case/pass/switches-case-pass.exp [new file with mode: 0644]