]> git.sur5r.net Git - cc65/commitdiff
Fixed a problem: When a struct or unit was declared with a tag name, it was
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 2 Feb 2013 22:31:26 +0000 (22:31 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 2 Feb 2013 22:31:26 +0000 (22:31 +0000)
possible to use the opposite type with the tag name. That is "struct a" after
declaring "union a" and vice versa.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5980 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/compile.c
src/cc65/declare.c
src/cc65/locals.c
src/cc65/symentry.c
src/cc65/symentry.h
src/cc65/symtab.c
src/cc65/symtab.h

index f619d5b59b03bc9095178b618a2c6b607b049292..c87d3272918e0a02b860ce69f1f4faa6b231cb24 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2012, Ullrich von Bassewitz                                      */
+/* (C) 2000-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -150,7 +150,7 @@ static void Parse (void)
              * This means that "extern int i;" will not get storage allocated.
              */
            if ((Decl.StorageClass & SC_FUNC) != SC_FUNC          &&
-                (Decl.StorageClass & SC_TYPEDEF) != SC_TYPEDEF    &&
+                (Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF    &&
                 ((Spec.Flags & DS_DEF_STORAGE) != 0         ||
                  (Decl.StorageClass & (SC_EXTERN|SC_STATIC)) == SC_STATIC ||
                  ((Decl.StorageClass & SC_EXTERN) != 0 &&
index 800000105cb901a217911ccf6a3199bd32e22195..5f4a0f10f6635deff7f3337939cf66436dc51c11 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2010, Ullrich von Bassewitz                                      */
+/* (C) 1998-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -527,17 +527,17 @@ static int ParseFieldWidth (Declaration* Decl)
 
 
 
-static SymEntry* StructOrUnionForwardDecl (const char* Name)
+static SymEntry* StructOrUnionForwardDecl (const char* Name, unsigned Type)
 /* Handle a struct or union forward decl */
 {
-    /* Try to find a struct with the given name. If there is none,
+    /* Try to find a struct/union with the given name. If there is none,
      * insert a forward declaration into the current lexical level.
      */
     SymEntry* Entry = FindTagSym (Name);
     if (Entry == 0) {
-        Entry = AddStructSym (Name, 0, 0);
-    } else if (SymIsLocal (Entry) && (Entry->Flags & SC_STRUCT) != SC_STRUCT) {
-        /* Already defined in the level, but no struct */
+        Entry = AddStructSym (Name, Type, 0, 0);
+    } else if ((Entry->Flags & SC_TYPEMASK) != Type) {
+        /* Already defined, but no struct */
         Error ("Symbol `%s' is already different kind", Name);
     }
     return Entry;
@@ -574,7 +574,7 @@ static unsigned CopyAnonStructFields (const Declaration* Decl, int Offs)
         /* Enter a copy of this symbol adjusting the offset. We will just
          * reuse the type string here.
          */
-        AddLocalSym (Entry->Name, Entry->Type,SC_STRUCTFIELD, Offs + Entry->V.Offs);
+        AddLocalSym (Entry->Name, Entry->Type, SC_STRUCTFIELD, Offs + Entry->V.Offs);
 
         /* Currently, there can not be any attributes, but if there will be
          * some in the future, we want to know this.
@@ -604,11 +604,11 @@ static SymEntry* ParseUnionDecl (const char* Name)
 
     if (CurTok.Tok != TOK_LCURLY) {
        /* Just a forward declaration. */
-       return StructOrUnionForwardDecl (Name);
+       return StructOrUnionForwardDecl (Name, SC_UNION);
     }
 
     /* Add a forward declaration for the struct in the current lexical level */
-    Entry = AddStructSym (Name, 0, 0);
+    Entry = AddStructSym (Name, SC_UNION, 0, 0);
 
     /* Skip the curly brace */
     NextToken ();
@@ -688,7 +688,7 @@ NextMember: if (CurTok.Tok != TOK_COMMA) {
     LeaveStructLevel ();
 
     /* Make a real entry from the forward decl and return it */
-    return AddStructSym (Name, UnionSize, FieldTab);
+    return AddStructSym (Name, SC_UNION, UnionSize, FieldTab);
 }
 
 
@@ -707,11 +707,11 @@ static SymEntry* ParseStructDecl (const char* Name)
 
     if (CurTok.Tok != TOK_LCURLY) {
        /* Just a forward declaration. */
-       return StructOrUnionForwardDecl (Name);
+       return StructOrUnionForwardDecl (Name, SC_STRUCT);
     }
 
     /* Add a forward declaration for the struct in the current lexical level */
-    Entry = AddStructSym (Name, 0, 0);
+    Entry = AddStructSym (Name, SC_STRUCT, 0, 0);
 
     /* Skip the curly brace */
     NextToken ();
@@ -858,7 +858,7 @@ NextMember: if (CurTok.Tok != TOK_COMMA) {
     LeaveStructLevel ();
 
     /* Make a real entry from the forward decl and return it */
-    return AddStructSym (Name, StructSize, FieldTab);
+    return AddStructSym (Name, SC_STRUCT, StructSize, FieldTab);
 }
 
 
@@ -1613,7 +1613,7 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, declmode_t Mode)
      * int declaration.
      */
     if ((D->StorageClass & SC_FUNC) != SC_FUNC &&
-        (D->StorageClass & SC_TYPEDEF) != SC_TYPEDEF) {
+        (D->StorageClass & SC_TYPEMASK) != SC_TYPEDEF) {
         /* If the standard was not set explicitly to C89, print a warning
          * for variables with implicit int type.
          */
index ef7420475bd71318bcb0014515c817e1b2d0439c..20b6b511eb4ff7fed2782a1fc064c1b9f1b4c5e0 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2009, Ullrich von Bassewitz                                      */
+/* (C) 2000-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -176,7 +176,7 @@ static void ParseRegisterDecl (Declaration* Decl, int Reg)
 
 
 
-static void ParseAutoDecl (Declaration* Decl)    
+static void ParseAutoDecl (Declaration* Decl)
 /* Parse the declaration of an auto variable. */
 {
     unsigned  Flags;
@@ -440,7 +440,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
 
     /* Handle anything that needs storage (no functions, no typdefs) */
     if ((Decl.StorageClass & SC_FUNC) != SC_FUNC &&
-         (Decl.StorageClass & SC_TYPEDEF) != SC_TYPEDEF) {
+         (Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF) {
 
         /* If we have a register variable, try to allocate a register and
          * convert the declaration to "auto" if this is not possible.
index 1644c962f1e720ccebb25ec9511542b4e26541d4..67654a9f007d4e26219d8d2a7412c1bb3ada07fd 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2009, Ullrich von Bassewitz                                      */
+/* (C) 2000-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -100,6 +100,7 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
        { "SC_TYPEDEF",     SC_TYPEDEF          },
         { "SC_BITFIELD",    SC_BITFIELD         },
                { "SC_STRUCTFIELD", SC_STRUCTFIELD      },
+        { "SC_UNION",       SC_UNION            },
        { "SC_STRUCT",      SC_STRUCT           },
        { "SC_AUTO",        SC_AUTO             },
        { "SC_REGISTER",    SC_REGISTER         },
@@ -125,7 +126,7 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
     /* Print the assembler name if we have one */
     if (E->AsmName) {
         fprintf (F, "    AsmName: %s\n", E->AsmName);
-    }
+    }                                             
 
     /* Print the flags */
     SymFlags = E->Flags;
@@ -216,7 +217,7 @@ void SymSetAsmName (SymEntry* Sym)
 
     /* Cannot be used to change the name */
     PRECONDITION (Sym->AsmName == 0);
-                 
+
     /* The assembler name starts with an underline */
     Len = strlen (Sym->Name);
     Sym->AsmName = xmalloc (Len + 2);
index 08cac8d8063cc3a42ec8a4aa5a8400214b89bf59..54a7d32ad3e9685742bc2f53e4f101fe2c9a42f7 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2009, Ullrich von Bassewitz                                      */
+/* (C) 2000-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -87,10 +87,12 @@ struct LiteralPool;
 #define SC_REF                 0x2000U         /* Symbol is referenced */
 
 #define SC_TYPE                0x4000U         /* This is a type, struct, typedef, etc. */
-#define SC_STRUCT              0x4001U         /* Struct or union */
-#define SC_STRUCTFIELD  0x4002U                /* Struct or union field */
+#define SC_STRUCT              0x4001U         /* Struct */
+#define SC_UNION        0x4002U         /* Union */
+#define SC_STRUCTFIELD  0x4003U                /* Struct or union field */
 #define SC_BITFIELD     0x4004U         /* A bit-field inside a struct or union */
-#define SC_TYPEDEF             0x4008U         /* A typedef */
+#define SC_TYPEDEF             0x4005U         /* A typedef */
+#define SC_TYPEMASK     0x400FU         /* Mask for above types */
 
 #define SC_ZEROPAGE    0x8000U         /* Symbol marked as zeropage */
 
index 23b19695efc717024f0066f7622d91f133cb711d..d7a4b92dcd234476e1a949672d3ed459cce2a69a 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2011, Ullrich von Bassewitz                                      */
+/* (C) 2000-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -543,15 +543,20 @@ static void AddSymEntry (SymTable* T, SymEntry* S)
 
 
 
-SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab)
+SymEntry* AddStructSym (const char* Name, unsigned Type, unsigned Size, SymTable* Tab)
 /* Add a struct/union entry and return it */
 {
+    SymEntry* Entry;
+
+    /* Type must be struct or union */
+    PRECONDITION (Type == SC_STRUCT || Type == SC_UNION);
+
     /* Do we have an entry with this name already? */
-    SymEntry* Entry = FindSymInTable (TagTab, Name, HashStr (Name));
+    Entry = FindSymInTable (TagTab, Name, HashStr (Name));
     if (Entry) {
 
        /* We do have an entry. This may be a forward, so check it. */
-       if ((Entry->Flags & SC_STRUCT) == 0) {
+       if ((Entry->Flags & SC_TYPEMASK) != Type) {
            /* Existing symbol is not a struct */
            Error ("Symbol `%s' is already different kind", Name);
        } else if (Size > 0 && Entry->V.S.Size > 0) {
@@ -568,7 +573,7 @@ SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab)
     } else {
 
        /* Create a new entry */
-       Entry = NewSymEntry (Name, SC_STRUCT);
+       Entry = NewSymEntry (Name, Type);
 
        /* Set the struct data */
        Entry->V.S.SymTab = Tab;
index 3311e8b735e650cc853da2fb22932385192ed5f9..66216313cc005e7d56b3cd9de12d4e77c9b8c087 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2009, Ullrich von Bassewitz                                      */
+/* (C) 2000-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -144,7 +144,7 @@ SymEntry* FindStructField (const Type* TypeArray, const char* Name);
 
 
 
-SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab);
+SymEntry* AddStructSym (const char* Name, unsigned Type, unsigned Size, SymTable* Tab);
 /* Add a struct/union entry and return it */
 
 SymEntry* AddBitField (const char* Name, unsigned Offs, unsigned BitOffs, unsigned Width);