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);
66 sym
->ctype
.attribute
= &null_attr
;
70 struct struct_union_info
{
71 unsigned long max_align
;
72 unsigned long bit_size
;
77 * Unions are fairly easy to lay out ;)
79 static void lay_out_union(struct symbol
*sym
, struct struct_union_info
*info
)
81 examine_symbol_type(sym
);
83 // Unnamed bitfields do not affect alignment.
84 if (sym
->ident
|| !is_bitfield_type(sym
)) {
85 if (sym
->ctype
.alignment
> info
->max_align
)
86 info
->max_align
= sym
->ctype
.alignment
;
89 if (sym
->bit_size
> info
->bit_size
)
90 info
->bit_size
= sym
->bit_size
;
95 static int bitfield_base_size(struct symbol
*sym
)
97 if (sym
->type
== SYM_NODE
)
98 sym
= sym
->ctype
.base_type
;
99 if (sym
->type
== SYM_BITFIELD
)
100 sym
= sym
->ctype
.base_type
;
101 return sym
->bit_size
;
105 * Structures are a bit more interesting to lay out
107 static void lay_out_struct(struct symbol
*sym
, struct struct_union_info
*info
)
109 unsigned long bit_size
, align_bit_mask
;
112 examine_symbol_type(sym
);
114 // Unnamed bitfields do not affect alignment.
115 if (sym
->ident
|| !is_bitfield_type(sym
)) {
116 if (sym
->ctype
.alignment
> info
->max_align
)
117 info
->max_align
= sym
->ctype
.alignment
;
120 bit_size
= info
->bit_size
;
121 base_size
= sym
->bit_size
;
124 * Unsized arrays cause us to not align the resulting
128 info
->align_size
= 0;
132 align_bit_mask
= bytes_to_bits(sym
->ctype
.alignment
) - 1;
135 * Bitfields have some very special rules..
137 if (is_bitfield_type (sym
)) {
138 unsigned long bit_offset
= bit_size
& align_bit_mask
;
139 int room
= bitfield_base_size(sym
) - bit_offset
;
140 // Zero-width fields just fill up the unit.
141 int width
= base_size
? : (bit_offset
? room
: 0);
144 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
147 sym
->offset
= bits_to_bytes(bit_size
- bit_offset
);
148 sym
->bit_offset
= bit_offset
;
149 sym
->ctype
.base_type
->bit_offset
= bit_offset
;
150 info
->bit_size
= bit_size
+ width
;
151 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
157 * Otherwise, just align it right and add it up..
159 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
160 sym
->offset
= bits_to_bytes(bit_size
);
162 info
->bit_size
= bit_size
+ base_size
;
163 // warning (sym->pos, "regular: offset=%d", sym->offset);
166 static struct symbol
* examine_struct_union_type(struct symbol
*sym
, int advance
)
168 struct struct_union_info info
= {
173 unsigned long bit_size
, bit_align
;
174 void (*fn
)(struct symbol
*, struct struct_union_info
*);
175 struct symbol
*member
;
177 fn
= advance
? lay_out_struct
: lay_out_union
;
178 FOR_EACH_PTR(sym
->symbol_list
, member
) {
180 } END_FOR_EACH_PTR(member
);
182 if (!sym
->ctype
.alignment
)
183 sym
->ctype
.alignment
= info
.max_align
;
184 bit_size
= info
.bit_size
;
185 if (info
.align_size
) {
186 bit_align
= bytes_to_bits(sym
->ctype
.alignment
)-1;
187 bit_size
= (bit_size
+ bit_align
) & ~bit_align
;
189 sym
->bit_size
= bit_size
;
193 static struct symbol
*examine_base_type(struct symbol
*sym
)
195 struct symbol
*base_type
;
197 /* Check the base type */
198 base_type
= examine_symbol_type(sym
->ctype
.base_type
);
199 if (!base_type
|| base_type
->type
== SYM_PTR
)
201 sym
->ctype
.modifiers
|= base_type
->ctype
.modifiers
& MOD_PTRINHERIT
;
203 merge_attr(&sym
->ctype
, &base_type
->ctype
);
205 if (base_type
->type
== SYM_NODE
) {
206 base_type
= base_type
->ctype
.base_type
;
207 sym
->ctype
.base_type
= base_type
;
212 static struct symbol
* examine_array_type(struct symbol
*sym
)
214 struct symbol
*base_type
= examine_base_type(sym
);
215 unsigned long bit_size
, alignment
;
219 bit_size
= base_type
->bit_size
* get_expression_value(sym
->array_size
);
220 if (!sym
->array_size
|| sym
->array_size
->type
!= EXPR_VALUE
)
222 alignment
= base_type
->ctype
.alignment
;
223 if (!sym
->ctype
.alignment
)
224 sym
->ctype
.alignment
= alignment
;
225 sym
->bit_size
= bit_size
;
229 static struct symbol
*examine_bitfield_type(struct symbol
*sym
)
231 struct symbol
*base_type
= examine_base_type(sym
);
232 unsigned long bit_size
, alignment
, modifiers
;
236 bit_size
= base_type
->bit_size
;
237 if (sym
->bit_size
> bit_size
)
238 warning(sym
->pos
, "impossible field-width, %d, for this type", sym
->bit_size
);
240 alignment
= base_type
->ctype
.alignment
;
241 if (!sym
->ctype
.alignment
)
242 sym
->ctype
.alignment
= alignment
;
243 modifiers
= base_type
->ctype
.modifiers
;
245 /* Bitfields are unsigned, unless the base type was explicitly signed */
246 if (!(modifiers
& MOD_EXPLICITLY_SIGNED
))
247 modifiers
= (modifiers
& ~MOD_SIGNED
) | MOD_UNSIGNED
;
248 sym
->ctype
.modifiers
|= modifiers
& MOD_SIGNEDNESS
;
253 * "typeof" will have to merge the types together
255 void merge_type(struct symbol
*sym
, struct symbol
*base_type
)
257 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& ~MOD_STORAGE
);
258 merge_attr(&sym
->ctype
, &base_type
->ctype
);
259 sym
->ctype
.base_type
= base_type
->ctype
.base_type
;
260 if (sym
->ctype
.base_type
->type
== SYM_NODE
)
261 merge_type(sym
, sym
->ctype
.base_type
);
264 static int count_array_initializer(struct symbol
*t
, struct expression
*expr
)
270 * Arrays of character types are special; they can be initialized by
271 * string literal _or_ by string literal in braces. The latter means
272 * that with T x[] = {<string literal>} number of elements in x depends
273 * on T - if it's a character type, we get the length of string literal
274 * (including NUL), otherwise we have one element here.
276 if (t
->ctype
.base_type
== &int_type
&& t
->ctype
.modifiers
& MOD_CHAR
)
279 switch (expr
->type
) {
280 case EXPR_INITIALIZER
: {
281 struct expression
*entry
;
284 FOR_EACH_PTR(expr
->expr_list
, entry
) {
286 switch (entry
->type
) {
288 if (entry
->idx_to
>= nr
)
289 nr
= entry
->idx_to
+1;
293 str_len
= entry
->string
->length
;
297 } END_FOR_EACH_PTR(entry
);
298 if (count
== 1 && str_len
)
304 nr
= expr
->string
->length
;
311 static struct symbol
* examine_node_type(struct symbol
*sym
)
313 struct symbol
*base_type
= examine_base_type(sym
);
315 unsigned long alignment
;
317 /* SYM_NODE - figure out what the type of the node was.. */
323 bit_size
= base_type
->bit_size
;
324 alignment
= base_type
->ctype
.alignment
;
326 /* Pick up signedness information into the node */
327 sym
->ctype
.modifiers
|= (MOD_SIGNEDNESS
& base_type
->ctype
.modifiers
);
329 if (!sym
->ctype
.alignment
)
330 sym
->ctype
.alignment
= alignment
;
332 /* Unsized array? The size might come from the initializer.. */
333 if (bit_size
< 0 && base_type
->type
== SYM_ARRAY
&& sym
->initializer
) {
334 struct symbol
*node_type
= base_type
->ctype
.base_type
;
335 int count
= count_array_initializer(node_type
, sym
->initializer
);
337 if (node_type
&& node_type
->bit_size
>= 0)
338 bit_size
= node_type
->bit_size
* count
;
341 sym
->bit_size
= bit_size
;
345 static struct symbol
*examine_enum_type(struct symbol
*sym
)
347 struct symbol
*base_type
= examine_base_type(sym
);
349 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& MOD_SIGNEDNESS
);
350 sym
->bit_size
= bits_in_enum
;
351 if (base_type
->bit_size
> sym
->bit_size
)
352 sym
->bit_size
= base_type
->bit_size
;
353 sym
->ctype
.alignment
= enum_alignment
;
354 if (base_type
->ctype
.alignment
> sym
->ctype
.alignment
)
355 sym
->ctype
.alignment
= base_type
->ctype
.alignment
;
359 static struct symbol
*examine_pointer_type(struct symbol
*sym
)
362 * We need to set the pointer size first, and
363 * examine the thing we point to only afterwards.
364 * That's because this pointer type may end up
365 * being needed for the base type size evaluation.
368 sym
->bit_size
= bits_in_pointer
;
369 if (!sym
->ctype
.alignment
)
370 sym
->ctype
.alignment
= pointer_alignment
;
375 * Fill in type size and alignment information for
376 * regular SYM_TYPE things.
378 struct symbol
*examine_symbol_type(struct symbol
* sym
)
391 return examine_node_type(sym
);
393 return examine_array_type(sym
);
395 return examine_struct_union_type(sym
, 1);
397 return examine_struct_union_type(sym
, 0);
399 return examine_pointer_type(sym
);
401 return examine_enum_type(sym
);
403 return examine_bitfield_type(sym
);
405 /* Size and alignment had better already be set up */
408 struct symbol
*base
= evaluate_expression(sym
->initializer
);
410 if (is_bitfield_type(base
))
411 warning(base
->pos
, "typeof applied to bitfield type");
412 if (base
->type
== SYM_NODE
)
413 base
= base
->ctype
.base_type
;
414 sym
->type
= SYM_NODE
;
415 sym
->ctype
.modifiers
= 0;
416 sym
->ctype
.base_type
= base
;
417 return examine_node_type(sym
);
421 case SYM_PREPROCESSOR
:
422 sparse_error(sym
->pos
, "ctype on preprocessor command? (%s)", show_ident(sym
->ident
));
424 case SYM_UNINITIALIZED
:
425 // sparse_error(sym->pos, "ctype on uninitialized symbol %p", sym);
428 examine_base_type(sym
);
431 examine_base_type(sym
);
434 sparse_error(sym
->pos
, "Examining unknown symbol type %d", sym
->type
);
440 const char* get_type_name(enum type type
)
442 const char *type_lookup
[] = {
443 [SYM_UNINITIALIZED
] = "uninitialized",
444 [SYM_PREPROCESSOR
] = "preprocessor",
445 [SYM_BASETYPE
] = "basetype",
447 [SYM_PTR
] = "pointer",
448 [SYM_FN
] = "function",
449 [SYM_ARRAY
] = "array",
450 [SYM_STRUCT
] = "struct",
451 [SYM_UNION
] = "union",
453 [SYM_TYPEDEF
] = "typedef",
454 [SYM_TYPEOF
] = "typeof",
455 [SYM_MEMBER
] = "member",
456 [SYM_BITFIELD
] = "bitfield",
457 [SYM_LABEL
] = "label",
458 [SYM_RESTRICT
] = "restrict",
459 [SYM_FOULED
] = "fouled",
460 [SYM_KEYWORD
] = "keyword",
464 return type_lookup
[type
];
469 struct symbol
*examine_pointer_target(struct symbol
*sym
)
471 return examine_base_type(sym
);
474 static struct symbol_list
*restr
, *fouled
;
476 void create_fouled(struct symbol
*type
)
478 if (type
->bit_size
< bits_in_int
) {
479 struct symbol
*new = alloc_symbol(type
->pos
, type
->type
);
481 new->bit_size
= bits_in_int
;
482 new->type
= SYM_FOULED
;
483 new->ctype
.base_type
= type
;
484 add_symbol(&restr
, type
);
485 add_symbol(&fouled
, new);
489 struct symbol
*befoul(struct symbol
*type
)
491 struct symbol
*t1
, *t2
;
492 while (type
->type
== SYM_NODE
)
493 type
= type
->ctype
.base_type
;
494 PREPARE_PTR_LIST(restr
, t1
);
495 PREPARE_PTR_LIST(fouled
, t2
);
509 void check_declaration(struct symbol
*sym
)
512 struct symbol
*next
= sym
;
514 while ((next
= next
->next_id
) != NULL
) {
515 if (next
->namespace != sym
->namespace)
517 if (sym
->scope
== next
->scope
) {
518 sym
->same_symbol
= next
;
521 if (sym
->ctype
.modifiers
& next
->ctype
.modifiers
& MOD_EXTERN
) {
522 if ((sym
->ctype
.modifiers
^ next
->ctype
.modifiers
) & MOD_INLINE
)
524 sym
->same_symbol
= next
;
528 if (!Wshadow
|| warned
)
530 if (get_sym_type(next
) == SYM_FN
)
533 warning(sym
->pos
, "symbol '%s' shadows an earlier one", show_ident(sym
->ident
));
534 info(next
->pos
, "originally declared here");
538 void bind_symbol(struct symbol
*sym
, struct ident
*ident
, enum namespace ns
)
542 sparse_error(sym
->pos
, "internal error: symbol type already bound");
545 if (ident
->reserved
&& (ns
& (NS_TYPEDEF
| NS_STRUCT
| NS_LABEL
| NS_SYMBOL
))) {
546 sparse_error(sym
->pos
, "Trying to use reserved word '%s' as identifier", show_ident(ident
));
550 sym
->next_id
= ident
->symbols
;
551 ident
->symbols
= sym
;
552 if (sym
->ident
&& sym
->ident
!= ident
)
553 warning(sym
->pos
, "Symbol '%s' already bound", show_ident(sym
->ident
));
558 if (ns
== NS_SYMBOL
&& toplevel(scope
)) {
559 unsigned mod
= MOD_ADDRESSABLE
| MOD_TOPLEVEL
;
561 scope
= global_scope
;
562 if (sym
->ctype
.modifiers
& MOD_STATIC
||
563 is_extern_inline(sym
)) {
567 sym
->ctype
.modifiers
|= mod
;
572 scope
= function_scope
;
573 bind_scope(sym
, scope
);
576 struct symbol
*create_symbol(int stream
, const char *name
, int type
, int namespace)
578 struct token
*token
= built_in_token(stream
, name
);
579 struct symbol
*sym
= alloc_symbol(token
->pos
, type
);
581 bind_symbol(sym
, token
->ident
, namespace);
585 static int evaluate_to_integer(struct expression
*expr
)
587 expr
->ctype
= &int_ctype
;
591 static int evaluate_expect(struct expression
*expr
)
593 /* Should we evaluate it to return the type of the first argument? */
594 expr
->ctype
= &int_ctype
;
598 static int arguments_choose(struct expression
*expr
)
600 struct expression_list
*arglist
= expr
->args
;
601 struct expression
*arg
;
604 FOR_EACH_PTR (arglist
, arg
) {
605 if (!evaluate_expression(arg
))
608 } END_FOR_EACH_PTR(arg
);
610 sparse_error(expr
->pos
,
611 "not enough arguments for __builtin_choose_expr");
614 sparse_error(expr
->pos
,
615 "too many arguments for __builtin_choose_expr");
621 static int evaluate_choose(struct expression
*expr
)
623 struct expression_list
*list
= expr
->args
;
624 struct expression
*arg
, *args
[3];
627 /* there will be exactly 3; we'd already verified that */
628 FOR_EACH_PTR(list
, arg
) {
630 } END_FOR_EACH_PTR(arg
);
632 *expr
= get_expression_value(args
[0]) ? *args
[1] : *args
[2];
637 static int expand_expect(struct expression
*expr
, int cost
)
639 struct expression
*arg
= first_ptr_list((struct ptr_list
*) expr
->args
);
647 * __builtin_warning() has type "int" and always returns 1,
648 * so that you can use it in conditionals or whatever
650 static int expand_warning(struct expression
*expr
, int cost
)
652 struct expression
*arg
;
653 struct expression_list
*arglist
= expr
->args
;
655 FOR_EACH_PTR (arglist
, arg
) {
657 * Constant strings get printed out as a warning. By the
658 * time we get here, the EXPR_STRING has been fully
659 * evaluated, so by now it's an anonymous symbol with a
660 * string initializer.
662 * Just for the heck of it, allow any constant string
665 if (arg
->type
== EXPR_SYMBOL
) {
666 struct symbol
*sym
= arg
->symbol
;
667 if (sym
->initializer
&& sym
->initializer
->type
== EXPR_STRING
) {
668 struct string
*string
= sym
->initializer
->string
;
669 warning(expr
->pos
, "%*s", string
->length
-1, string
->data
);
675 * Any other argument is a conditional. If it's
676 * non-constant, or it is false, we exit and do
677 * not print any warning.
679 if (arg
->type
!= EXPR_VALUE
)
683 } END_FOR_EACH_PTR(arg
);
685 expr
->type
= EXPR_VALUE
;
691 static struct symbol_op constant_p_op
= {
692 .evaluate
= evaluate_to_integer
,
693 .expand
= expand_constant_p
696 static struct symbol_op safe_p_op
= {
697 .evaluate
= evaluate_to_integer
,
698 .expand
= expand_safe_p
701 static struct symbol_op warning_op
= {
702 .evaluate
= evaluate_to_integer
,
703 .expand
= expand_warning
706 static struct symbol_op expect_op
= {
707 .evaluate
= evaluate_expect
,
708 .expand
= expand_expect
711 static struct symbol_op choose_op
= {
712 .evaluate
= evaluate_choose
,
713 .args
= arguments_choose
,
719 static struct symbol builtin_fn_type
= { .type
= SYM_FN
/* , .variadic =1 */ };
720 static struct sym_init
{
722 struct symbol
*base_type
;
723 unsigned int modifiers
;
724 struct symbol_op
*op
;
725 } eval_init_table
[] = {
726 { "__builtin_constant_p", &builtin_fn_type
, MOD_TOPLEVEL
, &constant_p_op
},
727 { "__builtin_safe_p", &builtin_fn_type
, MOD_TOPLEVEL
, &safe_p_op
},
728 { "__builtin_warning", &builtin_fn_type
, MOD_TOPLEVEL
, &warning_op
},
729 { "__builtin_expect", &builtin_fn_type
, MOD_TOPLEVEL
, &expect_op
},
730 { "__builtin_choose_expr", &builtin_fn_type
, MOD_TOPLEVEL
, &choose_op
},
735 * Default empty attribute
737 struct attribute null_attr
= {};
742 struct symbol int_type
,
746 * C types (i.e. actual instances that the abstract types
749 struct symbol bool_ctype
, void_ctype
, type_ctype
,
750 char_ctype
, schar_ctype
, uchar_ctype
,
751 short_ctype
, sshort_ctype
, ushort_ctype
,
752 int_ctype
, sint_ctype
, uint_ctype
,
753 long_ctype
, slong_ctype
, ulong_ctype
,
754 llong_ctype
, sllong_ctype
, ullong_ctype
,
755 lllong_ctype
, slllong_ctype
, ulllong_ctype
,
756 float_ctype
, double_ctype
, ldouble_ctype
,
757 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
758 incomplete_ctype
, label_ctype
, bad_ctype
,
761 struct symbol zero_int
;
763 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
764 #define __IDENT(n,str,res) \
765 struct ident n = __INIT_IDENT(str,res)
767 #include "ident-list.h"
769 void init_symbols(void)
771 int stream
= init_stream("builtin", -1, includepath
);
772 struct sym_init
*ptr
;
774 #define __IDENT(n,str,res) \
776 #include "ident-list.h"
780 builtin_fn_type
.variadic
= 1;
781 builtin_fn_type
.ctype
.attribute
= &null_attr
;
782 for (ptr
= eval_init_table
; ptr
->name
; ptr
++) {
784 sym
= create_symbol(stream
, ptr
->name
, SYM_NODE
, NS_SYMBOL
);
785 sym
->ctype
.base_type
= ptr
->base_type
;
786 sym
->ctype
.modifiers
= ptr
->modifiers
;
787 sym
->ctype
.attribute
= &null_attr
;
792 #ifdef __CHAR_UNSIGNED__
793 #define CHAR_SIGNEDNESS MOD_UNSIGNED
795 #define CHAR_SIGNEDNESS MOD_SIGNED
798 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
799 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
800 #define MOD_LLL MOD_LONGLONGLONG
801 static const struct ctype_declare
{
804 unsigned long modifiers
;
807 struct symbol
*base_type
;
808 } ctype_declaration
[] = {
809 { &bool_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_bool
, &max_int_alignment
, &int_type
},
810 { &void_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
811 { &type_ctype
, SYM_BASETYPE
, MOD_TYPE
, NULL
, NULL
, NULL
},
812 { &incomplete_ctype
,SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
813 { &bad_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
815 { &char_ctype
, SYM_BASETYPE
, CHAR_SIGNEDNESS
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
816 { &schar_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
817 { &uchar_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
818 { &short_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
819 { &sshort_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
820 { &ushort_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
821 { &int_ctype
, SYM_BASETYPE
, MOD_SIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
822 { &sint_ctype
, SYM_BASETYPE
, MOD_ESIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
823 { &uint_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
824 { &long_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
825 { &slong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
826 { &ulong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
827 { &llong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
828 { &sllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
829 { &ullong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
830 { &lllong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
831 { &slllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
832 { &ulllong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
834 { &float_ctype
, SYM_BASETYPE
, 0, &bits_in_float
, &max_fp_alignment
, &fp_type
},
835 { &double_ctype
, SYM_BASETYPE
, MOD_LONG
, &bits_in_double
, &max_fp_alignment
, &fp_type
},
836 { &ldouble_ctype
, SYM_BASETYPE
, MOD_LONG
| MOD_LONGLONG
, &bits_in_longdouble
, &max_fp_alignment
, &fp_type
},
838 { &string_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &char_ctype
},
839 { &ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
840 { &null_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
841 { &label_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
842 { &lazy_ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
849 void init_ctype(void)
851 const struct ctype_declare
*ctype
;
853 for (ctype
= ctype_declaration
; ctype
->ptr
; ctype
++) {
854 struct symbol
*sym
= ctype
->ptr
;
855 unsigned long bit_size
= ctype
->bit_size
? *ctype
->bit_size
: -1;
856 unsigned long maxalign
= ctype
->maxalign
? *ctype
->maxalign
: 0;
857 unsigned long alignment
= bits_to_bytes(bit_size
+ bits_in_char
- 1);
859 if (alignment
> maxalign
)
860 alignment
= maxalign
;
861 sym
->type
= ctype
->type
;
862 sym
->bit_size
= bit_size
;
863 sym
->ctype
.alignment
= alignment
;
864 sym
->ctype
.base_type
= ctype
->base_type
;
865 sym
->ctype
.modifiers
= ctype
->modifiers
;
866 sym
->ctype
.attribute
= &null_attr
;