Add test-suite comment to bad-array-designated-initializer.c
[smatch.git] / symbol.h
blob2bde84dc91b788432273260ce4a7e8a19d4b2e73
1 #ifndef SYMBOL_H
2 #define SYMBOL_H
3 /*
4 * Basic symbol and namespace definitions.
6 * Copyright (C) 2003 Transmeta Corp.
7 * 2003 Linus Torvalds
9 * Licensed under the Open Software License version 1.1
12 #include "token.h"
15 * An identifier with semantic meaning is a "symbol".
17 * There's a 1:n relationship: each symbol is always
18 * associated with one identifier, while each identifier
19 * can have one or more semantic meanings due to C scope
20 * rules.
22 * The progression is symbol -> token -> identifier. The
23 * token contains the information on where the symbol was
24 * declared.
26 enum namespace {
27 NS_NONE = 0,
28 NS_MACRO = 1,
29 NS_TYPEDEF = 2,
30 NS_STRUCT = 4, // Also used for unions and enums.
31 NS_LABEL = 8,
32 NS_SYMBOL = 16,
33 NS_ITERATOR = 32,
34 NS_PREPROCESSOR = 64,
35 NS_UNDEF = 128,
36 NS_KEYWORD = 256,
39 enum type {
40 SYM_UNINITIALIZED,
41 SYM_PREPROCESSOR,
42 SYM_BASETYPE,
43 SYM_NODE,
44 SYM_PTR,
45 SYM_FN,
46 SYM_ARRAY,
47 SYM_STRUCT,
48 SYM_UNION,
49 SYM_ENUM,
50 SYM_TYPEDEF,
51 SYM_TYPEOF,
52 SYM_MEMBER,
53 SYM_BITFIELD,
54 SYM_LABEL,
55 SYM_RESTRICT,
56 SYM_FOULED,
57 SYM_KEYWORD,
58 SYM_BAD,
61 enum keyword {
62 KW_SPECIFIER = 1 << 0,
63 KW_MODIFIER = 1 << 1,
64 KW_QUALIFIER = 1 << 2,
65 KW_ATTRIBUTE = 1 << 3,
66 KW_TYPEOF = 1 << 4,
67 KW_STATEMENT = 1 << 5,
68 KW_ASM = 1 << 6,
69 KW_MODE = 1 << 7,
72 struct context {
73 struct expression *context;
74 unsigned int in, out;
77 extern struct context *alloc_context(void);
79 DECLARE_PTR_LIST(context_list, struct context);
81 struct ctype {
82 unsigned long modifiers;
83 unsigned long alignment;
84 struct context_list *contexts;
85 unsigned int as;
86 struct symbol *base_type;
89 struct symbol_op {
90 enum keyword type;
91 int (*evaluate)(struct expression *);
92 int (*expand)(struct expression *, int);
93 int (*args)(struct expression *);
95 /* keywords */
96 struct token *(*declarator)(struct token *token, struct ctype *ctype);
97 struct token *(*statement)(struct token *token, struct statement *stmt);
98 struct token *(*toplevel)(struct token *token, struct symbol_list **list);
99 struct token *(*attribute)(struct token *token, struct symbol *attr, struct ctype *ctype);
102 extern int expand_safe_p(struct expression *expr, int cost);
103 extern int expand_constant_p(struct expression *expr, int cost);
105 #define SYM_ATTR_WEAK 0
106 #define SYM_ATTR_NORMAL 1
107 #define SYM_ATTR_STRONG 2
109 struct symbol {
110 enum type type:8;
111 enum namespace namespace:9;
112 unsigned char used:1, attr:2, enum_member:1;
113 struct position pos; /* Where this symbol was declared */
114 struct ident *ident; /* What identifier this symbol is associated with */
115 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
116 struct symbol **id_list; /* Back pointer to symbol list head */
117 struct symbol *replace; /* What is this symbol shadowed by in copy-expression */
118 struct scope *scope;
119 union {
120 struct symbol *same_symbol;
121 struct symbol *next_subobject;
124 struct symbol_op *op;
126 union {
127 struct /* NS_MACRO */ {
128 struct token *expansion;
129 struct token *arglist;
130 struct scope *used_in;
132 struct /* NS_PREPROCESSOR */ {
133 int (*handler)(struct stream *, struct token **, struct token *);
134 int normal;
136 struct /* NS_SYMBOL */ {
137 unsigned long offset;
138 int bit_size;
139 unsigned int bit_offset:8,
140 arg_count:10,
141 variadic:1,
142 initialized:1,
143 examined:1,
144 expanding:1,
145 evaluated:1,
146 string:1;
147 struct expression *array_size;
148 struct ctype ctype;
149 struct symbol_list *arguments;
150 struct statement *stmt;
151 struct symbol_list *symbol_list;
152 struct statement *inline_stmt;
153 struct symbol_list *inline_symbol_list;
154 struct expression *initializer;
155 struct entrypoint *ep;
156 long long value; /* Initial value */
159 union /* backend */ {
160 struct basic_block *bb_target; /* label */
161 void *aux; /* Auxiliary info, e.g. backend information */
162 struct { /* sparse ctags */
163 char kind;
164 unsigned char visited:1;
167 pseudo_t pseudo;
170 /* Modifiers */
171 #define MOD_AUTO 0x0001
172 #define MOD_REGISTER 0x0002
173 #define MOD_STATIC 0x0004
174 #define MOD_EXTERN 0x0008
176 #define MOD_CONST 0x0010
177 #define MOD_VOLATILE 0x0020
178 #define MOD_SIGNED 0x0040
179 #define MOD_UNSIGNED 0x0080
181 #define MOD_CHAR 0x0100
182 #define MOD_SHORT 0x0200
183 #define MOD_LONG 0x0400
184 #define MOD_LONGLONG 0x0800
186 #define MOD_TYPEDEF 0x1000
188 #define MOD_INLINE 0x40000
189 #define MOD_ADDRESSABLE 0x80000
191 #define MOD_NOCAST 0x100000
192 #define MOD_NODEREF 0x200000
193 #define MOD_ACCESSED 0x400000
194 #define MOD_TOPLEVEL 0x800000 // scoping..
196 #define MOD_LABEL 0x1000000
197 #define MOD_ASSIGNED 0x2000000
198 #define MOD_TYPE 0x4000000
199 #define MOD_SAFE 0x8000000 // non-null/non-trapping pointer
201 #define MOD_USERTYPE 0x10000000
202 #define MOD_FORCE 0x20000000
203 #define MOD_EXPLICITLY_SIGNED 0x40000000
204 #define MOD_BITWISE 0x80000000
206 #define MOD_NONLOCAL (MOD_EXTERN | MOD_TOPLEVEL)
207 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
208 #define MOD_SIGNEDNESS (MOD_SIGNED | MOD_UNSIGNED | MOD_EXPLICITLY_SIGNED)
209 #define MOD_SPECIFIER (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG | MOD_SIGNEDNESS)
210 #define MOD_SIZE (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG)
211 #define MOD_IGNORE (MOD_TOPLEVEL | MOD_STORAGE | MOD_ADDRESSABLE | \
212 MOD_ASSIGNED | MOD_USERTYPE | MOD_FORCE | MOD_ACCESSED | MOD_EXPLICITLY_SIGNED)
213 #define MOD_PTRINHERIT (MOD_VOLATILE | MOD_CONST | MOD_NODEREF | MOD_STORAGE)
216 /* Current parsing/evaluation function */
217 extern struct symbol *current_fn;
219 /* Abstract types */
220 extern struct symbol int_type,
221 fp_type;
223 /* C types */
224 extern struct symbol bool_ctype, void_ctype, type_ctype,
225 char_ctype, schar_ctype, uchar_ctype,
226 short_ctype, sshort_ctype, ushort_ctype,
227 int_ctype, sint_ctype, uint_ctype,
228 long_ctype, slong_ctype, ulong_ctype,
229 llong_ctype, sllong_ctype, ullong_ctype,
230 float_ctype, double_ctype, ldouble_ctype,
231 string_ctype, ptr_ctype, lazy_ptr_ctype,
232 incomplete_ctype, label_ctype, bad_ctype;
234 /* Special internal symbols */
235 extern struct symbol zero_int;
237 #define __IDENT(n,str,res) \
238 extern struct ident n
239 #include "ident-list.h"
241 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
243 extern struct symbol_list *translation_unit_used_list;
245 extern void access_symbol(struct symbol *);
247 extern const char * type_difference(struct symbol *target, struct symbol *source,
248 unsigned long target_mod_ignore, unsigned long source_mod_ignore);
250 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
251 extern struct symbol *create_symbol(int stream, const char *name, int type, int namespace);
252 extern void init_symbols(void);
253 extern void init_ctype(void);
254 extern struct symbol *alloc_symbol(struct position, int type);
255 extern void show_type(struct symbol *);
256 extern const char *modifier_string(unsigned long mod);
257 extern void show_symbol(struct symbol *);
258 extern int show_symbol_expr_init(struct symbol *sym);
259 extern void show_type_list(struct symbol *);
260 extern void show_symbol_list(struct symbol_list *, const char *);
261 extern void add_symbol(struct symbol_list **, struct symbol *);
262 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
264 extern struct symbol *examine_symbol_type(struct symbol *);
265 extern void examine_simple_symbol_type(struct symbol *);
266 extern const char *show_typename(struct symbol *sym);
267 extern const char *builtin_typename(struct symbol *sym);
268 extern const char *builtin_ctypename(struct ctype *ctype);
270 extern void debug_symbol(struct symbol *);
271 extern void merge_type(struct symbol *sym, struct symbol *base_type);
272 extern void check_declaration(struct symbol *sym);
274 static inline struct symbol *get_base_type(const struct symbol *sym)
276 return examine_symbol_type(sym->ctype.base_type);
279 static inline int is_int_type(const struct symbol *type)
281 if (type->type == SYM_NODE)
282 type = type->ctype.base_type;
283 if (type->type == SYM_ENUM)
284 type = type->ctype.base_type;
285 return type->type == SYM_BITFIELD ||
286 type->ctype.base_type == &int_type;
289 static inline int is_enum_type(const struct symbol *type)
291 if (type->type == SYM_NODE)
292 type = type->ctype.base_type;
293 return (type->type == SYM_ENUM);
296 static inline int get_sym_type(struct symbol *type)
298 if (type->type == SYM_NODE)
299 type = type->ctype.base_type;
300 if (type->type == SYM_ENUM)
301 type = type->ctype.base_type;
302 return type->type;
305 static inline struct symbol *lookup_keyword(struct ident *ident, enum namespace ns)
307 if (!ident->keyword)
308 return NULL;
309 return lookup_symbol(ident, ns);
312 #define is_restricted_type(type) (get_sym_type(type) == SYM_RESTRICT)
313 #define is_fouled_type(type) (get_sym_type(type) == SYM_FOULED)
314 #define is_bitfield_type(type) (get_sym_type(type) == SYM_BITFIELD)
315 extern int is_ptr_type(struct symbol *);
317 void create_fouled(struct symbol *type);
318 struct symbol *befoul(struct symbol *type);
320 #endif /* SYMBOL_H */