From 0250c87ac6326d0a9114457d9d9af5b259044baa Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 20 Jul 2020 22:34:57 +0800 Subject: [PATCH] Fixed SC_* type masks by making them all bitwise-exclusive. --- src/cc65/compile.c | 2 +- src/cc65/declare.c | 2 +- src/cc65/expr.c | 2 +- src/cc65/symentry.h | 49 ++++++++++++++++++++++++--------------------- src/cc65/symtab.c | 6 +++--- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/cc65/compile.c b/src/cc65/compile.c index ef66d38d2..4806017eb 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -112,7 +112,7 @@ static void Parse (void) ParseDeclSpec (&Spec, SC_EXTERN | SC_STATIC, T_INT); /* Don't accept illegal storage classes */ - if ((Spec.StorageClass & SC_TYPE) == 0) { + if ((Spec.StorageClass & SC_TYPEMASK) == 0) { if ((Spec.StorageClass & SC_AUTO) != 0 || (Spec.StorageClass & SC_REGISTER) != 0) { Error ("Illegal storage class"); diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 2a21e5a76..3b1cf63e7 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -490,7 +490,7 @@ static void ParseEnumDecl (void) } /* Add an entry to the symbol table */ - AddConstSym (Ident, type_int, SC_ENUM, EnumVal++); + AddConstSym (Ident, type_int, SC_ENUM|SC_CONST, EnumVal++); /* Check for end of definition */ if (CurTok.Tok != TOK_COMMA) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 0b668f402..d31b153a5 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -758,7 +758,7 @@ static void Primary (ExprDesc* E) /* Check for illegal symbol types */ CHECK ((Sym->Flags & SC_LABEL) != SC_LABEL); - if (Sym->Flags & SC_TYPE) { + if (Sym->Flags & SC_ESUTYPEMASK) { /* Cannot use type symbols */ Error ("Variable identifier expected"); /* Assume an int type to make E valid */ diff --git a/src/cc65/symentry.h b/src/cc65/symentry.h index 62bf0b0e7..27c6ccc1e 100644 --- a/src/cc65/symentry.h +++ b/src/cc65/symentry.h @@ -69,39 +69,42 @@ struct CodeEntry; /* Storage classes and flags */ -#define SC_AUTO 0x0001U /* Auto variable */ -#define SC_REGISTER 0x0002U /* Register variable */ -#define SC_STATIC 0x0004U /* Static */ -#define SC_EXTERN 0x0008U /* Extern linkage */ +#define SC_NONE 0x0000U /* Nothing */ +#define SC_STRUCT 0x0001U /* Struct */ +#define SC_UNION 0x0002U /* Union */ +#define SC_TYPEDEF 0x0004U /* A typedef */ +#define SC_ESUTYPEMASK 0x0007U /* Mask for above types */ +#define SC_ENUM 0x0008U /* An enum */ +#define SC_BITFIELD 0x0010U /* A bit-field inside a struct or union */ +#define SC_TYPEMASK 0x001FU /* Mask for above types */ -#define SC_ENUM 0x0030U /* An enum */ #define SC_CONST 0x0020U /* A numeric constant with a type */ -#define SC_LABEL 0x0040U /* A goto label */ +#define SC_LABEL 0x0040U /* A goto code label */ #define SC_PARAM 0x0080U /* A function parameter */ #define SC_FUNC 0x0100U /* A function */ - #define SC_DEFTYPE 0x0200U /* Parameter has default type (=int, old style) */ -#define SC_STORAGE 0x0400U /* Symbol with associated storage */ -#define SC_DEFAULT 0x0800U /* Flag: default storage class was used */ +#define SC_STRUCTFIELD 0x0400U /* Struct or union field */ + +#define SC_DECL 0x0800U /* Symbol is declared in global scope */ #define SC_DEF 0x1000U /* Symbol is defined */ #define SC_REF 0x2000U /* Symbol is referenced */ -#define SC_TYPE 0x4000U /* This is a type, struct, typedef, etc. */ -#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 0x4005U /* A typedef */ -#define SC_TYPEMASK 0x400FU /* Mask for above types */ +#define SC_ZEROPAGE 0x4000U /* Symbol marked as zeropage */ -#define SC_ZEROPAGE 0x8000U /* Symbol marked as zeropage */ +#define SC_STORAGE 0x8000U /* Symbol with associated storage */ -#define SC_HAVEATTR 0x10000U /* Symbol has attributes */ +#define SC_AUTO 0x010000U /* Auto variable */ +#define SC_REGISTER 0x020000U /* Register variable */ +#define SC_STATIC 0x040000U /* Static - not to be confused with other *_STATIC */ +#define SC_EXTERN 0x080000U /* Extern linkage */ +#define SC_STORAGEMASK 0x0F0000U /* Storage type mask */ -#define SC_GOTO 0x20000U -#define SC_SPADJUSTMENT 0x40000U -#define SC_GOTO_IND 0x80000U /* Indirect goto */ +#define SC_HAVEATTR 0x100000U /* Symbol has attributes */ + +#define SC_GOTO 0x200000U +#define SC_SPADJUSTMENT 0x400000U +#define SC_GOTO_IND 0x800000U /* Indirect goto */ @@ -245,10 +248,10 @@ INLINE int SymIsRegVar (const SymEntry* Sym) /* Return true if the given entry is a register variable */ /* ### HACK! Fix the ugly type flags! */ { - return ((Sym->Flags & (SC_REGISTER|SC_TYPE)) == SC_REGISTER); + return ((Sym->Flags & (SC_REGISTER|SC_TYPEMASK)) == SC_REGISTER); } #else -# define SymIsRegVar(Sym) (((Sym)->Flags & (SC_REGISTER|SC_TYPE)) == SC_REGISTER) +# define SymIsRegVar(Sym) (((Sym)->Flags & (SC_REGISTER|SC_ESUTYPEMASK)) == SC_REGISTER) #endif int SymIsOutputFunc (const SymEntry* Sym); diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index f363d9134..1408f9f4c 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -821,7 +821,7 @@ SymEntry* AddLocalSym (const char* Name, const Type* T, unsigned Flags, int Offs /* Set the symbol attributes */ Entry->Type = TypeDup (T); - if ((Flags & SC_AUTO) == SC_AUTO) { + if ((Flags & SC_AUTO) == SC_AUTO || (Flags & SC_TYPEDEF) == SC_TYPEDEF) { Entry->V.Offs = Offs; } else if ((Flags & SC_REGISTER) == SC_REGISTER) { Entry->V.R.RegOffs = Offs; @@ -872,7 +872,7 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) } /* We have a symbol with this name already */ - if (Entry->Flags & SC_TYPE) { + if (Entry->Flags & SC_TYPEMASK) { Error ("Multiple definition for '%s'", Name); return Entry; } @@ -1109,7 +1109,7 @@ void EmitDebugInfo (void) } Sym = SymTab->SymHead; while (Sym) { - if ((Sym->Flags & (SC_CONST|SC_TYPE)) == 0) { + if ((Sym->Flags & (SC_CONST|SC_TYPEMASK)) == 0) { if (Sym->Flags & SC_AUTO) { AddTextLine ("%s, \"%s\", \"00\", auto, %d", Head, Sym->Name, Sym->V.Offs);