* support/Util/SDCCerr.h,
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 5 Mar 2004 07:15:07 +0000 (07:15 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 5 Mar 2004 07:15:07 +0000 (07:15 +0000)
* support/Util/SDCCerr.c,
* src/SDCC.y (struct_or_union_specifier, enum_specifier,
enumerator_list),
* src/SDCCsymt.c (addSymChain): show location of oriignal definition
for symbol conflicts.
* support/valdiags/tests/enum.c,
* support/valdiags/tests/tentdecl.c,
* support/valdiags/tests/struct.c: expect possible error messages
referring to original symbol definitions.
* src/SDCC.y (struct_or_union_specifier, struct_declarator),
* src/SDCCsymt.h,
* src/SDCCsymt.c (promoteAnonStructs): support anonymous struct/union

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

ChangeLog
src/SDCC.y
src/SDCCsymt.c
src/SDCCsymt.h
support/Util/SDCCerr.c
support/Util/SDCCerr.h
support/valdiag/tests/enum.c
support/valdiag/tests/struct.c
support/valdiag/tests/tentdecl.c

index 47c6e48e2b859690afaa986571d06ada8c913832..ee52289c16db870c228c8d529c10390fd9aebe26 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2004-03-05 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+       * support/Util/SDCCerr.h,
+       * support/Util/SDCCerr.c,
+       * src/SDCC.y (struct_or_union_specifier, enum_specifier,
+       enumerator_list),
+       * src/SDCCsymt.c (addSymChain): show location of oriignal definition
+       for symbol conflicts.
+       * support/valdiags/tests/enum.c,
+       * support/valdiags/tests/tentdecl.c,
+       * support/valdiags/tests/struct.c: expect possible error messages
+       referring to original symbol definitions.
+       * src/SDCC.y (struct_or_union_specifier, struct_declarator),
+       * src/SDCCsymt.h,
+       * src/SDCCsymt.c (promoteAnonStructs): support anonymous struct/union
+
 2004-03-03 Hans Dorn <hjdorn AT users.sourceforge.net>
 
        * src/pic16/gen.c (gencjne): fixed for right=REG / left=LIT
index 71f238c05146bd60af185992f28b0a32babd9e49..c66605232e1b0bdc8903bc6314360920c88012f3 100644 (file)
@@ -757,9 +757,10 @@ struct_or_union_specifier
               SPEC_SCLS(sym->etype) = 0;
             }
             for (dsym=sym->next; dsym; dsym=dsym->next) {
-              if (strcmp(sym->name, dsym->name)==0) {
+              if (*dsym->name && strcmp(sym->name, dsym->name)==0) {
                 werrorfl(sym->fileDef, sym->lineDef, E_DUPLICATE_MEMBER, 
                        $1==STRUCT ? "struct" : "union", sym->name);
+                werrorfl(dsym->fileDef, dsym->lineDef, E_PREVIOUS_DEF);
               }
             }
           }
@@ -768,7 +769,8 @@ struct_or_union_specifier
            sdef = $2 ;
            sdef->fields   = reverseSyms($5) ;   /* link the fields */
            sdef->size  = compStructSize($1,sdef);   /* update size of  */
-
+          promoteAnonStructs ($1, sdef);
+          
            /* Create the specifier */
            $$ = newLink (SPECIFIER) ;
            SPEC_NOUN($$) = V_STRUCT;
@@ -895,6 +897,8 @@ struct_declarator
                          else
                            $1->bitVar = bitsize;
                         }
+   | { $$ = newSymbol ("", NestLevel) ; }
+   
    ;
 
 enum_specifier
@@ -909,7 +913,10 @@ enum_specifier
 
      csym=findSym(enumTab,$2,$2->name);
      if ((csym && csym->level == $2->level))
-       werrorfl($2->fileDef, $2->lineDef, E_DUPLICATE_TYPEDEF,csym->name);
+       {
+         werrorfl($2->fileDef, $2->lineDef, E_DUPLICATE_TYPEDEF,csym->name);
+         werrorfl(csym->fileDef, csym->lineDef, E_PREVIOUS_DEF);
+       }
      
      enumtype = newEnumType ($4);      //copyLinkChain(cenum->type);
      SPEC_SCLS(getSpec(enumtype)) = 0;
@@ -944,7 +951,10 @@ enumerator_list
        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($3->fileDef, $3->lineDef, E_DUPLICATE_MEMBER, "enum", $3->name);
+              werrorfl(dsym->fileDef, dsym->lineDef, E_PREVIOUS_DEF);
+            }
         }
        
        $3->next = $1 ;
index 43996bf36bbbe4ad6a80995fd3cb5b77f4b3f952..c1c8a8ce72a13610cb66b86303f78fd78ca24025 100644 (file)
@@ -1030,6 +1030,8 @@ addSymChain (symbol * symHead)
            werror (E_EXTERN_MISMATCH, sym->name);
           else
            werror (E_DUPLICATE, sym->name);
+         werrorfl (csym->fileDef, csym->lineDef, E_PREVIOUS_DEF);
+         #if 0
          fprintf (stderr, "from type '");
          printTypeChain (csym->type, stderr);
          if (IS_SPEC (csym->etype) && SPEC_ABSA (csym->etype))
@@ -1039,6 +1041,7 @@ addSymChain (symbol * symHead)
          if (IS_SPEC (sym->etype) && SPEC_ABSA (sym->etype))
            fprintf(stderr, " at 0x%x", SPEC_ADDR (sym->etype));
          fprintf (stderr, "'\n");
+         #endif
          continue;
        }
 
@@ -1227,6 +1230,71 @@ compStructSize (int su, structdef * sdef)
     return (su == UNION ? usum : sum);
 }
 
+/*-------------------------------------------------------------------*/
+/* promoteAnonStructs - promote anonymous struct/union's fields into */
+/*                      an enclosing struct/union                    */
+/*-------------------------------------------------------------------*/
+void
+promoteAnonStructs (int su, structdef * sdef)
+{
+  symbol *field;
+  symbol *subfield;
+  symbol **tofield;
+  symbol *nextfield;
+  symbol *dupfield;
+  int base;
+
+  tofield = &sdef->fields;
+  field = sdef->fields;
+  while (field)
+    {
+      nextfield = field->next;
+      if (!*field->name && IS_STRUCT (field->type))
+       {
+         /* Found an anonymous struct/union. Replace it */
+         /* with the fields it contains and adjust all  */
+         /* the offsets */
+         
+         base = field->offset;
+         subfield = copySymbolChain (SPEC_STRUCT (field->type)->fields);
+         if (!subfield)
+           continue;           /* just in case it's empty */
+         
+         *tofield = subfield;
+         for (;;)
+           {
+             /* check for field name conflicts resulting from promotion */
+             dupfield = sdef->fields;
+             while (dupfield && dupfield != subfield)
+               {
+                 if (*subfield->name && !strcmp (dupfield->name, subfield->name))
+                   {
+                     werrorfl (subfield->fileDef, subfield->lineDef,
+                               E_DUPLICATE_MEMBER,
+                               su==STRUCT ? "struct" : "union",
+                               subfield->name);
+                     werrorfl (dupfield->fileDef, dupfield->lineDef,
+                               E_PREVIOUS_DEF);
+                   }
+                 dupfield = dupfield->next;
+               }
+             
+             subfield->offset += base;
+             if (subfield->next)
+               subfield = subfield->next;
+             else
+               break;
+           }
+         subfield->next = nextfield;
+         tofield = &subfield->next;
+       }
+      else
+       tofield = &field->next;
+      field = nextfield;
+    }
+}
+
+
 /*------------------------------------------------------------------*/
 /* checkSClass - check the storage class specification              */
 /*------------------------------------------------------------------*/
index 0ac55f77d55de518cfaf45e74a3fd2c718c35bc4..49ed5eb8d743dd9be9c59f413e0ad99a3ae2e4ad 100644 (file)
@@ -563,6 +563,7 @@ void checkTypeSanity(sym_link *etype, char *name);
 sym_link *typeFromStr (char *) ;
 STORAGE_CLASS sclsFromPtr(sym_link *ptr);
 sym_link *newEnumType (symbol *);
+void  promoteAnonStructs (int, structdef *);
 
 
 extern char *nounName(sym_link *); /* noun strings */
index b5a92ec46978b2e256115f21fc7251634cf64a97..7f3b8a76556232d1f3ab376f249b4ef5df85f1c2 100644 (file)
@@ -409,6 +409,8 @@ struct
    "pragma %s is deprecated, please see documentation for details" },
 { E_SIZEOF_INCOMPLETE_TYPE, ERROR_LEVEL_ERROR,
    "sizeof applied to an incomplete type" },
+{ E_PREVIOUS_DEF, ERROR_LEVEL_ERROR,
+   "previously defined here" },
 };
 
 /*
index 0565f37f2f3258e0abd9d85344b20293b1d94696..f1c3a14038c001783dd10f41044eaa5bfbdb6f6c 100644 (file)
@@ -192,6 +192,7 @@ SDCCERR - SDCC Standard error handler
 #define E_ENUM_NON_INTEGER 174      /* enumeration constant not an integer */
 #define W_DEPRECATED_PRAGMA 175     /* deprecated pragma */
 #define E_SIZEOF_INCOMPLETE_TYPE 176 /* sizeof applied to an incomplete type */
+#define E_PREVIOUS_DEF 177          /* previously defined here */
 
 /** Describes the maximum error level that will be logged.  Any level
  *  includes all of the levels listed after it.
index 78eeb00d28d71c698abb74db4f47abbe54dc26cc..9ed4f6fab02bbb8eddae5db8d1c7cfed5b802b4e 100644 (file)
@@ -63,7 +63,7 @@ enum tag
 #endif
 
 #ifdef TEST7
-enum tag
+enum tag       /* IGNORE */
 {
   first,
   second,
index 615024dfbe205b09d8506b6dcc7518dff435e6ce..3e15e51af643e40e4c3e08b820577bb8e1c8fa31 100644 (file)
@@ -10,7 +10,7 @@ struct tag {
 #ifdef TEST2
 struct tag {
   int good1;
-  int bad;
+  int bad;     /* IGNORE */
   int bad;     /* ERROR */
   int good2;
 } badstruct;
@@ -74,3 +74,31 @@ struct tag {
   int x;
 } ll;
 #endif
+
+#ifdef TEST8a
+struct tag {
+  int a;               /* IGNORE */
+  struct {
+    int a;             /* ERROR(SDCC) */ /* IGNORE(GCC) */
+    int b;
+  };
+} ll;  
+#endif
+
+#ifdef TEST8b
+struct tag {
+  int a;
+  struct {
+    int b;
+    int c;
+  };
+} ll;  
+
+void test(void)
+{
+  ll.a = 1;
+  ll.b = 2;
+  ll.c = 3;
+}
+
+#endif
index 90bc17fdad090078b98b0e34fb40d821d349a809..60d29862fcdd929dbba97ce972b4da75374af4ce 100644 (file)
@@ -71,14 +71,14 @@ int a=1;    /* ERROR */
 
 #ifdef TEST9
 #ifdef SDCC
-XDATA int a;
+XDATA int a;   /* IGNORE */
 DATA int a;    /* ERROR(SDCC && !(__z80 || __gbz80)) */
 #endif
 #endif
 
 #ifdef TEST9b
 #ifdef SDCC
-DATA int a;
+DATA int a;    /* IGNORE */
 XDATA int a;   /* ERROR(SDCC && !(__z80 || __gbz80)) */
 #endif
 #endif
@@ -99,21 +99,21 @@ XDATA int a;
 
 #ifdef TEST9e
 #ifdef SDCC
-extern XDATA int a;
+extern XDATA int a; /* IGNORE */
 DATA int a;    /* ERROR(SDCC && !(__z80 || __gbz80)) */
 #endif
 #endif
 
 #ifdef TEST9f
 #ifdef SDCC
-extern DATA int a;
+extern DATA int a; /* IGNORE */
 XDATA int a;   /* ERROR(SDCC && !(__z80 || __gbz80)) */
 #endif
 #endif
 
 #ifdef TEST10
 #if defined(SDCC) && !(defined(__z80) || defined(__gbz80))
-extern volatile XDATA at 0 int a;
+extern volatile XDATA at 0 int a; /* IGNORE */
 volatile XDATA int a;  /* ERROR(SDCC && !(__z80 || __gbz80)) */
 #endif
 #endif