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.
62 KW_SPECIFIER
= 1 << 0,
64 KW_QUALIFIER
= 1 << 2,
65 KW_ATTRIBUTE
= 1 << 3,
67 KW_STATEMENT
= 1 << 5,
73 struct expression
*context
;
77 extern struct context
*alloc_context(void);
79 DECLARE_PTR_LIST(context_list
, struct context
);
82 unsigned long modifiers
;
83 unsigned long alignment
;
84 struct context_list
*contexts
;
86 struct symbol
*base_type
;
91 int (*evaluate
)(struct expression
*);
92 int (*expand
)(struct expression
*, int);
93 int (*args
)(struct expression
*);
96 struct token
*(*declarator
)(struct token
*token
, struct ctype
*ctype
);
97 struct token
*(*statement
)(struct token
*token
, struct statement
*stmt
);
98 struct token
*(*toplevel
)(struct token
*token
, struct symbol_list
**list
);
99 struct token
*(*attribute
)(struct token
*token
, struct symbol
*attr
, struct ctype
*ctype
);
102 extern int expand_safe_p(struct expression
*expr
, int cost
);
103 extern int expand_constant_p(struct expression
*expr
, int cost
);
105 #define SYM_ATTR_WEAK 0
106 #define SYM_ATTR_NORMAL 1
107 #define SYM_ATTR_STRONG 2
111 enum namespace namespace:9;
112 unsigned char used
:1, attr
:2;
113 struct position pos
; /* Where this symbol was declared */
114 struct ident
*ident
; /* What identifier this symbol is associated with */
115 struct symbol
*next_id
; /* Next semantic symbol that shares this identifier */
116 struct symbol
**id_list
; /* Back pointer to symbol list head */
117 struct symbol
*replace
; /* What is this symbol shadowed by in copy-expression */
119 struct symbol
*same_symbol
;
120 struct symbol_op
*op
;
123 struct /* NS_MACRO */ {
124 struct token
*expansion
;
125 struct token
*arglist
;
126 struct scope
*used_in
;
128 struct /* NS_PREPROCESSOR */ {
129 int (*handler
)(struct stream
*, struct token
**, struct token
*);
132 struct /* NS_SYMBOL */ {
133 unsigned long offset
;
135 unsigned int bit_offset
:8,
143 struct expression
*array_size
;
145 struct symbol_list
*arguments
;
146 struct statement
*stmt
;
147 struct symbol_list
*symbol_list
;
148 struct statement
*inline_stmt
;
149 struct symbol_list
*inline_symbol_list
;
150 struct expression
*initializer
;
151 long long value
; /* Initial value */
154 union /* backend */ {
155 struct basic_block
*bb_target
; /* label */
156 void *aux
; /* Auxiliary info, e.g. backend information */
157 struct { /* sparse ctags */
159 unsigned char visited
:1;
166 #define MOD_AUTO 0x0001
167 #define MOD_REGISTER 0x0002
168 #define MOD_STATIC 0x0004
169 #define MOD_EXTERN 0x0008
171 #define MOD_CONST 0x0010
172 #define MOD_VOLATILE 0x0020
173 #define MOD_SIGNED 0x0040
174 #define MOD_UNSIGNED 0x0080
176 #define MOD_CHAR 0x0100
177 #define MOD_SHORT 0x0200
178 #define MOD_LONG 0x0400
179 #define MOD_LONGLONG 0x0800
181 #define MOD_TYPEDEF 0x1000
183 #define MOD_INLINE 0x40000
184 #define MOD_ADDRESSABLE 0x80000
186 #define MOD_NOCAST 0x100000
187 #define MOD_NODEREF 0x200000
188 #define MOD_ACCESSED 0x400000
189 #define MOD_TOPLEVEL 0x800000 // scoping..
191 #define MOD_LABEL 0x1000000
192 #define MOD_ASSIGNED 0x2000000
193 #define MOD_TYPE 0x4000000
194 #define MOD_SAFE 0x8000000 // non-null/non-trapping pointer
196 #define MOD_USERTYPE 0x10000000
197 #define MOD_FORCE 0x20000000
198 #define MOD_EXPLICITLY_SIGNED 0x40000000
199 #define MOD_BITWISE 0x80000000
201 #define MOD_NONLOCAL (MOD_EXTERN | MOD_TOPLEVEL)
202 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
203 #define MOD_SIGNEDNESS (MOD_SIGNED | MOD_UNSIGNED | MOD_EXPLICITLY_SIGNED)
204 #define MOD_SPECIFIER (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG | MOD_SIGNEDNESS)
205 #define MOD_SIZE (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG)
206 #define MOD_IGNORE (MOD_TOPLEVEL | MOD_STORAGE | MOD_ADDRESSABLE | \
207 MOD_ASSIGNED | MOD_USERTYPE | MOD_FORCE | MOD_ACCESSED | MOD_EXPLICITLY_SIGNED)
208 #define MOD_PTRINHERIT (MOD_VOLATILE | MOD_CONST | MOD_NODEREF | MOD_STORAGE)
211 /* Current parsing/evaluation function */
212 extern struct symbol
*current_fn
;
215 extern struct symbol int_type
,
219 extern struct symbol bool_ctype
, void_ctype
, type_ctype
,
220 char_ctype
, schar_ctype
, uchar_ctype
,
221 short_ctype
, sshort_ctype
, ushort_ctype
,
222 int_ctype
, sint_ctype
, uint_ctype
,
223 long_ctype
, slong_ctype
, ulong_ctype
,
224 llong_ctype
, sllong_ctype
, ullong_ctype
,
225 float_ctype
, double_ctype
, ldouble_ctype
,
226 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
227 incomplete_ctype
, label_ctype
, bad_ctype
;
229 /* Special internal symbols */
230 extern struct symbol zero_int
;
232 #define __IDENT(n,str,res) \
233 extern struct ident n
234 #include "ident-list.h"
236 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
238 extern struct symbol_list
*translation_unit_used_list
;
240 extern void access_symbol(struct symbol
*);
242 extern const char * type_difference(struct symbol
*target
, struct symbol
*source
,
243 unsigned long target_mod_ignore
, unsigned long source_mod_ignore
);
245 extern struct symbol
*lookup_symbol(struct ident
*, enum namespace);
246 extern struct symbol
*create_symbol(int stream
, const char *name
, int type
, int namespace);
247 extern void init_symbols(void);
248 extern void init_ctype(void);
249 extern struct symbol
*alloc_symbol(struct position
, int type
);
250 extern void show_type(struct symbol
*);
251 extern const char *modifier_string(unsigned long mod
);
252 extern void show_symbol(struct symbol
*);
253 extern int show_symbol_expr_init(struct symbol
*sym
);
254 extern void show_type_list(struct symbol
*);
255 extern void show_symbol_list(struct symbol_list
*, const char *);
256 extern void add_symbol(struct symbol_list
**, struct symbol
*);
257 extern void bind_symbol(struct symbol
*, struct ident
*, enum namespace);
259 extern struct symbol
*examine_symbol_type(struct symbol
*);
260 extern void examine_simple_symbol_type(struct symbol
*);
261 extern const char *show_typename(struct symbol
*sym
);
262 extern const char *builtin_typename(struct symbol
*sym
);
263 extern const char *builtin_ctypename(struct ctype
*ctype
);
265 extern void debug_symbol(struct symbol
*);
266 extern void merge_type(struct symbol
*sym
, struct symbol
*base_type
);
267 extern void check_declaration(struct symbol
*sym
);
269 static inline struct symbol
*get_base_type(const struct symbol
*sym
)
271 return examine_symbol_type(sym
->ctype
.base_type
);
274 static inline int is_int_type(const struct symbol
*type
)
276 if (type
->type
== SYM_NODE
)
277 type
= type
->ctype
.base_type
;
278 if (type
->type
== SYM_ENUM
)
279 type
= type
->ctype
.base_type
;
280 return type
->type
== SYM_BITFIELD
||
281 type
->ctype
.base_type
== &int_type
;
284 static inline int is_enum_type(const struct symbol
*type
)
286 if (type
->type
== SYM_NODE
)
287 type
= type
->ctype
.base_type
;
288 return (type
->type
== SYM_ENUM
);
291 static inline int get_sym_type(struct symbol
*type
)
293 if (type
->type
== SYM_NODE
)
294 type
= type
->ctype
.base_type
;
295 if (type
->type
== SYM_ENUM
)
296 type
= type
->ctype
.base_type
;
300 static inline struct symbol
*lookup_keyword(struct ident
*ident
, enum namespace ns
)
304 return lookup_symbol(ident
, ns
);
307 #define is_restricted_type(type) (get_sym_type(type) == SYM_RESTRICT)
308 #define is_fouled_type(type) (get_sym_type(type) == SYM_FOULED)
309 #define is_bitfield_type(type) (get_sym_type(type) == SYM_BITFIELD)
310 extern int is_ptr_type(struct symbol
*);
312 void create_fouled(struct symbol
*type
);
313 struct symbol
*befoul(struct symbol
*type
);
315 #endif /* SYMBOL_H */