Flesh out inlining some more.
[smatch.git] / symbol.h
blob40f0b838144258c2b2543153d6caffe59d5b91ec
1 #ifndef SYMBOL_H
2 #define SYMBOL_H
3 /*
4 * Basic symbol and namespace definitions.
6 * Copyright (C) 2003 Transmeta Corp.
8 * Licensed under the Open Software License version 1.1
9 */
11 #include "token.h"
14 * An identifier with semantic meaning is a "symbol".
16 * There's a 1:n relationship: each symbol is always
17 * associated with one identifier, while each identifier
18 * can have one or more semantic meanings due to C scope
19 * rules.
21 * The progression is symbol -> token -> identifier. The
22 * token contains the information on where the symbol was
23 * declared.
25 enum namespace {
26 NS_NONE,
27 NS_PREPROCESSOR,
28 NS_TYPEDEF,
29 NS_STRUCT,
30 NS_ENUM,
31 NS_LABEL,
32 NS_SYMBOL,
33 NS_ITERATOR,
36 enum type {
37 SYM_BASETYPE,
38 SYM_NODE,
39 SYM_PTR,
40 SYM_FN,
41 SYM_ARRAY,
42 SYM_STRUCT,
43 SYM_UNION,
44 SYM_ENUM,
45 SYM_TYPEDEF,
46 SYM_TYPEOF,
47 SYM_MEMBER,
48 SYM_BITFIELD,
49 SYM_LABEL,
52 struct ctype {
53 unsigned long modifiers;
54 unsigned long alignment;
55 unsigned int contextmask, context, as;
56 struct symbol *base_type;
59 struct symbol {
60 enum namespace namespace:8;
61 enum type type:8;
62 struct position pos; /* Where this symbol was declared */
63 struct ident *ident; /* What identifier this symbol is associated with */
64 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
65 struct symbol **id_list; /* Backpointer to symbol list head */
66 struct symbol *replace; /* What is this symbol shadowed by in copy-expression */
67 struct scope *scope;
68 struct symbol *same_symbol;
69 int (*evaluate)(struct expression *);
71 struct /* preprocessor_sym */ {
72 struct token *expansion;
73 struct token *arglist;
76 struct /* ctype_sym */ {
77 unsigned long offset;
78 unsigned int bit_size;
79 unsigned int bit_offset:8,
80 fieldwidth:8,
81 arg_count:10,
82 variadic:1,
83 used:1,
84 initialized:1;
85 int array_size;
86 struct ctype ctype;
87 struct symbol_list *arguments;
88 struct statement *stmt;
89 struct symbol_list *symbol_list;
90 struct expression *initializer;
91 long long value; /* Initial value */
93 void *aux; /* Auxiliary info, eg. backend information */
96 /* Modifiers */
97 #define MOD_AUTO 0x0001
98 #define MOD_REGISTER 0x0002
99 #define MOD_STATIC 0x0004
100 #define MOD_EXTERN 0x0008
102 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
104 #define MOD_CONST 0x0010
105 #define MOD_VOLATILE 0x0020
106 #define MOD_SIGNED 0x0040
107 #define MOD_UNSIGNED 0x0080
109 #define MOD_CHAR 0x0100
110 #define MOD_SHORT 0x0200
111 #define MOD_LONG 0x0400
112 #define MOD_LONGLONG 0x0800
114 #define MOD_TYPEDEF 0x1000
115 #define MOD_STRUCTOF 0x2000
116 #define MOD_UNIONOF 0x4000
117 #define MOD_ENUMOF 0x8000
119 #define MOD_TYPEOF 0x10000
120 #define MOD_ATTRIBUTE 0x20000
121 #define MOD_INLINE 0x40000
122 #define MOD_ADDRESSABLE 0x80000
124 #define MOD_NOCAST 0x100000
125 #define MOD_NODEREF 0x200000
126 #define MOD_ACCESSED 0x400000
127 #define MOD_TOPLEVEL 0x800000 // scoping..
129 #define MOD_LABEL 0x1000000
131 /* Basic types */
132 extern struct symbol void_type,
133 int_type,
134 label_type,
135 fp_type,
136 vector_type,
137 bad_type;
139 /* C types */
140 extern struct symbol bool_ctype, void_ctype,
141 char_ctype, uchar_ctype,
142 short_ctype, ushort_ctype,
143 int_ctype, uint_ctype,
144 long_ctype, ulong_ctype,
145 llong_ctype, ullong_ctype,
146 float_ctype, double_ctype, ldouble_ctype,
147 string_ctype, ptr_ctype, label_type;
150 /* Basic identifiers */
151 extern struct ident sizeof_ident,
152 alignof_ident,
153 __alignof_ident,
154 __alignof___ident,
155 if_ident,
156 else_ident,
157 switch_ident,
158 case_ident,
159 default_ident,
160 break_ident,
161 continue_ident,
162 for_ident,
163 while_ident,
164 do_ident,
165 goto_ident,
166 return_ident;
168 extern struct ident __asm___ident,
169 __asm_ident,
170 asm_ident,
171 __volatile___ident,
172 __volatile_ident,
173 volatile_ident,
174 __attribute___ident,
175 __attribute_ident,
176 pragma_ident;
178 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
180 extern struct symbol_list *used_list;
182 extern void access_symbol(struct symbol *);
185 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
186 extern void init_symbols(void);
187 extern struct symbol *alloc_symbol(struct position, int type);
188 extern void show_type(struct symbol *);
189 extern const char *modifier_string(unsigned long mod);
190 extern void show_symbol(struct symbol *);
191 extern void show_type_list(struct symbol *);
192 extern void show_symbol_list(struct symbol_list *, const char *);
193 extern void add_symbol(struct symbol_list **, struct symbol *);
194 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
196 extern struct symbol *examine_symbol_type(struct symbol *);
197 extern void examine_simple_symbol_type(struct symbol *);
198 extern const char *show_typename(struct symbol *sym);
200 extern void debug_symbol(struct symbol *);
201 extern void merge_type(struct symbol *sym, struct symbol *base_type);
202 extern void check_declaration(struct symbol *sym);
204 #endif /* SEMANTIC_H */