}
/* 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)
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 */
* 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 */
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 {
#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 */
/* Label name for static symbols */
unsigned Label;
- /* Value for enums */
- int EnumVal;
+ /* Value for constants (including enums) */
+ long ConstVal;
/* Data for structs/unions */
struct {
-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);
}
/* 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);
/* 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 */
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 */