]> git.sur5r.net Git - cc65/blob - src/ca65/symtab.h
Move scope type definitions to common/
[cc65] / src / ca65 / symtab.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 symtab.h                                  */
4 /*                                                                           */
5 /*                 Symbol table for the ca65 macroassembler                  */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2011, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef SYMTAB_H
37 #define SYMTAB_H
38
39
40
41 #include <stdio.h>
42
43 /* common */
44 #include "exprdefs.h"
45 #include "inline.h"
46
47 /* ca65 */
48 #include "segrange.h"
49 #include "symentry.h"
50
51
52
53 /*****************************************************************************/
54 /*                                   Data                                    */
55 /*****************************************************************************/
56
57
58
59 /* Symbol table flags */
60 #define ST_NONE         0x00            /* No flags */
61 #define ST_DEFINED      0x01            /* Scope has been defined */
62
63 /* A symbol table */
64 typedef struct SymTable SymTable;
65 struct SymTable {
66     SymTable*           Next;           /* Pointer to next table in list */
67     SymTable*           Left;           /* Pointer to smaller entry */
68     SymTable*           Right;          /* Pointer to greater entry */
69     SymTable*           Parent;         /* Link to enclosing scope if any */
70     SymTable*           Childs;         /* Pointer to child scopes */
71     SymEntry*           OwnerSym;       /* Symbol that "owns" the scope */
72     Collection          SegRanges;      /* Segment ranges for this scope */
73     unsigned            Id;             /* Scope id */
74     unsigned short      Flags;          /* Symbol table flags */
75     unsigned char       AddrSize;       /* Address size */
76     unsigned char       Type;           /* Type of the scope */
77     unsigned            Level;          /* Lexical level */
78     unsigned            TableSlots;     /* Number of hash table slots */
79     unsigned            TableEntries;   /* Number of entries in the table */
80     unsigned            Name;           /* Name of the scope */
81     SymEntry*           Table[1];       /* Dynamic allocation */
82 };
83
84 /* Symbol tables */
85 extern SymTable*        CurrentScope;   /* Pointer to current symbol table */
86 extern SymTable*        RootScope;      /* Root symbol table */
87
88
89
90 /*****************************************************************************/
91 /*                                   Code                                    */
92 /*****************************************************************************/
93
94
95
96 void SymEnterLevel (const StrBuf* ScopeName, unsigned char Type,
97                     unsigned char AddrSize, SymEntry* OwnerSym);
98 /* Enter a new lexical level */
99
100 void SymLeaveLevel (void);
101 /* Leave the current lexical level */
102
103 SymTable* SymFindScope (SymTable* Parent, const StrBuf* Name, int AllocNew);
104 /* Find a scope in the given enclosing scope */
105
106 SymTable* SymFindAnyScope (SymTable* Parent, const StrBuf* Name);
107 /* Find a scope in the given or any of its parent scopes. The function will
108  * never create a new symbol, since this can only be done in one specific
109  * scope.
110  */
111
112 SymEntry* SymFindLocal (SymEntry* Parent, const StrBuf* StrBuf, int AllocNew);
113 /* Find a cheap local symbol. If AllocNew is given and the entry is not
114  * found, create a new one. Return the entry found, or the new entry created,
115  * or - in case AllocNew is zero - return 0.
116  */
117
118 SymEntry* SymFind (SymTable* Scope, const StrBuf* Name, int AllocNew);
119 /* Find a new symbol table entry in the given table. If AllocNew is given and
120  * the entry is not found, create a new one. Return the entry found, or the
121  * new entry created, or - in case AllocNew is zero - return 0.
122  */
123
124 SymEntry* SymFindAny (SymTable* Scope, const StrBuf* Name);
125 /* Find a symbol in the given or any of its parent scopes. The function will
126  * never create a new symbol, since this can only be done in one specific
127  * scope.
128  */
129
130 #if defined(HAVE_INLINE)
131 INLINE unsigned char GetSymTabType (const SymTable* S)
132 /* Return the type of the given symbol table */
133 {
134     return S->Type;
135 }
136 #else
137 #  define GetSymTabType(S)      ((S)->Type)
138 #endif
139
140 unsigned char GetCurrentSymTabType ();
141 /* Return the type of the current symbol table */
142
143 void SymCheck (void);
144 /* Run through all symbols and check for anomalies and errors */
145
146 void SymDump (FILE* F);
147 /* Dump the symbol table */
148
149 void WriteImports (void);
150 /* Write the imports list to the object file */
151
152 void WriteExports (void);
153 /* Write the exports list to the object file */
154
155 void WriteDbgSyms (void);
156 /* Write a list of all symbols to the object file */
157
158 void WriteScopes (void);
159 /* Write the scope table to the object file */
160
161
162
163 /* End of symtab.h */
164
165 #endif
166
167
168