mirror of
https://github.com/cc65/cc65.git
synced 2025-03-01 11:29:27 +00:00
Made the enum/enumerator types clearer and improved DumpSymEntry() output.
This commit is contained in:
parent
18bd76bb90
commit
c66d0881b9
@ -490,7 +490,7 @@ static void ParseEnumDecl (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add an entry to the symbol table */
|
/* Add an entry to the symbol table */
|
||||||
AddConstSym (Ident, type_int, SC_ENUM|SC_CONST, EnumVal++);
|
AddConstSym (Ident, type_int, SC_ENUMERATOR|SC_CONST, EnumVal++);
|
||||||
|
|
||||||
/* Check for end of definition */
|
/* Check for end of definition */
|
||||||
if (CurTok.Tok != TOK_COMMA)
|
if (CurTok.Tok != TOK_COMMA)
|
||||||
|
@ -113,26 +113,29 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
|
|||||||
{ "SC_TYPEDEF", SC_TYPEDEF },
|
{ "SC_TYPEDEF", SC_TYPEDEF },
|
||||||
{ "SC_UNION", SC_UNION },
|
{ "SC_UNION", SC_UNION },
|
||||||
{ "SC_STRUCT", SC_STRUCT },
|
{ "SC_STRUCT", SC_STRUCT },
|
||||||
|
{ "SC_ENUM", SC_ENUM },
|
||||||
};
|
};
|
||||||
|
|
||||||
static SCFlagTable Flags[] = {
|
static SCFlagTable Types[] = {
|
||||||
/* Beware: Order is important! */
|
|
||||||
{ "SC_BITFIELD", SC_BITFIELD },
|
{ "SC_BITFIELD", SC_BITFIELD },
|
||||||
{ "SC_STRUCTFIELD", SC_STRUCTFIELD },
|
{ "SC_STRUCTFIELD", SC_STRUCTFIELD },
|
||||||
{ "SC_AUTO", SC_AUTO },
|
{ "SC_ENUMERATOR", SC_ENUMERATOR },
|
||||||
{ "SC_REGISTER", SC_REGISTER },
|
|
||||||
{ "SC_STATIC", SC_STATIC },
|
|
||||||
{ "SC_EXTERN", SC_EXTERN },
|
|
||||||
{ "SC_ENUM", SC_ENUM },
|
|
||||||
{ "SC_CONST", SC_CONST },
|
{ "SC_CONST", SC_CONST },
|
||||||
{ "SC_LABEL", SC_LABEL },
|
{ "SC_LABEL", SC_LABEL },
|
||||||
{ "SC_PARAM", SC_PARAM },
|
{ "SC_PARAM", SC_PARAM },
|
||||||
{ "SC_FUNC", SC_FUNC },
|
{ "SC_FUNC", SC_FUNC },
|
||||||
|
};
|
||||||
|
|
||||||
|
static SCFlagTable Storages[] = {
|
||||||
|
{ "SC_AUTO", SC_AUTO },
|
||||||
|
{ "SC_REGISTER", SC_REGISTER },
|
||||||
|
{ "SC_STATIC", SC_STATIC },
|
||||||
|
{ "SC_EXTERN", SC_EXTERN },
|
||||||
{ "SC_STORAGE", SC_STORAGE },
|
{ "SC_STORAGE", SC_STORAGE },
|
||||||
|
{ "SC_ZEROPAGE", SC_ZEROPAGE },
|
||||||
{ "SC_DECL", SC_DECL },
|
{ "SC_DECL", SC_DECL },
|
||||||
{ "SC_DEF", SC_DEF },
|
{ "SC_DEF", SC_DEF },
|
||||||
{ "SC_REF", SC_REF },
|
{ "SC_REF", SC_REF },
|
||||||
{ "SC_ZEROPAGE", SC_ZEROPAGE },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned I;
|
unsigned I;
|
||||||
@ -149,18 +152,28 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
|
|||||||
/* Print the flags */
|
/* Print the flags */
|
||||||
SymFlags = E->Flags;
|
SymFlags = E->Flags;
|
||||||
fprintf (F, " Flags:");
|
fprintf (F, " Flags:");
|
||||||
|
/* Enum, struct, union and typedefs */
|
||||||
if ((SymFlags & SC_ESUTYPEMASK) != 0) {
|
if ((SymFlags & SC_ESUTYPEMASK) != 0) {
|
||||||
for (I = 0; I < sizeof (ESUTypes) / sizeof (ESUTypes[0]); ++I) {
|
for (I = 0; I < sizeof (ESUTypes) / sizeof (ESUTypes[0]); ++I) {
|
||||||
if ((SymFlags & SC_ESUTYPEMASK) == ESUTypes[I].Val) {
|
if ((SymFlags & SC_ESUTYPEMASK) == ESUTypes[I].Val) {
|
||||||
SymFlags &= ~SC_ESUTYPEMASK;
|
SymFlags &= ~SC_ESUTYPEMASK;
|
||||||
fprintf (F, " %s", ESUTypes[I].Name);
|
fprintf (F, " %s", ESUTypes[I].Name);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (I = 0; I < sizeof (Flags) / sizeof (Flags[0]) && SymFlags != 0; ++I) {
|
/* Other type flags */
|
||||||
if ((SymFlags & Flags[I].Val) == Flags[I].Val) {
|
for (I = 0; I < sizeof (Types) / sizeof (Types[0]) && SymFlags != 0; ++I) {
|
||||||
SymFlags &= ~Flags[I].Val;
|
if ((SymFlags & Types[I].Val) == Types[I].Val) {
|
||||||
fprintf (F, " %s", Flags[I].Name);
|
SymFlags &= ~Types[I].Val;
|
||||||
|
fprintf (F, " %s", Types[I].Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Storage flags */
|
||||||
|
for (I = 0; I < sizeof (Storages) / sizeof (Storages[0]) && SymFlags != 0; ++I) {
|
||||||
|
if ((SymFlags & Storages[I].Val) == Storages[I].Val) {
|
||||||
|
SymFlags &= ~Storages[I].Val;
|
||||||
|
fprintf (F, " %s", Storages[I].Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (SymFlags != 0) {
|
if (SymFlags != 0) {
|
||||||
|
@ -72,9 +72,10 @@ struct CodeEntry;
|
|||||||
#define SC_NONE 0x0000U /* Nothing */
|
#define SC_NONE 0x0000U /* Nothing */
|
||||||
#define SC_STRUCT 0x0001U /* Struct */
|
#define SC_STRUCT 0x0001U /* Struct */
|
||||||
#define SC_UNION 0x0002U /* Union */
|
#define SC_UNION 0x0002U /* Union */
|
||||||
#define SC_TYPEDEF 0x0004U /* A typedef */
|
#define SC_ENUM 0x0003U /* Enum */
|
||||||
|
#define SC_TYPEDEF 0x0004U /* Typedef */
|
||||||
#define SC_ESUTYPEMASK 0x0007U /* Mask for above types */
|
#define SC_ESUTYPEMASK 0x0007U /* Mask for above types */
|
||||||
#define SC_ENUM 0x0008U /* An enumerator */
|
#define SC_ENUMERATOR 0x0008U /* An enumerator */
|
||||||
#define SC_BITFIELD 0x0010U /* A bit-field inside a struct or union */
|
#define SC_BITFIELD 0x0010U /* A bit-field inside a struct or union */
|
||||||
#define SC_TYPEMASK 0x001FU /* Mask for above types */
|
#define SC_TYPEMASK 0x001FU /* Mask for above types */
|
||||||
|
|
||||||
|
@ -633,7 +633,7 @@ SymEntry* AddConstSym (const char* Name, const Type* T, unsigned Flags, long Val
|
|||||||
/* Add an constant symbol to the symbol table and return it */
|
/* Add an constant symbol to the symbol table and return it */
|
||||||
{
|
{
|
||||||
/* Enums must be inserted in the global symbol table */
|
/* Enums must be inserted in the global symbol table */
|
||||||
SymTable* Tab = ((Flags & SC_ENUM) == SC_ENUM)? SymTab0 : SymTab;
|
SymTable* Tab = ((Flags & SC_ENUMERATOR) == SC_ENUMERATOR) ? SymTab0 : SymTab;
|
||||||
|
|
||||||
/* Do we have an entry with this name already? */
|
/* Do we have an entry with this name already? */
|
||||||
SymEntry* Entry = FindSymInTable (Tab, Name, HashStr (Name));
|
SymEntry* Entry = FindSymInTable (Tab, Name, HashStr (Name));
|
||||||
@ -867,8 +867,8 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags)
|
|||||||
/* If the existing symbol is an enumerated constant,
|
/* If the existing symbol is an enumerated constant,
|
||||||
** then avoid a compiler crash. See GitHub issue #728.
|
** then avoid a compiler crash. See GitHub issue #728.
|
||||||
*/
|
*/
|
||||||
if (Entry->Flags & SC_ENUM) {
|
if (Entry->Flags & SC_ENUMERATOR) {
|
||||||
Fatal ("Can't redeclare enum constant '%s' as global variable", Name);
|
Fatal ("Can't redeclare enumerator constant '%s' as global variable", Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have a symbol with this name already */
|
/* We have a symbol with this name already */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user