X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fsymtab.c;h=2c50775d797ffe9e96eaa1993fcc71d5f0141596;hb=c130e597b013e37c94afd6651be1e8859ba7e5ac;hp=5431cf0dc80e554999495d4800dacdbe3958d855;hpb=e6484f85c7f440aa8b12bbf956bed0b87e4ddeed;p=cc65 diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 5431cf0dc..2c50775d7 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -6,9 +6,9 @@ /* */ /* */ /* */ -/* (C) 2000-2001 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ +/* (C) 2000-2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ /* */ @@ -40,6 +40,7 @@ /* common */ #include "check.h" +#include "debugflag.h" #include "hashstr.h" #include "xmalloc.h" @@ -81,9 +82,6 @@ SymTable EmptySymTab = { #define SYMTAB_SIZE_STRUCT 19U #define SYMTAB_SIZE_LABEL 7U -/* Predefined lexical levels */ -#define LEX_LEVEL_GLOBAL 1U - /* The current and root symbol tables */ static unsigned LexicalLevel = 0; /* For safety checks */ static SymTable* SymTab0 = 0; @@ -163,7 +161,7 @@ static void CheckSymTable (SymTable* Tab) * defined but not used. */ if (((Flags & SC_AUTO) || (Flags & SC_STATIC)) && (Flags & SC_EXTERN) == 0) { - if ((Flags & SC_DEF) && !(Flags & SC_REF)) { + if (SymIsDef (Entry) && !SymIsRef (Entry)) { if (Flags & SC_PARAM) { Warning ("Parameter `%s' is never used", Entry->Name); } else { @@ -174,10 +172,10 @@ static void CheckSymTable (SymTable* Tab) /* If the entry is a label, check if it was defined in the function */ if (Flags & SC_LABEL) { - if ((Flags & SC_DEF) == 0) { + if (!SymIsDef (Entry)) { /* Undefined label */ Error ("Undefined label: `%s'", Entry->Name); - } else if ((Flags & SC_REF) == 0) { + } else if (!SymIsRef (Entry)) { /* Defined but not used */ Warning ("`%s' is defined but never used", Entry->Name); } @@ -198,6 +196,14 @@ static void CheckSymTable (SymTable* Tab) +unsigned GetLexicalLevel (void) +/* Return the current lexical level */ +{ + return LexicalLevel; +} + + + void EnterGlobalLevel (void) /* Enter the program global lexical level */ { @@ -441,6 +447,14 @@ SymEntry* FindSym (const char* Name) +SymEntry* FindGlobalSym (const char* Name) +/* Find the symbol with the given name in the global symbol table only */ +{ + return FindSymInTable (SymTab0, Name, HashStr (Name)); +} + + + SymEntry* FindLocalSym (const char* Name) /* Find the symbol with the given name in the current symbol table only */ { @@ -606,7 +620,7 @@ SymEntry* AddLabelSym (const char* Name, unsigned Flags) SymEntry* Entry = FindSymInTable (LabelTab, Name, HashStr (Name)); if (Entry) { - if ((Entry->Flags & SC_DEF) != 0 && (Flags & SC_DEF) != 0) { + if (SymIsDef (Entry) && (Flags & SC_DEF) != 0) { /* Trying to define the label more than once */ Error ("Label `%s' is defined more than once", Name); } @@ -648,7 +662,18 @@ SymEntry* AddLocalSym (const char* Name, const type* Type, unsigned Flags, int O /* Set the symbol attributes */ Entry->Type = TypeDup (Type); - Entry->V.Offs = Offs; + if ((Flags & SC_AUTO) == SC_AUTO) { + Entry->V.Offs = Offs; + } else if ((Flags & SC_REGISTER) == SC_REGISTER) { + Entry->V.R.RegOffs = Offs; + Entry->V.R.SaveOffs = oursp; /* ### Cleaner! */ + } else if ((Flags & SC_STATIC) == SC_STATIC) { + Entry->V.Label = Offs; + } else if ((Flags & SC_STRUCTFIELD) == SC_STRUCTFIELD) { + Entry->V.Offs = Offs; + } else { + Internal ("Invalid flags in AddLocalSym: %04X", Flags); + } /* Add the entry to the symbol table */ AddSymEntry (SymTab, Entry); @@ -692,17 +717,17 @@ SymEntry* AddGlobalSym (const char* Name, const type* Type, unsigned Flags) if (IsTypeArray (Type) && IsTypeArray (EType)) { /* Get the array sizes */ - unsigned Size = Decode (Type + 1); - unsigned ESize = Decode (EType + 1); + long Size = GetElementCount (Type); + long ESize = GetElementCount (EType); - if ((Size != 0 && ESize != 0) || + if ((Size != UNSPECIFIED && ESize != UNSPECIFIED && Size != ESize) || TypeCmp (Type+DECODE_SIZE+1, EType+DECODE_SIZE+1) < TC_EQUAL) { /* Types not identical: Conflicting types */ Error ("Conflicting types for `%s'", Name); return Entry; } else { /* Check if we have a size in the existing definition */ - if (ESize == 0) { + if (ESize == UNSPECIFIED) { /* Existing, size not given, use size from new def */ Encode (EType + 1, Size); } @@ -848,10 +873,10 @@ void EmitExternals (void) unsigned Flags = Entry->Flags; if (Flags & SC_EXTERN) { /* Only defined or referenced externs */ - if ((Flags & SC_REF) != 0 && (Flags & SC_DEF) == 0) { + if (SymIsRef (Entry) && !SymIsDef (Entry)) { /* An import */ g_defimport (Entry->Name, Flags & SC_ZEROPAGE); - } else if (Flags & SC_DEF) { + } else if (SymIsDef (Entry)) { /* An export */ g_defexport (Entry->Name, Flags & SC_ZEROPAGE); }