From 59bcc726b6ecf668aa1b8805cba84ec880bbf61e Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 23 Mar 2001 21:27:48 +0000 Subject: [PATCH] Make AddConstSym from AddEnumSym git-svn-id: svn://svn.cc65.org/cc65/trunk@660 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/declare.c | 2 +- src/cc65/expr.c | 2 +- src/cc65/function.c | 4 ++-- src/cc65/parser.c | 7 ++++--- src/cc65/symentry.h | 6 +++--- src/cc65/symtab.c | 14 +++++++------- src/cc65/symtab.h | 4 ++-- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 4b5009a9b..c5bf09777 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -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) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index af52c57cd..11c43b973 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -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 */ diff --git a/src/cc65/function.c b/src/cc65/function.c index c3dfc6cf7..8b4e92c74 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -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 */ diff --git a/src/cc65/parser.c b/src/cc65/parser.c index 932d3875a..b86cafd9c 100644 --- a/src/cc65/parser.c +++ b/src/cc65/parser.c @@ -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 { diff --git a/src/cc65/symentry.h b/src/cc65/symentry.h index 610a06ee3..2b69f7e17 100644 --- a/src/cc65/symentry.h +++ b/src/cc65/symentry.h @@ -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 { diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 9228e5628..16889c54a 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -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 */ diff --git a/src/cc65/symtab.h b/src/cc65/symtab.h index 2628ecd5e..f948ed14e 100644 --- a/src/cc65/symtab.h +++ b/src/cc65/symtab.h @@ -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 */ -- 2.39.2