diff options
author | Gaius Mulley <gaiusmod2@gmail.com> | 2023-09-14 19:35:24 +0100 |
---|---|---|
committer | Gaius Mulley <gaiusmod2@gmail.com> | 2023-09-14 19:35:24 +0100 |
commit | 4e1c5d5faf6b3dd32a9c8644d4fbf6471b7d9705 (patch) | |
tree | 07e18a89fc420e47656c61e2be659b15cb59b052 /gcc/testsuite/gm2 | |
parent | 3c834d85f2ec42c60995c2b678196a06cb744959 (diff) | |
download | gcc-4e1c5d5faf6b3dd32a9c8644d4fbf6471b7d9705.zip gcc-4e1c5d5faf6b3dd32a9c8644d4fbf6471b7d9705.tar.gz gcc-4e1c5d5faf6b3dd32a9c8644d4fbf6471b7d9705.tar.bz2 |
modula2: introduce case checking when switching on subranges
This patch extends the -Wcase-enum warning to catch missing elements
from subranges. The patch also includes removal of unused parameters
from M2SymInit.mod and M2CaseList.mod.
gcc/m2/ChangeLog:
* gm2-compiler/M2CaseList.mod (appendString): New procedure.
(appendEnum): Re-implement.
(NoOfSetElements): New procedure function.
(isPrintableChar): New procedure function.
(appendTree): New procedure.
(SubrangeErrors): New procedure.
(EmitMissingRangeErrors): Call SubrangeErrors if appropriate.
* gm2-compiler/M2SymInit.mod (SetFieldInitializedNo): Avoid
using a temporary variable once.
(IsLocalVar): Comment out.
(RecordContainsVarient): Remove fieldtype.
(GenerateNoteFlow): Remove lst parameter.
(CheckDeferredRecordAccess): Remove lst parameter.
(CheckUnary): Remove lst parameter. Remove procSym.
(CheckBinary): Remove lst parameter. Remove procSym.
(CheckIndrX): Remove lst parameter. Remove procSym.
(CheckXIndr): Remove bblst and procSym parameters.
(CheckRecordField): Remove procSym, op1tok, op2tok and op2.
(CheckBecomes): Remove procSym and bblst.
(CheckComparison): Remove procSym and bblst.
(CheckAddr): Remove procSym parameter.
* gm2-gcc/m2expr.cc (m2expr_CSTIntToString): New function.
(m2expr_CSTIntToChar): New function.
* gm2-gcc/m2expr.def (CSTIntToString): New procedure function
declaration.
(CSTIntToChar): New procedure function declaration.
* gm2-gcc/m2expr.h (m2expr_CSTIntToChar): New prototype.
(m2expr_CSTIntToString): New prototype.
gcc/testsuite/ChangeLog:
* gm2/switches/case/fail/subrangecase.mod: New test.
* gm2/switches/case/fail/subrangecase2.mod: New test.
* gm2/switches/case/fail/subrangecase3.mod: New test.
* gm2/switches/case/fail/subrangecase4.mod: New test.
* gm2/switches/case/fail/subrangecase5.mod: New test.
* gm2/switches/case/fail/subrangecase6.mod: New test.
* gm2/switches/case/pass/subrangecase.mod: New test.
* gm2/switches/case/pass/subrangecase2.mod: New test.
* gm2/switches/case/pass/subrangecase3.mod: New test.
* gm2/switches/case/pass/subrangecase4.mod: New test.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diffstat (limited to 'gcc/testsuite/gm2')
10 files changed, 228 insertions, 0 deletions
diff --git a/gcc/testsuite/gm2/switches/case/fail/subrangecase.mod b/gcc/testsuite/gm2/switches/case/fail/subrangecase.mod new file mode 100644 index 0000000..2c3b56e --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/fail/subrangecase.mod @@ -0,0 +1,24 @@ +MODULE subrangecase ; (*!m2iso+gm2*) + + +TYPE + DateRange = [1910..1920] ; + + +PROCEDURE init (d: DateRange) ; +BEGIN + CASE d OF + + (* 1910: | *) + 1911..1919: | + 1920: | + + END +END init ; + + +VAR + year: DateRange ; +BEGIN + init (year) +END subrangecase. diff --git a/gcc/testsuite/gm2/switches/case/fail/subrangecase2.mod b/gcc/testsuite/gm2/switches/case/fail/subrangecase2.mod new file mode 100644 index 0000000..d0e3a3a --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/fail/subrangecase2.mod @@ -0,0 +1,22 @@ +MODULE subrangecase2 ; (*!m2iso+gm2*) + + +TYPE + DateRange = [1910..1920] ; + + +PROCEDURE init (d: DateRange) ; +BEGIN + CASE d OF + + 1911..1920: | + + END +END init ; + + +VAR + year: DateRange ; +BEGIN + init (year) +END subrangecase2. diff --git a/gcc/testsuite/gm2/switches/case/fail/subrangecase3.mod b/gcc/testsuite/gm2/switches/case/fail/subrangecase3.mod new file mode 100644 index 0000000..5a34c0b --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/fail/subrangecase3.mod @@ -0,0 +1,23 @@ +MODULE subrangecase3 ; (*!m2iso+gm2*) + + +TYPE + DateRange = [1910..1920] ; + + +PROCEDURE init (d: DateRange) ; +BEGIN + CASE d OF + + 1910: | + 1912..1919: | + + END +END init ; + + +VAR + year: DateRange ; +BEGIN + init (year) +END subrangecase3. diff --git a/gcc/testsuite/gm2/switches/case/fail/subrangecase4.mod b/gcc/testsuite/gm2/switches/case/fail/subrangecase4.mod new file mode 100644 index 0000000..f8c4ae1 --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/fail/subrangecase4.mod @@ -0,0 +1,23 @@ +MODULE subrangecase4 ; (*!m2iso+gm2*) + + +TYPE + DateRange = [1910..1920] ; + + +PROCEDURE init (d: DateRange) ; +BEGIN + CASE d OF + + 1910: | + 1913..1918: | + + END +END init ; + + +VAR + year: DateRange ; +BEGIN + init (year) +END subrangecase4. diff --git a/gcc/testsuite/gm2/switches/case/fail/subrangecase5.mod b/gcc/testsuite/gm2/switches/case/fail/subrangecase5.mod new file mode 100644 index 0000000..ded38cd --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/fail/subrangecase5.mod @@ -0,0 +1,23 @@ +MODULE subrangecase5 ; (*!m2iso+gm2*) + + +TYPE + alphabet = ['a'..'z'] ; + + +PROCEDURE init (a: alphabet) ; +BEGIN + CASE a OF + + 'a', + 'e'..'x': + + END +END init ; + + +VAR + a: alphabet ; +BEGIN + init (a) +END subrangecase5. diff --git a/gcc/testsuite/gm2/switches/case/fail/subrangecase6.mod b/gcc/testsuite/gm2/switches/case/fail/subrangecase6.mod new file mode 100644 index 0000000..46e18c7 --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/fail/subrangecase6.mod @@ -0,0 +1,23 @@ +MODULE subrangecase6 ; (*!m2iso+gm2*) + + +TYPE + alphabet = [MIN (CHAR)..MAX (CHAR)] ; + + +PROCEDURE init (a: alphabet) ; +BEGIN + CASE a OF + + 'a', + 'e'..'x': + + END +END init ; + + +VAR + a: alphabet ; +BEGIN + init (a) +END subrangecase6. diff --git a/gcc/testsuite/gm2/switches/case/pass/subrangecase.mod b/gcc/testsuite/gm2/switches/case/pass/subrangecase.mod new file mode 100644 index 0000000..50bbf6a --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/pass/subrangecase.mod @@ -0,0 +1,24 @@ +MODULE subrangecase ; (*!m2iso+gm2*) + + +TYPE + DateRange = [1910..1920] ; + + +PROCEDURE init (d: DateRange) ; +BEGIN + CASE d OF + + 1910: | + 1911..1919: | + 1920: | + + END +END init ; + + +VAR + year: DateRange ; +BEGIN + init (year) +END subrangecase. diff --git a/gcc/testsuite/gm2/switches/case/pass/subrangecase2.mod b/gcc/testsuite/gm2/switches/case/pass/subrangecase2.mod new file mode 100644 index 0000000..cd14c0c --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/pass/subrangecase2.mod @@ -0,0 +1,22 @@ +MODULE subrangecase2 ; (*!m2iso+gm2*) + + +TYPE + DateRange = [1910..1920] ; + + +PROCEDURE init (d: DateRange) ; +BEGIN + CASE d OF + + 1910..1920: | + + END +END init ; + + +VAR + year: DateRange ; +BEGIN + init (year) +END subrangecase2. diff --git a/gcc/testsuite/gm2/switches/case/pass/subrangecase3.mod b/gcc/testsuite/gm2/switches/case/pass/subrangecase3.mod new file mode 100644 index 0000000..2f48373 --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/pass/subrangecase3.mod @@ -0,0 +1,23 @@ +MODULE subrangecase3 ; (*!m2iso+gm2*) + + +TYPE + DateRange = [1910..1920] ; + + +PROCEDURE init (d: DateRange) ; +BEGIN + CASE d OF + + 1910..1919: | + + ELSE + END +END init ; + + +VAR + year: DateRange ; +BEGIN + init (year) +END subrangecase3. diff --git a/gcc/testsuite/gm2/switches/case/pass/subrangecase4.mod b/gcc/testsuite/gm2/switches/case/pass/subrangecase4.mod new file mode 100644 index 0000000..8a2a672 --- /dev/null +++ b/gcc/testsuite/gm2/switches/case/pass/subrangecase4.mod @@ -0,0 +1,21 @@ +MODULE subrangecase4 ; (*!m2iso+gm2*) + + +TYPE + DateRange = [1910..1920] ; + + +PROCEDURE init (d: DateRange) ; +BEGIN + CASE d OF + + ELSE + END +END init ; + + +VAR + year: DateRange ; +BEGIN + init (year) +END subrangecase4. |