[PATCH] trivial ansi-c declear
[smatch.git] / symbol.h
blob7698e46be15e6c4d39fba6a29aa99a2f977784ba
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,
37 enum type {
38 SYM_UNINITIALIZED,
39 SYM_PREPROCESSOR,
40 SYM_BASETYPE,
41 SYM_NODE,
42 SYM_PTR,
43 SYM_FN,
44 SYM_ARRAY,
45 SYM_STRUCT,
46 SYM_UNION,
47 SYM_ENUM,
48 SYM_TYPEDEF,
49 SYM_TYPEOF,
50 SYM_MEMBER,
51 SYM_BITFIELD,
52 SYM_LABEL,
53 SYM_RESTRICT,
56 struct ctype {
57 unsigned long modifiers;
58 unsigned long alignment;
59 unsigned int contextmask, context, as;
60 struct symbol *base_type;
63 struct symbol_op {
64 int (*evaluate)(struct expression *);
65 int (*expand)(struct expression *);
66 };
68 struct symbol {
69 enum namespace namespace:8;
70 enum type type:8;
71 unsigned char used:1;
72 struct position pos; /* Where this symbol was declared */
73 struct ident *ident; /* What identifier this symbol is associated with */
74 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
75 struct symbol **id_list; /* Backpointer to symbol list head */
76 struct symbol *replace; /* What is this symbol shadowed by in copy-expression */
77 struct scope *scope;
78 struct symbol *same_symbol;
79 struct symbol_op *op;
81 union {
82 struct /* NS_MACRO */ {
83 struct token *expansion;
84 struct token *arglist;
86 struct /* NS_PREPROCESSOR */ {
87 int (*handler)(struct stream *, struct token **, struct token *);
89 struct /* NS_SYMBOL */ {
90 unsigned long offset;
91 unsigned int bit_size;
92 unsigned int bit_offset:8,
93 fieldwidth:8,
94 arg_count:10,
95 variadic:1,
96 initialized:1,
97 expanding:1;
98 struct expression *array_size;
99 struct ctype ctype;
100 struct symbol_list *arguments;
101 struct statement *stmt;
102 struct symbol_list *symbol_list;
103 struct statement *inline_stmt;
104 struct symbol_list *inline_symbol_list;
105 struct expression *initializer;
106 long long value; /* Initial value */
109 union /* backend */ {
110 struct basic_block *bb_target; /* label */
111 void *aux; /* Auxiliary info, eg. backend information */
115 /* Modifiers */
116 #define MOD_AUTO 0x0001
117 #define MOD_REGISTER 0x0002
118 #define MOD_STATIC 0x0004
119 #define MOD_EXTERN 0x0008
121 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
123 #define MOD_CONST 0x0010
124 #define MOD_VOLATILE 0x0020
125 #define MOD_SIGNED 0x0040
126 #define MOD_UNSIGNED 0x0080
128 #define MOD_CHAR 0x0100
129 #define MOD_SHORT 0x0200
130 #define MOD_LONG 0x0400
131 #define MOD_LONGLONG 0x0800
133 #define MOD_TYPEDEF 0x1000
134 #define MOD_STRUCTOF 0x2000
135 #define MOD_UNIONOF 0x4000
136 #define MOD_ENUMOF 0x8000
138 #define MOD_TYPEOF 0x10000
139 #define MOD_ATTRIBUTE 0x20000
140 #define MOD_INLINE 0x40000
141 #define MOD_ADDRESSABLE 0x80000
143 #define MOD_NOCAST 0x100000
144 #define MOD_NODEREF 0x200000
145 #define MOD_ACCESSED 0x400000
146 #define MOD_TOPLEVEL 0x800000 // scoping..
148 #define MOD_LABEL 0x1000000
149 #define MOD_ASSIGNED 0x2000000
150 #define MOD_TYPE 0x4000000
151 #define MOD_SAFE 0x8000000 // non-null/non-trapping pointer
153 #define MOD_USERTYPE 0x10000000
154 #define MOD_FORCE 0x20000000
155 #define MOD_EXPLICITLY_SIGNED 0x40000000
156 #define MOD_BITWISE 0x80000000
158 /* Basic types */
159 extern struct symbol void_type,
160 int_type,
161 fp_type,
162 vector_type,
163 bad_type;
165 /* C types */
166 extern struct symbol bool_ctype, void_ctype, type_ctype,
167 char_ctype, schar_ctype, uchar_ctype,
168 short_ctype, sshort_ctype, ushort_ctype,
169 int_ctype, sint_ctype, uint_ctype,
170 long_ctype, slong_ctype, ulong_ctype,
171 llong_ctype, sllong_ctype, ullong_ctype,
172 float_ctype, double_ctype, ldouble_ctype,
173 string_ctype, ptr_ctype, lazy_ptr_ctype,
174 incomplete_ctype, label_ctype;
177 #define __IDENT(n,str) \
178 extern struct ident n
179 #include "ident-list.h"
181 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
183 extern struct symbol_list *used_list;
185 extern void access_symbol(struct symbol *);
187 extern const char * type_difference(struct symbol *target, struct symbol *source,
188 unsigned long target_mod_ignore, unsigned long source_mod_ignore);
190 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
191 extern struct symbol *create_symbol(int stream, const char *name, int type, int namespace);
192 extern void init_symbols(void);
193 extern void init_ctype(void);
194 extern struct symbol *alloc_symbol(struct position, int type);
195 extern void show_type(struct symbol *);
196 extern const char *modifier_string(unsigned long mod);
197 extern void show_symbol(struct symbol *);
198 extern void show_type_list(struct symbol *);
199 extern void show_symbol_list(struct symbol_list *, const char *);
200 extern void add_symbol(struct symbol_list **, struct symbol *);
201 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
203 extern struct symbol *examine_symbol_type(struct symbol *);
204 extern void examine_simple_symbol_type(struct symbol *);
205 extern const char *show_typename(struct symbol *sym);
207 extern void debug_symbol(struct symbol *);
208 extern void merge_type(struct symbol *sym, struct symbol *base_type);
209 extern void check_declaration(struct symbol *sym);
211 static inline int is_int_type(const struct symbol *type)
213 if (type->type == SYM_NODE)
214 type = type->ctype.base_type;
215 return (type->type == SYM_ENUM) ||
216 (type->type == SYM_BITFIELD) ||
217 type->ctype.base_type == &int_type;
220 static inline int is_restricted_type(struct symbol *type)
222 if (type->type == SYM_NODE)
223 type = type->ctype.base_type;
224 return type->type == SYM_RESTRICT;
227 static inline int is_bitfield_type(const struct symbol *type)
229 if (type->type == SYM_NODE)
230 type = type->ctype.base_type;
231 return (type->type == SYM_BITFIELD);
234 #endif /* SEMANTIC_H */