Make AddConstSym from AddEnumSym

git-svn-id: svn://svn.cc65.org/cc65/trunk@660 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2001-03-23 21:27:48 +00:00
parent 4a6f7cadd0
commit 59bcc726b6
7 changed files with 20 additions and 19 deletions

View File

@@ -208,7 +208,7 @@ static void ParseEnumDecl (void)
} }
/* Add an entry to the symbol table */ /* Add an entry to the symbol table */
AddEnumSym (Ident, EnumVal++); AddConstSym (Ident, type_int, SC_ENUM, EnumVal++);
/* Check for end of definition */ /* Check for end of definition */
if (curtok != TOK_COMMA) if (curtok != TOK_COMMA)

View File

@@ -775,7 +775,7 @@ static int primary (struct expent* lval)
if ((Sym->Flags & SC_CONST) == SC_CONST) { if ((Sym->Flags & SC_CONST) == SC_CONST) {
/* Enum or some other numeric constant */ /* Enum or some other numeric constant */
lval->e_flags = E_MCONST; lval->e_flags = E_MCONST;
lval->e_const = Sym->V.EnumVal; lval->e_const = Sym->V.ConstVal;
return 0; return 0;
} else if ((Sym->Flags & SC_FUNC) == SC_FUNC) { } else if ((Sym->Flags & SC_FUNC) == SC_FUNC) {
/* Function */ /* Function */

View File

@@ -231,14 +231,14 @@ void NewFunc (SymEntry* Func)
* The latter is different depending on the type of the function (variadic * The latter is different depending on the type of the function (variadic
* or not). * or not).
*/ */
AddLocalSym ("__fixargs__", type_uint, SC_DEF | SC_CONST, D->ParamSize); AddConstSym ("__fixargs__", type_uint, SC_DEF | SC_CONST, D->ParamSize);
if (D->Flags & FD_ELLIPSIS) { if (D->Flags & FD_ELLIPSIS) {
/* Variadic function. The variable must be const. */ /* Variadic function. The variable must be const. */
static const type T [] = { T_UCHAR | T_QUAL_CONST, T_END }; static const type T [] = { T_UCHAR | T_QUAL_CONST, T_END };
AddLocalSym ("__argsize__", T, SC_DEF | SC_REF | SC_AUTO, 0); AddLocalSym ("__argsize__", T, SC_DEF | SC_REF | SC_AUTO, 0);
} else { } else {
/* Non variadic */ /* Non variadic */
AddLocalSym ("__argsize__", type_uchar, SC_DEF | SC_CONST, D->ParamSize); AddConstSym ("__argsize__", type_uchar, SC_DEF | SC_CONST, D->ParamSize);
} }
/* Function body now defined */ /* Function body now defined */

View File

@@ -275,10 +275,11 @@ static ExprNode* Primary (void)
return GetIntNode (0); return GetIntNode (0);
} }
/* Handle enum values as constant integers */ /* Handle constants including enum values */
if ((Sym->Flags & SC_ENUM) == SC_ENUM) { if ((Sym->Flags & SC_CONST) == SC_CONST) {
N = GetIntNode (Sym->V.EnumVal); N = AllocExprNode (NT_CONST, Sym->Type, RVALUE);
N->IVal = Sym->V.ConstVal;
} else { } else {

View File

@@ -97,8 +97,8 @@ struct SymEntry {
/* Label name for static symbols */ /* Label name for static symbols */
unsigned Label; unsigned Label;
/* Value for enums */ /* Value for constants (including enums) */
int EnumVal; long ConstVal;
/* Data for structs/unions */ /* Data for structs/unions */
struct { struct {

View File

@@ -567,13 +567,13 @@ SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab)
SymEntry* AddEnumSym (const char* Name, int Val) SymEntry* AddConstSym (const char* Name, const type* Type, unsigned Flags, long Val)
/* Add an enum symbol to the symbol table and return it */ /* Add an constant symbol to the symbol table and return it */
{ {
/* Do we have an entry with this name already? */ /* Do we have an entry with this name already? */
SymEntry* Entry = FindSymInTable (SymTab, Name, HashStr (Name)); SymEntry* Entry = FindSymInTable (SymTab, Name, HashStr (Name));
if (Entry) { if (Entry) {
if (Entry->Flags != SC_ENUM) { if ((Entry->Flags & SC_CONST) != SC_CONST) {
Error ("Symbol `%s' is already different kind", Name); Error ("Symbol `%s' is already different kind", Name);
} else { } else {
Error ("Multiple definition for `%s'", Name); Error ("Multiple definition for `%s'", Name);
@@ -582,13 +582,13 @@ SymEntry* AddEnumSym (const char* Name, int Val)
} }
/* Create a new entry */ /* Create a new entry */
Entry = NewSymEntry (Name, SC_ENUM); Entry = NewSymEntry (Name, Flags);
/* Enum values are ints */ /* Enum values are ints */
Entry->Type = TypeDup (type_int); Entry->Type = TypeDup (Type);
/* Set the enum data */ /* Set the enum data */
Entry->V.EnumVal = Val; Entry->V.ConstVal = Val;
/* Add the entry to the symbol table */ /* Add the entry to the symbol table */
AddSymEntry (SymTab, Entry); AddSymEntry (SymTab, Entry);

View File

@@ -137,8 +137,8 @@ SymEntry* FindStructField (const type* TypeArray, const char* Name);
SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab); SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab);
/* Add a struct/union entry and return it */ /* Add a struct/union entry and return it */
SymEntry* AddEnumSym (const char* Name, int Val); SymEntry* AddConstSym (const char* Name, const type* Type, unsigned Flags, long Val);
/* Add an enum symbol to the symbol table and return it */ /* Add an constant symbol to the symbol table and return it */
SymEntry* AddLabelSym (const char* Name, unsigned Flags); SymEntry* AddLabelSym (const char* Name, unsigned Flags);
/* Add a goto label to the symbol table */ /* Add a goto label to the symbol table */