public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3925] modula2: -Wcase-enum detect singular/plural and use switch during build
@ 2023-09-13 14:53 Gaius Mulley
  0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2023-09-13 14:53 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3af2af15798cb6243e2643f98f62c9270b1ca5d2

commit r14-3925-g3af2af15798cb6243e2643f98f62c9270b1ca5d2
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Wed Sep 13 15:51:59 2023 +0100

    modula2: -Wcase-enum detect singular/plural and use switch during build
    
    This patch generates a singular or plural message relating to the
    number of enums missing.  Use -Wcase-enum when building of the
    modula-2 libraries and m2/stage2/cc1gm2.
    
    gcc/m2/ChangeLog:
    
            * Make-lang.in (GM2_FLAGS): Add -Wcase-enum.
            (GM2_ISO_FLAGS): Add -Wcase-enum.
            * gm2-compiler/M2CaseList.mod (EnumerateErrors): Issue
            singular or plural start text prior to the enum list.
            Remove unused parameter tokenno.
            (EmitMissingRangeErrors): New procedure.
            (MissingCaseBounds): Call EmitMissingRangeErrors.
            (MissingCaseStatementBounds): Call EmitMissingRangeErrors.
            * gm2-libs-iso/TextIO.mod: Fix spacing.
    
    libgm2/ChangeLog:
    
            * libm2cor/Makefile.am (libm2cor_la_M2FLAGS): Add
            -Wcase-enum.
            * libm2cor/Makefile.in: Regenerate.
            * libm2iso/Makefile.am (libm2iso_la_M2FLAGS): Add
            -Wcase-enum.
            * libm2iso/Makefile.in: Regenerate.
            * libm2log/Makefile.am (libm2log_la_M2FLAGS): Add
            -Wcase-enum.
            * libm2log/Makefile.in: Regenerate.
            * libm2pim/Makefile.am (libm2pim_la_M2FLAGS): Add
            -Wcase-enum.
            * libm2pim/Makefile.in: Regenerate.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

Diff:
---
 gcc/m2/Make-lang.in                | 19 +++++++++++--------
 gcc/m2/gm2-compiler/M2CaseList.mod | 36 ++++++++++++++++++++++++++++++------
 gcc/m2/gm2-libs-iso/TextIO.mod     |  2 +-
 libgm2/libm2cor/Makefile.am        |  2 +-
 libgm2/libm2cor/Makefile.in        |  2 +-
 libgm2/libm2iso/Makefile.am        |  2 +-
 libgm2/libm2iso/Makefile.in        |  2 +-
 libgm2/libm2log/Makefile.am        |  2 +-
 libgm2/libm2log/Makefile.in        |  2 +-
 libgm2/libm2pim/Makefile.am        |  2 +-
 libgm2/libm2pim/Makefile.in        |  2 +-
 11 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index ca1581fe643e..7338bfe77103 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -474,18 +474,21 @@ GM2_G=-g -fm2-g
 GM2_CPP=
 # GM2_DEBUG_STRMEM=-fcpp
 GM2_DEBUG_STRMEM=
-GM2_FLAGS=-Wunused-variable -Wuninit-variable-checking \
- -fsoft-check-all \
- -fno-return -Wreturn-type \
+GM2_FLAGS=-fsoft-check-all \
+ -fno-return \
  $(GM2_G) $(GM2_O) \
  -funbounded-by-reference -fpim -fextended-opaque \
- -Wpedantic-cast -Wpedantic-param-names -ffunction-sections \
- -fdata-sections $(GM2_CPP) # -fauto-init
+ -Wcase-enum -Wpedantic-cast -Wpedantic-param-names \
+ -Wreturn-type -Wunused-variable -Wuninit-variable-checking \
+ -ffunction-sections -fdata-sections \
+ $(GM2_CPP) # -fauto-init
 GM2_ISO_FLAGS=-fsoft-check-all $(GM2_G) $(GM2_O) \
- -fno-return -Wreturn-type \
+ -fno-return \
  -funbounded-by-reference -fiso -fextended-opaque \
- -Wpedantic-cast -Wpedantic-param-names -ffunction-sections \
- -fdata-sections $(GM2_CPP)
+ -Wcase-enum -Wpedantic-cast -Wpedantic-param-names -Wreturn-type \
+ -Wunused-variable -Wuninit-variable-checking \
+ -ffunction-sections -fdata-sections \
+ $(GM2_CPP)
 GM2_MIN_FLAGS=$(GM2_G) $(GM2_OS) \
  -funbounded-by-reference -fextended-opaque \
  -Wpedantic-cast -Wpedantic-param-names -fno-exceptions \
diff --git a/gcc/m2/gm2-compiler/M2CaseList.mod b/gcc/m2/gm2-compiler/M2CaseList.mod
index c7596356ddf5..18ea1fecf2b7 100644
--- a/gcc/m2/gm2-compiler/M2CaseList.mod
+++ b/gcc/m2/gm2-compiler/M2CaseList.mod
@@ -36,9 +36,11 @@ FROM DynamicStrings IMPORT InitString, InitStringCharStar, ConCat, Mark, KillStr
 FROM m2tree IMPORT Tree ;
 FROM m2block IMPORT RememberType ;
 FROM m2type IMPORT GetMinFrom ;
+FROM m2expr IMPORT GetIntegerOne ;
 FROM Storage IMPORT ALLOCATE ;
 FROM M2Base IMPORT IsExpressionCompatible ;
 FROM M2Printf IMPORT printf1 ;
+FROM M2LexBuf IMPORT TokenToLocation ;
 
 FROM SymbolTable IMPORT NulSym, IsConst, IsFieldVarient, IsRecord, IsRecordField, GetVarientTag, GetType,
                         ForeachLocalSymDo, GetSymName, IsEnumeration, SkipType, NoOfElements, GetNth ;
@@ -842,16 +844,22 @@ END appendStr ;
 
 
 (*
-   EnumerateErrors -
+   EnumerateErrors - populate errorString with the contents of enumList.
 *)
 
-PROCEDURE EnumerateErrors (tokenno: CARDINAL; enumList: List) ;
+PROCEDURE EnumerateErrors (enumList: List) ;
 VAR
    i, n: CARDINAL ;
 BEGIN
    n := NoOfItemsInList (enumList) ;
    IF (enumList # NIL) AND (n > 0)
    THEN
+      IF n = 1
+      THEN
+         errorString := InitString ('{%W}the missing enumeration field is: ') ;
+      ELSE
+         errorString := InitString ('{%W}the missing enumeration fields are: ') ;
+      END ;
       appendEnum (GetItemFromList (enumList, 1)) ;
       IF n > 1
       THEN
@@ -871,6 +879,24 @@ BEGIN
 END EnumerateErrors ;
 
 
+(*
+   EmitMissingRangeErrors - emits a singular/plural error message for an enumeration type.
+*)
+
+PROCEDURE EmitMissingRangeErrors (tokenno: CARDINAL; type: CARDINAL; set: SetRange) ;
+BEGIN
+   errorString := NIL ;
+   IF IsEnumeration (type)
+   THEN
+      EnumerateErrors (ErrorRanges (type, set))
+   END ;
+   IF errorString # NIL
+   THEN
+      MetaErrorStringT0 (tokenno, errorString)
+   END
+END EmitMissingRangeErrors ;
+
+
 (*
    MissingCaseBounds - returns true if there were any missing bounds
                        in the varient record case list, c.  It will
@@ -902,7 +928,7 @@ BEGIN
                MetaErrorT2 (tokenno,
                             'not all variant record alternatives in the {%kCASE} clause are specified, hint you either need to specify each value of {%2ad} or use an {%kELSE} clause',
                             varient, type) ;
-               EnumerateErrors (tokenno, ErrorRanges (type, set))
+               EmitMissingRangeErrors (tokenno, type, set)
             END ;
             set := DisposeRanges (set)
          END
@@ -944,9 +970,7 @@ BEGIN
                   MetaErrorT1 (tokenno,
                                'not all enumeration values in the {%kCASE} statements are specified, hint you either need to specify each value of {%1Wad} or use an {%kELSE} clause',
                                type) ;
-                  errorString := InitString ('{%W}the missing enumeration fields are: ') ;
-                  EnumerateErrors (tokenno, ErrorRanges (type, set)) ;
-                  MetaErrorStringT0 (tokenno, errorString)
+                  EmitMissingRangeErrors (tokenno, type, set)
                END ;
                set := DisposeRanges (set)
             END
diff --git a/gcc/m2/gm2-libs-iso/TextIO.mod b/gcc/m2/gm2-libs-iso/TextIO.mod
index a6ca17edecb6..eab156d20762 100644
--- a/gcc/m2/gm2-libs-iso/TextIO.mod
+++ b/gcc/m2/gm2-libs-iso/TextIO.mod
@@ -68,7 +68,7 @@ END DumpState ;
 *)
 
 PROCEDURE SetNul (cid: IOChan.ChanId; i: CARDINAL;
-                     VAR s: ARRAY OF CHAR; range: BOOLEAN) ;
+                  VAR s: ARRAY OF CHAR; range: BOOLEAN) ;
 BEGIN
    IF DebugState
    THEN
diff --git a/libgm2/libm2cor/Makefile.am b/libgm2/libm2cor/Makefile.am
index 48de40c22dd1..ae96b4bfe783 100644
--- a/libgm2/libm2cor/Makefile.am
+++ b/libgm2/libm2cor/Makefile.am
@@ -117,7 +117,7 @@ libm2cor_la_M2FLAGS = \
     -fm2-pathname=m2cor -I. -I$(GM2_SRC)/gm2-libs-coroutines \
     -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs \
     -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \
-    -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2cor
+    -fm2-g -g -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2cor
 if TARGET_DARWIN
 libm2cor_la_link_flags = -Wl,-undefined,dynamic_lookup
 else
diff --git a/libgm2/libm2cor/Makefile.in b/libgm2/libm2cor/Makefile.in
index 3b0b40fea608..565d3f0dc3e2 100644
--- a/libgm2/libm2cor/Makefile.in
+++ b/libgm2/libm2cor/Makefile.in
@@ -466,7 +466,7 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS)
 @BUILD_CORLIB_TRUE@    -fm2-pathname=m2cor -I. -I$(GM2_SRC)/gm2-libs-coroutines \
 @BUILD_CORLIB_TRUE@    -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs \
 @BUILD_CORLIB_TRUE@    -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \
-@BUILD_CORLIB_TRUE@    -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2cor
+@BUILD_CORLIB_TRUE@    -fm2-g -g -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2cor
 
 @BUILD_CORLIB_TRUE@@TARGET_DARWIN_FALSE@libm2cor_la_link_flags = 
 @BUILD_CORLIB_TRUE@@TARGET_DARWIN_TRUE@libm2cor_la_link_flags = -Wl,-undefined,dynamic_lookup
diff --git a/libgm2/libm2iso/Makefile.am b/libgm2/libm2iso/Makefile.am
index 1386f156caba..90d344f0fa89 100644
--- a/libgm2/libm2iso/Makefile.am
+++ b/libgm2/libm2iso/Makefile.am
@@ -191,7 +191,7 @@ libm2iso_la_CFLAGS = $(C_INCLUDES) -I. -I.. -I$(GM2_SRC)/gm2-libs-iso -I$(GM2_SR
 libm2iso_la_M2FLAGS = \
   -fm2-pathname=m2iso -I. -Ilibm2iso -I$(GM2_SRC)/gm2-libs-iso \
   -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs \
-  -fiso -fextended-opaque -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2iso
+  -fiso -fextended-opaque -fm2-g -g -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2iso
 if TARGET_DARWIN
 libm2iso_la_link_flags = -Wl,-undefined,dynamic_lookup
 else
diff --git a/libgm2/libm2iso/Makefile.in b/libgm2/libm2iso/Makefile.in
index b939581b7c1b..7f82b182ff9d 100644
--- a/libgm2/libm2iso/Makefile.in
+++ b/libgm2/libm2iso/Makefile.in
@@ -567,7 +567,7 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS)
 @BUILD_ISOLIB_TRUE@libm2iso_la_M2FLAGS = \
 @BUILD_ISOLIB_TRUE@  -fm2-pathname=m2iso -I. -Ilibm2iso -I$(GM2_SRC)/gm2-libs-iso \
 @BUILD_ISOLIB_TRUE@  -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs \
-@BUILD_ISOLIB_TRUE@  -fiso -fextended-opaque -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2iso
+@BUILD_ISOLIB_TRUE@  -fiso -fextended-opaque -fm2-g -g -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2iso
 
 @BUILD_ISOLIB_TRUE@@TARGET_DARWIN_FALSE@libm2iso_la_link_flags = 
 @BUILD_ISOLIB_TRUE@@TARGET_DARWIN_TRUE@libm2iso_la_link_flags = -Wl,-undefined,dynamic_lookup
diff --git a/libgm2/libm2log/Makefile.am b/libgm2/libm2log/Makefile.am
index a15747fd2453..27f38406b076 100644
--- a/libgm2/libm2log/Makefile.am
+++ b/libgm2/libm2log/Makefile.am
@@ -136,7 +136,7 @@ libm2log_la_M2FLAGS = \
  -fm2-pathname=m2log -I$(GM2_SRC)/gm2-libs-log \
  -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs \
  -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \
- -Wreturn-type -fcase -fm2-prefix=m2log
+ -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2log
 if TARGET_DARWIN
 libm2log_la_link_flags = -Wl,-undefined,dynamic_lookup
 else
diff --git a/libgm2/libm2log/Makefile.in b/libgm2/libm2log/Makefile.in
index ba34a6b445a2..97d7bdb63965 100644
--- a/libgm2/libm2log/Makefile.in
+++ b/libgm2/libm2log/Makefile.in
@@ -475,7 +475,7 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS)
 @BUILD_LOGLIB_TRUE@ -fm2-pathname=m2log -I$(GM2_SRC)/gm2-libs-log \
 @BUILD_LOGLIB_TRUE@ -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs \
 @BUILD_LOGLIB_TRUE@ -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \
-@BUILD_LOGLIB_TRUE@ -Wreturn-type -fcase -fm2-prefix=m2log
+@BUILD_LOGLIB_TRUE@ -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2log
 
 @BUILD_LOGLIB_TRUE@@TARGET_DARWIN_FALSE@libm2log_la_link_flags = 
 @BUILD_LOGLIB_TRUE@@TARGET_DARWIN_TRUE@libm2log_la_link_flags = -Wl,-undefined,dynamic_lookup
diff --git a/libgm2/libm2pim/Makefile.am b/libgm2/libm2pim/Makefile.am
index ebfeba1ac1df..ac172b933376 100644
--- a/libgm2/libm2pim/Makefile.am
+++ b/libgm2/libm2pim/Makefile.am
@@ -169,7 +169,7 @@ libm2pim_la_CFLAGS = -I. -I.. -I$(GM2_SRC)/gm2-libs -I$(GM2_SRC)/gm2-libs-iso -D
 libm2pim_la_M2FLAGS = \
   -fm2-pathname=m2pim -I. -I$(GM2_SRC)/gm2-libs \
   -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \
-  -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2pim
+  -fm2-g -g -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2pim
 if TARGET_DARWIN
 libm2pim_la_link_flags = -Wl,-undefined,dynamic_lookup
 else
diff --git a/libgm2/libm2pim/Makefile.in b/libgm2/libm2pim/Makefile.in
index 660488f9692e..3bd2a9f95050 100644
--- a/libgm2/libm2pim/Makefile.in
+++ b/libgm2/libm2pim/Makefile.in
@@ -536,7 +536,7 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS)
 @BUILD_PIMLIB_TRUE@libm2pim_la_M2FLAGS = \
 @BUILD_PIMLIB_TRUE@  -fm2-pathname=m2pim -I. -I$(GM2_SRC)/gm2-libs \
 @BUILD_PIMLIB_TRUE@  -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \
-@BUILD_PIMLIB_TRUE@  -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2pim
+@BUILD_PIMLIB_TRUE@  -fm2-g -g -Wcase-enum -Wreturn-type -fcase -fm2-prefix=m2pim
 
 @BUILD_PIMLIB_TRUE@@TARGET_DARWIN_FALSE@libm2pim_la_link_flags = 
 @BUILD_PIMLIB_TRUE@@TARGET_DARWIN_TRUE@libm2pim_la_link_flags = -Wl,-undefined,dynamic_lookup

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-13 14:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-13 14:53 [gcc r14-3925] modula2: -Wcase-enum detect singular/plural and use switch during build Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).