Add test-suite comment to bad-array-designated-initializer.c
[smatch.git] / symbol.c
blob329fed985455c5d811690e9fd3d90aeac926562e
1 /*
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
8 */
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
13 #include "lib.h"
14 #include "allocate.h"
15 #include "token.h"
16 #include "parse.h"
17 #include "symbol.h"
18 #include "scope.h"
19 #include "expression.h"
21 #include "target.h"
24 * Secondary symbol list for stuff that needs to be output because it
25 * was used.
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)
44 struct symbol *sym;
46 for (sym = ident->symbols; sym; sym = sym->next_id) {
47 if (sym->namespace & ns) {
48 sym->used = 1;
49 return sym;
52 return sym;
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);
63 sym->type = type;
64 sym->pos = pos;
65 return sym;
68 struct struct_union_info {
69 unsigned long max_align;
70 unsigned long bit_size;
71 int align_size;
75 * Unions are fairly easy to lay out ;)
77 static void lay_out_union(struct symbol *sym, struct struct_union_info *info)
79 examine_symbol_type(sym);
81 // Unnamed bitfields do not affect alignment.
82 if (sym->ident || !is_bitfield_type(sym)) {
83 if (sym->ctype.alignment > info->max_align)
84 info->max_align = sym->ctype.alignment;
87 if (sym->bit_size > info->bit_size)
88 info->bit_size = sym->bit_size;
90 sym->offset = 0;
93 static int bitfield_base_size(struct symbol *sym)
95 if (sym->type == SYM_NODE)
96 sym = sym->ctype.base_type;
97 if (sym->type == SYM_BITFIELD)
98 sym = sym->ctype.base_type;
99 return sym->bit_size;
103 * Structures are a bit more interesting to lay out
105 static void lay_out_struct(struct symbol *sym, struct struct_union_info *info)
107 unsigned long bit_size, align_bit_mask;
108 int base_size;
110 examine_symbol_type(sym);
112 // Unnamed bitfields do not affect alignment.
113 if (sym->ident || !is_bitfield_type(sym)) {
114 if (sym->ctype.alignment > info->max_align)
115 info->max_align = sym->ctype.alignment;
118 bit_size = info->bit_size;
119 base_size = sym->bit_size;
122 * Unsized arrays cause us to not align the resulting
123 * structure size
125 if (base_size < 0) {
126 info->align_size = 0;
127 base_size = 0;
130 align_bit_mask = (sym->ctype.alignment << 3) - 1;
133 * Bitfields have some very special rules..
135 if (is_bitfield_type (sym)) {
136 unsigned long bit_offset = bit_size & align_bit_mask;
137 int room = bitfield_base_size(sym) - bit_offset;
138 // Zero-width fields just fill up the unit.
139 int width = base_size ? : (bit_offset ? room : 0);
141 if (width > room) {
142 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
143 bit_offset = 0;
145 sym->offset = (bit_size - bit_offset) >> 3;
146 sym->bit_offset = bit_offset;
147 sym->ctype.base_type->bit_offset = bit_offset;
148 info->bit_size = bit_size + width;
149 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
151 return;
155 * Otherwise, just align it right and add it up..
157 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
158 sym->offset = bit_size >> 3;
160 info->bit_size = bit_size + base_size;
161 // warning (sym->pos, "regular: offset=%d", sym->offset);
164 static struct symbol * examine_struct_union_type(struct symbol *sym, int advance)
166 struct struct_union_info info = {
167 .max_align = 1,
168 .bit_size = 0,
169 .align_size = 1
171 unsigned long bit_size, bit_align;
172 void (*fn)(struct symbol *, struct struct_union_info *);
173 struct symbol *member;
175 fn = advance ? lay_out_struct : lay_out_union;
176 FOR_EACH_PTR(sym->symbol_list, member) {
177 fn(member, &info);
178 } END_FOR_EACH_PTR(member);
180 if (!sym->ctype.alignment)
181 sym->ctype.alignment = info.max_align;
182 bit_size = info.bit_size;
183 if (info.align_size) {
184 bit_align = (sym->ctype.alignment << 3)-1;
185 bit_size = (bit_size + bit_align) & ~bit_align;
187 sym->bit_size = bit_size;
188 return sym;
191 static struct symbol *examine_base_type(struct symbol *sym)
193 struct symbol *base_type;
195 /* Check the base type */
196 base_type = sym->ctype.base_type;
197 if (base_type) {
198 base_type = examine_symbol_type(base_type);
200 /* "typeof" can cause this */
201 if (base_type && base_type->type == SYM_NODE)
202 merge_type(sym, base_type);
204 return base_type;
207 static struct symbol * examine_array_type(struct symbol *sym)
209 struct symbol *base_type = examine_base_type(sym);
210 unsigned long bit_size, alignment;
212 if (!base_type)
213 return sym;
214 bit_size = base_type->bit_size * get_expression_value(sym->array_size);
215 if (!sym->array_size || sym->array_size->type != EXPR_VALUE)
216 bit_size = -1;
217 alignment = base_type->ctype.alignment;
218 if (!sym->ctype.alignment)
219 sym->ctype.alignment = alignment;
220 sym->bit_size = bit_size;
221 return sym;
224 static struct symbol *examine_bitfield_type(struct symbol *sym)
226 struct symbol *base_type = examine_base_type(sym);
227 unsigned long bit_size, alignment, modifiers;
229 if (!base_type)
230 return sym;
231 bit_size = base_type->bit_size;
232 if (sym->bit_size > bit_size)
233 warning(sym->pos, "impossible field-width, %d, for this type", sym->bit_size);
235 alignment = base_type->ctype.alignment;
236 if (!sym->ctype.alignment)
237 sym->ctype.alignment = alignment;
238 modifiers = base_type->ctype.modifiers;
240 /* Bitfields are unsigned, unless the base type was explicitly signed */
241 if (!(modifiers & MOD_EXPLICITLY_SIGNED))
242 modifiers = (modifiers & ~MOD_SIGNED) | MOD_UNSIGNED;
243 sym->ctype.modifiers |= modifiers & MOD_SIGNEDNESS;
244 return sym;
248 * "typeof" will have to merge the types together
250 void merge_type(struct symbol *sym, struct symbol *base_type)
252 sym->ctype.as |= base_type->ctype.as;
253 sym->ctype.modifiers |= (base_type->ctype.modifiers & ~MOD_STORAGE);
254 concat_ptr_list((struct ptr_list *)base_type->ctype.contexts,
255 (struct ptr_list **)&sym->ctype.contexts);
256 sym->ctype.base_type = base_type->ctype.base_type;
257 if (sym->ctype.base_type->type == SYM_NODE)
258 merge_type(sym, sym->ctype.base_type);
261 static int count_array_initializer(struct symbol *t, struct expression *expr)
263 int nr = 0;
264 int is_char = 0;
267 * Arrays of character types are special; they can be initialized by
268 * string literal _or_ by string literal in braces. The latter means
269 * that with T x[] = {<string literal>} number of elements in x depends
270 * on T - if it's a character type, we get the length of string literal
271 * (including NUL), otherwise we have one element here.
273 if (t->ctype.base_type == &int_type && t->ctype.modifiers & MOD_CHAR)
274 is_char = 1;
276 switch (expr->type) {
277 case EXPR_INITIALIZER: {
278 struct expression *entry;
279 int count = 0;
280 int str_len = 0;
281 FOR_EACH_PTR(expr->expr_list, entry) {
282 count++;
283 switch (entry->type) {
284 case EXPR_INDEX:
285 if (entry->idx_to >= nr)
286 nr = entry->idx_to+1;
287 break;
288 case EXPR_STRING:
289 if (is_char)
290 str_len = entry->string->length;
291 default:
292 nr++;
294 } END_FOR_EACH_PTR(entry);
295 if (count == 1 && str_len)
296 nr = str_len;
297 break;
299 case EXPR_STRING:
300 if (is_char)
301 nr = expr->string->length;
302 default:
303 break;
305 return nr;
308 static struct symbol * examine_node_type(struct symbol *sym)
310 struct symbol *base_type = examine_base_type(sym);
311 int bit_size;
312 unsigned long alignment, modifiers;
314 /* SYM_NODE - figure out what the type of the node was.. */
315 modifiers = sym->ctype.modifiers;
317 bit_size = 0;
318 alignment = 0;
319 if (!base_type)
320 return sym;
322 bit_size = base_type->bit_size;
323 alignment = base_type->ctype.alignment;
325 /* Pick up signedness information into the node */
326 sym->ctype.modifiers |= (MOD_SIGNEDNESS & base_type->ctype.modifiers);
328 if (!sym->ctype.alignment)
329 sym->ctype.alignment = alignment;
331 /* Unsized array? The size might come from the initializer.. */
332 if (bit_size < 0 && base_type->type == SYM_ARRAY && sym->initializer) {
333 struct symbol *node_type = base_type->ctype.base_type;
334 int count = count_array_initializer(node_type, sym->initializer);
336 if (node_type && node_type->bit_size >= 0)
337 bit_size = node_type->bit_size * count;
340 sym->bit_size = bit_size;
341 return sym;
344 static struct symbol *examine_enum_type(struct symbol *sym)
346 struct symbol *base_type = examine_base_type(sym);
348 sym->ctype.modifiers |= (base_type->ctype.modifiers & MOD_SIGNEDNESS);
349 sym->bit_size = bits_in_enum;
350 if (base_type->bit_size > sym->bit_size)
351 sym->bit_size = base_type->bit_size;
352 sym->ctype.alignment = enum_alignment;
353 if (base_type->ctype.alignment > sym->ctype.alignment)
354 sym->ctype.alignment = base_type->ctype.alignment;
355 return sym;
358 static struct symbol *examine_pointer_type(struct symbol *sym)
361 * We need to set the pointer size first, and
362 * examine the thing we point to only afterwards.
363 * That's because this pointer type may end up
364 * being needed for the base type size evaluation.
366 if (!sym->bit_size)
367 sym->bit_size = bits_in_pointer;
368 if (!sym->ctype.alignment)
369 sym->ctype.alignment = pointer_alignment;
370 return sym;
374 * Fill in type size and alignment information for
375 * regular SYM_TYPE things.
377 struct symbol *examine_symbol_type(struct symbol * sym)
379 if (!sym)
380 return sym;
382 /* Already done? */
383 if (sym->examined)
384 return sym;
385 sym->examined = 1;
387 switch (sym->type) {
388 case SYM_FN:
389 case SYM_NODE:
390 return examine_node_type(sym);
391 case SYM_ARRAY:
392 return examine_array_type(sym);
393 case SYM_STRUCT:
394 return examine_struct_union_type(sym, 1);
395 case SYM_UNION:
396 return examine_struct_union_type(sym, 0);
397 case SYM_PTR:
398 return examine_pointer_type(sym);
399 case SYM_ENUM:
400 return examine_enum_type(sym);
401 case SYM_BITFIELD:
402 return examine_bitfield_type(sym);
403 case SYM_BASETYPE:
404 /* Size and alignment had better already be set up */
405 return sym;
406 case SYM_TYPEOF: {
407 struct symbol *base = evaluate_expression(sym->initializer);
408 if (base) {
409 if (is_bitfield_type(base))
410 warning(base->pos, "typeof applied to bitfield type");
411 if (base->type == SYM_NODE)
412 base = base->ctype.base_type;
413 switch (base->type) {
414 case SYM_RESTRICT:
415 case SYM_UNION:
416 case SYM_STRUCT:
417 sym->type = SYM_NODE;
418 sym->ctype.modifiers = 0;
419 sym->ctype.base_type = base;
420 return examine_node_type(sym);
422 *sym = *base;
423 break;
425 break;
427 case SYM_PREPROCESSOR:
428 sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident));
429 return NULL;
430 case SYM_UNINITIALIZED:
431 sparse_error(sym->pos, "ctype on uninitialized symbol %p", sym);
432 return NULL;
433 case SYM_RESTRICT:
434 examine_base_type(sym);
435 return sym;
436 case SYM_FOULED:
437 examine_base_type(sym);
438 return sym;
439 default:
440 sparse_error(sym->pos, "Examining unknown symbol type %d", sym->type);
441 break;
443 return sym;
446 static struct symbol_list *restr, *fouled;
448 void create_fouled(struct symbol *type)
450 if (type->bit_size < bits_in_int) {
451 struct symbol *new = alloc_symbol(type->pos, type->type);
452 *new = *type;
453 new->bit_size = bits_in_int;
454 new->type = SYM_FOULED;
455 new->ctype.base_type = type;
456 add_symbol(&restr, type);
457 add_symbol(&fouled, new);
461 struct symbol *befoul(struct symbol *type)
463 struct symbol *t1, *t2;
464 while (type->type == SYM_NODE)
465 type = type->ctype.base_type;
466 PREPARE_PTR_LIST(restr, t1);
467 PREPARE_PTR_LIST(fouled, t2);
468 for (;;) {
469 if (t1 == type)
470 return t2;
471 if (!t1)
472 break;
473 NEXT_PTR_LIST(t1);
474 NEXT_PTR_LIST(t2);
476 FINISH_PTR_LIST(t2);
477 FINISH_PTR_LIST(t1);
478 return NULL;
481 void check_declaration(struct symbol *sym)
483 int warned = 0;
484 struct symbol *next = sym;
486 while ((next = next->next_id) != NULL) {
487 if (next->namespace != sym->namespace)
488 continue;
489 if (sym->scope == next->scope) {
490 sym->same_symbol = next;
491 return;
493 if (sym->ctype.modifiers & next->ctype.modifiers & MOD_EXTERN) {
494 sym->same_symbol = next;
495 return;
498 if (!Wshadow || warned)
499 continue;
500 if (get_sym_type(next) == SYM_FN)
501 continue;
502 warned = 1;
503 warning(sym->pos, "symbol '%s' shadows an earlier one", show_ident(sym->ident));
504 info(next->pos, "originally declared here");
508 void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns)
510 struct scope *scope;
511 if (sym->id_list) {
512 sparse_error(sym->pos, "internal error: symbol type already bound");
513 return;
515 if (ident->reserved && (ns & (NS_TYPEDEF | NS_STRUCT | NS_LABEL | NS_SYMBOL))) {
516 sparse_error(sym->pos, "Trying to use reserved word '%s' as identifier", show_ident(ident));
517 return;
519 sym->namespace = ns;
520 sym->next_id = ident->symbols;
521 ident->symbols = sym;
522 sym->id_list = &ident->symbols;
523 if (sym->ident && sym->ident != ident)
524 warning(sym->pos, "Symbol '%s' already bound", show_ident(sym->ident));
525 sym->ident = ident;
527 scope = block_scope;
528 if (ns == NS_SYMBOL && toplevel(scope)) {
529 unsigned mod = MOD_ADDRESSABLE | MOD_TOPLEVEL;
530 scope = global_scope;
531 if (sym->ctype.modifiers & MOD_STATIC) {
532 scope = file_scope;
533 mod = MOD_TOPLEVEL;
535 sym->ctype.modifiers |= mod;
537 if (ns == NS_MACRO)
538 scope = file_scope;
539 if (ns == NS_LABEL)
540 scope = function_scope;
541 bind_scope(sym, scope);
544 struct symbol *create_symbol(int stream, const char *name, int type, int namespace)
546 struct token *token = built_in_token(stream, name);
547 struct symbol *sym = alloc_symbol(token->pos, type);
549 bind_symbol(sym, token->ident, namespace);
550 return sym;
553 static int evaluate_to_integer(struct expression *expr)
555 expr->ctype = &int_ctype;
556 return 1;
559 static int evaluate_expect(struct expression *expr)
561 /* Should we evaluate it to return the type of the first argument? */
562 expr->ctype = &int_ctype;
563 return 1;
566 static int arguments_choose(struct expression *expr)
568 struct expression_list *arglist = expr->args;
569 struct expression *arg;
570 int i = 0;
572 FOR_EACH_PTR (arglist, arg) {
573 if (!evaluate_expression(arg))
574 return 0;
575 i++;
576 } END_FOR_EACH_PTR(arg);
577 if (i < 3) {
578 sparse_error(expr->pos,
579 "not enough arguments for __builtin_choose_expr");
580 return 0;
581 } if (i > 3) {
582 sparse_error(expr->pos,
583 "too many arguments for __builtin_choose_expr");
584 return 0;
586 return 1;
589 static int evaluate_choose(struct expression *expr)
591 struct expression_list *list = expr->args;
592 struct expression *arg, *args[3];
593 int n = 0;
595 /* there will be exactly 3; we'd already verified that */
596 FOR_EACH_PTR(list, arg) {
597 args[n++] = arg;
598 } END_FOR_EACH_PTR(arg);
600 *expr = get_expression_value(args[0]) ? *args[1] : *args[2];
602 return 1;
605 static int expand_expect(struct expression *expr, int cost)
607 struct expression *arg = first_ptr_list((struct ptr_list *) expr->args);
609 if (arg)
610 *expr = *arg;
611 return 0;
615 * __builtin_warning() has type "int" and always returns 1,
616 * so that you can use it in conditionals or whatever
618 static int expand_warning(struct expression *expr, int cost)
620 struct expression *arg;
621 struct expression_list *arglist = expr->args;
623 FOR_EACH_PTR (arglist, arg) {
625 * Constant strings get printed out as a warning. By the
626 * time we get here, the EXPR_STRING has been fully
627 * evaluated, so by now it's an anonymous symbol with a
628 * string initializer.
630 * Just for the heck of it, allow any constant string
631 * symbol.
633 if (arg->type == EXPR_SYMBOL) {
634 struct symbol *sym = arg->symbol;
635 if (sym->initializer && sym->initializer->type == EXPR_STRING) {
636 struct string *string = sym->initializer->string;
637 warning(expr->pos, "%*s", string->length-1, string->data);
639 continue;
643 * Any other argument is a conditional. If it's
644 * non-constant, or it is false, we exit and do
645 * not print any warning.
647 if (arg->type != EXPR_VALUE)
648 goto out;
649 if (!arg->value)
650 goto out;
651 } END_FOR_EACH_PTR(arg);
652 out:
653 expr->type = EXPR_VALUE;
654 expr->value = 1;
655 return 0;
659 * Type and storage class keywords need to have the symbols
660 * created for them, so that the parser can have enough semantic
661 * information to do parsing.
663 * "double" == "long float", "long double" == "long long float"
665 static struct sym_init {
666 const char *name;
667 struct symbol *base_type;
668 unsigned int modifiers;
669 struct symbol_op *op;
670 } symbol_init_table[] = {
671 /* Storage class */
672 { "auto", NULL, MOD_AUTO },
673 { "register", NULL, MOD_REGISTER },
674 { "static", NULL, MOD_STATIC },
675 { "extern", NULL, MOD_EXTERN },
677 /* Type specifiers */
678 { "void", &void_ctype, 0 },
679 { "char", NULL, MOD_CHAR },
680 { "short", NULL, MOD_SHORT },
681 { "int", &int_type, 0 },
682 { "long", NULL, MOD_LONG },
683 { "float", &fp_type, 0 },
684 { "double", &fp_type, MOD_LONG },
685 { "signed", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
686 { "__signed", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
687 { "__signed__", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
688 { "unsigned", NULL, MOD_UNSIGNED },
689 { "__label__", &label_ctype, MOD_LABEL | MOD_UNSIGNED },
690 { "_Bool", &bool_ctype, MOD_UNSIGNED },
692 /* Predeclared types */
693 { "__builtin_va_list", &int_type, 0 },
695 { NULL, NULL, 0 }
698 static struct symbol_op constant_p_op = {
699 .evaluate = evaluate_to_integer,
700 .expand = expand_constant_p
703 static struct symbol_op safe_p_op = {
704 .evaluate = evaluate_to_integer,
705 .expand = expand_safe_p
708 static struct symbol_op warning_op = {
709 .evaluate = evaluate_to_integer,
710 .expand = expand_warning
713 static struct symbol_op expect_op = {
714 .evaluate = evaluate_expect,
715 .expand = expand_expect
718 static struct symbol_op choose_op = {
719 .evaluate = evaluate_choose,
720 .args = arguments_choose,
724 * Builtin functions
726 static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ };
727 static struct sym_init eval_init_table[] = {
728 { "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op },
729 { "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op },
730 { "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op },
731 { "__builtin_expect", &builtin_fn_type, MOD_TOPLEVEL, &expect_op },
732 { "__builtin_choose_expr", &builtin_fn_type, MOD_TOPLEVEL, &choose_op },
733 { NULL, NULL, 0 }
738 * Abstract types
740 struct symbol int_type,
741 fp_type;
744 * C types (i.e. actual instances that the abstract types
745 * can map onto)
747 struct symbol bool_ctype, void_ctype, type_ctype,
748 char_ctype, schar_ctype, uchar_ctype,
749 short_ctype, sshort_ctype, ushort_ctype,
750 int_ctype, sint_ctype, uint_ctype,
751 long_ctype, slong_ctype, ulong_ctype,
752 llong_ctype, sllong_ctype, ullong_ctype,
753 float_ctype, double_ctype, ldouble_ctype,
754 string_ctype, ptr_ctype, lazy_ptr_ctype,
755 incomplete_ctype, label_ctype, bad_ctype;
757 struct symbol zero_int;
759 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
760 #define __IDENT(n,str,res) \
761 struct ident n = __INIT_IDENT(str,res)
763 #include "ident-list.h"
765 void init_symbols(void)
767 int stream = init_stream("builtin", -1, includepath);
768 struct sym_init *ptr;
770 #define __IDENT(n,str,res) \
771 hash_ident(&n)
772 #include "ident-list.h"
774 init_parser(stream);
775 for (ptr = symbol_init_table; ptr->name; ptr++) {
776 struct symbol *sym;
777 sym = create_symbol(stream, ptr->name, SYM_NODE, NS_TYPEDEF);
778 sym->ident->reserved = 1;
779 sym->ctype.base_type = ptr->base_type;
780 sym->ctype.modifiers = ptr->modifiers;
783 builtin_fn_type.variadic = 1;
784 for (ptr = eval_init_table; ptr->name; ptr++) {
785 struct symbol *sym;
786 sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL);
787 sym->ctype.base_type = ptr->base_type;
788 sym->ctype.modifiers = ptr->modifiers;
789 sym->op = ptr->op;
793 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
794 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
795 static const struct ctype_declare {
796 struct symbol *ptr;
797 enum type type;
798 unsigned long modifiers;
799 int *bit_size;
800 int *maxalign;
801 struct symbol *base_type;
802 } ctype_declaration[] = {
803 { &bool_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_bool, &max_int_alignment, &int_type },
804 { &void_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
805 { &type_ctype, SYM_BASETYPE, MOD_TYPE, NULL, NULL, NULL },
806 { &incomplete_ctype,SYM_BASETYPE, 0, NULL, NULL, NULL },
807 { &bad_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
809 { &char_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
810 { &schar_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
811 { &uchar_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
812 { &short_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
813 { &sshort_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
814 { &ushort_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
815 { &int_ctype, SYM_BASETYPE, MOD_SIGNED, &bits_in_int, &max_int_alignment, &int_type },
816 { &sint_ctype, SYM_BASETYPE, MOD_ESIGNED, &bits_in_int, &max_int_alignment, &int_type },
817 { &uint_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_int, &max_int_alignment, &int_type },
818 { &long_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
819 { &slong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
820 { &ulong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
821 { &llong_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
822 { &sllong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
823 { &ullong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
825 { &float_ctype, SYM_BASETYPE, 0, &bits_in_float, &max_fp_alignment, &fp_type },
826 { &double_ctype, SYM_BASETYPE, MOD_LONG, &bits_in_double, &max_fp_alignment, &fp_type },
827 { &ldouble_ctype, SYM_BASETYPE, MOD_LONG | MOD_LONGLONG, &bits_in_longdouble, &max_fp_alignment, &fp_type },
829 { &string_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &char_ctype },
830 { &ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
831 { &label_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
832 { &lazy_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
833 { NULL, }
835 #undef MOD_LL
836 #undef MOD_ESIGNED
838 void init_ctype(void)
840 const struct ctype_declare *ctype;
842 for (ctype = ctype_declaration ; ctype->ptr; ctype++) {
843 struct symbol *sym = ctype->ptr;
844 unsigned long bit_size = ctype->bit_size ? *ctype->bit_size : -1;
845 unsigned long maxalign = ctype->maxalign ? *ctype->maxalign : 0;
846 unsigned long alignment = (bit_size + 7) >> 3;
848 if (alignment > maxalign)
849 alignment = maxalign;
850 sym->type = ctype->type;
851 sym->bit_size = bit_size;
852 sym->ctype.alignment = alignment;
853 sym->ctype.base_type = ctype->base_type;
854 sym->ctype.modifiers = ctype->modifiers;