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);
85 struct struct_union_info
{
86 unsigned long max_align
;
87 unsigned long bit_size
;
92 * Unions are fairly easy to lay out ;)
94 static void lay_out_union(struct symbol
*sym
, struct struct_union_info
*info
)
96 examine_symbol_type(sym
);
98 // Unnamed bitfields do not affect alignment.
99 if (sym
->ident
|| !is_bitfield_type(sym
)) {
100 if (sym
->ctype
.alignment
> info
->max_align
)
101 info
->max_align
= sym
->ctype
.alignment
;
104 if (sym
->bit_size
> info
->bit_size
)
105 info
->bit_size
= sym
->bit_size
;
110 static int bitfield_base_size(struct symbol
*sym
)
112 if (sym
->type
== SYM_NODE
)
113 sym
= sym
->ctype
.base_type
;
114 if (sym
->type
== SYM_BITFIELD
)
115 sym
= sym
->ctype
.base_type
;
116 return sym
->bit_size
;
120 * Structures are a bit more interesting to lay out
122 static void lay_out_struct(struct symbol
*sym
, struct struct_union_info
*info
)
124 unsigned long bit_size
, align_bit_mask
;
127 examine_symbol_type(sym
);
129 // Unnamed bitfields do not affect alignment.
130 if (sym
->ident
|| !is_bitfield_type(sym
)) {
131 if (sym
->ctype
.alignment
> info
->max_align
)
132 info
->max_align
= sym
->ctype
.alignment
;
135 bit_size
= info
->bit_size
;
136 base_size
= sym
->bit_size
;
139 * Unsized arrays cause us to not align the resulting
143 info
->align_size
= 0;
147 align_bit_mask
= bytes_to_bits(sym
->ctype
.alignment
) - 1;
150 * Bitfields have some very special rules..
152 if (is_bitfield_type (sym
)) {
153 unsigned long bit_offset
= bit_size
& align_bit_mask
;
154 int room
= bitfield_base_size(sym
) - bit_offset
;
155 // Zero-width fields just fill up the unit.
156 int width
= base_size
? : (bit_offset
? room
: 0);
159 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
162 sym
->offset
= bits_to_bytes(bit_size
- bit_offset
);
163 sym
->bit_offset
= bit_offset
;
164 sym
->ctype
.base_type
->bit_offset
= bit_offset
;
165 info
->bit_size
= bit_size
+ width
;
166 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
172 * Otherwise, just align it right and add it up..
174 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
175 sym
->offset
= bits_to_bytes(bit_size
);
177 info
->bit_size
= bit_size
+ base_size
;
178 // warning (sym->pos, "regular: offset=%d", sym->offset);
181 static struct symbol
* examine_struct_union_type(struct symbol
*sym
, int advance
)
183 struct struct_union_info info
= {
188 unsigned long bit_size
, bit_align
;
189 void (*fn
)(struct symbol
*, struct struct_union_info
*);
190 struct symbol
*member
;
192 fn
= advance
? lay_out_struct
: lay_out_union
;
193 FOR_EACH_PTR(sym
->symbol_list
, member
) {
195 } END_FOR_EACH_PTR(member
);
197 if (!sym
->ctype
.alignment
)
198 sym
->ctype
.alignment
= info
.max_align
;
199 bit_size
= info
.bit_size
;
200 if (info
.align_size
) {
201 bit_align
= bytes_to_bits(sym
->ctype
.alignment
)-1;
202 bit_size
= (bit_size
+ bit_align
) & ~bit_align
;
204 sym
->bit_size
= bit_size
;
208 static struct symbol
*examine_base_type(struct symbol
*sym
)
210 struct symbol
*base_type
;
212 /* Check the base type */
213 base_type
= examine_symbol_type(sym
->ctype
.base_type
);
214 if (!base_type
|| base_type
->type
== SYM_PTR
)
216 sym
->ctype
.as
|= base_type
->ctype
.as
;
217 sym
->ctype
.modifiers
|= base_type
->ctype
.modifiers
& MOD_PTRINHERIT
;
218 concat_ptr_list((struct ptr_list
*)base_type
->ctype
.contexts
,
219 (struct ptr_list
**)&sym
->ctype
.contexts
);
220 if (base_type
->type
== SYM_NODE
) {
221 base_type
= base_type
->ctype
.base_type
;
222 sym
->ctype
.base_type
= base_type
;
227 static struct symbol
* examine_array_type(struct symbol
*sym
)
229 struct symbol
*base_type
= examine_base_type(sym
);
230 unsigned long bit_size
= -1, alignment
;
231 struct expression
*array_size
= sym
->array_size
;
237 bit_size
= base_type
->bit_size
* get_expression_value_silent(array_size
);
238 if (array_size
->type
!= EXPR_VALUE
) {
240 warning(array_size
->pos
, "Variable length array is used.");
244 alignment
= base_type
->ctype
.alignment
;
245 if (!sym
->ctype
.alignment
)
246 sym
->ctype
.alignment
= alignment
;
247 sym
->bit_size
= bit_size
;
251 static struct symbol
*examine_bitfield_type(struct symbol
*sym
)
253 struct symbol
*base_type
= examine_base_type(sym
);
254 unsigned long bit_size
, alignment
, modifiers
;
258 bit_size
= base_type
->bit_size
;
259 if (sym
->bit_size
> bit_size
)
260 warning(sym
->pos
, "impossible field-width, %d, for this type", sym
->bit_size
);
262 alignment
= base_type
->ctype
.alignment
;
263 if (!sym
->ctype
.alignment
)
264 sym
->ctype
.alignment
= alignment
;
265 modifiers
= base_type
->ctype
.modifiers
;
267 /* Bitfields are unsigned, unless the base type was explicitly signed */
268 if (!(modifiers
& MOD_EXPLICITLY_SIGNED
))
269 modifiers
= (modifiers
& ~MOD_SIGNED
) | MOD_UNSIGNED
;
270 sym
->ctype
.modifiers
|= modifiers
& MOD_SIGNEDNESS
;
275 * "typeof" will have to merge the types together
277 void merge_type(struct symbol
*sym
, struct symbol
*base_type
)
279 sym
->ctype
.as
|= base_type
->ctype
.as
;
280 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& ~MOD_STORAGE
);
281 concat_ptr_list((struct ptr_list
*)base_type
->ctype
.contexts
,
282 (struct ptr_list
**)&sym
->ctype
.contexts
);
283 sym
->ctype
.base_type
= base_type
->ctype
.base_type
;
284 if (sym
->ctype
.base_type
->type
== SYM_NODE
)
285 merge_type(sym
, sym
->ctype
.base_type
);
288 static int count_array_initializer(struct symbol
*t
, struct expression
*expr
)
294 * Arrays of character types are special; they can be initialized by
295 * string literal _or_ by string literal in braces. The latter means
296 * that with T x[] = {<string literal>} number of elements in x depends
297 * on T - if it's a character type, we get the length of string literal
298 * (including NUL), otherwise we have one element here.
300 if (t
->ctype
.base_type
== &int_type
&& t
->ctype
.modifiers
& MOD_CHAR
)
303 switch (expr
->type
) {
304 case EXPR_INITIALIZER
: {
305 struct expression
*entry
;
308 FOR_EACH_PTR(expr
->expr_list
, entry
) {
310 switch (entry
->type
) {
312 if (entry
->idx_to
>= nr
)
313 nr
= entry
->idx_to
+1;
316 struct expression
*e
= entry
;
318 while (e
&& e
->type
== EXPR_PREOP
&& e
->op
== '(')
320 if (e
&& e
->type
== EXPR_STRING
) {
324 str_len
= entry
->string
->length
;
333 } END_FOR_EACH_PTR(entry
);
334 if (count
== 1 && str_len
)
340 struct expression
*e
= expr
;
341 while (e
&& e
->type
== EXPR_PREOP
&& e
->op
== '(')
343 if (e
&& e
->type
== EXPR_STRING
) {
347 nr
= expr
->string
->length
;
357 static struct symbol
* examine_node_type(struct symbol
*sym
)
359 struct symbol
*base_type
= examine_base_type(sym
);
361 unsigned long alignment
;
363 /* SYM_NODE - figure out what the type of the node was.. */
369 bit_size
= base_type
->bit_size
;
370 alignment
= base_type
->ctype
.alignment
;
372 /* Pick up signedness information into the node */
373 sym
->ctype
.modifiers
|= (MOD_SIGNEDNESS
& base_type
->ctype
.modifiers
);
375 if (!sym
->ctype
.alignment
)
376 sym
->ctype
.alignment
= alignment
;
378 /* Unsized array? The size might come from the initializer.. */
379 if (bit_size
< 0 && base_type
->type
== SYM_ARRAY
&& sym
->initializer
) {
380 struct symbol
*node_type
= base_type
->ctype
.base_type
;
381 int count
= count_array_initializer(node_type
, sym
->initializer
);
383 if (node_type
&& node_type
->bit_size
>= 0)
384 bit_size
= node_type
->bit_size
* count
;
387 sym
->bit_size
= bit_size
;
391 static struct symbol
*examine_enum_type(struct symbol
*sym
)
393 struct symbol
*base_type
= examine_base_type(sym
);
395 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& MOD_SIGNEDNESS
);
396 sym
->bit_size
= bits_in_enum
;
397 if (base_type
->bit_size
> sym
->bit_size
)
398 sym
->bit_size
= base_type
->bit_size
;
399 sym
->ctype
.alignment
= enum_alignment
;
400 if (base_type
->ctype
.alignment
> sym
->ctype
.alignment
)
401 sym
->ctype
.alignment
= base_type
->ctype
.alignment
;
405 static struct symbol
*examine_pointer_type(struct symbol
*sym
)
408 * We need to set the pointer size first, and
409 * examine the thing we point to only afterwards.
410 * That's because this pointer type may end up
411 * being needed for the base type size evaluation.
414 sym
->bit_size
= bits_in_pointer
;
415 if (!sym
->ctype
.alignment
)
416 sym
->ctype
.alignment
= pointer_alignment
;
421 * Fill in type size and alignment information for
422 * regular SYM_TYPE things.
424 struct symbol
*examine_symbol_type(struct symbol
* sym
)
437 return examine_node_type(sym
);
439 return examine_array_type(sym
);
441 return examine_struct_union_type(sym
, 1);
443 return examine_struct_union_type(sym
, 0);
445 return examine_pointer_type(sym
);
447 return examine_enum_type(sym
);
449 return examine_bitfield_type(sym
);
451 /* Size and alignment had better already be set up */
454 struct symbol
*base
= evaluate_expression(sym
->initializer
);
456 if (is_bitfield_type(base
))
457 warning(base
->pos
, "typeof applied to bitfield type");
458 if (base
->type
== SYM_NODE
)
459 base
= base
->ctype
.base_type
;
460 sym
->type
= SYM_NODE
;
461 sym
->ctype
.modifiers
= 0;
462 sym
->ctype
.base_type
= base
;
463 return examine_node_type(sym
);
467 case SYM_PREPROCESSOR
:
468 sparse_error(sym
->pos
, "ctype on preprocessor command? (%s)", show_ident(sym
->ident
));
470 case SYM_UNINITIALIZED
:
471 sparse_error(sym
->pos
, "ctype on uninitialized symbol %p", sym
);
474 examine_base_type(sym
);
477 examine_base_type(sym
);
480 sparse_error(sym
->pos
, "Examining unknown symbol type %d", sym
->type
);
486 const char* get_type_name(enum type type
)
488 const char *type_lookup
[] = {
489 [SYM_UNINITIALIZED
] = "uninitialized",
490 [SYM_PREPROCESSOR
] = "preprocessor",
491 [SYM_BASETYPE
] = "basetype",
493 [SYM_PTR
] = "pointer",
494 [SYM_FN
] = "function",
495 [SYM_ARRAY
] = "array",
496 [SYM_STRUCT
] = "struct",
497 [SYM_UNION
] = "union",
499 [SYM_TYPEDEF
] = "typedef",
500 [SYM_TYPEOF
] = "typeof",
501 [SYM_MEMBER
] = "member",
502 [SYM_BITFIELD
] = "bitfield",
503 [SYM_LABEL
] = "label",
504 [SYM_RESTRICT
] = "restrict",
505 [SYM_FOULED
] = "fouled",
506 [SYM_KEYWORD
] = "keyword",
510 return type_lookup
[type
];
515 struct symbol
*examine_pointer_target(struct symbol
*sym
)
517 return examine_base_type(sym
);
520 static struct symbol_list
*restr
, *fouled
;
522 void create_fouled(struct symbol
*type
)
524 if (type
->bit_size
< bits_in_int
) {
525 struct symbol
*new = alloc_symbol(type
->pos
, type
->type
);
527 new->bit_size
= bits_in_int
;
528 new->type
= SYM_FOULED
;
529 new->ctype
.base_type
= type
;
530 add_symbol(&restr
, type
);
531 add_symbol(&fouled
, new);
535 struct symbol
*befoul(struct symbol
*type
)
537 struct symbol
*t1
, *t2
;
538 while (type
->type
== SYM_NODE
)
539 type
= type
->ctype
.base_type
;
540 PREPARE_PTR_LIST(restr
, t1
);
541 PREPARE_PTR_LIST(fouled
, t2
);
555 void check_declaration(struct symbol
*sym
)
558 struct symbol
*next
= sym
;
560 while ((next
= next
->next_id
) != NULL
) {
561 if (next
->namespace != sym
->namespace)
563 if (sym
->scope
== next
->scope
) {
564 sym
->same_symbol
= next
;
567 if (sym
->ctype
.modifiers
& next
->ctype
.modifiers
& MOD_EXTERN
) {
568 if ((sym
->ctype
.modifiers
^ next
->ctype
.modifiers
) & MOD_INLINE
)
570 sym
->same_symbol
= next
;
574 if (!Wshadow
|| warned
)
576 if (get_sym_type(next
) == SYM_FN
)
579 warning(sym
->pos
, "symbol '%s' shadows an earlier one", show_ident(sym
->ident
));
580 info(next
->pos
, "originally declared here");
584 void bind_symbol(struct symbol
*sym
, struct ident
*ident
, enum namespace ns
)
588 sparse_error(sym
->pos
, "internal error: symbol type already bound");
591 if (ident
->reserved
&& (ns
& (NS_TYPEDEF
| NS_STRUCT
| NS_LABEL
| NS_SYMBOL
))) {
592 sparse_error(sym
->pos
, "Trying to use reserved word '%s' as identifier", show_ident(ident
));
596 sym
->next_id
= ident
->symbols
;
597 ident
->symbols
= sym
;
598 if (sym
->ident
&& sym
->ident
!= ident
)
599 warning(sym
->pos
, "Symbol '%s' already bound", show_ident(sym
->ident
));
604 if (ns
== NS_SYMBOL
&& toplevel(scope
)) {
605 unsigned mod
= MOD_ADDRESSABLE
| MOD_TOPLEVEL
;
607 scope
= global_scope
;
608 if (sym
->ctype
.modifiers
& MOD_STATIC
||
609 is_extern_inline(sym
)) {
613 sym
->ctype
.modifiers
|= mod
;
618 scope
= function_scope
;
619 bind_scope(sym
, scope
);
622 struct symbol
*create_symbol(int stream
, const char *name
, int type
, int namespace)
624 struct token
*token
= built_in_token(stream
, name
);
625 struct symbol
*sym
= alloc_symbol(token
->pos
, type
);
627 bind_symbol(sym
, token
->ident
, namespace);
631 static int evaluate_to_integer(struct expression
*expr
)
633 expr
->ctype
= &int_ctype
;
637 static int evaluate_expect(struct expression
*expr
)
639 /* Should we evaluate it to return the type of the first argument? */
640 expr
->ctype
= &int_ctype
;
644 static int arguments_choose(struct expression
*expr
)
646 struct expression_list
*arglist
= expr
->args
;
647 struct expression
*arg
;
650 FOR_EACH_PTR (arglist
, arg
) {
651 if (!evaluate_expression(arg
))
654 } END_FOR_EACH_PTR(arg
);
656 sparse_error(expr
->pos
,
657 "not enough arguments for __builtin_choose_expr");
660 sparse_error(expr
->pos
,
661 "too many arguments for __builtin_choose_expr");
667 static int evaluate_choose(struct expression
*expr
)
669 struct expression_list
*list
= expr
->args
;
670 struct expression
*arg
, *args
[3];
673 /* there will be exactly 3; we'd already verified that */
674 FOR_EACH_PTR(list
, arg
) {
676 } END_FOR_EACH_PTR(arg
);
678 *expr
= get_expression_value(args
[0]) ? *args
[1] : *args
[2];
683 static int expand_expect(struct expression
*expr
, int cost
)
685 struct expression
*arg
= first_ptr_list((struct ptr_list
*) expr
->args
);
693 * __builtin_warning() has type "int" and always returns 1,
694 * so that you can use it in conditionals or whatever
696 static int expand_warning(struct expression
*expr
, int cost
)
698 struct expression
*arg
;
699 struct expression_list
*arglist
= expr
->args
;
701 FOR_EACH_PTR (arglist
, arg
) {
703 * Constant strings get printed out as a warning. By the
704 * time we get here, the EXPR_STRING has been fully
705 * evaluated, so by now it's an anonymous symbol with a
706 * string initializer.
708 * Just for the heck of it, allow any constant string
711 if (arg
->type
== EXPR_SYMBOL
) {
712 struct symbol
*sym
= arg
->symbol
;
713 if (sym
->initializer
&& sym
->initializer
->type
== EXPR_STRING
) {
714 struct string
*string
= sym
->initializer
->string
;
715 warning(expr
->pos
, "%*s", string
->length
-1, string
->data
);
721 * Any other argument is a conditional. If it's
722 * non-constant, or it is false, we exit and do
723 * not print any warning.
725 if (arg
->type
!= EXPR_VALUE
)
729 } END_FOR_EACH_PTR(arg
);
731 expr
->type
= EXPR_VALUE
;
737 static struct symbol_op constant_p_op
= {
738 .evaluate
= evaluate_to_integer
,
739 .expand
= expand_constant_p
742 static struct symbol_op safe_p_op
= {
743 .evaluate
= evaluate_to_integer
,
744 .expand
= expand_safe_p
747 static struct symbol_op warning_op
= {
748 .evaluate
= evaluate_to_integer
,
749 .expand
= expand_warning
752 static struct symbol_op expect_op
= {
753 .evaluate
= evaluate_expect
,
754 .expand
= expand_expect
757 static struct symbol_op choose_op
= {
758 .evaluate
= evaluate_choose
,
759 .args
= arguments_choose
,
765 static struct symbol builtin_fn_type
= { .type
= SYM_FN
/* , .variadic =1 */ };
766 static struct sym_init
{
768 struct symbol
*base_type
;
769 unsigned int modifiers
;
770 struct symbol_op
*op
;
771 } eval_init_table
[] = {
772 { "__builtin_constant_p", &builtin_fn_type
, MOD_TOPLEVEL
, &constant_p_op
},
773 { "__builtin_safe_p", &builtin_fn_type
, MOD_TOPLEVEL
, &safe_p_op
},
774 { "__builtin_warning", &builtin_fn_type
, MOD_TOPLEVEL
, &warning_op
},
775 { "__builtin_expect", &builtin_fn_type
, MOD_TOPLEVEL
, &expect_op
},
776 { "__builtin_choose_expr", &builtin_fn_type
, MOD_TOPLEVEL
, &choose_op
},
784 struct symbol int_type
,
788 * C types (i.e. actual instances that the abstract types
791 struct symbol bool_ctype
, void_ctype
, type_ctype
,
792 char_ctype
, schar_ctype
, uchar_ctype
,
793 short_ctype
, sshort_ctype
, ushort_ctype
,
794 int_ctype
, sint_ctype
, uint_ctype
,
795 long_ctype
, slong_ctype
, ulong_ctype
,
796 llong_ctype
, sllong_ctype
, ullong_ctype
,
797 lllong_ctype
, slllong_ctype
, ulllong_ctype
,
798 float_ctype
, double_ctype
, ldouble_ctype
,
799 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
800 incomplete_ctype
, label_ctype
, bad_ctype
,
803 struct symbol zero_int
;
805 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
806 #define __IDENT(n,str,res) \
807 struct ident n = __INIT_IDENT(str,res)
809 #include "ident-list.h"
811 void init_symbols(void)
813 int stream
= init_stream("builtin", -1, includepath
);
814 struct sym_init
*ptr
;
816 #define __IDENT(n,str,res) \
818 #include "ident-list.h"
822 builtin_fn_type
.variadic
= 1;
823 for (ptr
= eval_init_table
; ptr
->name
; ptr
++) {
825 sym
= create_symbol(stream
, ptr
->name
, SYM_NODE
, NS_SYMBOL
);
826 sym
->ctype
.base_type
= ptr
->base_type
;
827 sym
->ctype
.modifiers
= ptr
->modifiers
;
832 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
833 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
834 #define MOD_LLL MOD_LONGLONGLONG
835 static const struct ctype_declare
{
838 unsigned long modifiers
;
841 struct symbol
*base_type
;
842 } ctype_declaration
[] = {
843 { &bool_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_bool
, &max_int_alignment
, &int_type
},
844 { &void_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
845 { &type_ctype
, SYM_BASETYPE
, MOD_TYPE
, NULL
, NULL
, NULL
},
846 { &incomplete_ctype
,SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
847 { &bad_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
849 { &char_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
850 { &schar_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
851 { &uchar_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
852 { &short_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
853 { &sshort_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
854 { &ushort_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
855 { &int_ctype
, SYM_BASETYPE
, MOD_SIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
856 { &sint_ctype
, SYM_BASETYPE
, MOD_ESIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
857 { &uint_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
858 { &long_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
859 { &slong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
860 { &ulong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
861 { &llong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
862 { &sllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
863 { &ullong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
864 { &lllong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
865 { &slllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
866 { &ulllong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
868 { &float_ctype
, SYM_BASETYPE
, 0, &bits_in_float
, &max_fp_alignment
, &fp_type
},
869 { &double_ctype
, SYM_BASETYPE
, MOD_LONG
, &bits_in_double
, &max_fp_alignment
, &fp_type
},
870 { &ldouble_ctype
, SYM_BASETYPE
, MOD_LONG
| MOD_LONGLONG
, &bits_in_longdouble
, &max_fp_alignment
, &fp_type
},
872 { &string_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &char_ctype
},
873 { &ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
874 { &null_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
875 { &label_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
876 { &lazy_ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
883 void init_ctype(void)
885 const struct ctype_declare
*ctype
;
887 for (ctype
= ctype_declaration
; ctype
->ptr
; ctype
++) {
888 struct symbol
*sym
= ctype
->ptr
;
889 unsigned long bit_size
= ctype
->bit_size
? *ctype
->bit_size
: -1;
890 unsigned long maxalign
= ctype
->maxalign
? *ctype
->maxalign
: 0;
891 unsigned long alignment
= bits_to_bytes(bit_size
+ bits_in_char
- 1);
893 if (alignment
> maxalign
)
894 alignment
= maxalign
;
895 sym
->type
= ctype
->type
;
896 sym
->bit_size
= bit_size
;
897 sym
->ctype
.alignment
= alignment
;
898 sym
->ctype
.base_type
= ctype
->base_type
;
899 sym
->ctype
.modifiers
= ctype
->modifiers
;