]> git.sur5r.net Git - cc65/blobdiff - src/ca65/symbol.c
Merge remote-tracking branch 'upstream/master' into a5200
[cc65] / src / ca65 / symbol.c
index c81899fa9f0d90e6510defd5d86ecbe4a5b12149..5eed70bebff96a4fbfba2f537a5f1de6ed740bc3 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2008 Ullrich von Bassewitz                                       */
-/*               Roemerstrasse 52                                            */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1998-2012, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 #include "nexttok.h"
 #include "scanner.h"
 #include "symbol.h"
-#include "symtab.h"
 
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -62,25 +61,26 @@ SymTable* ParseScopedIdent (StrBuf* Name, StrBuf* FullName)
  * by the caller for error messages or similar.
  */
 {
+    SymTable* Scope;
+
     /* Clear both passed string buffers */
     SB_Clear (Name);
     SB_Clear (FullName);
 
     /* Get the starting table */
-    SymTable* Scope;
-    if (Tok == TOK_NAMESPACE) {
+    if (CurTok.Tok == TOK_NAMESPACE) {
 
         /* Start from the root scope */
         Scope = RootScope;
 
-    } else if (Tok == TOK_IDENT) {
+    } else if (CurTok.Tok == TOK_IDENT) {
 
         /* Remember the name and skip it */
-        SB_Copy (Name, &SVal);
+        SB_Copy (Name, &CurTok.SVal);
         NextTok ();
 
         /* If no namespace symbol follows, we're already done */
-        if (Tok != TOK_NAMESPACE) {
+        if (CurTok.Tok != TOK_NAMESPACE) {
             SB_Terminate (FullName);
             return CurrentScope;
         }
@@ -115,19 +115,19 @@ SymTable* ParseScopedIdent (StrBuf* Name, StrBuf* FullName)
     while (1) {
 
         /* Next token must be an identifier. */
-        if (Tok != TOK_IDENT) {
+        if (CurTok.Tok != TOK_IDENT) {
             Error ("Identifier expected");
             return 0;
         }
 
         /* Remember and skip the identifier */
-        SB_Copy (Name, &SVal);
+        SB_Copy (Name, &CurTok.SVal);
         NextTok ();
 
         /* If a namespace token follows, we search for another scope, otherwise
          * the name is a symbol and we're done.
          */
-        if (Tok != TOK_NAMESPACE) {
+        if (CurTok.Tok != TOK_NAMESPACE) {
             /* Symbol */
             return Scope;
         }
@@ -151,7 +151,7 @@ SymTable* ParseScopedIdent (StrBuf* Name, StrBuf* FullName)
 
 
 
-SymEntry* ParseScopedSymName (int AllocNew)
+SymEntry* ParseScopedSymName (SymFindAction Action)
 /* Parse a (possibly scoped) symbol name, search for it in the symbol table
  * and return the symbol table entry.
  */
@@ -177,17 +177,17 @@ SymEntry* ParseScopedSymName (int AllocNew)
         /* Search for the symbol and return it. If no scope was specified,
          * search also in the upper levels.
          */
-        if (NoScope && !AllocNew) {
+        if (NoScope && (Action & SYM_ALLOC_NEW) == 0) {
             Sym = SymFindAny (Scope, &Ident);
         } else {
-            Sym = SymFind (Scope, &Ident, AllocNew);
+            Sym = SymFind (Scope, &Ident, Action);
         }
     } else {
         /* No scope ==> no symbol. To avoid errors in the calling routine that
-         * may not expect NULL to be returned if AllocNew is true, create a new
-         * symbol.
+         * may not expect NULL to be returned if Action contains SYM_ALLOC_NEW,
+         * create a new symbol.
          */
-        if (AllocNew) {
+        if (Action & SYM_ALLOC_NEW) { 
             Sym = NewSymEntry (&Ident, SF_NONE);
         } else {
             Sym = 0;
@@ -244,3 +244,21 @@ SymTable* ParseScopedSymTable (void)
 
 
 
+SymEntry* ParseAnySymName (SymFindAction Action)
+/* 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 (CurTok.Tok == TOK_LOCAL_IDENT) {
+        Sym = SymFindLocal (SymLast, &CurTok.SVal, Action);
+        NextTok ();
+    } else {
+        Sym = ParseScopedSymName (Action);
+    }
+
+    /* Return the symbol found */
+    return Sym;
+}