1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-12 02:30:44 +00:00

Fixed a problem: When a struct or unit was declared with a tag name, it was

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
This commit is contained in:
uz 2013-02-02 22:31:26 +00:00
parent 41cac25914
commit fd679d92d0
7 changed files with 41 additions and 33 deletions

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2012, Ullrich von Bassewitz */ /* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -150,7 +150,7 @@ static void Parse (void)
* This means that "extern int i;" will not get storage allocated. * This means that "extern int i;" will not get storage allocated.
*/ */
if ((Decl.StorageClass & SC_FUNC) != SC_FUNC && 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 || ((Spec.Flags & DS_DEF_STORAGE) != 0 ||
(Decl.StorageClass & (SC_EXTERN|SC_STATIC)) == SC_STATIC || (Decl.StorageClass & (SC_EXTERN|SC_STATIC)) == SC_STATIC ||
((Decl.StorageClass & SC_EXTERN) != 0 && ((Decl.StorageClass & SC_EXTERN) != 0 &&

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2010, Ullrich von Bassewitz */ /* (C) 1998-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* 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 */ /* 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. * insert a forward declaration into the current lexical level.
*/ */
SymEntry* Entry = FindTagSym (Name); SymEntry* Entry = FindTagSym (Name);
if (Entry == 0) { if (Entry == 0) {
Entry = AddStructSym (Name, 0, 0); Entry = AddStructSym (Name, Type, 0, 0);
} else if (SymIsLocal (Entry) && (Entry->Flags & SC_STRUCT) != SC_STRUCT) { } else if ((Entry->Flags & SC_TYPEMASK) != Type) {
/* Already defined in the level, but no struct */ /* Already defined, but no struct */
Error ("Symbol `%s' is already different kind", Name); Error ("Symbol `%s' is already different kind", Name);
} }
return Entry; 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 /* Enter a copy of this symbol adjusting the offset. We will just
* reuse the type string here. * 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 /* Currently, there can not be any attributes, but if there will be
* some in the future, we want to know this. * some in the future, we want to know this.
@ -604,11 +604,11 @@ static SymEntry* ParseUnionDecl (const char* Name)
if (CurTok.Tok != TOK_LCURLY) { if (CurTok.Tok != TOK_LCURLY) {
/* Just a forward declaration. */ /* Just a forward declaration. */
return StructOrUnionForwardDecl (Name); return StructOrUnionForwardDecl (Name, SC_UNION);
} }
/* Add a forward declaration for the struct in the current lexical level */ /* 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 */ /* Skip the curly brace */
NextToken (); NextToken ();
@ -688,7 +688,7 @@ NextMember: if (CurTok.Tok != TOK_COMMA) {
LeaveStructLevel (); LeaveStructLevel ();
/* Make a real entry from the forward decl and return it */ /* 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) { if (CurTok.Tok != TOK_LCURLY) {
/* Just a forward declaration. */ /* Just a forward declaration. */
return StructOrUnionForwardDecl (Name); return StructOrUnionForwardDecl (Name, SC_STRUCT);
} }
/* Add a forward declaration for the struct in the current lexical level */ /* 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 */ /* Skip the curly brace */
NextToken (); NextToken ();
@ -858,7 +858,7 @@ NextMember: if (CurTok.Tok != TOK_COMMA) {
LeaveStructLevel (); LeaveStructLevel ();
/* Make a real entry from the forward decl and return it */ /* 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. * int declaration.
*/ */
if ((D->StorageClass & SC_FUNC) != SC_FUNC && 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 /* If the standard was not set explicitly to C89, print a warning
* for variables with implicit int type. * for variables with implicit int type.
*/ */

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2009, Ullrich von Bassewitz */ /* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -440,7 +440,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
/* Handle anything that needs storage (no functions, no typdefs) */ /* Handle anything that needs storage (no functions, no typdefs) */
if ((Decl.StorageClass & SC_FUNC) != SC_FUNC && 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 /* If we have a register variable, try to allocate a register and
* convert the declaration to "auto" if this is not possible. * convert the declaration to "auto" if this is not possible.

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2009, Ullrich von Bassewitz */ /* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -100,6 +100,7 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
{ "SC_TYPEDEF", SC_TYPEDEF }, { "SC_TYPEDEF", SC_TYPEDEF },
{ "SC_BITFIELD", SC_BITFIELD }, { "SC_BITFIELD", SC_BITFIELD },
{ "SC_STRUCTFIELD", SC_STRUCTFIELD }, { "SC_STRUCTFIELD", SC_STRUCTFIELD },
{ "SC_UNION", SC_UNION },
{ "SC_STRUCT", SC_STRUCT }, { "SC_STRUCT", SC_STRUCT },
{ "SC_AUTO", SC_AUTO }, { "SC_AUTO", SC_AUTO },
{ "SC_REGISTER", SC_REGISTER }, { "SC_REGISTER", SC_REGISTER },

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2009, Ullrich von Bassewitz */ /* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -87,10 +87,12 @@ struct LiteralPool;
#define SC_REF 0x2000U /* Symbol is referenced */ #define SC_REF 0x2000U /* Symbol is referenced */
#define SC_TYPE 0x4000U /* This is a type, struct, typedef, etc. */ #define SC_TYPE 0x4000U /* This is a type, struct, typedef, etc. */
#define SC_STRUCT 0x4001U /* Struct or union */ #define SC_STRUCT 0x4001U /* Struct */
#define SC_STRUCTFIELD 0x4002U /* Struct or union field */ #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_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 */ #define SC_ZEROPAGE 0x8000U /* Symbol marked as zeropage */

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2011, Ullrich von Bassewitz */ /* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* 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 */ /* 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? */ /* Do we have an entry with this name already? */
SymEntry* Entry = FindSymInTable (TagTab, Name, HashStr (Name)); Entry = FindSymInTable (TagTab, Name, HashStr (Name));
if (Entry) { if (Entry) {
/* We do have an entry. This may be a forward, so check it. */ /* 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 */ /* Existing symbol is not a struct */
Error ("Symbol `%s' is already different kind", Name); Error ("Symbol `%s' is already different kind", Name);
} else if (Size > 0 && Entry->V.S.Size > 0) { } else if (Size > 0 && Entry->V.S.Size > 0) {
@ -568,7 +573,7 @@ SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab)
} else { } else {
/* Create a new entry */ /* Create a new entry */
Entry = NewSymEntry (Name, SC_STRUCT); Entry = NewSymEntry (Name, Type);
/* Set the struct data */ /* Set the struct data */
Entry->V.S.SymTab = Tab; Entry->V.S.SymTab = Tab;

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2009, Ullrich von Bassewitz */ /* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* 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 */ /* Add a struct/union entry and return it */
SymEntry* AddBitField (const char* Name, unsigned Offs, unsigned BitOffs, unsigned Width); SymEntry* AddBitField (const char* Name, unsigned Offs, unsigned BitOffs, unsigned Width);