4 * Basic symbol and namespace definitions.
6 * Copyright (C) 2003 Transmeta Corp.
9 * Licensed under the Open Software License version 1.1
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
22 * The progression is symbol -> token -> identifier. The
23 * token contains the information on where the symbol was
30 NS_STRUCT
= 4, // Also used for unions and enums.
60 struct expression
*context
;
64 extern struct context
*alloc_context(void);
66 DECLARE_PTR_LIST(context_list
, struct context
);
69 unsigned long modifiers
;
70 unsigned long alignment
;
71 struct context_list
*contexts
;
73 struct symbol
*base_type
;
77 int (*evaluate
)(struct expression
*);
78 int (*expand
)(struct expression
*, int);
79 int (*args
)(struct expression
*);
82 extern int expand_safe_p(struct expression
*expr
, int cost
);
83 extern int expand_constant_p(struct expression
*expr
, int cost
);
85 #define SYM_ATTR_WEAK 0
86 #define SYM_ATTR_NORMAL 1
87 #define SYM_ATTR_STRONG 2
90 enum namespace namespace:8;
92 unsigned char used
:1, attr
:2;
93 struct position pos
; /* Where this symbol was declared */
94 struct ident
*ident
; /* What identifier this symbol is associated with */
95 struct symbol
*next_id
; /* Next semantic symbol that shares this identifier */
96 struct symbol
**id_list
; /* Backpointer to symbol list head */
97 struct symbol
*replace
; /* What is this symbol shadowed by in copy-expression */
99 struct symbol
*same_symbol
;
100 struct symbol_op
*op
;
103 struct /* NS_MACRO */ {
104 struct token
*expansion
;
105 struct token
*arglist
;
106 struct scope
*used_in
;
108 struct /* NS_PREPROCESSOR */ {
109 int (*handler
)(struct stream
*, struct token
**, struct token
*);
112 struct /* NS_SYMBOL */ {
113 unsigned long offset
;
115 unsigned int bit_offset
:8,
122 struct expression
*array_size
;
124 struct symbol_list
*arguments
;
125 struct statement
*stmt
;
126 struct symbol_list
*symbol_list
;
127 struct statement
*inline_stmt
;
128 struct symbol_list
*inline_symbol_list
;
129 struct expression
*initializer
;
130 long long value
; /* Initial value */
133 union /* backend */ {
134 struct basic_block
*bb_target
; /* label */
135 void *aux
; /* Auxiliary info, eg. backend information */
136 struct { /* sparse ctags */
138 unsigned char visited
:1;
145 #define MOD_AUTO 0x0001
146 #define MOD_REGISTER 0x0002
147 #define MOD_STATIC 0x0004
148 #define MOD_EXTERN 0x0008
150 #define MOD_CONST 0x0010
151 #define MOD_VOLATILE 0x0020
152 #define MOD_SIGNED 0x0040
153 #define MOD_UNSIGNED 0x0080
155 #define MOD_CHAR 0x0100
156 #define MOD_SHORT 0x0200
157 #define MOD_LONG 0x0400
158 #define MOD_LONGLONG 0x0800
160 #define MOD_TYPEDEF 0x1000
161 #define MOD_STRUCTOF 0x2000
162 #define MOD_UNIONOF 0x4000
163 #define MOD_ENUMOF 0x8000
165 #define MOD_TYPEOF 0x10000
166 #define MOD_ATTRIBUTE 0x20000
167 #define MOD_INLINE 0x40000
168 #define MOD_ADDRESSABLE 0x80000
170 #define MOD_NOCAST 0x100000
171 #define MOD_NODEREF 0x200000
172 #define MOD_ACCESSED 0x400000
173 #define MOD_TOPLEVEL 0x800000 // scoping..
175 #define MOD_LABEL 0x1000000
176 #define MOD_ASSIGNED 0x2000000
177 #define MOD_TYPE 0x4000000
178 #define MOD_SAFE 0x8000000 // non-null/non-trapping pointer
180 #define MOD_USERTYPE 0x10000000
181 #define MOD_FORCE 0x20000000
182 #define MOD_EXPLICITLY_SIGNED 0x40000000
183 #define MOD_BITWISE 0x80000000
185 #define MOD_NONLOCAL (MOD_EXTERN | MOD_TOPLEVEL)
186 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
187 #define MOD_SPECIALBITS (MOD_STRUCTOF | MOD_UNIONOF | MOD_ENUMOF | MOD_ATTRIBUTE | MOD_TYPEOF)
188 #define MOD_SIGNEDNESS (MOD_SIGNED | MOD_UNSIGNED | MOD_EXPLICITLY_SIGNED)
189 #define MOD_SPECIFIER (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG | MOD_SIGNEDNESS)
190 #define MOD_SIZE (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG)
191 #define MOD_IGNORE (MOD_TOPLEVEL | MOD_STORAGE | MOD_ADDRESSABLE | \
192 MOD_ASSIGNED | MOD_USERTYPE | MOD_FORCE | MOD_ACCESSED | MOD_EXPLICITLY_SIGNED)
195 /* Current parsing/evaluation function */
196 extern struct symbol
*current_fn
;
199 extern struct symbol int_type
,
203 extern struct symbol bool_ctype
, void_ctype
, type_ctype
,
204 char_ctype
, schar_ctype
, uchar_ctype
,
205 short_ctype
, sshort_ctype
, ushort_ctype
,
206 int_ctype
, sint_ctype
, uint_ctype
,
207 long_ctype
, slong_ctype
, ulong_ctype
,
208 llong_ctype
, sllong_ctype
, ullong_ctype
,
209 float_ctype
, double_ctype
, ldouble_ctype
,
210 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
211 incomplete_ctype
, label_ctype
, bad_ctype
;
213 /* Special internal symbols */
214 extern struct symbol zero_int
;
216 #define __IDENT(n,str,res) \
217 extern struct ident n
218 #include "ident-list.h"
220 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
222 extern struct symbol_list
*translation_unit_used_list
;
224 extern void access_symbol(struct symbol
*);
226 extern const char * type_difference(struct symbol
*target
, struct symbol
*source
,
227 unsigned long target_mod_ignore
, unsigned long source_mod_ignore
);
229 extern struct symbol
*lookup_symbol(struct ident
*, enum namespace);
230 extern struct symbol
*create_symbol(int stream
, const char *name
, int type
, int namespace);
231 extern void init_symbols(void);
232 extern void init_ctype(void);
233 extern struct symbol
*alloc_symbol(struct position
, int type
);
234 extern void show_type(struct symbol
*);
235 extern const char *modifier_string(unsigned long mod
);
236 extern void show_symbol(struct symbol
*);
237 extern int show_symbol_expr_init(struct symbol
*sym
);
238 extern void show_type_list(struct symbol
*);
239 extern void show_symbol_list(struct symbol_list
*, const char *);
240 extern void add_symbol(struct symbol_list
**, struct symbol
*);
241 extern void bind_symbol(struct symbol
*, struct ident
*, enum namespace);
243 extern struct symbol
*examine_symbol_type(struct symbol
*);
244 extern void examine_simple_symbol_type(struct symbol
*);
245 extern const char *show_typename(struct symbol
*sym
);
247 extern void debug_symbol(struct symbol
*);
248 extern void merge_type(struct symbol
*sym
, struct symbol
*base_type
);
249 extern void check_declaration(struct symbol
*sym
);
251 static inline struct symbol
*get_base_type(const struct symbol
*sym
)
253 return examine_symbol_type(sym
->ctype
.base_type
);
256 static inline int is_int_type(const struct symbol
*type
)
258 if (type
->type
== SYM_NODE
)
259 type
= type
->ctype
.base_type
;
260 if (type
->type
== SYM_ENUM
)
261 type
= type
->ctype
.base_type
;
262 return type
->type
== SYM_BITFIELD
||
263 type
->ctype
.base_type
== &int_type
;
266 static inline int is_enum_type(const struct symbol
*type
)
268 if (type
->type
== SYM_NODE
)
269 type
= type
->ctype
.base_type
;
270 return (type
->type
== SYM_ENUM
);
273 static inline int get_sym_type(struct symbol
*type
)
275 if (type
->type
== SYM_NODE
)
276 type
= type
->ctype
.base_type
;
277 if (type
->type
== SYM_ENUM
)
278 type
= type
->ctype
.base_type
;
282 #define is_restricted_type(type) (get_sym_type(type) == SYM_RESTRICT)
283 #define is_fouled_type(type) (get_sym_type(type) == SYM_FOULED)
284 #define is_bitfield_type(type) (get_sym_type(type) == SYM_BITFIELD)
285 extern int is_ptr_type(struct symbol
*);
287 void create_fouled(struct symbol
*type
);
288 struct symbol
*befoul(struct symbol
*type
);
290 #endif /* SYMBOL_H */