/* */
/* */
/* */
-/* (C) 1998-2011, Ullrich von Bassewitz */
+/* (C) 1998-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
#define SF_IMPORT 0x0008 /* Import this symbol */
#define SF_GLOBAL 0x0010 /* Global symbol */
#define SF_LOCAL 0x0020 /* Cheap local symbol */
-#define SF_LABEL 0x0080 /* Used as a label */
-#define SF_VAR 0x0100 /* Variable symbol */
-#define SF_FORCED 0x0400 /* Forced import, SF_IMPORT also set */
-#define SF_MULTDEF 0x2000 /* Multiply defined symbol */
-#define SF_DEFINED 0x4000 /* Defined */
-#define SF_REFERENCED 0x8000 /* Referenced */
+#define SF_LABEL 0x0040 /* Used as a label */
+#define SF_VAR 0x0080 /* Variable symbol */
+#define SF_FORCED 0x0100 /* Forced import, SF_IMPORT also set */
+#define SF_FIXED 0x0200 /* May not be trampoline */
+#define SF_MULTDEF 0x1000 /* Multiply defined symbol */
+#define SF_DEFINED 0x2000 /* Defined */
+#define SF_REFERENCED 0x4000 /* Referenced */
/* Combined values */
#define SF_REFIMP (SF_REFERENCED|SF_IMPORT) /* A ref'd import */
/* */
/* */
/* */
-/* (C) 1998-2011, Ullrich von Bassewitz */
+/* (C) 1998-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
}
}
+ /* Mark the scope as closed */
+ CurrentScope->Flags |= ST_CLOSED;
+
/* Leave the scope */
CurrentScope = CurrentScope->Parent;
}
/* If we found an entry, return it */
if (Cmp == 0) {
+ if (SymTabIsClosed (Scope)) {
+ S->Flags |= SF_FIXED;
+ }
return S;
}
if (AllocNew) {
- /* Otherwise create a new entry, insert and return it */
+ /* Otherwise create a new entry, insert and return it. If the scope is
+ * already closed, mark the symbol as fixed so it won't be resolved
+ * by a symbol in the enclosing scopes later.
+ */
SymEntry* N = NewSymEntry (Name, SF_NONE);
+ if (SymTabIsClosed (Scope)) {
+ N->Flags |= SF_FIXED;
+ }
N->Sym.Tab = Scope;
if (S == 0) {
Scope->Table[Hash] = N;
* because for such symbols there is a real entry in one of the parent
* scopes.
*/
- Sym = SymFind (Scope, Name, SYM_FIND_EXISTING);
- if (Sym) {
+ unsigned Hash = HashBuf (Name) % Scope->TableSlots;
+ if (SymSearchTree (Scope->Table[Hash], Name, &Sym) == 0) {
if (Sym->Flags & SF_UNUSED) {
Sym = 0;
} else {
{
/* Undefined symbol. It may be...
*
- * - An undefined symbol in a nested lexical level. In this
- * case, search for the symbol in the higher levels and
+ * - An undefined symbol in a nested lexical level. If the symbol is not
+ * fixed to this level, search for the symbol in the higher levels and
* make the entry a trampoline entry if we find one.
*
- * - If the symbol is not found, it is a real undefined symbol.
- * If the AutoImport flag is set, make it an import. If the
- * AutoImport flag is not set, it's an error.
+ * - If the symbol is not found, it is a real undefined symbol. If the
+ * AutoImport flag is set, make it an import. If the AutoImport flag is
+ * not set, it's an error.
*/
SymEntry* Sym = 0;
- SymTable* Tab = GetSymParentScope (S);
- while (Tab) {
- Sym = SymFind (Tab, GetStrBuf (S->Name), SYM_FIND_EXISTING);
- if (Sym && (Sym->Flags & (SF_DEFINED | SF_IMPORT)) != 0) {
- /* We've found a symbol in a higher level that is
- * either defined in the source, or an import.
- */
- break;
+ if ((S->Flags & SF_FIXED) == 0) {
+ SymTable* Tab = GetSymParentScope (S);
+ while (Tab) {
+ Sym = SymFind (Tab, GetStrBuf (S->Name), SYM_FIND_EXISTING);
+ if (Sym && (Sym->Flags & (SF_DEFINED | SF_IMPORT)) != 0) {
+ /* We've found a symbol in a higher level that is
+ * either defined in the source, or an import.
+ */
+ break;
+ }
+ /* No matching symbol found in this level. Look further */
+ Tab = Tab->Parent;
}
- /* No matching symbol found in this level. Look further */
- Tab = Tab->Parent;
}
if (Sym) {
/* */
/* */
/* */
-/* (C) 1998-2011, Ullrich von Bassewitz */
+/* (C) 1998-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* Symbol table flags */
#define ST_NONE 0x00 /* No flags */
#define ST_DEFINED 0x01 /* Scope has been defined */
+#define ST_CLOSED 0x02 /* Scope is closed */
/* A symbol table */
typedef struct SymTable SymTable;
# define GetSymTabType(S) ((S)->Type)
#endif
+#if defined(HAVE_INLINE)
+INLINE int SymTabIsClosed (const SymTable* S)
+/* Return true if the symbol table has been closed */
+{
+ return (S->Flags & ST_CLOSED) != 0;
+}
+#else
+# define SymTabIsClosed(S) (((S)->Flags & ST_CLOSED) != 0)
+#endif
+
void SymCheck (void);
/* Run through all symbols and check for anomalies and errors */