aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gm2
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2023-09-12 10:50:44 +0100
committerGaius Mulley <gaiusmod2@gmail.com>2023-09-12 10:50:44 +0100
commit89b5866742a17c38cc98edd9e434cff8e3a3c7ea (patch)
tree3bb85bb9a6fc8240c9449bac46ef7c4ea0a320ab /gcc/testsuite/gm2
parent56004123ab74193d88ad297877fa4e2a0d7ef5b1 (diff)
downloadgcc-89b5866742a17c38cc98edd9e434cff8e3a3c7ea.zip
gcc-89b5866742a17c38cc98edd9e434cff8e3a3c7ea.tar.gz
gcc-89b5866742a17c38cc98edd9e434cff8e3a3c7ea.tar.bz2
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>
Diffstat (limited to 'gcc/testsuite/gm2')
-rw-r--r--gcc/testsuite/gm2/switches/case/fail/missingclause.mod23
-rw-r--r--gcc/testsuite/gm2/switches/case/fail/switches-case-fail.exp37
-rw-r--r--gcc/testsuite/gm2/switches/case/pass/enumcase.mod24
-rw-r--r--gcc/testsuite/gm2/switches/case/pass/enumcase2.mod22
-rw-r--r--gcc/testsuite/gm2/switches/case/pass/switches-case-pass.exp37
5 files changed, 143 insertions, 0 deletions
diff --git a/gcc/testsuite/gm2/switches/case/fail/missingclause.mod b/gcc/testsuite/gm2/switches/case/fail/missingclause.mod
new file mode 100644
index 0000000..153ed9b
--- /dev/null
+++ b/gcc/testsuite/gm2/switches/case/fail/missingclause.mod
@@ -0,0 +1,23 @@
+MODULE missingclause ; (*!m2iso+gm2*)
+
+
+TYPE
+ colour = (red, green, blue) ;
+
+
+PROCEDURE init (c: colour) ;
+BEGIN
+ CASE c OF
+
+ red,
+ blue: (* User forgets green. *)
+
+ END
+END init ;
+
+
+VAR
+ rgb: colour ;
+BEGIN
+ init (rgb)
+END missingclause.
diff --git a/gcc/testsuite/gm2/switches/case/fail/switches-case-fail.exp b/gcc/testsuite/gm2/switches/case/fail/switches-case-fail.exp
new file mode 100644
index 0000000..2a3d48c
--- /dev/null
+++ b/gcc/testsuite/gm2/switches/case/fail/switches-case-fail.exp
@@ -0,0 +1,37 @@
+# Expect driver script for GCC Regression Tests
+# Copyright (C) 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# This file was written by Gaius Mulley (gaius.mulley@southwales.ac.uk)
+# for GNU Modula-2.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+# load support procs
+load_lib gm2-torture.exp
+
+gm2_init_iso "${srcdir}/gm2/switches/case/fail/" -Wcase-enum -Werror
+
+foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/*.mod]] {
+ # If we're only testing specific files and this isn't one of them, skip it.
+ if ![runtest_file_p $runtests $testcase] then {
+ continue
+ }
+
+ gm2-torture-fail $testcase
+}
diff --git a/gcc/testsuite/gm2/switches/case/pass/enumcase.mod b/gcc/testsuite/gm2/switches/case/pass/enumcase.mod
new file mode 100644
index 0000000..7876598f
--- /dev/null
+++ b/gcc/testsuite/gm2/switches/case/pass/enumcase.mod
@@ -0,0 +1,24 @@
+MODULE enumcase ; (*!m2iso+gm2*)
+
+
+TYPE
+ colour = (red, blue, green) ;
+
+PROCEDURE init (c: colour) ;
+BEGIN
+ CASE c OF
+
+ red: |
+ (* blue..green: *)
+ blue,
+ green:
+
+ END
+END init ;
+
+
+VAR
+ rgb: colour ;
+BEGIN
+ init (rgb)
+END enumcase.
diff --git a/gcc/testsuite/gm2/switches/case/pass/enumcase2.mod b/gcc/testsuite/gm2/switches/case/pass/enumcase2.mod
new file mode 100644
index 0000000..796bc80
--- /dev/null
+++ b/gcc/testsuite/gm2/switches/case/pass/enumcase2.mod
@@ -0,0 +1,22 @@
+MODULE enumcase2 ; (*!m2iso+gm2*)
+
+
+TYPE
+ colour = (red, blue, green) ;
+
+PROCEDURE init (c: colour) ;
+BEGIN
+ CASE c OF
+
+ red: |
+ blue..green:
+
+ END
+END init ;
+
+
+VAR
+ rgb: colour ;
+BEGIN
+ init (rgb)
+END enumcase2.
diff --git a/gcc/testsuite/gm2/switches/case/pass/switches-case-pass.exp b/gcc/testsuite/gm2/switches/case/pass/switches-case-pass.exp
new file mode 100644
index 0000000..92124ae
--- /dev/null
+++ b/gcc/testsuite/gm2/switches/case/pass/switches-case-pass.exp
@@ -0,0 +1,37 @@
+# Expect driver script for GCC Regression Tests
+# Copyright (C) 2003-2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# This file was written by Gaius Mulley (gaius.mulley@southwales.ac.uk)
+# for GNU Modula-2.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+# load support procs
+load_lib gm2-torture.exp
+
+gm2_init_iso "${srcdir}/gm2/switches/case/pass" -Wcase-enum -Werror
+
+foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/*.mod]] {
+ # If we're only testing specific files and this isn't one of them, skip it.
+ if ![runtest_file_p $runtests $testcase] then {
+ continue
+ }
+
+ gm2-torture $testcase
+}