1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-26 05:29:30 +00:00
This commit is contained in:
laubzega 2024-05-06 21:01:50 -04:00 committed by GitHub
commit c2c0abf7c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 57 additions and 5 deletions

View File

@ -83,7 +83,6 @@ static ExprNode* FreeExprNodes = 0;
static unsigned FreeNodeCount = 0; static unsigned FreeNodeCount = 0;
/*****************************************************************************/ /*****************************************************************************/
/* Helpers */ /* Helpers */
/*****************************************************************************/ /*****************************************************************************/
@ -1646,8 +1645,10 @@ long ConstExpression (void)
{ {
long Val; long Val;
ProcessingConst = 1;
/* Read the expression */ /* Read the expression */
ExprNode* Expr = Expression (); ExprNode* Expr = Expression ();
ProcessingConst = 0;
/* Study the expression */ /* Study the expression */
ExprDesc D; ExprDesc D;

View File

@ -58,6 +58,9 @@ StrBuf FullDepName = STATIC_STRBUF_INITIALIZER; /* Full dependency file */
const char ObjExt[] = ".o";/* Default object extension */ const char ObjExt[] = ".o";/* Default object extension */
char LocalStart = '@'; /* This char starts local symbols */ char LocalStart = '@'; /* This char starts local symbols */
unsigned char ProcessingConst = 0; /* Currently processed expression
** is supposed to be const
*/
unsigned char IgnoreCase = 0; /* Ignore case on identifiers? */ unsigned char IgnoreCase = 0; /* Ignore case on identifiers? */
unsigned char AutoImport = 0; /* Mark unresolveds as import */ unsigned char AutoImport = 0; /* Mark unresolveds as import */

View File

@ -60,6 +60,9 @@ extern StrBuf FullDepName; /* Name of full dependencies file */
extern const char ObjExt[]; /* Default object extension */ extern const char ObjExt[]; /* Default object extension */
extern char LocalStart; /* This char starts local symbols */ extern char LocalStart; /* This char starts local symbols */
extern unsigned char ProcessingConst; /* Currently processed expression
** is supposed to be const
*/
extern unsigned char IgnoreCase; /* Ignore case on identifiers? */ extern unsigned char IgnoreCase; /* Ignore case on identifiers? */
extern unsigned char AutoImport; /* Mark unresolveds as import */ extern unsigned char AutoImport; /* Mark unresolveds as import */

View File

@ -40,12 +40,11 @@
/* ca65 */ /* ca65 */
#include "error.h" #include "error.h"
#include "global.h"
#include "nexttok.h" #include "nexttok.h"
#include "scanner.h" #include "scanner.h"
#include "symbol.h" #include "symbol.h"
/*****************************************************************************/ /*****************************************************************************/
/* Code */ /* Code */
/*****************************************************************************/ /*****************************************************************************/
@ -159,7 +158,7 @@ SymEntry* ParseScopedSymName (SymFindAction Action)
StrBuf ScopeName = STATIC_STRBUF_INITIALIZER; StrBuf ScopeName = STATIC_STRBUF_INITIALIZER;
StrBuf Ident = STATIC_STRBUF_INITIALIZER; StrBuf Ident = STATIC_STRBUF_INITIALIZER;
int NoScope; int NoScope;
SymEntry* Sym; SymEntry* Sym = 0;
/* Parse the scoped symbol name */ /* Parse the scoped symbol name */
SymTable* Scope = ParseScopedIdent (&Ident, &ScopeName); SymTable* Scope = ParseScopedIdent (&Ident, &ScopeName);
@ -179,8 +178,32 @@ SymEntry* ParseScopedSymName (SymFindAction Action)
*/ */
if (NoScope && (Action & SYM_ALLOC_NEW) == 0) { if (NoScope && (Action & SYM_ALLOC_NEW) == 0) {
Sym = SymFindAny (Scope, &Ident); Sym = SymFindAny (Scope, &Ident);
if (Sym == 0) {
Sym = SymFindInChildren (Scope, &Ident);
}
} else { } else {
Sym = SymFind (Scope, &Ident, Action); /* If we are processing a symbol within an expression, which the
** parser expects to be constant, that symbol had to be defined
** already for the expression to resolve correctly. Search for it
** in the current scope first, and if not found, retry in all
** enclosing scopes.
*/
if ((Action & SYM_ALLOC_NEW) && ProcessingConst) {
Sym = SymFind (Scope, &Ident, SYM_FIND_EXISTING);
if (Sym == 0) {
Sym = SymFindAny (Scope, &Ident);
}
}
/* If still not found, or if in non-const expression, it will just
** get added to the current scope.
*/
if (Sym == 0) {
Sym = SymFind (Scope, &Ident, Action);
}
} }
} else { } else {
/* No scope ==> no symbol. To avoid errors in the calling routine that /* No scope ==> no symbol. To avoid errors in the calling routine that

View File

@ -424,6 +424,22 @@ SymEntry* SymFind (SymTable* Scope, const StrBuf* Name, SymFindAction Action)
} }
SymEntry* SymFindInChildren (SymTable* Parent, const StrBuf* Name)
{
SymTable* Scope = Parent->Childs;
SymEntry* Sym = 0;
if (Scope) {
do {
Sym = SymFind (Scope, Name, SYM_CHECK_ONLY);
Scope = Scope->Next;
} while (Sym == 0 && Scope != 0);
}
return Sym;
}
SymEntry* SymFindAny (SymTable* Scope, const StrBuf* Name) SymEntry* SymFindAny (SymTable* Scope, const StrBuf* Name)
/* Find a symbol in the given or any of its parent scopes. The function will /* Find a symbol in the given or any of its parent scopes. The function will

View File

@ -122,6 +122,12 @@ SymEntry* SymFindLocal (SymEntry* Parent, const StrBuf* Name, SymFindAction Acti
** created, or - in case Action is SYM_FIND_EXISTING - return 0. ** created, or - in case Action is SYM_FIND_EXISTING - return 0.
*/ */
SymEntry* SymFindInChildren (SymTable* Scope, const StrBuf* Name);
/* Find a symbol in children scopes of given scope (if they exist). The
** function will never create a new symbol, since this can only be done in one
** specific scope.
*/
SymEntry* SymFind (SymTable* Scope, const StrBuf* Name, SymFindAction Action); SymEntry* SymFind (SymTable* Scope, const StrBuf* Name, SymFindAction Action);
/* Find a new symbol table entry in the given table. If Action contains /* Find a new symbol table entry in the given table. If Action contains
** SYM_ALLOC_NEW and the entry is not found, create a new one. Return the ** SYM_ALLOC_NEW and the entry is not found, create a new one. Return the