From 4f9f06c20ab343c93351f853d18d8bb5fc70af11 Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 21 Nov 2002 23:28:32 +0000 Subject: [PATCH] Fixed a bug git-svn-id: svn://svn.cc65.org/cc65/trunk@1565 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/symtab.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/ca65/symtab.c b/src/ca65/symtab.c index c28bdce5c..8b9425767 100644 --- a/src/ca65/symtab.c +++ b/src/ca65/symtab.c @@ -360,21 +360,6 @@ static SymEntry* SymFindAny (SymTable* Tab, const char* Name) -static SymEntry* SymRefInternal (SymTable* Table, const char* Name) -/* Search for the symbol in the given table and return it */ -{ - /* Try to find the symbol, create a new one if the symbol does not exist */ - SymEntry* S = SymFind (Table, Name, SF_ALLOC_NEW); - - /* Mark the symbol as referenced */ - S->Flags |= SF_REFERENCED; - - /* Return it */ - return S; -} - - - void SymEnterLevel (void) /* Enter a new lexical level */ { @@ -453,9 +438,20 @@ void SymDef (const char* Name, ExprNode* Expr, int ZP, int Label) SymEntry* SymRef (const char* Name) /* Search for the symbol and return it */ -{ - /* Reference the symbol in the current table */ - return SymRefInternal (SymTab, Name); +{ + /* Try to find the symbol in any visible table */ + SymEntry* S = SymFindAny (SymTab, Name); + + /* If we could not find the symbol, create it in the local symtab */ + if (S == 0) { + S = SymFind (SymTab, Name, SF_ALLOC_NEW); + } + + /* Mark the symbol as referenced */ + S->Flags |= SF_REFERENCED; + + /* Return it */ + return S; } @@ -463,8 +459,14 @@ SymEntry* SymRef (const char* Name) SymEntry* SymRefGlobal (const char* Name) /* Search for the symbol in the global namespace and return it */ { - /* Reference the symbol in the current table */ - return SymRefInternal (RootTab, Name); + /* Try to find the symbol, create a new one if the symbol does not exist */ + SymEntry* S = SymFind (RootTab, Name, SF_ALLOC_NEW); + + /* Mark the symbol as referenced */ + S->Flags |= SF_REFERENCED; + + /* Return it */ + return S; } -- 2.39.5