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
;
93 * Unions are fairly easy to lay out ;)
95 static void lay_out_union(struct symbol
*sym
, struct struct_union_info
*info
)
97 examine_symbol_type(sym
);
99 // Unnamed bitfields do not affect alignment.
100 if (sym
->ident
|| !is_bitfield_type(sym
)) {
101 if (sym
->ctype
.alignment
> info
->max_align
)
102 info
->max_align
= sym
->ctype
.alignment
;
105 if (sym
->bit_size
> info
->bit_size
)
106 info
->bit_size
= sym
->bit_size
;
111 static int bitfield_base_size(struct symbol
*sym
)
113 if (sym
->type
== SYM_NODE
)
114 sym
= sym
->ctype
.base_type
;
115 if (sym
->type
== SYM_BITFIELD
)
116 sym
= sym
->ctype
.base_type
;
117 return sym
->bit_size
;
121 * Structures are a bit more interesting to lay out
123 static void lay_out_struct(struct symbol
*sym
, struct struct_union_info
*info
)
125 unsigned long bit_size
, align_bit_mask
;
128 examine_symbol_type(sym
);
130 // Unnamed bitfields do not affect alignment.
131 if (sym
->ident
|| !is_bitfield_type(sym
)) {
132 if (sym
->ctype
.alignment
> info
->max_align
)
133 info
->max_align
= sym
->ctype
.alignment
;
136 bit_size
= info
->bit_size
;
137 base_size
= sym
->bit_size
;
140 * Unsized arrays cause us to not align the resulting
144 info
->align_size
= 0;
148 align_bit_mask
= bytes_to_bits(sym
->ctype
.alignment
) - 1;
151 * Bitfields have some very special rules..
153 if (is_bitfield_type (sym
)) {
154 unsigned long bit_offset
= bit_size
& align_bit_mask
;
155 int room
= bitfield_base_size(sym
) - bit_offset
;
156 // Zero-width fields just fill up the unit.
157 int width
= base_size
? : (bit_offset
? room
: 0);
160 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
163 sym
->offset
= bits_to_bytes(bit_size
- bit_offset
);
164 sym
->bit_offset
= bit_offset
;
165 sym
->ctype
.base_type
->bit_offset
= bit_offset
;
166 info
->bit_size
= bit_size
+ width
;
167 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
173 * Otherwise, just align it right and add it up..
175 bit_size
= (bit_size
+ align_bit_mask
) & ~align_bit_mask
;
176 sym
->offset
= bits_to_bytes(bit_size
);
178 info
->bit_size
= bit_size
+ base_size
;
179 // warning (sym->pos, "regular: offset=%d", sym->offset);
182 static struct symbol
* examine_struct_union_type(struct symbol
*sym
, int advance
)
184 struct struct_union_info info
= {
189 unsigned long bit_size
, bit_align
;
190 void (*fn
)(struct symbol
*, struct struct_union_info
*);
191 struct symbol
*member
;
193 fn
= advance
? lay_out_struct
: lay_out_union
;
194 FOR_EACH_PTR(sym
->symbol_list
, member
) {
196 } END_FOR_EACH_PTR(member
);
198 if (!sym
->ctype
.alignment
)
199 sym
->ctype
.alignment
= info
.max_align
;
200 bit_size
= info
.bit_size
;
201 if (info
.align_size
) {
202 bit_align
= bytes_to_bits(sym
->ctype
.alignment
)-1;
203 bit_size
= (bit_size
+ bit_align
) & ~bit_align
;
205 sym
->bit_size
= bit_size
;
209 static struct symbol
*examine_base_type(struct symbol
*sym
)
211 struct symbol
*base_type
;
213 /* Check the base type */
214 base_type
= examine_symbol_type(sym
->ctype
.base_type
);
215 if (!base_type
|| base_type
->type
== SYM_PTR
)
217 sym
->ctype
.modifiers
|= base_type
->ctype
.modifiers
& MOD_PTRINHERIT
;
219 merge_attr(&sym
->ctype
, &base_type
->ctype
);
221 if (base_type
->type
== SYM_NODE
) {
222 base_type
= base_type
->ctype
.base_type
;
223 sym
->ctype
.base_type
= base_type
;
228 static struct symbol
* examine_array_type(struct symbol
*sym
)
230 struct symbol
*base_type
= examine_base_type(sym
);
231 unsigned long bit_size
= -1, alignment
;
232 struct expression
*array_size
= sym
->array_size
;
238 bit_size
= base_type
->bit_size
* get_expression_value_silent(array_size
);
239 if (array_size
->type
!= EXPR_VALUE
) {
241 warning(array_size
->pos
, "Variable length array is used.");
245 alignment
= base_type
->ctype
.alignment
;
246 if (!sym
->ctype
.alignment
)
247 sym
->ctype
.alignment
= alignment
;
248 sym
->bit_size
= bit_size
;
252 static struct symbol
*examine_bitfield_type(struct symbol
*sym
)
254 struct symbol
*base_type
= examine_base_type(sym
);
255 unsigned long bit_size
, alignment
, modifiers
;
259 bit_size
= base_type
->bit_size
;
260 if (sym
->bit_size
> bit_size
)
261 warning(sym
->pos
, "impossible field-width, %d, for this type", sym
->bit_size
);
263 alignment
= base_type
->ctype
.alignment
;
264 if (!sym
->ctype
.alignment
)
265 sym
->ctype
.alignment
= alignment
;
266 modifiers
= base_type
->ctype
.modifiers
;
268 /* Bitfields are unsigned, unless the base type was explicitly signed */
269 if (!(modifiers
& MOD_EXPLICITLY_SIGNED
))
270 modifiers
= (modifiers
& ~MOD_SIGNED
) | MOD_UNSIGNED
;
271 sym
->ctype
.modifiers
|= modifiers
& MOD_SIGNEDNESS
;
276 * "typeof" will have to merge the types together
278 void merge_type(struct symbol
*sym
, struct symbol
*base_type
)
280 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& ~MOD_STORAGE
);
281 merge_attr(&sym
->ctype
, &base_type
->ctype
);
282 sym
->ctype
.base_type
= base_type
->ctype
.base_type
;
283 if (sym
->ctype
.base_type
->type
== SYM_NODE
)
284 merge_type(sym
, sym
->ctype
.base_type
);
287 static int count_array_initializer(struct symbol
*t
, struct expression
*expr
)
293 * Arrays of character types are special; they can be initialized by
294 * string literal _or_ by string literal in braces. The latter means
295 * that with T x[] = {<string literal>} number of elements in x depends
296 * on T - if it's a character type, we get the length of string literal
297 * (including NUL), otherwise we have one element here.
299 if (t
->ctype
.base_type
== &int_type
&& t
->ctype
.modifiers
& MOD_CHAR
)
302 switch (expr
->type
) {
303 case EXPR_INITIALIZER
: {
304 struct expression
*entry
;
307 FOR_EACH_PTR(expr
->expr_list
, entry
) {
309 switch (entry
->type
) {
311 if (entry
->idx_to
>= nr
)
312 nr
= entry
->idx_to
+1;
315 struct expression
*e
= entry
;
317 while (e
&& e
->type
== EXPR_PREOP
&& e
->op
== '(')
319 if (e
&& e
->type
== EXPR_STRING
) {
323 str_len
= entry
->string
->length
;
332 } END_FOR_EACH_PTR(entry
);
333 if (count
== 1 && str_len
)
339 struct expression
*e
= expr
;
340 while (e
&& e
->type
== EXPR_PREOP
&& e
->op
== '(')
342 if (e
&& e
->type
== EXPR_STRING
) {
346 nr
= expr
->string
->length
;
356 static struct expression
*get_symbol_initializer(struct symbol
*sym
)
359 if (sym
->initializer
)
360 return sym
->initializer
;
361 } while ((sym
= sym
->same_symbol
) != NULL
);
365 static struct symbol
* examine_node_type(struct symbol
*sym
)
367 struct symbol
*base_type
= examine_base_type(sym
);
369 unsigned long alignment
;
371 /* SYM_NODE - figure out what the type of the node was.. */
377 bit_size
= base_type
->bit_size
;
378 alignment
= base_type
->ctype
.alignment
;
380 /* Pick up signedness information into the node */
381 sym
->ctype
.modifiers
|= (MOD_SIGNEDNESS
& base_type
->ctype
.modifiers
);
383 if (!sym
->ctype
.alignment
)
384 sym
->ctype
.alignment
= alignment
;
386 /* Unsized array? The size might come from the initializer.. */
387 if (bit_size
< 0 && base_type
->type
== SYM_ARRAY
) {
388 struct expression
*initializer
= get_symbol_initializer(sym
);
390 struct symbol
*node_type
= base_type
->ctype
.base_type
;
391 int count
= count_array_initializer(node_type
, initializer
);
393 if (node_type
&& node_type
->bit_size
>= 0)
394 bit_size
= node_type
->bit_size
* count
;
398 sym
->bit_size
= bit_size
;
402 static struct symbol
*examine_enum_type(struct symbol
*sym
)
404 struct symbol
*base_type
= examine_base_type(sym
);
406 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& MOD_SIGNEDNESS
);
407 sym
->bit_size
= bits_in_enum
;
408 if (base_type
->bit_size
> sym
->bit_size
)
409 sym
->bit_size
= base_type
->bit_size
;
410 sym
->ctype
.alignment
= enum_alignment
;
411 if (base_type
->ctype
.alignment
> sym
->ctype
.alignment
)
412 sym
->ctype
.alignment
= base_type
->ctype
.alignment
;
416 static struct symbol
*examine_pointer_type(struct symbol
*sym
)
419 * We need to set the pointer size first, and
420 * examine the thing we point to only afterwards.
421 * That's because this pointer type may end up
422 * being needed for the base type size evaluation.
425 sym
->bit_size
= bits_in_pointer
;
426 if (!sym
->ctype
.alignment
)
427 sym
->ctype
.alignment
= pointer_alignment
;
432 * Fill in type size and alignment information for
433 * regular SYM_TYPE things.
435 struct symbol
*examine_symbol_type(struct symbol
* sym
)
448 return examine_node_type(sym
);
450 return examine_array_type(sym
);
452 return examine_struct_union_type(sym
, 1);
454 return examine_struct_union_type(sym
, 0);
456 return examine_pointer_type(sym
);
458 return examine_enum_type(sym
);
460 return examine_bitfield_type(sym
);
462 /* Size and alignment had better already be set up */
465 struct symbol
*base
= evaluate_expression(sym
->initializer
);
467 if (is_bitfield_type(base
))
468 warning(base
->pos
, "typeof applied to bitfield type");
469 if (base
->type
== SYM_NODE
)
470 base
= base
->ctype
.base_type
;
471 sym
->type
= SYM_NODE
;
472 sym
->ctype
.modifiers
= 0;
473 sym
->ctype
.base_type
= base
;
474 return examine_node_type(sym
);
478 case SYM_PREPROCESSOR
:
479 sparse_error(sym
->pos
, "ctype on preprocessor command? (%s)", show_ident(sym
->ident
));
481 case SYM_UNINITIALIZED
:
482 // sparse_error(sym->pos, "ctype on uninitialized symbol %p", sym);
485 examine_base_type(sym
);
488 examine_base_type(sym
);
491 sparse_error(sym
->pos
, "Examining unknown symbol type %d", sym
->type
);
497 const char* get_type_name(enum type type
)
499 const char *type_lookup
[] = {
500 [SYM_UNINITIALIZED
] = "uninitialized",
501 [SYM_PREPROCESSOR
] = "preprocessor",
502 [SYM_BASETYPE
] = "basetype",
504 [SYM_PTR
] = "pointer",
505 [SYM_FN
] = "function",
506 [SYM_ARRAY
] = "array",
507 [SYM_STRUCT
] = "struct",
508 [SYM_UNION
] = "union",
510 [SYM_TYPEDEF
] = "typedef",
511 [SYM_TYPEOF
] = "typeof",
512 [SYM_MEMBER
] = "member",
513 [SYM_BITFIELD
] = "bitfield",
514 [SYM_LABEL
] = "label",
515 [SYM_RESTRICT
] = "restrict",
516 [SYM_FOULED
] = "fouled",
517 [SYM_KEYWORD
] = "keyword",
521 return type_lookup
[type
];
526 struct symbol
*examine_pointer_target(struct symbol
*sym
)
528 return examine_base_type(sym
);
531 static struct symbol_list
*restr
, *fouled
;
533 void create_fouled(struct symbol
*type
)
535 if (type
->bit_size
< bits_in_int
) {
536 struct symbol
*new = alloc_symbol(type
->pos
, type
->type
);
538 new->bit_size
= bits_in_int
;
539 new->type
= SYM_FOULED
;
540 new->ctype
.base_type
= type
;
541 add_symbol(&restr
, type
);
542 add_symbol(&fouled
, new);
546 struct symbol
*befoul(struct symbol
*type
)
548 struct symbol
*t1
, *t2
;
549 while (type
->type
== SYM_NODE
)
550 type
= type
->ctype
.base_type
;
551 PREPARE_PTR_LIST(restr
, t1
);
552 PREPARE_PTR_LIST(fouled
, t2
);
566 void check_declaration(struct symbol
*sym
)
569 struct symbol
*next
= sym
;
571 while ((next
= next
->next_id
) != NULL
) {
572 if (next
->namespace != sym
->namespace)
574 if (sym
->scope
== next
->scope
) {
575 sym
->same_symbol
= next
;
578 if (sym
->ctype
.modifiers
& next
->ctype
.modifiers
& MOD_EXTERN
) {
579 if ((sym
->ctype
.modifiers
^ next
->ctype
.modifiers
) & MOD_INLINE
)
581 sym
->same_symbol
= next
;
585 if (!Wshadow
|| warned
)
587 if (get_sym_type(next
) == SYM_FN
)
590 warning(sym
->pos
, "symbol '%s' shadows an earlier one", show_ident(sym
->ident
));
591 info(next
->pos
, "originally declared here");
595 void bind_symbol(struct symbol
*sym
, struct ident
*ident
, enum namespace ns
)
599 sparse_error(sym
->pos
, "internal error: symbol type already bound");
602 if (ident
->reserved
&& (ns
& (NS_TYPEDEF
| NS_STRUCT
| NS_LABEL
| NS_SYMBOL
))) {
603 sparse_error(sym
->pos
, "Trying to use reserved word '%s' as identifier", show_ident(ident
));
607 sym
->next_id
= ident
->symbols
;
608 ident
->symbols
= sym
;
609 if (sym
->ident
&& sym
->ident
!= ident
)
610 warning(sym
->pos
, "Symbol '%s' already bound", show_ident(sym
->ident
));
615 if (ns
== NS_SYMBOL
&& toplevel(scope
)) {
616 unsigned mod
= MOD_ADDRESSABLE
| MOD_TOPLEVEL
;
618 scope
= global_scope
;
619 if (sym
->ctype
.modifiers
& MOD_STATIC
||
620 is_extern_inline(sym
)) {
624 sym
->ctype
.modifiers
|= mod
;
629 scope
= function_scope
;
630 bind_scope(sym
, scope
);
633 struct symbol
*create_symbol(int stream
, const char *name
, int type
, int namespace)
635 struct token
*token
= built_in_token(stream
, name
);
636 struct symbol
*sym
= alloc_symbol(token
->pos
, type
);
638 bind_symbol(sym
, token
->ident
, namespace);
642 static int evaluate_to_integer(struct expression
*expr
)
644 expr
->ctype
= &int_ctype
;
648 static int evaluate_expect(struct expression
*expr
)
650 /* Should we evaluate it to return the type of the first argument? */
651 expr
->ctype
= &int_ctype
;
655 static int arguments_choose(struct expression
*expr
)
657 struct expression_list
*arglist
= expr
->args
;
658 struct expression
*arg
;
661 FOR_EACH_PTR (arglist
, arg
) {
662 if (!evaluate_expression(arg
))
665 } END_FOR_EACH_PTR(arg
);
667 sparse_error(expr
->pos
,
668 "not enough arguments for __builtin_choose_expr");
671 sparse_error(expr
->pos
,
672 "too many arguments for __builtin_choose_expr");
678 static int evaluate_choose(struct expression
*expr
)
680 struct expression_list
*list
= expr
->args
;
681 struct expression
*arg
, *args
[3];
684 /* there will be exactly 3; we'd already verified that */
685 FOR_EACH_PTR(list
, arg
) {
687 } END_FOR_EACH_PTR(arg
);
689 *expr
= get_expression_value(args
[0]) ? *args
[1] : *args
[2];
694 static int expand_expect(struct expression
*expr
, int cost
)
696 struct expression
*arg
= first_ptr_list((struct ptr_list
*) expr
->args
);
704 * __builtin_warning() has type "int" and always returns 1,
705 * so that you can use it in conditionals or whatever
707 static int expand_warning(struct expression
*expr
, int cost
)
709 struct expression
*arg
;
710 struct expression_list
*arglist
= expr
->args
;
712 FOR_EACH_PTR (arglist
, arg
) {
714 * Constant strings get printed out as a warning. By the
715 * time we get here, the EXPR_STRING has been fully
716 * evaluated, so by now it's an anonymous symbol with a
717 * string initializer.
719 * Just for the heck of it, allow any constant string
722 if (arg
->type
== EXPR_SYMBOL
) {
723 struct symbol
*sym
= arg
->symbol
;
724 if (sym
->initializer
&& sym
->initializer
->type
== EXPR_STRING
) {
725 struct string
*string
= sym
->initializer
->string
;
726 warning(expr
->pos
, "%*s", string
->length
-1, string
->data
);
732 * Any other argument is a conditional. If it's
733 * non-constant, or it is false, we exit and do
734 * not print any warning.
736 if (arg
->type
!= EXPR_VALUE
)
740 } END_FOR_EACH_PTR(arg
);
742 expr
->type
= EXPR_VALUE
;
748 static struct symbol_op constant_p_op
= {
749 .evaluate
= evaluate_to_integer
,
750 .expand
= expand_constant_p
753 static struct symbol_op safe_p_op
= {
754 .evaluate
= evaluate_to_integer
,
755 .expand
= expand_safe_p
758 static struct symbol_op warning_op
= {
759 .evaluate
= evaluate_to_integer
,
760 .expand
= expand_warning
763 static struct symbol_op expect_op
= {
764 .evaluate
= evaluate_expect
,
765 .expand
= expand_expect
768 static struct symbol_op choose_op
= {
769 .evaluate
= evaluate_choose
,
770 .args
= arguments_choose
,
776 static struct symbol builtin_fn_type
= { .type
= SYM_FN
/* , .variadic =1 */ };
777 static struct sym_init
{
779 struct symbol
*base_type
;
780 unsigned int modifiers
;
781 struct symbol_op
*op
;
782 } eval_init_table
[] = {
783 { "__builtin_constant_p", &builtin_fn_type
, MOD_TOPLEVEL
, &constant_p_op
},
784 { "__builtin_safe_p", &builtin_fn_type
, MOD_TOPLEVEL
, &safe_p_op
},
785 { "__builtin_warning", &builtin_fn_type
, MOD_TOPLEVEL
, &warning_op
},
786 { "__builtin_expect", &builtin_fn_type
, MOD_TOPLEVEL
, &expect_op
},
787 { "__builtin_choose_expr", &builtin_fn_type
, MOD_TOPLEVEL
, &choose_op
},
792 * Default empty attribute
794 struct attribute null_attr
= {};
799 struct symbol int_type
,
803 * C types (i.e. actual instances that the abstract types
806 struct symbol bool_ctype
, void_ctype
, type_ctype
,
807 char_ctype
, schar_ctype
, uchar_ctype
,
808 short_ctype
, sshort_ctype
, ushort_ctype
,
809 int_ctype
, sint_ctype
, uint_ctype
,
810 long_ctype
, slong_ctype
, ulong_ctype
,
811 llong_ctype
, sllong_ctype
, ullong_ctype
,
812 lllong_ctype
, slllong_ctype
, ulllong_ctype
,
813 float_ctype
, double_ctype
, ldouble_ctype
,
814 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
815 incomplete_ctype
, label_ctype
, bad_ctype
,
818 struct symbol zero_int
;
820 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
821 #define __IDENT(n,str,res) \
822 struct ident n = __INIT_IDENT(str,res)
824 #include "ident-list.h"
826 void init_symbols(void)
828 int stream
= init_stream("builtin", -1, includepath
);
829 struct sym_init
*ptr
;
831 #define __IDENT(n,str,res) \
833 #include "ident-list.h"
837 builtin_fn_type
.variadic
= 1;
838 builtin_fn_type
.ctype
.attribute
= &null_attr
;
839 for (ptr
= eval_init_table
; ptr
->name
; ptr
++) {
841 sym
= create_symbol(stream
, ptr
->name
, SYM_NODE
, NS_SYMBOL
);
842 sym
->ctype
.base_type
= ptr
->base_type
;
843 sym
->ctype
.modifiers
= ptr
->modifiers
;
844 sym
->ctype
.attribute
= &null_attr
;
849 #ifdef __CHAR_UNSIGNED__
850 #define CHAR_SIGNEDNESS MOD_UNSIGNED
852 #define CHAR_SIGNEDNESS MOD_SIGNED
855 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
856 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
857 #define MOD_LLL MOD_LONGLONGLONG
858 static const struct ctype_declare
{
861 unsigned long modifiers
;
864 struct symbol
*base_type
;
865 } ctype_declaration
[] = {
866 { &bool_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_bool
, &max_int_alignment
, &int_type
},
867 { &void_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
868 { &type_ctype
, SYM_BASETYPE
, MOD_TYPE
, NULL
, NULL
, NULL
},
869 { &incomplete_ctype
,SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
870 { &bad_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
872 { &char_ctype
, SYM_BASETYPE
, CHAR_SIGNEDNESS
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
873 { &schar_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
874 { &uchar_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
875 { &short_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
876 { &sshort_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
877 { &ushort_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
878 { &int_ctype
, SYM_BASETYPE
, MOD_SIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
879 { &sint_ctype
, SYM_BASETYPE
, MOD_ESIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
880 { &uint_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
881 { &long_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
882 { &slong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
883 { &ulong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
884 { &llong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
885 { &sllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
886 { &ullong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
887 { &lllong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
888 { &slllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
889 { &ulllong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
891 { &float_ctype
, SYM_BASETYPE
, 0, &bits_in_float
, &max_fp_alignment
, &fp_type
},
892 { &double_ctype
, SYM_BASETYPE
, MOD_LONG
, &bits_in_double
, &max_fp_alignment
, &fp_type
},
893 { &ldouble_ctype
, SYM_BASETYPE
, MOD_LONG
| MOD_LONGLONG
, &bits_in_longdouble
, &max_fp_alignment
, &fp_type
},
895 { &string_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &char_ctype
},
896 { &ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
897 { &null_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
898 { &label_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
899 { &lazy_ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
906 void init_ctype(void)
908 const struct ctype_declare
*ctype
;
910 for (ctype
= ctype_declaration
; ctype
->ptr
; ctype
++) {
911 struct symbol
*sym
= ctype
->ptr
;
912 unsigned long bit_size
= ctype
->bit_size
? *ctype
->bit_size
: -1;
913 unsigned long maxalign
= ctype
->maxalign
? *ctype
->maxalign
: 0;
914 unsigned long alignment
= bits_to_bytes(bit_size
+ bits_in_char
- 1);
916 if (alignment
> maxalign
)
917 alignment
= maxalign
;
918 sym
->type
= ctype
->type
;
919 sym
->bit_size
= bit_size
;
920 sym
->ctype
.alignment
= alignment
;
921 sym
->ctype
.base_type
= ctype
->base_type
;
922 sym
->ctype
.modifiers
= ctype
->modifiers
;
923 sym
->ctype
.attribute
= &null_attr
;