2 * Symbol lookup and handling.
4 * Copyright (C) 2003 Transmeta Corp.
5 * 2003-2004 Linus Torvalds
7 * Licensed under the Open Software License version 1.1
19 #include "expression.h"
24 * Secondary symbol list for stuff that needs to be output because it
27 struct symbol_list
*translation_unit_used_list
= NULL
;
30 * If the symbol is an inline symbol, add it to the list of symbols to parse
32 void access_symbol(struct symbol
*sym
)
34 if (sym
->ctype
.modifiers
& MOD_INLINE
) {
35 if (!(sym
->ctype
.modifiers
& MOD_ACCESSED
)) {
36 add_symbol(&translation_unit_used_list
, sym
);
37 sym
->ctype
.modifiers
|= MOD_ACCESSED
;
42 struct symbol
*lookup_symbol(struct ident
*ident
, enum namespace ns
)
46 for (sym
= ident
->symbols
; sym
; sym
= sym
->next_id
) {
47 if (sym
->namespace & ns
) {
55 struct context
*alloc_context(void)
57 return __alloc_context(0);
60 struct symbol
*alloc_symbol(struct position pos
, int type
)
62 struct symbol
*sym
= __alloc_symbol(0);
69 struct struct_union_info
{
70 unsigned long max_align
;
71 unsigned long bit_size
;
76 * Unions are fairly easy to lay out ;)
78 static void lay_out_union(struct symbol
*sym
, struct struct_union_info
*info
)
80 examine_symbol_type(sym
);
82 // Unnamed bitfields do not affect alignment.
83 if (sym
->ident
|| !is_bitfield_type(sym
)) {
84 if (sym
->ctype
.alignment
> info
->max_align
)
85 info
->max_align
= sym
->ctype
.alignment
;
88 if (sym
->bit_size
> info
->bit_size
)
89 info
->bit_size
= sym
->bit_size
;
94 static int bitfield_base_size(struct symbol
*sym
)
96 if (sym
->type
== SYM_NODE
)
97 sym
= sym
->ctype
.base_type
;
98 if (sym
->type
== SYM_BITFIELD
)
99 sym
= sym
->ctype
.base_type
;
100 return sym
->bit_size
;
104 * Structures are a bit more interesting to lay out
106 static void lay_out_struct(struct symbol
*sym
, struct struct_union_info
*info
)
108 unsigned long bit_size
, align_bit_mask
;
111 examine_symbol_type(sym
);
113 // Unnamed bitfields do not affect alignment.
114 if (sym
->ident
|| !is_bitfield_type(sym
)) {
115 if (sym
->ctype
.alignment
> info
->max_align
)
116 info
->max_align
= sym
->ctype
.alignment
;
119 bit_size
= info
->bit_size
;
120 base_size
= sym
->bit_size
;
123 * Unsized arrays cause us to not align the resulting
127 info
->align_size
= 0;
131 align_bit_mask
= bytes_to_bits(sym
->ctype
.alignment
) - 1;
134 * Bitfields have some very special rules..
136 if (is_bitfield_type (sym
)) {
137 unsigned long bit_offset
= bit_size
& align_bit_mask
;
138 int room
= bitfield_base_size(sym
) - bit_offset
;
139 // Zero-width fields just fill up the unit.
140 int width
= base_size
? : (bit_offset
? room
: 0);
143 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
146 sym
->offset
= bits_to_bytes(bit_size
- bit_offset
);
147 sym
->bit_offset
= bit_offset
;
148 sym
->ctype
.base_type
->bit_offset
= bit_offset
;
149 info
->bit_size
= bit_size
+ width
;
150 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
156 * Otherwise, just align it right and add it up..
158 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
159 sym
->offset
= bits_to_bytes(bit_size
);
161 info
->bit_size
= bit_size
+ base_size
;
162 // warning (sym->pos, "regular: offset=%d", sym->offset);
165 static struct symbol
* examine_struct_union_type(struct symbol
*sym
, int advance
)
167 struct struct_union_info info
= {
172 unsigned long bit_size
, bit_align
;
173 void (*fn
)(struct symbol
*, struct struct_union_info
*);
174 struct symbol
*member
;
176 fn
= advance
? lay_out_struct
: lay_out_union
;
177 FOR_EACH_PTR(sym
->symbol_list
, member
) {
179 } END_FOR_EACH_PTR(member
);
181 if (!sym
->ctype
.alignment
)
182 sym
->ctype
.alignment
= info
.max_align
;
183 bit_size
= info
.bit_size
;
184 if (info
.align_size
) {
185 bit_align
= bytes_to_bits(sym
->ctype
.alignment
)-1;
186 bit_size
= (bit_size
+ bit_align
) & ~bit_align
;
188 sym
->bit_size
= bit_size
;
192 static struct symbol
*examine_base_type(struct symbol
*sym
)
194 struct symbol
*base_type
;
196 /* Check the base type */
197 base_type
= examine_symbol_type(sym
->ctype
.base_type
);
198 if (!base_type
|| base_type
->type
== SYM_PTR
)
200 sym
->ctype
.as
|= base_type
->ctype
.as
;
201 sym
->ctype
.modifiers
|= base_type
->ctype
.modifiers
& MOD_PTRINHERIT
;
202 concat_ptr_list((struct ptr_list
*)base_type
->ctype
.contexts
,
203 (struct ptr_list
**)&sym
->ctype
.contexts
);
204 if (base_type
->type
== SYM_NODE
) {
205 base_type
= base_type
->ctype
.base_type
;
206 sym
->ctype
.base_type
= base_type
;
211 static struct symbol
* examine_array_type(struct symbol
*sym
)
213 struct symbol
*base_type
= examine_base_type(sym
);
214 unsigned long bit_size
= -1, alignment
;
215 struct expression
*array_size
= sym
->array_size
;
221 bit_size
= base_type
->bit_size
* get_expression_value_silent(array_size
);
222 if (array_size
->type
!= EXPR_VALUE
) {
224 warning(array_size
->pos
, "Variable length array is used.");
228 alignment
= base_type
->ctype
.alignment
;
229 if (!sym
->ctype
.alignment
)
230 sym
->ctype
.alignment
= alignment
;
231 sym
->bit_size
= bit_size
;
235 static struct symbol
*examine_bitfield_type(struct symbol
*sym
)
237 struct symbol
*base_type
= examine_base_type(sym
);
238 unsigned long bit_size
, alignment
, modifiers
;
242 bit_size
= base_type
->bit_size
;
243 if (sym
->bit_size
> bit_size
)
244 warning(sym
->pos
, "impossible field-width, %d, for this type", sym
->bit_size
);
246 alignment
= base_type
->ctype
.alignment
;
247 if (!sym
->ctype
.alignment
)
248 sym
->ctype
.alignment
= alignment
;
249 modifiers
= base_type
->ctype
.modifiers
;
251 /* Bitfields are unsigned, unless the base type was explicitly signed */
252 if (!(modifiers
& MOD_EXPLICITLY_SIGNED
))
253 modifiers
= (modifiers
& ~MOD_SIGNED
) | MOD_UNSIGNED
;
254 sym
->ctype
.modifiers
|= modifiers
& MOD_SIGNEDNESS
;
259 * "typeof" will have to merge the types together
261 void merge_type(struct symbol
*sym
, struct symbol
*base_type
)
263 sym
->ctype
.as
|= base_type
->ctype
.as
;
264 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& ~MOD_STORAGE
);
265 concat_ptr_list((struct ptr_list
*)base_type
->ctype
.contexts
,
266 (struct ptr_list
**)&sym
->ctype
.contexts
);
267 sym
->ctype
.base_type
= base_type
->ctype
.base_type
;
268 if (sym
->ctype
.base_type
->type
== SYM_NODE
)
269 merge_type(sym
, sym
->ctype
.base_type
);
272 static int count_array_initializer(struct symbol
*t
, struct expression
*expr
)
278 * Arrays of character types are special; they can be initialized by
279 * string literal _or_ by string literal in braces. The latter means
280 * that with T x[] = {<string literal>} number of elements in x depends
281 * on T - if it's a character type, we get the length of string literal
282 * (including NUL), otherwise we have one element here.
284 if (t
->ctype
.base_type
== &int_type
&& t
->ctype
.modifiers
& MOD_CHAR
)
287 switch (expr
->type
) {
288 case EXPR_INITIALIZER
: {
289 struct expression
*entry
;
292 FOR_EACH_PTR(expr
->expr_list
, entry
) {
294 switch (entry
->type
) {
296 if (entry
->idx_to
>= nr
)
297 nr
= entry
->idx_to
+1;
301 str_len
= entry
->string
->length
;
305 } END_FOR_EACH_PTR(entry
);
306 if (count
== 1 && str_len
)
312 nr
= expr
->string
->length
;
319 static struct symbol
* examine_node_type(struct symbol
*sym
)
321 struct symbol
*base_type
= examine_base_type(sym
);
323 unsigned long alignment
;
325 /* SYM_NODE - figure out what the type of the node was.. */
331 bit_size
= base_type
->bit_size
;
332 alignment
= base_type
->ctype
.alignment
;
334 /* Pick up signedness information into the node */
335 sym
->ctype
.modifiers
|= (MOD_SIGNEDNESS
& base_type
->ctype
.modifiers
);
337 if (!sym
->ctype
.alignment
)
338 sym
->ctype
.alignment
= alignment
;
340 /* Unsized array? The size might come from the initializer.. */
341 if (bit_size
< 0 && base_type
->type
== SYM_ARRAY
&& sym
->initializer
) {
342 struct symbol
*node_type
= base_type
->ctype
.base_type
;
343 int count
= count_array_initializer(node_type
, sym
->initializer
);
345 if (node_type
&& node_type
->bit_size
>= 0)
346 bit_size
= node_type
->bit_size
* count
;
349 sym
->bit_size
= bit_size
;
353 static struct symbol
*examine_enum_type(struct symbol
*sym
)
355 struct symbol
*base_type
= examine_base_type(sym
);
357 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& MOD_SIGNEDNESS
);
358 sym
->bit_size
= bits_in_enum
;
359 if (base_type
->bit_size
> sym
->bit_size
)
360 sym
->bit_size
= base_type
->bit_size
;
361 sym
->ctype
.alignment
= enum_alignment
;
362 if (base_type
->ctype
.alignment
> sym
->ctype
.alignment
)
363 sym
->ctype
.alignment
= base_type
->ctype
.alignment
;
367 static struct symbol
*examine_pointer_type(struct symbol
*sym
)
370 * We need to set the pointer size first, and
371 * examine the thing we point to only afterwards.
372 * That's because this pointer type may end up
373 * being needed for the base type size evaluation.
376 sym
->bit_size
= bits_in_pointer
;
377 if (!sym
->ctype
.alignment
)
378 sym
->ctype
.alignment
= pointer_alignment
;
383 * Fill in type size and alignment information for
384 * regular SYM_TYPE things.
386 struct symbol
*examine_symbol_type(struct symbol
* sym
)
399 return examine_node_type(sym
);
401 return examine_array_type(sym
);
403 return examine_struct_union_type(sym
, 1);
405 return examine_struct_union_type(sym
, 0);
407 return examine_pointer_type(sym
);
409 return examine_enum_type(sym
);
411 return examine_bitfield_type(sym
);
413 /* Size and alignment had better already be set up */
416 struct symbol
*base
= evaluate_expression(sym
->initializer
);
418 if (is_bitfield_type(base
))
419 warning(base
->pos
, "typeof applied to bitfield type");
420 if (base
->type
== SYM_NODE
)
421 base
= base
->ctype
.base_type
;
422 sym
->type
= SYM_NODE
;
423 sym
->ctype
.modifiers
= 0;
424 sym
->ctype
.base_type
= base
;
425 return examine_node_type(sym
);
429 case SYM_PREPROCESSOR
:
430 sparse_error(sym
->pos
, "ctype on preprocessor command? (%s)", show_ident(sym
->ident
));
432 case SYM_UNINITIALIZED
:
433 sparse_error(sym
->pos
, "ctype on uninitialized symbol %p", sym
);
436 examine_base_type(sym
);
439 examine_base_type(sym
);
442 sparse_error(sym
->pos
, "Examining unknown symbol type %d", sym
->type
);
448 const char* get_type_name(enum type type
)
450 const char *type_lookup
[] = {
451 [SYM_UNINITIALIZED
] = "uninitialized",
452 [SYM_PREPROCESSOR
] = "preprocessor",
453 [SYM_BASETYPE
] = "basetype",
455 [SYM_PTR
] = "pointer",
456 [SYM_FN
] = "function",
457 [SYM_ARRAY
] = "array",
458 [SYM_STRUCT
] = "struct",
459 [SYM_UNION
] = "union",
461 [SYM_TYPEDEF
] = "typedef",
462 [SYM_TYPEOF
] = "typeof",
463 [SYM_MEMBER
] = "member",
464 [SYM_BITFIELD
] = "bitfield",
465 [SYM_LABEL
] = "label",
466 [SYM_RESTRICT
] = "restrict",
467 [SYM_FOULED
] = "fouled",
468 [SYM_KEYWORD
] = "keyword",
472 return type_lookup
[type
];
477 struct symbol
*examine_pointer_target(struct symbol
*sym
)
479 return examine_base_type(sym
);
482 static struct symbol_list
*restr
, *fouled
;
484 void create_fouled(struct symbol
*type
)
486 if (type
->bit_size
< bits_in_int
) {
487 struct symbol
*new = alloc_symbol(type
->pos
, type
->type
);
489 new->bit_size
= bits_in_int
;
490 new->type
= SYM_FOULED
;
491 new->ctype
.base_type
= type
;
492 add_symbol(&restr
, type
);
493 add_symbol(&fouled
, new);
497 struct symbol
*befoul(struct symbol
*type
)
499 struct symbol
*t1
, *t2
;
500 while (type
->type
== SYM_NODE
)
501 type
= type
->ctype
.base_type
;
502 PREPARE_PTR_LIST(restr
, t1
);
503 PREPARE_PTR_LIST(fouled
, t2
);
517 void check_declaration(struct symbol
*sym
)
520 struct symbol
*next
= sym
;
522 while ((next
= next
->next_id
) != NULL
) {
523 if (next
->namespace != sym
->namespace)
525 if (sym
->scope
== next
->scope
) {
526 sym
->same_symbol
= next
;
529 if (sym
->ctype
.modifiers
& next
->ctype
.modifiers
& MOD_EXTERN
) {
530 if ((sym
->ctype
.modifiers
^ next
->ctype
.modifiers
) & MOD_INLINE
)
532 sym
->same_symbol
= next
;
536 if (!Wshadow
|| warned
)
538 if (get_sym_type(next
) == SYM_FN
)
541 warning(sym
->pos
, "symbol '%s' shadows an earlier one", show_ident(sym
->ident
));
542 info(next
->pos
, "originally declared here");
546 void bind_symbol(struct symbol
*sym
, struct ident
*ident
, enum namespace ns
)
550 sparse_error(sym
->pos
, "internal error: symbol type already bound");
553 if (ident
->reserved
&& (ns
& (NS_TYPEDEF
| NS_STRUCT
| NS_LABEL
| NS_SYMBOL
))) {
554 sparse_error(sym
->pos
, "Trying to use reserved word '%s' as identifier", show_ident(ident
));
558 sym
->next_id
= ident
->symbols
;
559 ident
->symbols
= sym
;
560 if (sym
->ident
&& sym
->ident
!= ident
)
561 warning(sym
->pos
, "Symbol '%s' already bound", show_ident(sym
->ident
));
566 if (ns
== NS_SYMBOL
&& toplevel(scope
)) {
567 unsigned mod
= MOD_ADDRESSABLE
| MOD_TOPLEVEL
;
569 scope
= global_scope
;
570 if (sym
->ctype
.modifiers
& MOD_STATIC
||
571 is_extern_inline(sym
)) {
575 sym
->ctype
.modifiers
|= mod
;
580 scope
= function_scope
;
581 bind_scope(sym
, scope
);
584 struct symbol
*create_symbol(int stream
, const char *name
, int type
, int namespace)
586 struct token
*token
= built_in_token(stream
, name
);
587 struct symbol
*sym
= alloc_symbol(token
->pos
, type
);
589 bind_symbol(sym
, token
->ident
, namespace);
593 static int evaluate_to_integer(struct expression
*expr
)
595 expr
->ctype
= &int_ctype
;
599 static int evaluate_expect(struct expression
*expr
)
601 /* Should we evaluate it to return the type of the first argument? */
602 expr
->ctype
= &int_ctype
;
606 static int arguments_choose(struct expression
*expr
)
608 struct expression_list
*arglist
= expr
->args
;
609 struct expression
*arg
;
612 FOR_EACH_PTR (arglist
, arg
) {
613 if (!evaluate_expression(arg
))
616 } END_FOR_EACH_PTR(arg
);
618 sparse_error(expr
->pos
,
619 "not enough arguments for __builtin_choose_expr");
622 sparse_error(expr
->pos
,
623 "too many arguments for __builtin_choose_expr");
629 static int evaluate_choose(struct expression
*expr
)
631 struct expression_list
*list
= expr
->args
;
632 struct expression
*arg
, *args
[3];
635 /* there will be exactly 3; we'd already verified that */
636 FOR_EACH_PTR(list
, arg
) {
638 } END_FOR_EACH_PTR(arg
);
640 *expr
= get_expression_value(args
[0]) ? *args
[1] : *args
[2];
645 static int expand_expect(struct expression
*expr
, int cost
)
647 struct expression
*arg
= first_ptr_list((struct ptr_list
*) expr
->args
);
655 * __builtin_warning() has type "int" and always returns 1,
656 * so that you can use it in conditionals or whatever
658 static int expand_warning(struct expression
*expr
, int cost
)
660 struct expression
*arg
;
661 struct expression_list
*arglist
= expr
->args
;
663 FOR_EACH_PTR (arglist
, arg
) {
665 * Constant strings get printed out as a warning. By the
666 * time we get here, the EXPR_STRING has been fully
667 * evaluated, so by now it's an anonymous symbol with a
668 * string initializer.
670 * Just for the heck of it, allow any constant string
673 if (arg
->type
== EXPR_SYMBOL
) {
674 struct symbol
*sym
= arg
->symbol
;
675 if (sym
->initializer
&& sym
->initializer
->type
== EXPR_STRING
) {
676 struct string
*string
= sym
->initializer
->string
;
677 warning(expr
->pos
, "%*s", string
->length
-1, string
->data
);
683 * Any other argument is a conditional. If it's
684 * non-constant, or it is false, we exit and do
685 * not print any warning.
687 if (arg
->type
!= EXPR_VALUE
)
691 } END_FOR_EACH_PTR(arg
);
693 expr
->type
= EXPR_VALUE
;
699 static struct symbol_op constant_p_op
= {
700 .evaluate
= evaluate_to_integer
,
701 .expand
= expand_constant_p
704 static struct symbol_op safe_p_op
= {
705 .evaluate
= evaluate_to_integer
,
706 .expand
= expand_safe_p
709 static struct symbol_op warning_op
= {
710 .evaluate
= evaluate_to_integer
,
711 .expand
= expand_warning
714 static struct symbol_op expect_op
= {
715 .evaluate
= evaluate_expect
,
716 .expand
= expand_expect
719 static struct symbol_op choose_op
= {
720 .evaluate
= evaluate_choose
,
721 .args
= arguments_choose
,
727 static struct symbol builtin_fn_type
= { .type
= SYM_FN
/* , .variadic =1 */ };
728 static struct sym_init
{
730 struct symbol
*base_type
;
731 unsigned int modifiers
;
732 struct symbol_op
*op
;
733 } eval_init_table
[] = {
734 { "__builtin_constant_p", &builtin_fn_type
, MOD_TOPLEVEL
, &constant_p_op
},
735 { "__builtin_safe_p", &builtin_fn_type
, MOD_TOPLEVEL
, &safe_p_op
},
736 { "__builtin_warning", &builtin_fn_type
, MOD_TOPLEVEL
, &warning_op
},
737 { "__builtin_expect", &builtin_fn_type
, MOD_TOPLEVEL
, &expect_op
},
738 { "__builtin_choose_expr", &builtin_fn_type
, MOD_TOPLEVEL
, &choose_op
},
746 struct symbol int_type
,
750 * C types (i.e. actual instances that the abstract types
753 struct symbol bool_ctype
, void_ctype
, type_ctype
,
754 char_ctype
, schar_ctype
, uchar_ctype
,
755 short_ctype
, sshort_ctype
, ushort_ctype
,
756 int_ctype
, sint_ctype
, uint_ctype
,
757 long_ctype
, slong_ctype
, ulong_ctype
,
758 llong_ctype
, sllong_ctype
, ullong_ctype
,
759 lllong_ctype
, slllong_ctype
, ulllong_ctype
,
760 float_ctype
, double_ctype
, ldouble_ctype
,
761 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
762 incomplete_ctype
, label_ctype
, bad_ctype
,
765 struct symbol zero_int
;
767 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
768 #define __IDENT(n,str,res) \
769 struct ident n = __INIT_IDENT(str,res)
771 #include "ident-list.h"
773 void init_symbols(void)
775 int stream
= init_stream("builtin", -1, includepath
);
776 struct sym_init
*ptr
;
778 #define __IDENT(n,str,res) \
780 #include "ident-list.h"
784 builtin_fn_type
.variadic
= 1;
785 for (ptr
= eval_init_table
; ptr
->name
; ptr
++) {
787 sym
= create_symbol(stream
, ptr
->name
, SYM_NODE
, NS_SYMBOL
);
788 sym
->ctype
.base_type
= ptr
->base_type
;
789 sym
->ctype
.modifiers
= ptr
->modifiers
;
794 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
795 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
796 #define MOD_LLL MOD_LONGLONGLONG
797 static const struct ctype_declare
{
800 unsigned long modifiers
;
803 struct symbol
*base_type
;
804 } ctype_declaration
[] = {
805 { &bool_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_bool
, &max_int_alignment
, &int_type
},
806 { &void_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
807 { &type_ctype
, SYM_BASETYPE
, MOD_TYPE
, NULL
, NULL
, NULL
},
808 { &incomplete_ctype
,SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
809 { &bad_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
811 { &char_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
812 { &schar_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
813 { &uchar_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
814 { &short_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
815 { &sshort_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
816 { &ushort_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
817 { &int_ctype
, SYM_BASETYPE
, MOD_SIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
818 { &sint_ctype
, SYM_BASETYPE
, MOD_ESIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
819 { &uint_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
820 { &long_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
821 { &slong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
822 { &ulong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
823 { &llong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
824 { &sllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
825 { &ullong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
826 { &lllong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
827 { &slllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
828 { &ulllong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
830 { &float_ctype
, SYM_BASETYPE
, 0, &bits_in_float
, &max_fp_alignment
, &fp_type
},
831 { &double_ctype
, SYM_BASETYPE
, MOD_LONG
, &bits_in_double
, &max_fp_alignment
, &fp_type
},
832 { &ldouble_ctype
, SYM_BASETYPE
, MOD_LONG
| MOD_LONGLONG
, &bits_in_longdouble
, &max_fp_alignment
, &fp_type
},
834 { &string_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &char_ctype
},
835 { &ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
836 { &null_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
837 { &label_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
838 { &lazy_ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
845 void init_ctype(void)
847 const struct ctype_declare
*ctype
;
849 for (ctype
= ctype_declaration
; ctype
->ptr
; ctype
++) {
850 struct symbol
*sym
= ctype
->ptr
;
851 unsigned long bit_size
= ctype
->bit_size
? *ctype
->bit_size
: -1;
852 unsigned long maxalign
= ctype
->maxalign
? *ctype
->maxalign
: 0;
853 unsigned long alignment
= bits_to_bytes(bit_size
+ bits_in_char
- 1);
855 if (alignment
> maxalign
)
856 alignment
= maxalign
;
857 sym
->type
= ctype
->type
;
858 sym
->bit_size
= bit_size
;
859 sym
->ctype
.alignment
= alignment
;
860 sym
->ctype
.base_type
= ctype
->base_type
;
861 sym
->ctype
.modifiers
= ctype
->modifiers
;