1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-24 11:31:31 +00:00

Redefining enums/structs/unions of 0 size is no longer treated as declarations and thus forbidden.

This commit is contained in:
acqn 2020-08-03 01:31:52 +08:00 committed by Oliver Schmidt
parent cdfc1afd89
commit f59d6b8f6a
2 changed files with 15 additions and 9 deletions

View File

@ -920,7 +920,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, SC_UNION, UnionSize, FieldTab); return AddStructSym (Name, SC_UNION | SC_DEF, UnionSize, FieldTab);
} }
@ -1102,7 +1102,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, SC_STRUCT, StructSize, FieldTab); return AddStructSym (Name, SC_STRUCT | SC_DEF, StructSize, FieldTab);
} }

View File

@ -52,13 +52,13 @@
#include "declare.h" #include "declare.h"
#include "error.h" #include "error.h"
#include "funcdesc.h" #include "funcdesc.h"
#include "function.h"
#include "global.h" #include "global.h"
#include "input.h"
#include "stackptr.h" #include "stackptr.h"
#include "symentry.h" #include "symentry.h"
#include "typecmp.h" #include "typecmp.h"
#include "symtab.h" #include "symtab.h"
#include "function.h"
#include "input.h"
@ -728,6 +728,10 @@ SymEntry* AddEnumSym (const char* Name, const Type* Type, SymTable* Tab)
Entry->V.E.SymTab = Tab; Entry->V.E.SymTab = Tab;
Entry->V.E.Type = Type; Entry->V.E.Type = Type;
if (Type != 0) {
Entry->Flags |= SC_DEF;
}
/* Add it to the current table */ /* Add it to the current table */
AddSymEntry (CurTagTab, Entry); AddSymEntry (CurTagTab, Entry);
} }
@ -738,11 +742,12 @@ SymEntry* AddEnumSym (const char* Name, const Type* Type, SymTable* Tab)
SymEntry* AddStructSym (const char* Name, unsigned Type, unsigned Size, SymTable* Tab) SymEntry* AddStructSym (const char* Name, unsigned Flags, unsigned Size, SymTable* Tab)
/* Add a struct/union entry and return it */ /* Add a struct/union entry and return it */
{ {
SymTable* CurTagTab = TagTab; SymTable* CurTagTab = TagTab;
SymEntry* Entry; SymEntry* Entry;
unsigned Type = (Flags & SC_TYPEMASK);
/* Type must be struct or union */ /* Type must be struct or union */
PRECONDITION (Type == SC_STRUCT || Type == SC_UNION); PRECONDITION (Type == SC_STRUCT || Type == SC_UNION);
@ -756,13 +761,14 @@ SymEntry* AddStructSym (const char* Name, unsigned Type, unsigned Size, SymTable
/* 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);
Entry = 0; Entry = 0;
} else if (Size > 0 && Entry->V.S.Size > 0) { } else if ((Entry->Flags & Flags & SC_DEF) == SC_DEF) {
/* Both structs are definitions. */ /* Both structs are definitions. */
Error ("Multiple definition for '%s'", Name); Error ("Multiple definition for '%s'", Name);
Entry = 0; Entry = 0;
} else { } else {
/* Define the struct size if it is given */ /* Define the struct size if it is a definition */
if (Size > 0) { if ((Flags & SC_DEF) == SC_DEF) {
Entry->Flags = Flags;
Entry->V.S.SymTab = Tab; Entry->V.S.SymTab = Tab;
Entry->V.S.Size = Size; Entry->V.S.Size = Size;
} }
@ -777,7 +783,7 @@ SymEntry* AddStructSym (const char* Name, unsigned Type, unsigned Size, SymTable
if (Entry == 0) { if (Entry == 0) {
/* Create a new entry */ /* Create a new entry */
Entry = NewSymEntry (Name, Type); Entry = NewSymEntry (Name, Flags);
/* Set the struct data */ /* Set the struct data */
Entry->V.S.SymTab = Tab; Entry->V.S.SymTab = Tab;