Linearize post-ops and casts.
[smatch.git] / symbol.h
blobde6344b7592de901a3c98a3289451ea05bbd46a7
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,
28 NS_PREPROCESSOR,
29 NS_TYPEDEF,
30 NS_STRUCT,
31 NS_ENUM,
32 NS_LABEL,
33 NS_SYMBOL,
34 NS_ITERATOR,
37 enum type {
38 SYM_BASETYPE,
39 SYM_NODE,
40 SYM_PTR,
41 SYM_FN,
42 SYM_ARRAY,
43 SYM_STRUCT,
44 SYM_UNION,
45 SYM_ENUM,
46 SYM_TYPEDEF,
47 SYM_TYPEOF,
48 SYM_MEMBER,
49 SYM_BITFIELD,
50 SYM_LABEL,
53 struct ctype {
54 unsigned long modifiers;
55 unsigned long alignment;
56 unsigned int contextmask, context, as;
57 struct symbol *base_type;
60 struct symbol_op {
61 int (*evaluate)(struct expression *);
62 void (*expand)(struct expression *);
63 };
65 struct symbol {
66 enum namespace namespace:8;
67 enum type type:8;
68 struct position pos; /* Where this symbol was declared */
69 struct ident *ident; /* What identifier this symbol is associated with */
70 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
71 struct symbol **id_list; /* Backpointer to symbol list head */
72 struct symbol *replace; /* What is this symbol shadowed by in copy-expression */
73 struct scope *scope;
74 struct symbol *same_symbol;
75 struct symbol_op *op;
77 struct /* preprocessor_sym */ {
78 struct token *expansion;
79 struct token *arglist;
82 struct /* ctype_sym */ {
83 unsigned long offset;
84 unsigned int bit_size;
85 unsigned int bit_offset:8,
86 fieldwidth:8,
87 arg_count:10,
88 variadic:1,
89 used:1,
90 initialized:1;
91 struct expression *array_size;
92 struct ctype ctype;
93 struct symbol_list *arguments;
94 struct statement *stmt;
95 struct symbol_list *symbol_list;
96 struct expression *initializer;
97 struct basic_block *bb_target; /* label */
98 struct basic_block_list *bb_parents; /* sources */
99 long long value; /* Initial value */
101 void *aux; /* Auxiliary info, eg. backend information */
104 /* Modifiers */
105 #define MOD_AUTO 0x0001
106 #define MOD_REGISTER 0x0002
107 #define MOD_STATIC 0x0004
108 #define MOD_EXTERN 0x0008
110 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
112 #define MOD_CONST 0x0010
113 #define MOD_VOLATILE 0x0020
114 #define MOD_SIGNED 0x0040
115 #define MOD_UNSIGNED 0x0080
117 #define MOD_CHAR 0x0100
118 #define MOD_SHORT 0x0200
119 #define MOD_LONG 0x0400
120 #define MOD_LONGLONG 0x0800
122 #define MOD_TYPEDEF 0x1000
123 #define MOD_STRUCTOF 0x2000
124 #define MOD_UNIONOF 0x4000
125 #define MOD_ENUMOF 0x8000
127 #define MOD_TYPEOF 0x10000
128 #define MOD_ATTRIBUTE 0x20000
129 #define MOD_INLINE 0x40000
130 #define MOD_ADDRESSABLE 0x80000
132 #define MOD_NOCAST 0x100000
133 #define MOD_NODEREF 0x200000
134 #define MOD_ACCESSED 0x400000
135 #define MOD_TOPLEVEL 0x800000 // scoping..
137 #define MOD_LABEL 0x1000000
138 #define MOD_ASSIGNED 0x2000000
140 /* Basic types */
141 extern struct symbol void_type,
142 int_type,
143 label_type,
144 fp_type,
145 vector_type,
146 bad_type;
148 /* C types */
149 extern struct symbol bool_ctype, void_ctype,
150 char_ctype, uchar_ctype,
151 short_ctype, ushort_ctype,
152 int_ctype, uint_ctype,
153 long_ctype, ulong_ctype,
154 llong_ctype, ullong_ctype,
155 float_ctype, double_ctype, ldouble_ctype,
156 string_ctype, ptr_ctype, label_type;
159 /* Basic identifiers */
160 extern struct ident sizeof_ident,
161 alignof_ident,
162 __alignof_ident,
163 __alignof___ident,
164 if_ident,
165 else_ident,
166 switch_ident,
167 case_ident,
168 default_ident,
169 break_ident,
170 continue_ident,
171 for_ident,
172 while_ident,
173 do_ident,
174 goto_ident,
175 return_ident;
177 extern struct ident __asm___ident,
178 __asm_ident,
179 asm_ident,
180 __volatile___ident,
181 __volatile_ident,
182 volatile_ident,
183 __attribute___ident,
184 __attribute_ident,
185 defined_ident,
186 __VA_ARGS___ident,
187 __LINE___ident,
188 __FILE___ident,
189 pragma_ident;
191 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
193 extern struct symbol_list *used_list;
195 extern void access_symbol(struct symbol *);
198 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
199 extern void init_symbols(void);
200 extern struct symbol *alloc_symbol(struct position, int type);
201 extern void show_type(struct symbol *);
202 extern const char *modifier_string(unsigned long mod);
203 extern void show_symbol(struct symbol *);
204 extern void show_type_list(struct symbol *);
205 extern void show_symbol_list(struct symbol_list *, const char *);
206 extern void add_symbol(struct symbol_list **, struct symbol *);
207 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
209 extern struct symbol *examine_symbol_type(struct symbol *);
210 extern void examine_simple_symbol_type(struct symbol *);
211 extern const char *show_typename(struct symbol *sym);
213 extern void debug_symbol(struct symbol *);
214 extern void merge_type(struct symbol *sym, struct symbol *base_type);
215 extern void check_declaration(struct symbol *sym);
217 #endif /* SEMANTIC_H */