1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-18 07:29:36 +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 */
/* 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 &&

View 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.
*/

View 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.

View 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);

View 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 */

View 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;

View 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);