fixed bug #702907
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 4 Apr 2003 09:39:06 +0000 (09:39 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 4 Apr 2003 09:39:06 +0000 (09:39 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2477 4a8a32a2-be11-0410-ad9d-d568d2c75423

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

index aef72885009a5335f58230dec61103c88fad4a68..f530bf02b6e650688fcf811a0789a1e422c9ea87 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2003-04-04    <johan@balder>
+
+       * src/SDCC.y: fixed bug #702907
+
 2003-04-03    <johan@balder>
 
        * device/lib/_mulint.c (_muluint): new #pragma LESS_PEDANTIC
index 25ba60f94c3fe74bba1db7dc218c038862df1225..644ecc5196dce307a181e688905d42c00e4498a2 100644 (file)
@@ -662,8 +662,19 @@ struct_or_union_specifier
    : struct_or_union opt_stag '{' struct_declaration_list '}'
         {
            structdef *sdef ;
+          symbol *sym, *dsym;
+
+          // check for duplicate structure members
+          for (sym=$4; sym; sym=sym->next) {
+            for (dsym=sym->next; dsym; dsym=dsym->next) {
+              if (strcmp(sym->name, dsym->name)==0) {
+                werror(E_DUPLICATE_MEMBER, 
+                       $1==STRUCT ? "struct" : "union", sym->name);
+              }
+            }
+          }
 
-           /* Create a structdef   */
+           /* Create a structdef   */     
            sdef = $2 ;
            sdef->fields   = reverseSyms($4) ;   /* link the fields */
            sdef->size  = compStructSize($1,sdef);   /* update size of  */
@@ -709,11 +720,12 @@ struct_declaration_list
    : struct_declaration
    | struct_declaration_list struct_declaration
        {
-          symbol *sym = $2;
-          /* go to the end of the chain */
-          while (sym->next) sym = sym->next;
+          symbol *sym=$2;
 
+          /* go to the end of the chain */
+          while (sym->next) sym=sym->next;
            sym->next = $1 ;
+        
            $$ = $2;
        }
    ;
@@ -765,39 +777,55 @@ struct_declarator
 
 enum_specifier
    : ENUM            '{' enumerator_list '}' {
-                                                //addSymChain ($3);
-                                                //allocVariables(reverseSyms($3)) ;
-                                                $$ = copyLinkChain(cenum->type);
-                                             }
+           symbol *sym, *dsym;
+          char _error=0;
+
+          // check for duplicate enums
+          for (sym=$3; sym; sym=sym->next) {
+            for (dsym=sym->next; dsym; dsym=dsym->next) {
+              if (strcmp(sym->name, dsym->name)==0) {
+                werror(E_DUPLICATE_MEMBER, "enum", sym->name);
+                _error++;
+              }
+            }
+          }
+          if (_error==0) {
+            $$ = copyLinkChain(cenum->type);
+          } else {
+            $$ = newIntLink();
+            SPEC_NOUN($$)=0;
+          }
+         }
+
    | ENUM identifier '{' enumerator_list '}' {
-                                                symbol *csym ;
-
-                                                $2->type = copyLinkChain(cenum->type);
-                                                $2->etype = getSpec($2->type);
-                                                /* add this to the enumerator table */
-                                                if (!(csym=findSym(enumTab,$2,$2->name)) && 
-                                                   (csym && csym->level == $2->level))
-                                                   werror(E_DUPLICATE_TYPEDEF,csym->name);
-
-                                                addSym ( enumTab,$2,$2->name,$2->level,$2->block, 0);
-                                               //addSymChain ($4);
-                                                //allocVariables (reverseSyms($4));
-                                                $$ = copyLinkChain(cenum->type);
-                                                SPEC_SCLS(getSpec($$)) = 0 ;
-                                             }
+     symbol *csym ;
+     
+     $2->type = copyLinkChain(cenum->type);
+     $2->etype = getSpec($2->type);
+     /* add this to the enumerator table */
+     if (!(csym=findSym(enumTab,$2,$2->name)) && 
+        (csym && csym->level == $2->level))
+       werror(E_DUPLICATE_TYPEDEF,csym->name);
+     
+     addSym ( enumTab,$2,$2->name,$2->level,$2->block, 0);
+     //addSymChain ($4);
+     //allocVariables (reverseSyms($4));
+     $$ = copyLinkChain(cenum->type);
+     SPEC_SCLS(getSpec($$)) = 0 ;
+   }
    | ENUM identifier                         {
-                                                symbol *csym ;
-
-                                                /* check the enumerator table */
-                                                if ((csym = findSym(enumTab,$2,$2->name)))
-                                                   $$ = copyLinkChain(csym->type);
-                                                else  {
-                                                   $$ = newLink(SPECIFIER) ;
-                                                   SPEC_NOUN($$) = V_INT   ;
-                                                }
-
-                                                SPEC_SCLS(getSpec($$)) = 0 ;
-                                             }
+     symbol *csym ;
+     
+     /* check the enumerator table */
+     if ((csym = findSym(enumTab,$2,$2->name)))
+       $$ = copyLinkChain(csym->type);
+     else  {
+       $$ = newLink(SPECIFIER) ;
+       SPEC_NOUN($$) = V_INT   ;
+     }
+     
+     SPEC_SCLS(getSpec($$)) = 0 ;
+   }
    ;
 
 enumerator_list
index 1bc00c115e43c26f527a4dd0615fcec86f3ece48..817c493f514f471f3de6617fbb113eb75083ff38 100644 (file)
@@ -380,6 +380,8 @@ struct
     "must specify assembler file name with -o in c1 mode" },
 { W_ILLEGAL_OPT_COMBINATION, ERROR_LEVEL_WARNING,
     "illegal combination of options (--c1mode, -E, -S -c)" },
+{ E_DUPLICATE_MEMBER, ERROR_LEVEL_ERROR,
+    "duplicate %s member '%s'" },
 };
 
 /*
index 73987cb0f28c1dfc5cd2d5d663c63c8e4313d8c0..82f980a4248a86917019857bde8732a54abe5d9a 100644 (file)
@@ -178,6 +178,7 @@ SDCCERR - SDCC Standard error handler
 #define W_NO_FILE_ARG_IN_C1 160
 #define E_NEED_OPT_O_IN_C1 161
 #define W_ILLEGAL_OPT_COMBINATION 162
+#define E_DUPLICATE_MEMBER 163
 
 /** Describes the maximum error level that will be logged.  Any level
  *  includes all of the levels listed after it.