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
54 unsigned long modifiers
;
55 unsigned long alignment
;
56 unsigned int contextmask
, context
, as
;
57 struct symbol
*base_type
;
61 int (*evaluate
)(struct expression
*);
62 int (*expand
)(struct expression
*);
66 enum namespace namespace:8;
68 struct position pos
; /* Where this symbol was declared */
69 struct ident
*ident
; /* What identifier this symbol is associated with */
70 struct symbol
*next_id
; /* Next semantic symbol that shares this identifier */
71 struct symbol
**id_list
; /* Backpointer to symbol list head */
72 struct symbol
*replace
; /* What is this symbol shadowed by in copy-expression */
74 struct symbol
*same_symbol
;
77 struct /* preprocessor_sym */ {
78 struct token
*expansion
;
79 struct token
*arglist
;
82 struct /* ctype_sym */ {
84 unsigned int bit_size
;
85 unsigned int bit_offset
:8,
92 struct expression
*array_size
;
94 struct symbol_list
*arguments
;
95 struct statement
*stmt
;
96 struct symbol_list
*symbol_list
;
97 struct expression
*initializer
;
98 long long value
; /* Initial value */
100 union /* backend */ {
101 struct basic_block
*bb_target
; /* label */
102 void *aux
; /* Auxiliary info, eg. backend information */
107 #define MOD_AUTO 0x0001
108 #define MOD_REGISTER 0x0002
109 #define MOD_STATIC 0x0004
110 #define MOD_EXTERN 0x0008
112 #define MOD_STORAGE (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
114 #define MOD_CONST 0x0010
115 #define MOD_VOLATILE 0x0020
116 #define MOD_SIGNED 0x0040
117 #define MOD_UNSIGNED 0x0080
119 #define MOD_CHAR 0x0100
120 #define MOD_SHORT 0x0200
121 #define MOD_LONG 0x0400
122 #define MOD_LONGLONG 0x0800
124 #define MOD_TYPEDEF 0x1000
125 #define MOD_STRUCTOF 0x2000
126 #define MOD_UNIONOF 0x4000
127 #define MOD_ENUMOF 0x8000
129 #define MOD_TYPEOF 0x10000
130 #define MOD_ATTRIBUTE 0x20000
131 #define MOD_INLINE 0x40000
132 #define MOD_ADDRESSABLE 0x80000
134 #define MOD_NOCAST 0x100000
135 #define MOD_NODEREF 0x200000
136 #define MOD_ACCESSED 0x400000
137 #define MOD_TOPLEVEL 0x800000 // scoping..
139 #define MOD_LABEL 0x1000000
140 #define MOD_ASSIGNED 0x2000000
141 #define MOD_TYPE 0x4000000
142 #define MOD_SAFE 0x8000000 // non-null/non-trapping pointer
144 #define MOD_USERTYPE 0x10000000
145 #define MOD_FORCE 0x20000000
146 #define MOD_EXPLICITLY_SIGNED 0x40000000
149 extern struct symbol void_type
,
157 extern struct symbol bool_ctype
, void_ctype
, type_ctype
,
158 char_ctype
, uchar_ctype
,
159 short_ctype
, ushort_ctype
,
160 int_ctype
, uint_ctype
,
161 long_ctype
, ulong_ctype
,
162 llong_ctype
, ullong_ctype
,
163 float_ctype
, double_ctype
, ldouble_ctype
,
164 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
168 /* Basic identifiers */
169 extern struct ident sizeof_ident
,
186 extern struct ident __asm___ident
,
200 #define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
202 extern struct symbol_list
*used_list
;
204 extern void access_symbol(struct symbol
*);
206 extern const char * type_difference(struct symbol
*target
, struct symbol
*source
,
207 unsigned long target_mod_ignore
, unsigned long source_mod_ignore
);
209 extern struct symbol
*lookup_symbol(struct ident
*, enum namespace);
210 extern void init_symbols(void);
211 extern void init_ctype(void);
212 extern struct symbol
*alloc_symbol(struct position
, int type
);
213 extern void show_type(struct symbol
*);
214 extern const char *modifier_string(unsigned long mod
);
215 extern void show_symbol(struct symbol
*);
216 extern void show_type_list(struct symbol
*);
217 extern void show_symbol_list(struct symbol_list
*, const char *);
218 extern void add_symbol(struct symbol_list
**, struct symbol
*);
219 extern void bind_symbol(struct symbol
*, struct ident
*, enum namespace);
221 extern struct symbol
*examine_symbol_type(struct symbol
*);
222 extern void examine_simple_symbol_type(struct symbol
*);
223 extern const char *show_typename(struct symbol
*sym
);
225 extern void debug_symbol(struct symbol
*);
226 extern void merge_type(struct symbol
*sym
, struct symbol
*base_type
);
227 extern void check_declaration(struct symbol
*sym
);
229 static inline int is_int_type(struct symbol
*type
)
231 if (type
->type
== SYM_NODE
)
232 type
= type
->ctype
.base_type
;
233 return (type
->type
== SYM_ENUM
) ||
234 (type
->type
== SYM_BITFIELD
) ||
235 type
->ctype
.base_type
== &int_type
;
238 #endif /* SEMANTIC_H */