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.
58 unsigned long modifiers
;
59 unsigned long alignment
;
60 unsigned int in_context
, out_context
, as
;
61 struct symbol
*base_type
;
65 int (*evaluate
)(struct expression
*);
66 int (*expand
)(struct expression
*, int);
69 extern int expand_safe_p(struct expression
*expr
, int cost
);
70 extern int expand_constant_p(struct expression
*expr
, int cost
);
73 enum namespace namespace:8;
75 unsigned char used
:1, weak
:1;
76 struct position pos
; /* Where this symbol was declared */
77 struct ident
*ident
; /* What identifier this symbol is associated with */
78 struct symbol
*next_id
; /* Next semantic symbol that shares this identifier */
79 struct symbol
**id_list
; /* Backpointer to symbol list head */
80 struct symbol
*replace
; /* What is this symbol shadowed by in copy-expression */
82 struct symbol
*same_symbol
;
86 struct /* NS_MACRO */ {
87 struct token
*expansion
;
88 struct token
*arglist
;
90 struct /* NS_PREPROCESSOR */ {
91 int (*handler
)(struct stream
*, struct token
**, struct token
*);
93 struct /* NS_SYMBOL */ {
96 unsigned int bit_offset
:8,
102 struct expression
*array_size
;
104 struct symbol_list
*arguments
;
105 struct statement
*stmt
;
106 struct symbol_list
*symbol_list
;
107 struct statement
*inline_stmt
;
108 struct symbol_list
*inline_symbol_list
;
109 struct expression
*initializer
;
110 long long value
; /* Initial value */
113 union /* backend */ {
114 struct basic_block
*bb_target
; /* label */
115 void *aux
; /* Auxiliary info, eg. backend information */
121 #define MOD_AUTO 0x0001
122 #define MOD_REGISTER 0x0002
123 #define MOD_STATIC 0x0004
124 #define MOD_EXTERN 0x0008
126 #define MOD_CONST 0x0010
127 #define MOD_VOLATILE 0x0020
128 #define MOD_SIGNED 0x0040
129 #define MOD_UNSIGNED 0x0080
131 #define MOD_CHAR 0x0100
132 #define MOD_SHORT 0x0200
133 #define MOD_LONG 0x0400
134 #define MOD_LONGLONG 0x0800
136 #define MOD_TYPEDEF 0x1000
137 #define MOD_STRUCTOF 0x2000
138 #define MOD_UNIONOF 0x4000
139 #define MOD_ENUMOF 0x8000
141 #define MOD_TYPEOF 0x10000
142 #define MOD_ATTRIBUTE 0x20000
143 #define MOD_INLINE 0x40000
144 #define MOD_ADDRESSABLE 0x80000
146 #define MOD_NOCAST 0x100000
147 #define MOD_NODEREF 0x200000
148 #define MOD_ACCESSED 0x400000
149 #define MOD_TOPLEVEL 0x800000 // scoping..
151 #define MOD_LABEL 0x1000000
152 #define MOD_ASSIGNED 0x2000000
153 #define MOD_TYPE 0x4000000
154 #define MOD_SAFE 0x8000000 // non-null/non-trapping pointer
156 #define MOD_USERTYPE 0x10000000
157 #define MOD_FORCE 0x20000000
158 #define MOD_EXPLICITLY_SIGNED 0x40000000
159 #define MOD_BITWISE 0x80000000
161 #define MOD_NONLOCAL (MOD_EXTERN | MOD_TOPLEVEL)
162 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
163 #define MOD_SPECIALBITS (MOD_STRUCTOF | MOD_UNIONOF | MOD_ENUMOF | MOD_ATTRIBUTE | MOD_TYPEOF)
164 #define MOD_SIGNEDNESS (MOD_SIGNED | MOD_UNSIGNED | MOD_EXPLICITLY_SIGNED)
165 #define MOD_SPECIFIER (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG | MOD_SIGNEDNESS)
166 #define MOD_SIZE (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG)
167 #define MOD_IGNORE (MOD_TOPLEVEL | MOD_STORAGE | MOD_ADDRESSABLE | \
168 MOD_ASSIGNED | MOD_USERTYPE | MOD_FORCE | MOD_ACCESSED | MOD_EXPLICITLY_SIGNED)
171 /* Current parsing/evaluation function */
172 extern struct symbol
*current_fn
;
175 extern struct symbol int_type
,
179 extern struct symbol bool_ctype
, void_ctype
, type_ctype
,
180 char_ctype
, schar_ctype
, uchar_ctype
,
181 short_ctype
, sshort_ctype
, ushort_ctype
,
182 int_ctype
, sint_ctype
, uint_ctype
,
183 long_ctype
, slong_ctype
, ulong_ctype
,
184 llong_ctype
, sllong_ctype
, ullong_ctype
,
185 float_ctype
, double_ctype
, ldouble_ctype
,
186 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
187 incomplete_ctype
, label_ctype
, bad_ctype
;
190 #define __IDENT(n,str,res) \
191 extern struct ident n
192 #include "ident-list.h"
194 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
196 extern struct symbol_list
*translation_unit_used_list
;
198 extern void access_symbol(struct symbol
*);
200 extern const char * type_difference(struct symbol
*target
, struct symbol
*source
,
201 unsigned long target_mod_ignore
, unsigned long source_mod_ignore
);
203 extern struct symbol
*lookup_symbol(struct ident
*, enum namespace);
204 extern struct symbol
*create_symbol(int stream
, const char *name
, int type
, int namespace);
205 extern void init_symbols(void);
206 extern void init_ctype(void);
207 extern struct symbol
*alloc_symbol(struct position
, int type
);
208 extern void show_type(struct symbol
*);
209 extern const char *modifier_string(unsigned long mod
);
210 extern void show_symbol(struct symbol
*);
211 extern void show_type_list(struct symbol
*);
212 extern void show_symbol_list(struct symbol_list
*, const char *);
213 extern void add_symbol(struct symbol_list
**, struct symbol
*);
214 extern void bind_symbol(struct symbol
*, struct ident
*, enum namespace);
216 extern struct symbol
*examine_symbol_type(struct symbol
*);
217 extern void examine_simple_symbol_type(struct symbol
*);
218 extern const char *show_typename(struct symbol
*sym
);
220 extern void debug_symbol(struct symbol
*);
221 extern void merge_type(struct symbol
*sym
, struct symbol
*base_type
);
222 extern void check_declaration(struct symbol
*sym
);
224 static inline int is_int_type(const struct symbol
*type
)
226 if (type
->type
== SYM_NODE
)
227 type
= type
->ctype
.base_type
;
228 if (type
->type
== SYM_ENUM
)
229 type
= type
->ctype
.base_type
;
230 return type
->type
== SYM_BITFIELD
||
231 type
->ctype
.base_type
== &int_type
;
234 static inline int get_sym_type(struct symbol
*type
)
236 if (type
->type
== SYM_NODE
)
237 type
= type
->ctype
.base_type
;
238 if (type
->type
== SYM_ENUM
)
239 type
= type
->ctype
.base_type
;
243 #define is_restricted_type(type) (get_sym_type(type) == SYM_RESTRICT)
244 #define is_bitfield_type(type) (get_sym_type(type) == SYM_BITFIELD)
245 extern int is_ptr_type(struct symbol
*);
247 #endif /* SEMANTIC_H */