From 7d506c84c96b05e6d1dcc82be7a6978974f24547 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 26 Jul 2010 17:28:34 +0000 Subject: [PATCH] Make .DEF, .REF and friends also work with cheap local symbols. git-svn-id: svn://svn.cc65.org/cc65/trunk@4767 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/condasm.c | 16 ++++++++-------- src/ca65/expr.c | 12 ++++-------- src/ca65/main.c | 9 ++------- src/ca65/symbol.c | 29 +++++++++++++++++++++++++---- src/ca65/symbol.h | 13 +++++++++---- 5 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/ca65/condasm.c b/src/ca65/condasm.c index b92db812d..e89bcf62b 100644 --- a/src/ca65/condasm.c +++ b/src/ca65/condasm.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000-2004 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2000-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -310,7 +310,7 @@ void DoConditionals (void) D = AllocIf (".IFDEF", 1); NextTok (); if (IfCond) { - SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING); + SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING); SetIfCond (D, Sym != 0 && SymIsDef (Sym)); } IfCond = GetCurrentIfCond (); @@ -346,7 +346,7 @@ void DoConditionals (void) D = AllocIf (".IFNDEF", 1); NextTok (); if (IfCond) { - SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING); + SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING); SetIfCond (D, Sym == 0 || !SymIsDef (Sym)); ExpectSep (); } @@ -357,7 +357,7 @@ void DoConditionals (void) D = AllocIf (".IFNREF", 1); NextTok (); if (IfCond) { - SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING); + SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING); SetIfCond (D, Sym == 0 || !SymIsRef (Sym)); ExpectSep (); } @@ -408,7 +408,7 @@ void DoConditionals (void) D = AllocIf (".IFREF", 1); NextTok (); if (IfCond) { - SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING); + SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING); SetIfCond (D, Sym != 0 && SymIsRef (Sym)); ExpectSep (); } diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 4d41c06f6..56d728e9c 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -385,7 +385,7 @@ static ExprNode* FuncDefined (void) /* Handle the .DEFINED builtin function */ { /* Parse the symbol name and search for the symbol */ - SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING); + SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING); /* Check if the symbol is defined */ return GenLiteralExpr (Sym != 0 && SymIsDef (Sym)); @@ -597,7 +597,7 @@ static ExprNode* FuncReferenced (void) /* Handle the .REFERENCED builtin function */ { /* Parse the symbol name and search for the symbol */ - SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING); + SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING); /* Check if the symbol is referenced */ return GenLiteralExpr (Sym != 0 && SymIsRef (Sym)); @@ -867,13 +867,9 @@ static ExprNode* Factor (void) case TOK_NAMESPACE: case TOK_IDENT: - N = Symbol (ParseScopedSymName (SYM_ALLOC_NEW)); - break; - case TOK_LOCAL_IDENT: - N = Symbol (SymFindLocal (SymLast, &SVal, SYM_ALLOC_NEW)); - NextTok (); - break; + N = Symbol (ParseAnySymName (SYM_ALLOC_NEW)); + break; case TOK_ULABEL: N = ULabRef (IVal); diff --git a/src/ca65/main.c b/src/ca65/main.c index b552e8363..eae7c384f 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -360,7 +360,7 @@ static void OptAutoImport (const char* Opt attribute ((unused)), static void OptBinIncludeDir (const char* Opt attribute ((unused)), const char* Arg) /* Add an include search path for binaries */ -{ +{ AddSearchPath (BinSearchPath, Arg); } @@ -632,12 +632,7 @@ static void OneLine (void) int HadWS = WS; /* Generate the symbol table entry, then skip the name */ - if (Tok == TOK_LOCAL_IDENT) { - Sym = SymFindLocal (SymLast, &SVal, SYM_ALLOC_NEW); - NextTok (); - } else { - Sym = ParseScopedSymName (SYM_ALLOC_NEW); - } + Sym = ParseAnySymName (SYM_ALLOC_NEW); /* If a colon follows, this is a label definition. If there * is no colon, it's an assignment. diff --git a/src/ca65/symbol.c b/src/ca65/symbol.c index 444decfc5..3be3b9b5c 100644 --- a/src/ca65/symbol.c +++ b/src/ca65/symbol.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2008 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -245,3 +245,24 @@ SymTable* ParseScopedSymTable (void) +SymEntry* ParseAnySymName (int AllocNew) +/* Parse a cheap local symbol or a a (possibly scoped) symbol name, search + * for it in the symbol table and return the symbol table entry. + */ +{ + SymEntry* Sym; + + /* Distinguish cheap locals and other symbols */ + if (Tok == TOK_LOCAL_IDENT) { + Sym = SymFindLocal (SymLast, &SVal, AllocNew); + NextTok (); + } else { + Sym = ParseScopedSymName (AllocNew); + } + + /* Return the symbol found */ + return Sym; +} + + + diff --git a/src/ca65/symbol.h b/src/ca65/symbol.h index 4d0bcbf7d..b790fcacb 100644 --- a/src/ca65/symbol.h +++ b/src/ca65/symbol.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2008 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -74,6 +74,11 @@ struct SymTable* ParseScopedSymTable (void); * symbol space and return the symbol table struct. */ +struct SymEntry* ParseAnySymName (int AllocNew); +/* Parse a cheap local symbol or a a (possibly scoped) symbol name, search + * for it in the symbol table and return the symbol table entry. + */ + /* End of symbol.h */ -- 2.39.5