]> git.sur5r.net Git - cc65/blobdiff - src/ca65/symentry.c
Finished implemenation of commands to delete macros. Added the new commands to
[cc65] / src / ca65 / symentry.c
index 7bae7e019a43ead8f1697ceea7e7ffd117749afa..763820731c954d9d1d785877882256a1dd8df706 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2008 Ullrich von Bassewitz                                       */
-/*               Roemerstrasse 52                                            */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1998-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -37,6 +37,7 @@
 
 /* common */
 #include "addrsize.h"
+#include "symdefs.h"
 #include "xmalloc.h"
 
 /* ca65 */
@@ -85,11 +86,14 @@ SymEntry* NewSymEntry (const StrBuf* Name, unsigned Flags)
     S->Right             = 0;
     S->Locals            = 0;
     S->Sym.Tab    = 0;
-    S->Pos               = CurPos;
+    S->LineInfos  = EmptyCollection;
+    GetFullLineInfo (&S->LineInfos, 1);
     for (I = 0; I < sizeof (S->GuessedUse) / sizeof (S->GuessedUse[0]); ++I) {
         S->GuessedUse[I] = 0;
     }
     S->Flags             = Flags;
+    S->DebugSymId = ~0U;
+    S->ImportId   = ~0U;
     S->Expr       = 0;
     S->ExprRefs   = AUTO_COLLECTION_INITIALIZER;
     S->ExportSize = ADDR_SIZE_DEFAULT;
@@ -284,9 +288,9 @@ void SymDef (SymEntry* S, ExprNode* Expr, unsigned char AddrSize, unsigned Flags
             S->ExportSize = S->AddrSize;
         } else if (S->AddrSize > S->ExportSize) {
             /* We're exporting a symbol smaller than it actually is */
-            PWarning (GetSymPos (S), 1, "Symbol `%m%p' is %s but exported %s",
-                      GetSymName (S), AddrSizeToStr (S->AddrSize),
-                      AddrSizeToStr (S->ExportSize));
+            LIWarning (&S->LineInfos, 1, "Symbol `%m%p' is %s but exported %s",
+                       GetSymName (S), AddrSizeToStr (S->AddrSize),
+                       AddrSizeToStr (S->ExportSize));
         }
     }
 
@@ -575,7 +579,7 @@ void SymGuessedAddrSize (SymEntry* Sym, unsigned char AddrSize)
     }
 
     /* Ok, remember the file position */
-    Sym->GuessedUse[AddrSize-1] = xdup (&CurPos, sizeof (CurPos));
+    Sym->GuessedUse[AddrSize-1] = xdup (&CurTok.Pos, sizeof (CurTok.Pos));
 }
 
 
@@ -604,7 +608,7 @@ void SymImportFromGlobal (SymEntry* S)
 
 
 
-int SymIsConst (SymEntry* S, long* Val)
+int SymIsConst (const SymEntry* S, long* Val)
 /* Return true if the given symbol has a constant value. If Val is not NULL
  * and the symbol has a constant value, store it's value there.
  */
@@ -623,6 +627,11 @@ SymTable* GetSymParentScope (SymEntry* S)
     if ((S->Flags & SF_LOCAL) != 0) {
         /* This is a cheap local symbol */
         return 0;
+    } else if (S->Sym.Tab == 0) {
+        /* Symbol not in a table. This may happen if there have been errors
+         * before. Return NULL in this case to avoid further errors.
+         */
+        return 0;
     } else {
         /* This is a global symbol */
         return S->Sym.Tab->Parent;
@@ -662,11 +671,39 @@ long GetSymVal (SymEntry* S)
 
 
 
-unsigned GetSymIndex (const SymEntry* S)
-/* Return the symbol index for the given symbol */
+unsigned GetSymImportId (const SymEntry* S)
+/* Return the import id for the given symbol */
+{
+    PRECONDITION (S != 0 && (S->Flags & SF_IMPORT) && S->ImportId != ~0U);
+    return S->ImportId;
+}
+
+
+
+unsigned GetSymInfoFlags (const SymEntry* S, long* ConstVal)
+/* Return a set of flags used when writing symbol information into a file.
+ * If the SYM_CONST bit is set, ConstVal will contain the constant value
+ * of the symbol. The result does not include the condes count.
+ * See common/symdefs.h for more information.
+ */
+{
+    /* Setup info flags */
+    unsigned Flags = 0;
+    Flags |= SymIsConst (S, ConstVal)? SYM_CONST : SYM_EXPR;
+    Flags |= (S->Flags & SF_LABEL)? SYM_LABEL : SYM_EQUATE;
+    Flags |= (S->Flags & SF_LOCAL)? SYM_CHEAP_LOCAL : SYM_STD;
+
+    /* Return the result */
+    return Flags;
+}
+
+
+
+const FilePos* GetSymPos (const SymEntry* S)
+/* Return the position of first occurence in the source for the given symbol */
 {
-    PRECONDITION (S != 0 && (S->Flags & SF_INDEXED) != 0);
-    return S->Index;
+    /* The actual source entry is in slot zero */
+    return &((const LineInfo*) CollConstAt (&S->LineInfos, 0))->Pos;
 }