1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-09 22:29:35 +00:00

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 */
AddEnumSym (Ident, EnumVal++);
AddConstSym (Ident, type_int, SC_ENUM, EnumVal++);
/* Check for end of definition */
if (curtok != TOK_COMMA)

View File

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

View File

@ -231,14 +231,14 @@ void NewFunc (SymEntry* Func)
* The latter is different depending on the type of the function (variadic
* 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) {
/* Variadic function. The variable must be const. */
static const type T [] = { T_UCHAR | T_QUAL_CONST, T_END };
AddLocalSym ("__argsize__", T, SC_DEF | SC_REF | SC_AUTO, 0);
} else {
/* 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 */

View File

@ -275,10 +275,11 @@ static ExprNode* Primary (void)
return GetIntNode (0);
}
/* Handle enum values as constant integers */
if ((Sym->Flags & SC_ENUM) == SC_ENUM) {
/* Handle constants including enum values */
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 {

View File

@ -56,7 +56,7 @@
#define SC_STATIC 0x0004U
#define SC_EXTERN 0x0008U
#define SC_ENUM 0x0030U /* An enum (numeric constant) */
#define SC_ENUM 0x0030U /* An enum (numeric constant) */
#define SC_CONST 0x0020U /* A numeric constant with a type */
#define SC_LABEL 0x0040U /* A goto label */
#define SC_PARAM 0x0080U /* This is a function parameter */
@ -97,8 +97,8 @@ struct SymEntry {
/* Label name for static symbols */
unsigned Label;
/* Value for enums */
int EnumVal;
/* Value for constants (including enums) */
long ConstVal;
/* Data for structs/unions */
struct {

View File

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

View File

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