/* */
/* */
/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2003 Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* common */
#include "exprdefs.h"
+#include "inline.h"
/* ca65 */
#include "symentry.h"
/*****************************************************************************/
-/* Code */
+/* Data */
/*****************************************************************************/
-void SymEnterLevel (void);
-/* Enter a new lexical level */
+/* Symbol table flags */
+#define ST_NONE 0x00 /* No flags */
+#define ST_DEFINED 0x01 /* Scope has been defined */
-void SymLeaveLevel (void);
-/* Leave the current lexical level */
+/* Symbol table types */
+#define ST_GLOBAL 0x00 /* Root level */
+#define ST_PROC 0x01 /* .PROC */
+#define ST_SCOPE 0x02 /* .SCOPE */
+#define ST_STRUCT 0x03 /* .STRUCT/.UNION */
+#define ST_ENUM 0x04 /* .ENUM */
+#define ST_UNDEF 0xFF
-void SymDef (const char* Name, ExprNode* Expr, int ZP);
-/* Define a new symbol */
+/* A symbol table */
+typedef struct SymTable SymTable;
+struct SymTable {
+ SymTable* Left; /* Pointer to smaller entry */
+ SymTable* Right; /* Pointer to greater entry */
+ SymTable* Parent; /* Link to enclosing scope if any */
+ SymTable* Childs; /* Pointer to child scopes */
+ unsigned short Flags; /* Symbol table flags */
+ unsigned char AddrSize; /* Address size */
+ unsigned char Type; /* Type of the scope */
+ unsigned Level; /* Lexical level */
+ unsigned TableSlots; /* Number of hash table slots */
+ unsigned TableEntries; /* Number of entries in the table */
+ unsigned Name; /* Name of the scope */
+ SymEntry* Table[1]; /* Dynamic allocation */
+};
-SymEntry* SymRef (const char* Name);
-/* Search for the symbol and return it */
+/* Symbol tables */
+SymTable* CurrentScope; /* Pointer to current symbol table */
+SymTable* RootScope; /* Root symbol table */
-SymEntry* SymRefGlobal (const char* Name);
-/* Search for the symbol in the global namespace and return it */
-int SymIsDef (const char* Name);
-/* Return true if the given symbol is already defined */
-int SymIsRef (const char* Name);
-/* Return true if the given symbol has been referenced */
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
-void SymImport (const char* Name, int ZP);
-/* Mark the given symbol as an imported symbol */
-void SymExport (const char* Name, int ZP);
-/* Mark the given symbol as an exported symbol */
-void SymGlobal (const char* Name, int ZP);
-/* Mark the given symbol as a global symbol, that is, as a symbol that is
- * either imported or exported.
- */
+void SymEnterLevel (const char* ScopeName, unsigned char Type, unsigned char AddrSize);
+/* Enter a new lexical level */
+
+void SymLeaveLevel (void);
+/* Leave the current lexical level */
+
+SymTable* SymFindScope (SymTable* Parent, const char* Name, int AllocNew);
+/* Find a scope in the given enclosing scope */
-void SymInitializer (const char* Name, int ZP);
-/* Mark the given symbol as an initializer. This will also mark the symbol as
- * an export. Initializers may never be zero page symbols, the ZP parameter
- * is supplied to make the prototype the same as the other functions (this
- * is used in pseudo.c). Passing something else but zero as ZP argument will
- * trigger an internal error.
+SymTable* SymFindAnyScope (SymTable* Parent, const char* Name);
+/* Find a scope in the given or any of its parent scopes. The function will
+ * never create a new symbol, since this can only be done in one specific
+ * scope.
*/
-int SymIsConst (SymEntry* Sym);
-/* Return true if the given symbol has a constant value */
+SymEntry* SymFind (SymTable* Scope, const char* Name, int AllocNew);
+/* Find a new symbol table entry in the given table. If AllocNew is given and
+ * the entry is not found, create a new one. Return the entry found, or the
+ * new entry created, or - in case AllocNew is zero - return 0.
+ */
int SymIsZP (SymEntry* Sym);
/* Return true if the symbol is explicitly marked as zeropage symbol */
-int SymIsImport (SymEntry* Sym);
-/* Return true if the given symbol is marked as import */
-
-int SymHasExpr (SymEntry* Sym);
-/* Return true if the given symbol has an associated expression */
-
-void SymMarkUser (SymEntry* Sym);
-/* Set a user mark on the specified symbol */
-
-void SymUnmarkUser (SymEntry* Sym);
-/* Remove a user mark from the specified symbol */
-
-int SymHasUserMark (SymEntry* Sym);
-/* Return the state of the user mark for the specified symbol */
-
-long GetSymVal (SymEntry* Sym);
-/* Return the symbol value */
-
-ExprNode* GetSymExpr (SymEntry* Sym);
-/* Get the expression for a non-const symbol */
-
-const char* GetSymName (SymEntry* Sym);
-/* Return the name of the symbol */
-
-unsigned GetSymIndex (SymEntry* Sym);
-/* Return the symbol index for the given symbol */
+#if defined(HAVE_INLINE)
+INLINE unsigned char GetSymTabType (const SymTable* S)
+/* Return the type of the given symbol table */
+{
+ return S->Type;
+}
+#else
+# define GetSymTabType(S) ((S)->Type)
+#endif
-const FilePos* GetSymPos (SymEntry* Sym);
-/* Return the position of first occurence in the source for the given symbol */
+unsigned char GetCurrentSymTabType ();
+/* Return the type of the current symbol table */
void SymCheck (void);
/* Run through all symbols and check for anomalies and errors */