]> git.sur5r.net Git - cc65/blob - src/cc65/symentry.h
Fixed an error in struct compare. For one, the behaviour was not standard
[cc65] / src / cc65 / symentry.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                symentry.h                                 */
4 /*                                                                           */
5 /*               Symbol table entries for the cc65 C compiler                */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2002 Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
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 SYMENTRY_H
37 #define SYMENTRY_H
38
39
40
41 #include <stdio.h>
42
43 /* cc65 */
44 #include "datatype.h"
45
46
47
48 /*****************************************************************************/
49 /*                                  Forwards                                 */
50 /*****************************************************************************/
51
52
53
54 struct Segments;
55
56
57
58 /*****************************************************************************/
59 /*                              struct SymEntry                              */
60 /*****************************************************************************/
61
62
63
64 /* Storage classes and flags */
65 #define SC_AUTO         0x0001U
66 #define SC_REGISTER     0x0002U /* Register variable, is in static storage */
67 #define SC_STATIC       0x0004U
68 #define SC_EXTERN       0x0008U
69
70 #define SC_ENUM         0x0030U /* An enum (numeric constant) */
71 #define SC_CONST        0x0020U /* A numeric constant with a type */
72 #define SC_LABEL        0x0040U /* A goto label */
73 #define SC_PARAM        0x0080U /* This is a function parameter */
74 #define SC_FUNC         0x0100U /* Function entry */
75
76 #define SC_STORAGE      0x0400U /* Symbol with associated storage */
77 #define SC_DEFAULT      0x0800U /* Flag: default storage class was used */
78
79 #define SC_DEF          0x1000U /* Symbol is defined */
80 #define SC_REF          0x2000U /* Symbol is referenced */
81
82 #define SC_TYPE         0x4000U /* This is a type, struct, typedef, etc. */
83 #define SC_STRUCT       0x4001U /* Struct or union */
84 #define SC_SFLD         0x4002U /* Struct or union field */
85 #define SC_TYPEDEF      0x4003U /* A typedef */
86
87 #define SC_ZEROPAGE     0x8000U /* Symbol marked as zeropage */
88
89
90
91 /* Symbol table entry */
92 typedef struct SymEntry SymEntry;
93 struct SymEntry {
94     SymEntry*                   NextHash; /* Next entry in hash list */
95     SymEntry*                   PrevSym;  /* Previous symbol in dl list */
96     SymEntry*                   NextSym;  /* Next symbol double linked list */
97     SymEntry*                   Link;     /* General purpose single linked list */
98     struct SymTable*            Owner;    /* Symbol table the symbol is in */
99     unsigned                    Flags;    /* Symbol flags */
100     type*                       Type;     /* Symbol type */
101     char*                       AsmName;  /* Assembler name if any */
102
103     /* Data that differs for the different symbol types */
104     union {
105
106         /* Offset for locals or struct members */
107         int                     Offs;
108
109         /* Label name for static symbols */
110         unsigned                Label;
111
112         /* Value for constants (including enums) */
113         long                    ConstVal;
114
115         /* Data for structs/unions */
116         struct {
117             struct SymTable*    SymTab;   /* Member symbol table */
118             unsigned            Size;     /* Size of the union/struct */
119         } S;
120
121         /* Data for functions */
122         struct {
123             struct FuncDesc*    Func;     /* Function descriptor */
124             struct Segments*    Seg;      /* Segments for this function */
125         } F;
126
127     } V;
128     char                       Name[1]; /* Name, dynamically allocated */
129 };
130
131
132
133 /*****************************************************************************/
134 /*                                   Code                                    */
135 /*****************************************************************************/
136
137
138
139 SymEntry* NewSymEntry (const char* Name, unsigned Flags);
140 /* Create a new symbol table with the given name */
141
142 void FreeSymEntry (SymEntry* E);
143 /* Free a symbol entry */
144
145 void DumpSymEntry (FILE* F, const SymEntry* E);
146 /* Dump the given symbol table entry to the file in readable form */
147
148 int IsTypeDef (const SymEntry* E);
149 /* Return true if the given entry is a typedef entry */
150
151 void ChangeSymType (SymEntry* Entry, type* Type);
152 /* Change the type of the given symbol */
153
154 void ChangeAsmName (SymEntry* Entry, const char* NewAsmName);
155 /* Change the assembler name of the symbol */
156
157 int HasAnonName (const SymEntry* Entry);
158 /* Return true if the symbol entry has an anonymous name */
159
160
161
162 /* End of symentry.h */
163 #endif
164
165
166