[PATCH] evaluate_sign() typo
[smatch.git] / symbol.h
blob996600052f6e42c8675878917ba5e25a254e549b
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_PREPROCESSOR = 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,
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_op {
60 int (*evaluate)(struct expression *);
61 int (*expand)(struct expression *);
62 };
64 struct symbol {
65 enum namespace namespace:8;
66 enum type type:8;
67 struct position pos; /* Where this symbol was declared */
68 struct ident *ident; /* What identifier this symbol is associated with */
69 struct symbol *next_id; /* Next semantic symbol that shares this identifier */
70 struct symbol **id_list; /* Backpointer to symbol list head */
71 struct symbol *replace; /* What is this symbol shadowed by in copy-expression */
72 struct scope *scope;
73 struct symbol *same_symbol;
74 struct symbol_op *op;
76 struct /* preprocessor_sym */ {
77 struct token *expansion;
78 struct token *arglist;
81 struct /* ctype_sym */ {
82 unsigned long offset;
83 unsigned int bit_size;
84 unsigned int bit_offset:8,
85 fieldwidth:8,
86 arg_count:10,
87 variadic:1,
88 used:1,
89 initialized:1,
90 expanding: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 statement *inline_stmt;
97 struct symbol_list *inline_symbol_list;
98 struct expression *initializer;
99 long long value; /* Initial value */
101 union /* backend */ {
102 struct basic_block *bb_target; /* label */
103 void *aux; /* Auxiliary info, eg. backend information */
107 /* Modifiers */
108 #define MOD_AUTO 0x0001
109 #define MOD_REGISTER 0x0002
110 #define MOD_STATIC 0x0004
111 #define MOD_EXTERN 0x0008
113 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
115 #define MOD_CONST 0x0010
116 #define MOD_VOLATILE 0x0020
117 #define MOD_SIGNED 0x0040
118 #define MOD_UNSIGNED 0x0080
120 #define MOD_CHAR 0x0100
121 #define MOD_SHORT 0x0200
122 #define MOD_LONG 0x0400
123 #define MOD_LONGLONG 0x0800
125 #define MOD_TYPEDEF 0x1000
126 #define MOD_STRUCTOF 0x2000
127 #define MOD_UNIONOF 0x4000
128 #define MOD_ENUMOF 0x8000
130 #define MOD_TYPEOF 0x10000
131 #define MOD_ATTRIBUTE 0x20000
132 #define MOD_INLINE 0x40000
133 #define MOD_ADDRESSABLE 0x80000
135 #define MOD_NOCAST 0x100000
136 #define MOD_NODEREF 0x200000
137 #define MOD_ACCESSED 0x400000
138 #define MOD_TOPLEVEL 0x800000 // scoping..
140 #define MOD_LABEL 0x1000000
141 #define MOD_ASSIGNED 0x2000000
142 #define MOD_TYPE 0x4000000
143 #define MOD_SAFE 0x8000000 // non-null/non-trapping pointer
145 #define MOD_USERTYPE 0x10000000
146 #define MOD_FORCE 0x20000000
147 #define MOD_EXPLICITLY_SIGNED 0x40000000
149 /* Basic types */
150 extern struct symbol void_type,
151 int_type,
152 label_type,
153 fp_type,
154 vector_type,
155 bad_type;
157 /* C types */
158 extern struct symbol bool_ctype, void_ctype, type_ctype,
159 char_ctype, uchar_ctype,
160 short_ctype, ushort_ctype,
161 int_ctype, uint_ctype,
162 long_ctype, ulong_ctype,
163 llong_ctype, ullong_ctype,
164 float_ctype, double_ctype, ldouble_ctype,
165 string_ctype, ptr_ctype, lazy_ptr_ctype,
166 incomplete_ctype;
169 #define __IDENT(n,str) \
170 extern struct ident n
171 #include "ident-list.h"
173 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
175 extern struct symbol_list *used_list;
177 extern void access_symbol(struct symbol *);
179 extern const char * type_difference(struct symbol *target, struct symbol *source,
180 unsigned long target_mod_ignore, unsigned long source_mod_ignore);
182 extern struct symbol *lookup_symbol(struct ident *, enum namespace);
183 extern void init_symbols(void);
184 extern void init_ctype(void);
185 extern struct symbol *alloc_symbol(struct position, int type);
186 extern void show_type(struct symbol *);
187 extern const char *modifier_string(unsigned long mod);
188 extern void show_symbol(struct symbol *);
189 extern void show_type_list(struct symbol *);
190 extern void show_symbol_list(struct symbol_list *, const char *);
191 extern void add_symbol(struct symbol_list **, struct symbol *);
192 extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
194 extern struct symbol *examine_symbol_type(struct symbol *);
195 extern void examine_simple_symbol_type(struct symbol *);
196 extern const char *show_typename(struct symbol *sym);
198 extern void debug_symbol(struct symbol *);
199 extern void merge_type(struct symbol *sym, struct symbol *base_type);
200 extern void check_declaration(struct symbol *sym);
202 static inline int is_int_type(const struct symbol *type)
204 if (type->type == SYM_NODE)
205 type = type->ctype.base_type;
206 return (type->type == SYM_ENUM) ||
207 (type->type == SYM_BITFIELD) ||
208 type->ctype.base_type == &int_type;
211 static inline int is_bitfield_type(const struct symbol *type)
213 if (type->type == SYM_NODE)
214 type = type->ctype.base_type;
215 return (type->type == SYM_BITFIELD);
218 #endif /* SEMANTIC_H */