* src/SDCC.y (struct_or_union_specifier),
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 31 Dec 2003 23:12:39 +0000 (23:12 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 31 Dec 2003 23:12:39 +0000 (23:12 +0000)
* support/Util/SDCCerr.c,
* support/Util/SDCCerr.h: verify that struct & union tags are used
as declared.

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3070 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCC.y
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 3fa04f34e2d8b703b4c3b6277aacb8523789b67f..9f7ff2d7910ec5e2cf554a3b50f2167ec3d91bc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2003-12-31 Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       * src/SDCC.y (struct_or_union_specifier),
+       * support/Util/SDCCerr.c,
+       * support/Util/SDCCerr.h: verify that struct & union tags are used
+       as declared.
+
 2003-12-29 Erik Petrich <epetrich@ivorytower.norman.ok.us>
 
        * src/SDCCglobl.h: missing from yesterday's commits
index fd2659a55df71231b4c703c7284731a73ab50e1c..9c9eee76f7dd8da977476c3385f7b229da95e30b 100644 (file)
@@ -727,13 +727,26 @@ sfr_attributes
    ;
 
 struct_or_union_specifier
-   : struct_or_union opt_stag '{' struct_declaration_list '}'
+   : struct_or_union opt_stag
+        {
+           if (!$2->type)
+             {
+               $2->type = $1;
+             }
+           else
+             {
+               if ($2->type != $1)
+                 werror(E_BAD_TAG, $2->tag, $1==STRUCT ? "struct" : "union");
+             }
+
+       }
+           '{' struct_declaration_list '}'
         {
            structdef *sdef ;
           symbol *sym, *dsym;
 
           // check for errors in structure members
-          for (sym=$4; sym; sym=sym->next) {
+          for (sym=$5; sym; sym=sym->next) {
             if (IS_ABSOLUTE(sym->etype)) {
               werrorfl(filename, sym->lineDef, E_NOT_ALLOWED, "'at'");
               SPEC_ABSA(sym->etype) = 0;
@@ -752,7 +765,7 @@ struct_or_union_specifier
 
            /* Create a structdef   */     
            sdef = $2 ;
-           sdef->fields   = reverseSyms($4) ;   /* link the fields */
+           sdef->fields   = reverseSyms($5) ;   /* link the fields */
            sdef->size  = compStructSize($1,sdef);   /* update size of  */
 
            /* Create the specifier */
@@ -764,7 +777,17 @@ struct_or_union_specifier
          {
             $$ = newLink(SPECIFIER) ;
             SPEC_NOUN($$) = V_STRUCT;
-            SPEC_STRUCT($$) = $2 ;
+            SPEC_STRUCT($$) = $2;
+
+           if (!$2->type)
+             {
+               $2->type = $1;
+             }
+           else
+             {
+               if ($2->type != $1)
+                 werror(E_BAD_TAG, $2->tag, $1==STRUCT ? "struct" : "union");
+             }
          }
    ;
 
index 9720ce5769507a6815d257d4b8d984b3afdc0027..e3f5981525302ca911aa66cfcb2cec47091e42d3 100644 (file)
@@ -401,6 +401,8 @@ struct
     "not allowed in a critical section" },
 { E_NOT_ALLOWED, ERROR_LEVEL_ERROR,
     "%s not allowed here" },
+{ E_BAD_TAG, ERROR_LEVEL_ERROR,
+    "'%s' is not a %s tag" },
 };
 
 /*
index aaafb642f7bfab8086dd1927912d0b5ab9939d9d..dca6e2ab803b9131efb5345b93e228ffefd6a37e 100644 (file)
@@ -188,6 +188,7 @@ SDCCERR - SDCC Standard error handler
 #define W_SAVE_RESTORE 170          /* unmatched #pragma SAVE and #pragma RESTORE */
 #define E_INVALID_CRITICAL 171     /* operation invalid in critical sequence */
 #define E_NOT_ALLOWED 172          /* %s not allowed here */
+#define E_BAD_TAG 173               /* '%s' is not a %s tag */
 
 /** Describes the maximum error level that will be logged.  Any level
  *  includes all of the levels listed after it.