2 * Symbol lookup and handling.
4 * Copyright (C) 2003 Transmeta Corp.
5 * 2003-2004 Linus Torvalds
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
35 #include "expression.h"
40 * Secondary symbol list for stuff that needs to be output because it
43 struct symbol_list
*translation_unit_used_list
= NULL
;
46 * If the symbol is an inline symbol, add it to the list of symbols to parse
48 void access_symbol(struct symbol
*sym
)
50 if (sym
->ctype
.modifiers
& MOD_INLINE
) {
51 if (!(sym
->ctype
.modifiers
& MOD_ACCESSED
)) {
52 add_symbol(&translation_unit_used_list
, sym
);
53 sym
->ctype
.modifiers
|= MOD_ACCESSED
;
58 struct symbol
*lookup_symbol(struct ident
*ident
, enum namespace ns
)
62 for (sym
= ident
->symbols
; sym
; sym
= sym
->next_id
) {
63 if (sym
->namespace & ns
) {
71 struct context
*alloc_context(void)
73 return __alloc_context(0);
76 struct symbol
*alloc_symbol(struct position pos
, int type
)
78 struct symbol
*sym
= __alloc_symbol(0);
82 sym
->ctype
.attribute
= &null_attr
;
86 struct struct_union_info
{
87 unsigned long max_align
;
88 unsigned long bit_size
;
94 * Unions are fairly easy to lay out ;)
96 static void lay_out_union(struct symbol
*sym
, struct struct_union_info
*info
)
98 examine_symbol_type(sym
);
100 // Unnamed bitfields do not affect alignment.
101 if (sym
->ident
|| !is_bitfield_type(sym
)) {
102 if (sym
->ctype
.alignment
> info
->max_align
)
103 info
->max_align
= sym
->ctype
.alignment
;
106 if (sym
->bit_size
> info
->bit_size
)
107 info
->bit_size
= sym
->bit_size
;
112 static int bitfield_base_size(struct symbol
*sym
)
114 if (sym
->type
== SYM_NODE
)
115 sym
= sym
->ctype
.base_type
;
116 if (sym
->type
== SYM_BITFIELD
)
117 sym
= sym
->ctype
.base_type
;
118 return sym
->bit_size
;
122 * Structures are a bit more interesting to lay out
124 static void lay_out_struct(struct symbol
*sym
, struct struct_union_info
*info
)
126 unsigned long bit_size
, align_bit_mask
;
129 examine_symbol_type(sym
);
131 // Unnamed bitfields do not affect alignment.
132 if (sym
->ident
|| !is_bitfield_type(sym
)) {
133 if (!info
->is_packed
&& sym
->ctype
.alignment
> info
->max_align
)
134 info
->max_align
= sym
->ctype
.alignment
;
137 bit_size
= info
->bit_size
;
138 base_size
= sym
->bit_size
;
141 * Unsized arrays cause us to not align the resulting
145 info
->align_size
= 0;
152 align_bit_mask
= bytes_to_bits(sym
->ctype
.alignment
) - 1;
155 * Bitfields have some very special rules..
157 if (is_bitfield_type (sym
)) {
158 unsigned long bit_offset
= bit_size
& align_bit_mask
;
159 int room
= bitfield_base_size(sym
) - bit_offset
;
160 // Zero-width fields just fill up the unit.
161 int width
= base_size
? : (bit_offset
? room
: 0);
164 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
167 sym
->offset
= bits_to_bytes(bit_size
- bit_offset
);
168 sym
->bit_offset
= bit_offset
;
169 sym
->ctype
.base_type
->bit_offset
= bit_offset
;
170 info
->bit_size
= bit_size
+ width
;
171 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
177 * Otherwise, just align it right and add it up..
179 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
180 sym
->offset
= bits_to_bytes(bit_size
);
182 info
->bit_size
= bit_size
+ base_size
;
183 // warning (sym->pos, "regular: offset=%d", sym->offset);
186 static struct symbol
* examine_struct_union_type(struct symbol
*sym
, int advance
)
188 struct struct_union_info info
= {
193 unsigned long bit_size
, bit_align
;
194 void (*fn
)(struct symbol
*, struct struct_union_info
*);
195 struct symbol
*member
;
197 info
.is_packed
= sym
->ctype
.attribute
->is_packed
;
198 fn
= advance
? lay_out_struct
: lay_out_union
;
199 FOR_EACH_PTR(sym
->symbol_list
, member
) {
201 } END_FOR_EACH_PTR(member
);
203 if (!sym
->ctype
.alignment
)
204 sym
->ctype
.alignment
= info
.max_align
;
205 bit_size
= info
.bit_size
;
206 if (info
.align_size
) {
207 bit_align
= bytes_to_bits(sym
->ctype
.alignment
)-1;
208 bit_size
= (bit_size
+ bit_align
) & ~bit_align
;
210 sym
->bit_size
= bit_size
;
214 static struct symbol
*examine_base_type(struct symbol
*sym
)
216 struct symbol
*base_type
;
218 /* Check the base type */
219 base_type
= examine_symbol_type(sym
->ctype
.base_type
);
220 if (!base_type
|| base_type
->type
== SYM_PTR
)
222 sym
->ctype
.modifiers
|= base_type
->ctype
.modifiers
& MOD_PTRINHERIT
;
224 merge_attr(&sym
->ctype
, &base_type
->ctype
);
226 if (base_type
->type
== SYM_NODE
) {
227 base_type
= base_type
->ctype
.base_type
;
228 sym
->ctype
.base_type
= base_type
;
233 static struct symbol
* examine_array_type(struct symbol
*sym
)
235 struct symbol
*base_type
= examine_base_type(sym
);
236 unsigned long bit_size
= -1, alignment
;
237 struct expression
*array_size
= sym
->array_size
;
243 bit_size
= array_element_offset(base_type
->bit_size
,
244 get_expression_value_silent(array_size
));
245 if (array_size
->type
!= EXPR_VALUE
) {
247 warning(array_size
->pos
, "Variable length array is used.");
251 alignment
= base_type
->ctype
.alignment
;
252 if (!sym
->ctype
.alignment
)
253 sym
->ctype
.alignment
= alignment
;
254 sym
->bit_size
= bit_size
;
258 static struct symbol
*examine_bitfield_type(struct symbol
*sym
)
260 struct symbol
*base_type
= examine_base_type(sym
);
261 unsigned long bit_size
, alignment
, modifiers
;
265 bit_size
= base_type
->bit_size
;
266 if (sym
->bit_size
> bit_size
)
267 warning(sym
->pos
, "impossible field-width, %d, for this type", sym
->bit_size
);
269 alignment
= base_type
->ctype
.alignment
;
270 if (!sym
->ctype
.alignment
)
271 sym
->ctype
.alignment
= alignment
;
272 modifiers
= base_type
->ctype
.modifiers
;
274 /* Bitfields are unsigned, unless the base type was explicitly signed */
275 if (!(modifiers
& MOD_EXPLICITLY_SIGNED
))
276 modifiers
= (modifiers
& ~MOD_SIGNED
) | MOD_UNSIGNED
;
277 sym
->ctype
.modifiers
|= modifiers
& MOD_SIGNEDNESS
;
282 * "typeof" will have to merge the types together
284 void merge_type(struct symbol
*sym
, struct symbol
*base_type
)
286 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& ~MOD_STORAGE
);
287 merge_attr(&sym
->ctype
, &base_type
->ctype
);
288 sym
->ctype
.base_type
= base_type
->ctype
.base_type
;
289 if (sym
->ctype
.base_type
->type
== SYM_NODE
)
290 merge_type(sym
, sym
->ctype
.base_type
);
293 static int count_array_initializer(struct symbol
*t
, struct expression
*expr
)
299 * Arrays of character types are special; they can be initialized by
300 * string literal _or_ by string literal in braces. The latter means
301 * that with T x[] = {<string literal>} number of elements in x depends
302 * on T - if it's a character type, we get the length of string literal
303 * (including NUL), otherwise we have one element here.
305 if (t
->ctype
.base_type
== &int_type
&& t
->ctype
.modifiers
& MOD_CHAR
)
308 switch (expr
->type
) {
309 case EXPR_INITIALIZER
: {
310 struct expression
*entry
;
313 FOR_EACH_PTR(expr
->expr_list
, entry
) {
315 switch (entry
->type
) {
317 if (entry
->idx_to
>= nr
)
318 nr
= entry
->idx_to
+1;
321 struct expression
*e
= entry
;
323 while (e
&& e
->type
== EXPR_PREOP
&& e
->op
== '(')
325 if (e
&& e
->type
== EXPR_STRING
) {
329 str_len
= entry
->string
->length
;
338 } END_FOR_EACH_PTR(entry
);
339 if (count
== 1 && str_len
)
345 struct expression
*e
= expr
;
346 while (e
&& e
->type
== EXPR_PREOP
&& e
->op
== '(')
348 if (e
&& e
->type
== EXPR_STRING
) {
352 nr
= expr
->string
->length
;
362 static struct expression
*get_symbol_initializer(struct symbol
*sym
)
365 if (sym
->initializer
)
366 return sym
->initializer
;
367 } while ((sym
= sym
->same_symbol
) != NULL
);
371 static struct symbol
* examine_node_type(struct symbol
*sym
)
373 struct symbol
*base_type
= examine_base_type(sym
);
375 unsigned long alignment
;
377 /* SYM_NODE - figure out what the type of the node was.. */
383 bit_size
= base_type
->bit_size
;
384 alignment
= base_type
->ctype
.alignment
;
386 /* Pick up signedness information into the node */
387 sym
->ctype
.modifiers
|= (MOD_SIGNEDNESS
& base_type
->ctype
.modifiers
);
389 if (!sym
->ctype
.alignment
)
390 sym
->ctype
.alignment
= alignment
;
392 /* Unsized array? The size might come from the initializer.. */
393 if (bit_size
< 0 && base_type
->type
== SYM_ARRAY
) {
394 struct expression
*initializer
= get_symbol_initializer(sym
);
396 struct symbol
*node_type
= base_type
->ctype
.base_type
;
397 int count
= count_array_initializer(node_type
, initializer
);
399 if (node_type
&& node_type
->bit_size
>= 0)
400 bit_size
= node_type
->bit_size
* count
;
404 sym
->bit_size
= bit_size
;
408 static struct symbol
*examine_enum_type(struct symbol
*sym
)
410 struct symbol
*base_type
= examine_base_type(sym
);
412 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& MOD_SIGNEDNESS
);
413 sym
->bit_size
= bits_in_enum
;
414 if (base_type
->bit_size
> sym
->bit_size
)
415 sym
->bit_size
= base_type
->bit_size
;
416 sym
->ctype
.alignment
= enum_alignment
;
417 if (base_type
->ctype
.alignment
> sym
->ctype
.alignment
)
418 sym
->ctype
.alignment
= base_type
->ctype
.alignment
;
422 static struct symbol
*examine_pointer_type(struct symbol
*sym
)
425 * We need to set the pointer size first, and
426 * examine the thing we point to only afterwards.
427 * That's because this pointer type may end up
428 * being needed for the base type size evaluation.
431 sym
->bit_size
= bits_in_pointer
;
432 if (!sym
->ctype
.alignment
)
433 sym
->ctype
.alignment
= pointer_alignment
;
438 * Fill in type size and alignment information for
439 * regular SYM_TYPE things.
441 struct symbol
*examine_symbol_type(struct symbol
* sym
)
454 return examine_node_type(sym
);
456 return examine_array_type(sym
);
458 return examine_struct_union_type(sym
, 1);
460 return examine_struct_union_type(sym
, 0);
462 return examine_pointer_type(sym
);
464 return examine_enum_type(sym
);
466 return examine_bitfield_type(sym
);
468 /* Size and alignment had better already be set up */
471 struct symbol
*base
= evaluate_expression(sym
->initializer
);
473 if (is_bitfield_type(base
))
474 warning(base
->pos
, "typeof applied to bitfield type");
475 if (base
->type
== SYM_NODE
)
476 base
= base
->ctype
.base_type
;
477 sym
->type
= SYM_NODE
;
478 sym
->ctype
.modifiers
= 0;
479 sym
->ctype
.base_type
= base
;
480 return examine_node_type(sym
);
484 case SYM_PREPROCESSOR
:
485 sparse_error(sym
->pos
, "ctype on preprocessor command? (%s)", show_ident(sym
->ident
));
487 case SYM_UNINITIALIZED
:
488 // sparse_error(sym->pos, "ctype on uninitialized symbol %p", sym);
491 examine_base_type(sym
);
494 examine_base_type(sym
);
497 sparse_error(sym
->pos
, "Examining unknown symbol type %d", sym
->type
);
503 const char* get_type_name(enum type type
)
505 const char *type_lookup
[] = {
506 [SYM_UNINITIALIZED
] = "uninitialized",
507 [SYM_PREPROCESSOR
] = "preprocessor",
508 [SYM_BASETYPE
] = "basetype",
510 [SYM_PTR
] = "pointer",
511 [SYM_FN
] = "function",
512 [SYM_ARRAY
] = "array",
513 [SYM_STRUCT
] = "struct",
514 [SYM_UNION
] = "union",
516 [SYM_TYPEDEF
] = "typedef",
517 [SYM_TYPEOF
] = "typeof",
518 [SYM_MEMBER
] = "member",
519 [SYM_BITFIELD
] = "bitfield",
520 [SYM_LABEL
] = "label",
521 [SYM_RESTRICT
] = "restrict",
522 [SYM_FOULED
] = "fouled",
523 [SYM_KEYWORD
] = "keyword",
527 return type_lookup
[type
];
532 struct symbol
*examine_pointer_target(struct symbol
*sym
)
534 return examine_base_type(sym
);
537 static struct symbol_list
*restr
, *fouled
;
539 void create_fouled(struct symbol
*type
)
541 if (type
->bit_size
< bits_in_int
) {
542 struct symbol
*new = alloc_symbol(type
->pos
, type
->type
);
544 new->bit_size
= bits_in_int
;
545 new->type
= SYM_FOULED
;
546 new->ctype
.base_type
= type
;
547 add_symbol(&restr
, type
);
548 add_symbol(&fouled
, new);
552 struct symbol
*befoul(struct symbol
*type
)
554 struct symbol
*t1
, *t2
;
555 while (type
->type
== SYM_NODE
)
556 type
= type
->ctype
.base_type
;
557 PREPARE_PTR_LIST(restr
, t1
);
558 PREPARE_PTR_LIST(fouled
, t2
);
572 void check_declaration(struct symbol
*sym
)
575 struct symbol
*next
= sym
;
577 while ((next
= next
->next_id
) != NULL
) {
578 if (next
->namespace != sym
->namespace)
580 if (sym
->scope
== next
->scope
) {
581 sym
->same_symbol
= next
;
584 /* Extern in block level matches a TOPLEVEL non-static symbol */
585 if (sym
->ctype
.modifiers
& MOD_EXTERN
) {
586 if ((next
->ctype
.modifiers
& (MOD_TOPLEVEL
|MOD_STATIC
)) == MOD_TOPLEVEL
) {
587 sym
->same_symbol
= next
;
592 if (!Wshadow
|| warned
)
594 if (get_sym_type(next
) == SYM_FN
)
597 warning(sym
->pos
, "symbol '%s' shadows an earlier one", show_ident(sym
->ident
));
598 info(next
->pos
, "originally declared here");
602 void bind_symbol(struct symbol
*sym
, struct ident
*ident
, enum namespace ns
)
606 sparse_error(sym
->pos
, "internal error: symbol type already bound");
609 if (ident
->reserved
&& (ns
& (NS_TYPEDEF
| NS_STRUCT
| NS_LABEL
| NS_SYMBOL
))) {
610 sparse_error(sym
->pos
, "Trying to use reserved word '%s' as identifier", show_ident(ident
));
614 sym
->next_id
= ident
->symbols
;
615 ident
->symbols
= sym
;
616 if (sym
->ident
&& sym
->ident
!= ident
)
617 warning(sym
->pos
, "Symbol '%s' already bound", show_ident(sym
->ident
));
622 if (ns
== NS_SYMBOL
&& toplevel(scope
)) {
623 unsigned mod
= MOD_ADDRESSABLE
| MOD_TOPLEVEL
;
625 scope
= global_scope
;
626 if (sym
->ctype
.modifiers
& MOD_STATIC
||
627 is_extern_inline(sym
)) {
631 sym
->ctype
.modifiers
|= mod
;
636 scope
= function_scope
;
637 bind_scope(sym
, scope
);
640 struct symbol
*create_symbol(int stream
, const char *name
, int type
, int namespace)
642 struct token
*token
= built_in_token(stream
, name
);
643 struct symbol
*sym
= alloc_symbol(token
->pos
, type
);
645 bind_symbol(sym
, token
->ident
, namespace);
649 static int evaluate_to_integer(struct expression
*expr
)
651 expr
->ctype
= &int_ctype
;
655 static int evaluate_expect(struct expression
*expr
)
657 /* Should we evaluate it to return the type of the first argument? */
658 expr
->ctype
= &int_ctype
;
662 static int arguments_choose(struct expression
*expr
)
664 struct expression_list
*arglist
= expr
->args
;
665 struct expression
*arg
;
668 FOR_EACH_PTR (arglist
, arg
) {
669 if (!evaluate_expression(arg
))
672 } END_FOR_EACH_PTR(arg
);
674 sparse_error(expr
->pos
,
675 "not enough arguments for __builtin_choose_expr");
678 sparse_error(expr
->pos
,
679 "too many arguments for __builtin_choose_expr");
685 static int evaluate_choose(struct expression
*expr
)
687 struct expression_list
*list
= expr
->args
;
688 struct expression
*arg
, *args
[3];
691 /* there will be exactly 3; we'd already verified that */
692 FOR_EACH_PTR(list
, arg
) {
694 } END_FOR_EACH_PTR(arg
);
696 *expr
= get_expression_value(args
[0]) ? *args
[1] : *args
[2];
701 static int expand_expect(struct expression
*expr
, int cost
)
703 struct expression
*arg
= first_ptr_list((struct ptr_list
*) expr
->args
);
711 * __builtin_warning() has type "int" and always returns 1,
712 * so that you can use it in conditionals or whatever
714 static int expand_warning(struct expression
*expr
, int cost
)
716 struct expression
*arg
;
717 struct expression_list
*arglist
= expr
->args
;
719 FOR_EACH_PTR (arglist
, arg
) {
721 * Constant strings get printed out as a warning. By the
722 * time we get here, the EXPR_STRING has been fully
723 * evaluated, so by now it's an anonymous symbol with a
724 * string initializer.
726 * Just for the heck of it, allow any constant string
729 if (arg
->type
== EXPR_SYMBOL
) {
730 struct symbol
*sym
= arg
->symbol
;
731 if (sym
->initializer
&& sym
->initializer
->type
== EXPR_STRING
) {
732 struct string
*string
= sym
->initializer
->string
;
733 warning(expr
->pos
, "%*s", string
->length
-1, string
->data
);
739 * Any other argument is a conditional. If it's
740 * non-constant, or it is false, we exit and do
741 * not print any warning.
743 if (arg
->type
!= EXPR_VALUE
)
747 } END_FOR_EACH_PTR(arg
);
749 expr
->type
= EXPR_VALUE
;
755 static struct symbol_op constant_p_op
= {
756 .evaluate
= evaluate_to_integer
,
757 .expand
= expand_constant_p
760 static struct symbol_op safe_p_op
= {
761 .evaluate
= evaluate_to_integer
,
762 .expand
= expand_safe_p
765 static struct symbol_op warning_op
= {
766 .evaluate
= evaluate_to_integer
,
767 .expand
= expand_warning
770 static struct symbol_op expect_op
= {
771 .evaluate
= evaluate_expect
,
772 .expand
= expand_expect
775 static struct symbol_op choose_op
= {
776 .evaluate
= evaluate_choose
,
777 .args
= arguments_choose
,
783 static struct symbol builtin_fn_type
= { .type
= SYM_FN
/* , .variadic =1 */ };
784 static struct sym_init
{
786 struct symbol
*base_type
;
787 unsigned int modifiers
;
788 struct symbol_op
*op
;
789 } eval_init_table
[] = {
790 { "__builtin_constant_p", &builtin_fn_type
, MOD_TOPLEVEL
, &constant_p_op
},
791 { "__builtin_safe_p", &builtin_fn_type
, MOD_TOPLEVEL
, &safe_p_op
},
792 { "__builtin_warning", &builtin_fn_type
, MOD_TOPLEVEL
, &warning_op
},
793 { "__builtin_expect", &builtin_fn_type
, MOD_TOPLEVEL
, &expect_op
},
794 { "__builtin_choose_expr", &builtin_fn_type
, MOD_TOPLEVEL
, &choose_op
},
799 * Default empty attribute
801 struct attribute null_attr
= {};
806 struct symbol int_type
,
810 * C types (i.e. actual instances that the abstract types
813 struct symbol bool_ctype
, void_ctype
, type_ctype
,
814 char_ctype
, schar_ctype
, uchar_ctype
,
815 short_ctype
, sshort_ctype
, ushort_ctype
,
816 int_ctype
, sint_ctype
, uint_ctype
,
817 long_ctype
, slong_ctype
, ulong_ctype
,
818 llong_ctype
, sllong_ctype
, ullong_ctype
,
819 lllong_ctype
, slllong_ctype
, ulllong_ctype
,
820 float_ctype
, double_ctype
, ldouble_ctype
,
821 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
822 incomplete_ctype
, label_ctype
, bad_ctype
,
825 struct symbol zero_int
;
827 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
828 #define __IDENT(n,str,res) \
829 struct ident n = __INIT_IDENT(str,res)
831 #include "ident-list.h"
833 void init_symbols(void)
835 int stream
= init_stream("builtin", -1, includepath
);
836 struct sym_init
*ptr
;
838 #define __IDENT(n,str,res) \
840 #include "ident-list.h"
844 builtin_fn_type
.variadic
= 1;
845 builtin_fn_type
.ctype
.attribute
= &null_attr
;
846 for (ptr
= eval_init_table
; ptr
->name
; ptr
++) {
848 sym
= create_symbol(stream
, ptr
->name
, SYM_NODE
, NS_SYMBOL
);
849 sym
->ctype
.base_type
= ptr
->base_type
;
850 sym
->ctype
.modifiers
= ptr
->modifiers
;
851 sym
->ctype
.attribute
= &null_attr
;
856 #ifdef __CHAR_UNSIGNED__
857 #define CHAR_SIGNEDNESS MOD_UNSIGNED
859 #define CHAR_SIGNEDNESS MOD_SIGNED
862 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
863 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
864 #define MOD_LLL MOD_LONGLONGLONG
865 static const struct ctype_declare
{
868 unsigned long modifiers
;
871 struct symbol
*base_type
;
872 } ctype_declaration
[] = {
873 { &bool_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_bool
, &max_int_alignment
, &int_type
},
874 { &void_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
875 { &type_ctype
, SYM_BASETYPE
, MOD_TYPE
, NULL
, NULL
, NULL
},
876 { &incomplete_ctype
,SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
877 { &bad_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
879 { &char_ctype
, SYM_BASETYPE
, CHAR_SIGNEDNESS
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
880 { &schar_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
881 { &uchar_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
882 { &short_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
883 { &sshort_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
884 { &ushort_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
885 { &int_ctype
, SYM_BASETYPE
, MOD_SIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
886 { &sint_ctype
, SYM_BASETYPE
, MOD_ESIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
887 { &uint_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
888 { &long_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
889 { &slong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
890 { &ulong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
891 { &llong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
892 { &sllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
893 { &ullong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
894 { &lllong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
895 { &slllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
896 { &ulllong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
898 { &float_ctype
, SYM_BASETYPE
, 0, &bits_in_float
, &max_fp_alignment
, &fp_type
},
899 { &double_ctype
, SYM_BASETYPE
, MOD_LONG
, &bits_in_double
, &max_fp_alignment
, &fp_type
},
900 { &ldouble_ctype
, SYM_BASETYPE
, MOD_LONG
| MOD_LONGLONG
, &bits_in_longdouble
, &max_fp_alignment
, &fp_type
},
902 { &string_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &char_ctype
},
903 { &ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
904 { &null_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
905 { &label_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
906 { &lazy_ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
913 void init_ctype(void)
915 const struct ctype_declare
*ctype
;
917 for (ctype
= ctype_declaration
; ctype
->ptr
; ctype
++) {
918 struct symbol
*sym
= ctype
->ptr
;
919 unsigned long bit_size
= ctype
->bit_size
? *ctype
->bit_size
: -1;
920 unsigned long maxalign
= ctype
->maxalign
? *ctype
->maxalign
: 0;
921 unsigned long alignment
= bits_to_bytes(bit_size
);
923 if (alignment
> maxalign
)
924 alignment
= maxalign
;
925 sym
->type
= ctype
->type
;
926 sym
->bit_size
= bit_size
;
927 sym
->ctype
.alignment
= alignment
;
928 sym
->ctype
.base_type
= ctype
->base_type
;
929 sym
->ctype
.modifiers
= ctype
->modifiers
;
930 sym
->ctype
.attribute
= &null_attr
;