[PATCH] fix of compound literals on inlining
[smatch.git] / symbol.h
blobbb71dfed890ab304570c6729df531ff6e2444c05
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_INVISIBLEMACRO = 128,
38 enum type {
39 SYM_UNINITIALIZED,
40 SYM_PREPROCESSOR,
41 SYM_BASETYPE,
42 SYM_NODE,
43 SYM_PTR,
44 SYM_FN,
45 SYM_ARRAY,
46 SYM_STRUCT,
47 SYM_UNION,
48 SYM_ENUM,
49 SYM_TYPEDEF,
50 SYM_TYPEOF,
51 SYM_MEMBER,
52 SYM_BITFIELD,
53 SYM_LABEL,
54 SYM_RESTRICT,
55 SYM_BAD,
58 struct ctype {
59 unsigned long modifiers;
60 unsigned long alignment;
61 unsigned int in_context, out_context, as;
62 struct symbol *base_type;
65 struct symbol_op {
66 int (*evaluate)(struct expression *);
67 int (*expand)(struct expression *, int);
68 };
70 extern int expand_safe_p(struct expression *expr, int cost);
71 extern int expand_constant_p(struct expression *expr, int cost);
73 struct symbol {
74 enum namespace namespace:8;
75 enum type type:8;
76 unsigned char used:1, weak:1;
77 struct position pos; /* Where this symbol was declared */
78 struct ident *ident; /* What identifier this symbol is associated with */
79 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
80 struct symbol **id_list; /* Backpointer to symbol list head */
81 struct symbol *replace; /* What is this symbol shadowed by in copy-expression */
82 struct scope *scope;
83 struct symbol *same_symbol;
84 struct symbol_op *op;
86 union {
87 struct /* NS_MACRO */ {
88 struct token *expansion;
89 struct token *arglist;
91 struct /* NS_PREPROCESSOR */ {
92 int (*handler)(struct stream *, struct token **, struct token *);
94 struct /* NS_SYMBOL */ {
95 unsigned long offset;
96 int bit_size;
97 unsigned int bit_offset:8,
98 arg_count:10,
99 variadic:1,
100 initialized:1,
101 examined:1,
102 expanding:1,
103 evaluated:1;
104 struct expression *array_size;
105 struct ctype ctype;
106 struct symbol_list *arguments;
107 struct statement *stmt;
108 struct symbol_list *symbol_list;
109 struct statement *inline_stmt;
110 struct symbol_list *inline_symbol_list;
111 struct expression *initializer;
112 long long value; /* Initial value */
115 union /* backend */ {
116 struct basic_block *bb_target; /* label */
117 void *aux; /* Auxiliary info, eg. backend information */
119 pseudo_t pseudo;
122 /* Modifiers */
123 #define MOD_AUTO 0x0001
124 #define MOD_REGISTER 0x0002
125 #define MOD_STATIC 0x0004
126 #define MOD_EXTERN 0x0008
128 #define MOD_CONST 0x0010
129 #define MOD_VOLATILE 0x0020
130 #define MOD_SIGNED 0x0040
131 #define MOD_UNSIGNED 0x0080
133 #define MOD_CHAR 0x0100
134 #define MOD_SHORT 0x0200
135 #define MOD_LONG 0x0400
136 #define MOD_LONGLONG 0x0800
138 #define MOD_TYPEDEF 0x1000
139 #define MOD_STRUCTOF 0x2000
140 #define MOD_UNIONOF 0x4000
141 #define MOD_ENUMOF 0x8000
143 #define MOD_TYPEOF 0x10000
144 #define MOD_ATTRIBUTE 0x20000
145 #define MOD_INLINE 0x40000
146 #define MOD_ADDRESSABLE 0x80000
148 #define MOD_NOCAST 0x100000
149 #define MOD_NODEREF 0x200000
150 #define MOD_ACCESSED 0x400000
151 #define MOD_TOPLEVEL 0x800000 // scoping..
153 #define MOD_LABEL 0x1000000
154 #define MOD_ASSIGNED 0x2000000
155 #define MOD_TYPE 0x4000000
156 #define MOD_SAFE 0x8000000 // non-null/non-trapping pointer
158 #define MOD_USERTYPE 0x10000000
159 #define MOD_FORCE 0x20000000
160 #define MOD_EXPLICITLY_SIGNED 0x40000000
161 #define MOD_BITWISE 0x80000000
163 #define MOD_NONLOCAL (MOD_EXTERN | MOD_TOPLEVEL)
164 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
165 #define MOD_SPECIALBITS (MOD_STRUCTOF | MOD_UNIONOF | MOD_ENUMOF | MOD_ATTRIBUTE | MOD_TYPEOF)
166 #define MOD_SIGNEDNESS (MOD_SIGNED | MOD_UNSIGNED | MOD_EXPLICITLY_SIGNED)
167 #define MOD_SPECIFIER (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG | MOD_SIGNEDNESS)
168 #define MOD_SIZE (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG)
169 #define MOD_IGNORE (MOD_TOPLEVEL | MOD_STORAGE | MOD_ADDRESSABLE | \
170 MOD_ASSIGNED | MOD_USERTYPE | MOD_FORCE | MOD_ACCESSED | MOD_EXPLICITLY_SIGNED)
173 /* Current parsing/evaluation function */
174 extern struct symbol *current_fn;
176 /* Abstract types */
177 extern struct symbol int_type,
178 fp_type;
180 /* C types */
181 extern struct symbol bool_ctype, void_ctype, type_ctype,
182 char_ctype, schar_ctype, uchar_ctype,
183 short_ctype, sshort_ctype, ushort_ctype,
184 int_ctype, sint_ctype, uint_ctype,
185 long_ctype, slong_ctype, ulong_ctype,
186 llong_ctype, sllong_ctype, ullong_ctype,
187 float_ctype, double_ctype, ldouble_ctype,
188 string_ctype, ptr_ctype, lazy_ptr_ctype,
189 incomplete_ctype, label_ctype, bad_ctype;
191 /* Special internal symbols */
192 extern struct symbol zero_int;
194 #define __IDENT(n,str,res) \
195 extern struct ident n
196 #include "ident-list.h"
198 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
200 extern struct symbol_list *translation_unit_used_list;
202 extern void access_symbol(struct symbol *);
204 extern const char * type_difference(struct symbol *target, struct symbol *source,
205 unsigned long target_mod_ignore, unsigned long source_mod_ignore);
207 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
208 extern struct symbol *create_symbol(int stream, const char *name, int type, int namespace);
209 extern void init_symbols(void);
210 extern void init_ctype(void);
211 extern struct symbol *alloc_symbol(struct position, int type);
212 extern void show_type(struct symbol *);
213 extern const char *modifier_string(unsigned long mod);
214 extern void show_symbol(struct symbol *);
215 extern int show_symbol_expr_init(struct symbol *sym);
216 extern void show_type_list(struct symbol *);
217 extern void show_symbol_list(struct symbol_list *, const char *);
218 extern void add_symbol(struct symbol_list **, struct symbol *);
219 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
221 extern struct symbol *examine_symbol_type(struct symbol *);
222 extern void examine_simple_symbol_type(struct symbol *);
223 extern const char *show_typename(struct symbol *sym);
225 extern void debug_symbol(struct symbol *);
226 extern void merge_type(struct symbol *sym, struct symbol *base_type);
227 extern void check_declaration(struct symbol *sym);
229 static inline struct symbol *get_base_type(const struct symbol *sym)
231 return examine_symbol_type(sym->ctype.base_type);
234 static inline int is_int_type(const struct symbol *type)
236 if (type->type == SYM_NODE)
237 type = type->ctype.base_type;
238 if (type->type == SYM_ENUM)
239 type = type->ctype.base_type;
240 return type->type == SYM_BITFIELD ||
241 type->ctype.base_type == &int_type;
244 static inline int get_sym_type(struct symbol *type)
246 if (type->type == SYM_NODE)
247 type = type->ctype.base_type;
248 if (type->type == SYM_ENUM)
249 type = type->ctype.base_type;
250 return type->type;
253 #define is_restricted_type(type) (get_sym_type(type) == SYM_RESTRICT)
254 #define is_bitfield_type(type) (get_sym_type(type) == SYM_BITFIELD)
255 extern int is_ptr_type(struct symbol *);
257 #endif /* SEMANTIC_H */