* device/lib/printf_large.c: 6 bytes less __data mem (6 more __idata)
[fw/sdcc] / src / SDCC.y
index e7bf6d42826da1487c7f6af4be3c65cc735e4514..79d6024b1372fbf2b14b6c74824536dfeae5bc07 100644 (file)
@@ -962,40 +962,37 @@ enum_specifier
    ;
 
 enumerator_list
-   : enumerator
-   | enumerator_list ',' {
-                         }
-   | enumerator_list ',' enumerator
-     {
-       symbol *dsym;
-
-       for (dsym=$1; dsym; dsym=dsym->next)
-         {
-           if (strcmp($3->name, dsym->name)==0)
-             {
-               werrorfl($3->fileDef, $3->lineDef, E_DUPLICATE_MEMBER, "enum", $3->name);
-               werrorfl(dsym->fileDef, dsym->lineDef, E_PREVIOUS_DEF);
-             }
-         }
-
-       $3->next = $1 ;
-       $$ = $3  ;
-     }
-   ;
+    : enumerator
+    | enumerator_list ','
+    | enumerator_list ',' enumerator
+      {
+        $3->next = $1 ;
+        $$ = $3  ;
+      }
+    ;
 
 enumerator
-   : identifier opt_assign_expr
-     {
-       /* make the symbol one level up */
-       $1->level-- ;
-       $1->type = copyLinkChain($2->type);
-       $1->etype= getSpec($1->type);
-       SPEC_ENUM($1->etype) = 1;
-       $$ = $1 ;
-       // do this now, so we can use it for the next enums in the list
-       addSymChain(&$1);
-     }
-   ;
+    : identifier opt_assign_expr
+      {
+        symbol *sym;
+
+        /* make the symbol one level up */
+        $1->level-- ;
+        // check if the symbol at the same level already exists
+        if ((sym = findSymWithLevel (SymbolTab, $1)) &&
+          sym->level == $1->level)
+          {
+            werrorfl ($1->fileDef, $1->lineDef, E_DUPLICATE_MEMBER, "enum", $1->name);
+            werrorfl (sym->fileDef, sym->lineDef, E_PREVIOUS_DEF);
+          }
+        $1->type = copyLinkChain ($2->type);
+        $1->etype= getSpec ($1->type);
+        SPEC_ENUM ($1->etype) = 1;
+        $$ = $1 ;
+        // do this now, so we can use it for the next enums in the list
+        addSymChain (&$1);
+      }
+    ;
 
 opt_assign_expr
    :  '='   constant_expr  {
@@ -1018,9 +1015,7 @@ opt_assign_expr
                                  $$ = cenum = constVal(lbuff);
                               }
                               else {
-                                 SNPRINTF(lbuff, sizeof(lbuff),
-                                          "%d",0);
-                                 $$ = cenum = constVal(lbuff);
+                                 $$ = cenum = constVal("0");
                               }
                            }
    ;
@@ -1450,15 +1445,12 @@ end_block   : '}'     { currBlockno = STACK_POP(blockNum); }
             ;
 
 compound_statement
-   : start_block end_block                    { $$ = createBlock(NULL,NULL); }
-   | start_block statement_list end_block     { $$ = createBlock(NULL,$2) ;  }
-   | start_block
-          declaration_list                    { addSymChain(&$2); }
-     end_block                                { $$ = createBlock($2,NULL) ;  }
+   : start_block end_block                    { $$ = createBlock(NULL, NULL); }
+   | start_block statement_list end_block     { $$ = createBlock(NULL, $2); }
+   | start_block declaration_list end_block   { $$ = createBlock($2, NULL); }
    | start_block
-          declaration_list                    {  addSymChain (&$2); }
-          statement_list
-     end_block                                {$$ = createBlock($2,$4)   ;  }
+          declaration_list statement_list
+     end_block                                {$$ = createBlock($2, $3); }
    | error ';'                                { $$ = NULL ; }
    ;
 
@@ -1473,6 +1465,7 @@ declaration_list
        else
          $$ = $1 ;
        ignoreTypedefType = 0;
+       addSymChain(&$1);
      }
 
    | declaration_list declaration
@@ -1496,6 +1489,7 @@ declaration_list
            $$ = $2 ;
        }
        ignoreTypedefType = 0;
+       addSymChain(&$2);
      }
    ;