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 expression
*get_symbol_initializer(struct symbol
*sym
)
360 if (sym
->initializer
)
361 return sym
->initializer
;
362 } while ((sym
= sym
->same_symbol
) != NULL
);
366 static struct symbol
* examine_node_type(struct symbol
*sym
)
368 struct symbol
*base_type
= examine_base_type(sym
);
370 unsigned long alignment
;
372 /* SYM_NODE - figure out what the type of the node was.. */
378 bit_size
= base_type
->bit_size
;
379 alignment
= base_type
->ctype
.alignment
;
381 /* Pick up signedness information into the node */
382 sym
->ctype
.modifiers
|= (MOD_SIGNEDNESS
& base_type
->ctype
.modifiers
);
384 if (!sym
->ctype
.alignment
)
385 sym
->ctype
.alignment
= alignment
;
387 /* Unsized array? The size might come from the initializer.. */
388 if (bit_size
< 0 && base_type
->type
== SYM_ARRAY
) {
389 struct expression
*initializer
= get_symbol_initializer(sym
);
391 struct symbol
*node_type
= base_type
->ctype
.base_type
;
392 int count
= count_array_initializer(node_type
, initializer
);
394 if (node_type
&& node_type
->bit_size
>= 0)
395 bit_size
= node_type
->bit_size
* count
;
399 sym
->bit_size
= bit_size
;
403 static struct symbol
*examine_enum_type(struct symbol
*sym
)
405 struct symbol
*base_type
= examine_base_type(sym
);
407 sym
->ctype
.modifiers
|= (base_type
->ctype
.modifiers
& MOD_SIGNEDNESS
);
408 sym
->bit_size
= bits_in_enum
;
409 if (base_type
->bit_size
> sym
->bit_size
)
410 sym
->bit_size
= base_type
->bit_size
;
411 sym
->ctype
.alignment
= enum_alignment
;
412 if (base_type
->ctype
.alignment
> sym
->ctype
.alignment
)
413 sym
->ctype
.alignment
= base_type
->ctype
.alignment
;
417 static struct symbol
*examine_pointer_type(struct symbol
*sym
)
420 * We need to set the pointer size first, and
421 * examine the thing we point to only afterwards.
422 * That's because this pointer type may end up
423 * being needed for the base type size evaluation.
426 sym
->bit_size
= bits_in_pointer
;
427 if (!sym
->ctype
.alignment
)
428 sym
->ctype
.alignment
= pointer_alignment
;
433 * Fill in type size and alignment information for
434 * regular SYM_TYPE things.
436 struct symbol
*examine_symbol_type(struct symbol
* sym
)
449 return examine_node_type(sym
);
451 return examine_array_type(sym
);
453 return examine_struct_union_type(sym
, 1);
455 return examine_struct_union_type(sym
, 0);
457 return examine_pointer_type(sym
);
459 return examine_enum_type(sym
);
461 return examine_bitfield_type(sym
);
463 /* Size and alignment had better already be set up */
466 struct symbol
*base
= evaluate_expression(sym
->initializer
);
468 if (is_bitfield_type(base
))
469 warning(base
->pos
, "typeof applied to bitfield type");
470 if (base
->type
== SYM_NODE
)
471 base
= base
->ctype
.base_type
;
472 sym
->type
= SYM_NODE
;
473 sym
->ctype
.modifiers
= 0;
474 sym
->ctype
.base_type
= base
;
475 return examine_node_type(sym
);
479 case SYM_PREPROCESSOR
:
480 sparse_error(sym
->pos
, "ctype on preprocessor command? (%s)", show_ident(sym
->ident
));
482 case SYM_UNINITIALIZED
:
483 sparse_error(sym
->pos
, "ctype on uninitialized symbol %p", sym
);
486 examine_base_type(sym
);
489 examine_base_type(sym
);
492 sparse_error(sym
->pos
, "Examining unknown symbol type %d", sym
->type
);
498 const char* get_type_name(enum type type
)
500 const char *type_lookup
[] = {
501 [SYM_UNINITIALIZED
] = "uninitialized",
502 [SYM_PREPROCESSOR
] = "preprocessor",
503 [SYM_BASETYPE
] = "basetype",
505 [SYM_PTR
] = "pointer",
506 [SYM_FN
] = "function",
507 [SYM_ARRAY
] = "array",
508 [SYM_STRUCT
] = "struct",
509 [SYM_UNION
] = "union",
511 [SYM_TYPEDEF
] = "typedef",
512 [SYM_TYPEOF
] = "typeof",
513 [SYM_MEMBER
] = "member",
514 [SYM_BITFIELD
] = "bitfield",
515 [SYM_LABEL
] = "label",
516 [SYM_RESTRICT
] = "restrict",
517 [SYM_FOULED
] = "fouled",
518 [SYM_KEYWORD
] = "keyword",
522 return type_lookup
[type
];
527 struct symbol
*examine_pointer_target(struct symbol
*sym
)
529 return examine_base_type(sym
);
532 static struct symbol_list
*restr
, *fouled
;
534 void create_fouled(struct symbol
*type
)
536 if (type
->bit_size
< bits_in_int
) {
537 struct symbol
*new = alloc_symbol(type
->pos
, type
->type
);
539 new->bit_size
= bits_in_int
;
540 new->type
= SYM_FOULED
;
541 new->ctype
.base_type
= type
;
542 add_symbol(&restr
, type
);
543 add_symbol(&fouled
, new);
547 struct symbol
*befoul(struct symbol
*type
)
549 struct symbol
*t1
, *t2
;
550 while (type
->type
== SYM_NODE
)
551 type
= type
->ctype
.base_type
;
552 PREPARE_PTR_LIST(restr
, t1
);
553 PREPARE_PTR_LIST(fouled
, t2
);
567 void check_declaration(struct symbol
*sym
)
570 struct symbol
*next
= sym
;
572 while ((next
= next
->next_id
) != NULL
) {
573 if (next
->namespace != sym
->namespace)
575 if (sym
->scope
== next
->scope
) {
576 sym
->same_symbol
= next
;
579 if (sym
->ctype
.modifiers
& next
->ctype
.modifiers
& MOD_EXTERN
) {
580 if ((sym
->ctype
.modifiers
^ next
->ctype
.modifiers
) & MOD_INLINE
)
582 sym
->same_symbol
= next
;
586 if (!Wshadow
|| warned
)
588 if (get_sym_type(next
) == SYM_FN
)
591 warning(sym
->pos
, "symbol '%s' shadows an earlier one", show_ident(sym
->ident
));
592 info(next
->pos
, "originally declared here");
596 void bind_symbol(struct symbol
*sym
, struct ident
*ident
, enum namespace ns
)
600 sparse_error(sym
->pos
, "internal error: symbol type already bound");
603 if (ident
->reserved
&& (ns
& (NS_TYPEDEF
| NS_STRUCT
| NS_LABEL
| NS_SYMBOL
))) {
604 sparse_error(sym
->pos
, "Trying to use reserved word '%s' as identifier", show_ident(ident
));
608 sym
->next_id
= ident
->symbols
;
609 ident
->symbols
= sym
;
610 if (sym
->ident
&& sym
->ident
!= ident
)
611 warning(sym
->pos
, "Symbol '%s' already bound", show_ident(sym
->ident
));
616 if (ns
== NS_SYMBOL
&& toplevel(scope
)) {
617 unsigned mod
= MOD_ADDRESSABLE
| MOD_TOPLEVEL
;
619 scope
= global_scope
;
620 if (sym
->ctype
.modifiers
& MOD_STATIC
||
621 is_extern_inline(sym
)) {
625 sym
->ctype
.modifiers
|= mod
;
630 scope
= function_scope
;
631 bind_scope(sym
, scope
);
634 struct symbol
*create_symbol(int stream
, const char *name
, int type
, int namespace)
636 struct token
*token
= built_in_token(stream
, name
);
637 struct symbol
*sym
= alloc_symbol(token
->pos
, type
);
639 bind_symbol(sym
, token
->ident
, namespace);
643 static int evaluate_to_integer(struct expression
*expr
)
645 expr
->ctype
= &int_ctype
;
649 static int evaluate_expect(struct expression
*expr
)
651 /* Should we evaluate it to return the type of the first argument? */
652 expr
->ctype
= &int_ctype
;
656 static int arguments_choose(struct expression
*expr
)
658 struct expression_list
*arglist
= expr
->args
;
659 struct expression
*arg
;
662 FOR_EACH_PTR (arglist
, arg
) {
663 if (!evaluate_expression(arg
))
666 } END_FOR_EACH_PTR(arg
);
668 sparse_error(expr
->pos
,
669 "not enough arguments for __builtin_choose_expr");
672 sparse_error(expr
->pos
,
673 "too many arguments for __builtin_choose_expr");
679 static int evaluate_choose(struct expression
*expr
)
681 struct expression_list
*list
= expr
->args
;
682 struct expression
*arg
, *args
[3];
685 /* there will be exactly 3; we'd already verified that */
686 FOR_EACH_PTR(list
, arg
) {
688 } END_FOR_EACH_PTR(arg
);
690 *expr
= get_expression_value(args
[0]) ? *args
[1] : *args
[2];
695 static int expand_expect(struct expression
*expr
, int cost
)
697 struct expression
*arg
= first_ptr_list((struct ptr_list
*) expr
->args
);
705 * __builtin_warning() has type "int" and always returns 1,
706 * so that you can use it in conditionals or whatever
708 static int expand_warning(struct expression
*expr
, int cost
)
710 struct expression
*arg
;
711 struct expression_list
*arglist
= expr
->args
;
713 FOR_EACH_PTR (arglist
, arg
) {
715 * Constant strings get printed out as a warning. By the
716 * time we get here, the EXPR_STRING has been fully
717 * evaluated, so by now it's an anonymous symbol with a
718 * string initializer.
720 * Just for the heck of it, allow any constant string
723 if (arg
->type
== EXPR_SYMBOL
) {
724 struct symbol
*sym
= arg
->symbol
;
725 if (sym
->initializer
&& sym
->initializer
->type
== EXPR_STRING
) {
726 struct string
*string
= sym
->initializer
->string
;
727 warning(expr
->pos
, "%*s", string
->length
-1, string
->data
);
733 * Any other argument is a conditional. If it's
734 * non-constant, or it is false, we exit and do
735 * not print any warning.
737 if (arg
->type
!= EXPR_VALUE
)
741 } END_FOR_EACH_PTR(arg
);
743 expr
->type
= EXPR_VALUE
;
749 static struct symbol_op constant_p_op
= {
750 .evaluate
= evaluate_to_integer
,
751 .expand
= expand_constant_p
754 static struct symbol_op safe_p_op
= {
755 .evaluate
= evaluate_to_integer
,
756 .expand
= expand_safe_p
759 static struct symbol_op warning_op
= {
760 .evaluate
= evaluate_to_integer
,
761 .expand
= expand_warning
764 static struct symbol_op expect_op
= {
765 .evaluate
= evaluate_expect
,
766 .expand
= expand_expect
769 static struct symbol_op choose_op
= {
770 .evaluate
= evaluate_choose
,
771 .args
= arguments_choose
,
777 static struct symbol builtin_fn_type
= { .type
= SYM_FN
/* , .variadic =1 */ };
778 static struct sym_init
{
780 struct symbol
*base_type
;
781 unsigned int modifiers
;
782 struct symbol_op
*op
;
783 } eval_init_table
[] = {
784 { "__builtin_constant_p", &builtin_fn_type
, MOD_TOPLEVEL
, &constant_p_op
},
785 { "__builtin_safe_p", &builtin_fn_type
, MOD_TOPLEVEL
, &safe_p_op
},
786 { "__builtin_warning", &builtin_fn_type
, MOD_TOPLEVEL
, &warning_op
},
787 { "__builtin_expect", &builtin_fn_type
, MOD_TOPLEVEL
, &expect_op
},
788 { "__builtin_choose_expr", &builtin_fn_type
, MOD_TOPLEVEL
, &choose_op
},
796 struct symbol int_type
,
800 * C types (i.e. actual instances that the abstract types
803 struct symbol bool_ctype
, void_ctype
, type_ctype
,
804 char_ctype
, schar_ctype
, uchar_ctype
,
805 short_ctype
, sshort_ctype
, ushort_ctype
,
806 int_ctype
, sint_ctype
, uint_ctype
,
807 long_ctype
, slong_ctype
, ulong_ctype
,
808 llong_ctype
, sllong_ctype
, ullong_ctype
,
809 lllong_ctype
, slllong_ctype
, ulllong_ctype
,
810 float_ctype
, double_ctype
, ldouble_ctype
,
811 string_ctype
, ptr_ctype
, lazy_ptr_ctype
,
812 incomplete_ctype
, label_ctype
, bad_ctype
,
815 struct symbol zero_int
;
817 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
818 #define __IDENT(n,str,res) \
819 struct ident n = __INIT_IDENT(str,res)
821 #include "ident-list.h"
823 void init_symbols(void)
825 int stream
= init_stream("builtin", -1, includepath
);
826 struct sym_init
*ptr
;
828 #define __IDENT(n,str,res) \
830 #include "ident-list.h"
834 builtin_fn_type
.variadic
= 1;
835 for (ptr
= eval_init_table
; ptr
->name
; ptr
++) {
837 sym
= create_symbol(stream
, ptr
->name
, SYM_NODE
, NS_SYMBOL
);
838 sym
->ctype
.base_type
= ptr
->base_type
;
839 sym
->ctype
.modifiers
= ptr
->modifiers
;
844 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
845 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
846 #define MOD_LLL MOD_LONGLONGLONG
847 static const struct ctype_declare
{
850 unsigned long modifiers
;
853 struct symbol
*base_type
;
854 } ctype_declaration
[] = {
855 { &bool_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_bool
, &max_int_alignment
, &int_type
},
856 { &void_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
857 { &type_ctype
, SYM_BASETYPE
, MOD_TYPE
, NULL
, NULL
, NULL
},
858 { &incomplete_ctype
,SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
859 { &bad_ctype
, SYM_BASETYPE
, 0, NULL
, NULL
, NULL
},
861 { &char_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
862 { &schar_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
863 { &uchar_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_CHAR
, &bits_in_char
, &max_int_alignment
, &int_type
},
864 { &short_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
865 { &sshort_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
866 { &ushort_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_SHORT
, &bits_in_short
, &max_int_alignment
, &int_type
},
867 { &int_ctype
, SYM_BASETYPE
, MOD_SIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
868 { &sint_ctype
, SYM_BASETYPE
, MOD_ESIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
869 { &uint_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
, &bits_in_int
, &max_int_alignment
, &int_type
},
870 { &long_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
871 { &slong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
872 { &ulong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LONG
, &bits_in_long
, &max_int_alignment
, &int_type
},
873 { &llong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
874 { &sllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
875 { &ullong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LL
, &bits_in_longlong
, &max_int_alignment
, &int_type
},
876 { &lllong_ctype
, SYM_BASETYPE
, MOD_SIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
877 { &slllong_ctype
, SYM_BASETYPE
, MOD_ESIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
878 { &ulllong_ctype
, SYM_BASETYPE
, MOD_UNSIGNED
| MOD_LLL
, &bits_in_longlonglong
, &max_int_alignment
, &int_type
},
880 { &float_ctype
, SYM_BASETYPE
, 0, &bits_in_float
, &max_fp_alignment
, &fp_type
},
881 { &double_ctype
, SYM_BASETYPE
, MOD_LONG
, &bits_in_double
, &max_fp_alignment
, &fp_type
},
882 { &ldouble_ctype
, SYM_BASETYPE
, MOD_LONG
| MOD_LONGLONG
, &bits_in_longdouble
, &max_fp_alignment
, &fp_type
},
884 { &string_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &char_ctype
},
885 { &ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
886 { &null_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
887 { &label_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
888 { &lazy_ptr_ctype
, SYM_PTR
, 0, &bits_in_pointer
, &pointer_alignment
, &void_ctype
},
895 void init_ctype(void)
897 const struct ctype_declare
*ctype
;
899 for (ctype
= ctype_declaration
; ctype
->ptr
; ctype
++) {
900 struct symbol
*sym
= ctype
->ptr
;
901 unsigned long bit_size
= ctype
->bit_size
? *ctype
->bit_size
: -1;
902 unsigned long maxalign
= ctype
->maxalign
? *ctype
->maxalign
: 0;
903 unsigned long alignment
= bits_to_bytes(bit_size
+ bits_in_char
- 1);
905 if (alignment
> maxalign
)
906 alignment
= maxalign
;
907 sym
->type
= ctype
->type
;
908 sym
->bit_size
= bit_size
;
909 sym
->ctype
.alignment
= alignment
;
910 sym
->ctype
.base_type
= ctype
->base_type
;
911 sym
->ctype
.modifiers
= ctype
->modifiers
;