X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fca65%2Fsymtab.h;h=ea7e66515c7bed5e036b9b522ee3b74c3671d77d;hb=c52916f461f5f723bc8f2146e346dcb2de3b2f18;hp=9176bc7022bb2372b0530b283980c8742f74ff62;hpb=bb115c8ae2828eaff69016ca592079827bb7e0a3;p=cc65 diff --git a/src/ca65/symtab.h b/src/ca65/symtab.h index 9176bc702..ea7e66515 100644 --- a/src/ca65/symtab.h +++ b/src/ca65/symtab.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (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 */ @@ -42,85 +42,99 @@ /* common */ #include "exprdefs.h" - +#include "inline.h" + /* ca65 */ #include "symentry.h" /*****************************************************************************/ -/* Code */ +/* Data */ /*****************************************************************************/ -void SymEnterLevel (void); -/* Enter a new lexical level */ - -void SymLeaveLevel (void); -/* Leave the current lexical level */ - -void SymDef (const char* Name, ExprNode* Expr, int ZP); -/* Define a new symbol */ +/* Symbol table flags */ +#define ST_NONE 0x00 /* No flags */ +#define ST_DEFINED 0x01 /* Scope has been defined */ -SymEntry* SymRef (const char* Name); -/* Search for the symbol and return it */ +/* A symbol table */ +typedef struct SymTable SymTable; +struct SymTable { + SymTable* Next; /* Pointer to next table in list */ + 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 */ + SymEntry* Label; /* Scope label */ + Collection Spans; /* Spans for this scope */ + unsigned Id; /* Scope id */ + 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* SymRefGlobal (const char* Name); -/* Search for the symbol in the global namespace and return it */ +/* Symbol tables */ +extern SymTable* CurrentScope; /* Pointer to current symbol table */ +extern SymTable* RootScope; /* Root symbol table */ -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 */ - -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. - */ -int SymIsConst (SymEntry* Sym); -/* Return true if the given symbol has a constant value */ -int SymIsZP (SymEntry* Sym); -/* Return true if the symbol is explicitly marked as zeropage symbol */ +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ -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 SymEnterLevel (const StrBuf* ScopeName, unsigned char Type, + unsigned char AddrSize, SymEntry* OwnerSym); +/* Enter a new lexical level */ -void SymUnmarkUser (SymEntry* Sym); -/* Remove a user mark from the specified symbol */ +void SymLeaveLevel (void); +/* Leave the current lexical level */ -int SymHasUserMark (SymEntry* Sym); -/* Return the state of the user mark for the specified symbol */ +SymTable* SymFindScope (SymTable* Parent, const StrBuf* Name, int AllocNew); +/* Find a scope in the given enclosing scope */ -long GetSymVal (SymEntry* Sym); -/* Return the symbol value */ +SymTable* SymFindAnyScope (SymTable* Parent, const StrBuf* 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. + */ -ExprNode* GetSymExpr (SymEntry* Sym); -/* Get the expression for a non-const symbol */ +SymEntry* SymFindLocal (SymEntry* Parent, const StrBuf* StrBuf, int AllocNew); +/* Find a cheap local symbol. 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. + */ -const char* GetSymName (SymEntry* Sym); -/* Return the name of the symbol */ +SymEntry* SymFind (SymTable* Scope, const StrBuf* 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. + */ -unsigned GetSymIndex (SymEntry* Sym); -/* Return the symbol index for the given symbol */ +SymEntry* SymFindAny (SymTable* Scope, const StrBuf* Name); +/* Find a symbol 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. + */ -const FilePos* GetSymPos (SymEntry* Sym); -/* Return the position of first occurence in the source 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 void SymCheck (void); /* Run through all symbols and check for anomalies and errors */ @@ -137,6 +151,9 @@ void WriteExports (void); void WriteDbgSyms (void); /* Write a list of all symbols to the object file */ +void WriteScopes (void); +/* Write the scope table to the object file */ + /* End of symtab.h */ @@ -145,4 +162,3 @@ void WriteDbgSyms (void); -