evaluate_initializer() is now static to within evaluate.c
[smatch.git] / symbol.h
blob61324c1098a4f6bc8e3c293961875ccd436ee320
1 #ifndef SEMANTIC_H
2 #define SEMANTIC_H
3 /*
4 * Basic symbol and namespace definitions.
6 * Copyright (C) 2003 Transmeta Corp, all rights reserved
7 */
9 #include "token.h"
12 * An identifier with semantic meaning is a "symbol".
14 * There's a 1:n relationship: each symbol is always
15 * associated with one identifier, while each identifier
16 * can have one or more semantic meanings due to C scope
17 * rules.
19 * The progression is symbol -> token -> identifier. The
20 * token contains the information on where the symbol was
21 * declared.
23 enum namespace {
24 NS_NONE,
25 NS_PREPROCESSOR,
26 NS_TYPEDEF,
27 NS_STRUCT,
28 NS_ENUM,
29 NS_LABEL,
30 NS_SYMBOL,
33 enum type {
34 SYM_BASETYPE,
35 SYM_NODE,
36 SYM_PTR,
37 SYM_FN,
38 SYM_ARRAY,
39 SYM_STRUCT,
40 SYM_UNION,
41 SYM_ENUM,
42 SYM_TYPEDEF,
43 SYM_TYPEOF,
44 SYM_MEMBER,
45 SYM_BITFIELD,
46 SYM_LABEL,
49 struct ctype {
50 unsigned long modifiers;
51 unsigned long alignment;
52 unsigned int contextmask, context, as;
53 struct symbol *base_type;
56 struct symbol {
57 enum namespace namespace:8;
58 enum type type:8;
59 struct position pos; /* Where this symbol was declared */
60 struct ident *ident; /* What identifier this symbol is associated with */
61 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
62 struct symbol **id_list; /* Backpointer to symbol list head */
63 union {
64 struct preprocessor_sym {
65 int busy;
66 struct token *expansion;
67 struct token *arglist;
69 struct ctype_symbol {
70 struct symbol *next; /* Next symbol at this level */
71 unsigned long offset;
72 unsigned int bit_size;
73 unsigned int bit_offset:8,
74 fieldwidth:8,
75 arg_count:10,
76 variadic:1;
77 int array_size;
78 struct ctype ctype;
79 struct symbol_list *arguments;
80 struct statement *stmt;
81 struct symbol_list *symbol_list;
82 struct expression *initializer;
83 long long value; /* Initial value */
88 /* Modifiers */
89 #define MOD_AUTO 0x0001
90 #define MOD_REGISTER 0x0002
91 #define MOD_STATIC 0x0004
92 #define MOD_EXTERN 0x0008
94 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN)
96 #define MOD_CONST 0x0010
97 #define MOD_VOLATILE 0x0020
98 #define MOD_SIGNED 0x0040
99 #define MOD_UNSIGNED 0x0080
101 #define MOD_CHAR 0x0100
102 #define MOD_SHORT 0x0200
103 #define MOD_LONG 0x0400
104 #define MOD_LONGLONG 0x0800
106 #define MOD_TYPEDEF 0x1000
107 #define MOD_STRUCTOF 0x2000
108 #define MOD_UNIONOF 0x4000
109 #define MOD_ENUMOF 0x8000
111 #define MOD_TYPEOF 0x10000
112 #define MOD_ATTRIBUTE 0x20000
114 #define MOD_NOCAST 0x100000
115 #define MOD_NODEREF 0x200000
117 /* Basic types */
118 extern struct symbol void_type,
119 int_type,
120 fp_type,
121 vector_type,
122 bad_type;
124 /* C types */
125 extern struct symbol bool_ctype, void_ctype,
126 char_ctype, uchar_ctype,
127 short_ctype, ushort_ctype,
128 int_ctype, uint_ctype,
129 long_ctype, ulong_ctype,
130 llong_ctype, ullong_ctype,
131 float_ctype, double_ctype, ldouble_ctype,
132 string_ctype, ptr_ctype;
135 /* Basic identifiers */
136 extern struct ident sizeof_ident,
137 alignof_ident,
138 __alignof_ident,
139 __alignof___ident,
140 if_ident,
141 else_ident,
142 switch_ident,
143 case_ident,
144 default_ident,
145 break_ident,
146 continue_ident,
147 for_ident,
148 while_ident,
149 do_ident,
150 goto_ident,
151 return_ident;
153 extern struct ident __asm___ident,
154 __asm_ident,
155 asm_ident,
156 __volatile___ident,
157 __volatile_ident,
158 volatile_ident,
159 __attribute___ident,
160 __attribute_ident;
162 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
164 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
165 extern void init_symbols(void);
166 extern struct symbol *alloc_symbol(struct position, int type);
167 extern void show_type(struct symbol *);
168 extern const char *modifier_string(unsigned long mod);
169 extern void show_symbol(struct symbol *);
170 extern void show_type_list(struct symbol *);
171 extern void show_symbol_list(struct symbol_list *, const char *);
172 extern void add_symbol(struct symbol_list **, struct symbol *);
173 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
175 extern struct symbol *examine_symbol_type(struct symbol *);
176 extern void examine_simple_symbol_type(struct symbol *);
178 #endif /* SEMANTIC_H */