[PATCH] casting null pointer constant to non-zero address space is always OK
[smatch.git] / symbol.c
blob7d64f7f430003a234b9b5a13dba8a63ddd8062fa
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 <stdlib.h>
12 #include <string.h>
14 #include "lib.h"
15 #include "allocate.h"
16 #include "token.h"
17 #include "parse.h"
18 #include "symbol.h"
19 #include "scope.h"
20 #include "expression.h"
22 #include "target.h"
25 * Secondary symbol list for stuff that needs to be output because it
26 * was used.
28 struct symbol_list *translation_unit_used_list = NULL;
31 * If the symbol is an inline symbol, add it to the list of symbols to parse
33 void access_symbol(struct symbol *sym)
35 if (sym->ctype.modifiers & MOD_INLINE) {
36 if (!(sym->ctype.modifiers & MOD_ACCESSED)) {
37 add_symbol(&translation_unit_used_list, sym);
38 sym->ctype.modifiers |= MOD_ACCESSED;
43 struct symbol *lookup_symbol(struct ident *ident, enum namespace ns)
45 struct symbol *sym;
47 for (sym = ident->symbols; sym; sym = sym->next_id) {
48 if (sym->namespace & ns) {
49 sym->used = 1;
50 return sym;
53 return sym;
56 struct context *alloc_context(void)
58 return __alloc_context(0);
61 struct symbol *alloc_symbol(struct position pos, int type)
63 struct symbol *sym = __alloc_symbol(0);
64 sym->type = type;
65 sym->pos = pos;
66 return sym;
69 struct struct_union_info {
70 unsigned long max_align;
71 unsigned long bit_size;
72 int align_size;
76 * Unions are fairly easy to lay out ;)
78 static void lay_out_union(struct symbol *sym, struct struct_union_info *info)
80 examine_symbol_type(sym);
82 // Unnamed bitfields do not affect alignment.
83 if (sym->ident || !is_bitfield_type(sym)) {
84 if (sym->ctype.alignment > info->max_align)
85 info->max_align = sym->ctype.alignment;
88 if (sym->bit_size > info->bit_size)
89 info->bit_size = sym->bit_size;
91 sym->offset = 0;
94 static int bitfield_base_size(struct symbol *sym)
96 if (sym->type == SYM_NODE)
97 sym = sym->ctype.base_type;
98 if (sym->type == SYM_BITFIELD)
99 sym = sym->ctype.base_type;
100 return sym->bit_size;
104 * Structures are a bit more interesting to lay out
106 static void lay_out_struct(struct symbol *sym, struct struct_union_info *info)
108 unsigned long bit_size, align_bit_mask;
109 int base_size;
111 examine_symbol_type(sym);
113 // Unnamed bitfields do not affect alignment.
114 if (sym->ident || !is_bitfield_type(sym)) {
115 if (sym->ctype.alignment > info->max_align)
116 info->max_align = sym->ctype.alignment;
119 bit_size = info->bit_size;
120 base_size = sym->bit_size;
123 * Unsized arrays cause us to not align the resulting
124 * structure size
126 if (base_size < 0) {
127 info->align_size = 0;
128 base_size = 0;
131 align_bit_mask = (sym->ctype.alignment << 3) - 1;
134 * Bitfields have some very special rules..
136 if (is_bitfield_type (sym)) {
137 unsigned long bit_offset = bit_size & align_bit_mask;
138 int room = bitfield_base_size(sym) - bit_offset;
139 // Zero-width fields just fill up the unit.
140 int width = base_size ? : (bit_offset ? room : 0);
142 if (width > room) {
143 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
144 bit_offset = 0;
146 sym->offset = (bit_size - bit_offset) >> 3;
147 sym->bit_offset = bit_offset;
148 sym->ctype.base_type->bit_offset = bit_offset;
149 info->bit_size = bit_size + width;
150 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
152 return;
156 * Otherwise, just align it right and add it up..
158 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
159 sym->offset = bit_size >> 3;
161 info->bit_size = bit_size + base_size;
162 // warning (sym->pos, "regular: offset=%d", sym->offset);
165 static struct symbol * examine_struct_union_type(struct symbol *sym, int advance)
167 struct struct_union_info info = {
168 .max_align = 1,
169 .bit_size = 0,
170 .align_size = 1
172 unsigned long bit_size, bit_align;
173 void (*fn)(struct symbol *, struct struct_union_info *);
174 struct symbol *member;
176 fn = advance ? lay_out_struct : lay_out_union;
177 FOR_EACH_PTR(sym->symbol_list, member) {
178 fn(member, &info);
179 } END_FOR_EACH_PTR(member);
181 if (!sym->ctype.alignment)
182 sym->ctype.alignment = info.max_align;
183 bit_size = info.bit_size;
184 if (info.align_size) {
185 bit_align = (sym->ctype.alignment << 3)-1;
186 bit_size = (bit_size + bit_align) & ~bit_align;
188 sym->bit_size = bit_size;
189 return sym;
192 static struct symbol *examine_base_type(struct symbol *sym)
194 struct symbol *base_type;
196 /* Check the basetype */
197 base_type = sym->ctype.base_type;
198 if (base_type) {
199 base_type = examine_symbol_type(base_type);
201 /* "typeof" can cause this */
202 if (base_type && base_type->type == SYM_NODE)
203 merge_type(sym, base_type);
205 return base_type;
208 static struct symbol * examine_array_type(struct symbol *sym)
210 struct symbol *base_type = examine_base_type(sym);
211 unsigned long bit_size, alignment;
213 if (!base_type)
214 return sym;
215 bit_size = base_type->bit_size * get_expression_value(sym->array_size);
216 if (!sym->array_size || sym->array_size->type != EXPR_VALUE)
217 bit_size = -1;
218 alignment = base_type->ctype.alignment;
219 if (!sym->ctype.alignment)
220 sym->ctype.alignment = alignment;
221 sym->bit_size = bit_size;
222 return sym;
225 static struct symbol *examine_bitfield_type(struct symbol *sym)
227 struct symbol *base_type = examine_base_type(sym);
228 unsigned long bit_size, alignment, modifiers;
230 if (!base_type)
231 return sym;
232 bit_size = base_type->bit_size;
233 if (sym->bit_size > bit_size)
234 warning(sym->pos, "impossible field-width, %d, for this type", sym->bit_size);
236 alignment = base_type->ctype.alignment;
237 if (!sym->ctype.alignment)
238 sym->ctype.alignment = alignment;
239 modifiers = base_type->ctype.modifiers;
241 /* Bitfields are unsigned, unless the base type was explicitly signed */
242 if (!(modifiers & MOD_EXPLICITLY_SIGNED))
243 modifiers = (modifiers & ~MOD_SIGNED) | MOD_UNSIGNED;
244 sym->ctype.modifiers |= modifiers & MOD_SIGNEDNESS;
245 return sym;
249 * "typeof" will have to merge the types together
251 void merge_type(struct symbol *sym, struct symbol *base_type)
253 sym->ctype.as |= base_type->ctype.as;
254 sym->ctype.modifiers |= (base_type->ctype.modifiers & ~MOD_STORAGE);
255 concat_ptr_list((struct ptr_list *)base_type->ctype.contexts,
256 (struct ptr_list **)&sym->ctype.contexts);
257 sym->ctype.base_type = base_type->ctype.base_type;
260 static int count_array_initializer(struct symbol *t, struct expression *expr)
262 int nr = 0;
263 int is_char = 0;
266 * Arrays of character types are special; they can be initialized by
267 * string literal _or_ by string literal in braces. The latter means
268 * that with T x[] = {<string literal>} number of elements in x depends
269 * on T - if it's a character type, we get the length of string literal
270 * (including NUL), otherwise we have one element here.
272 if (t->ctype.base_type == &int_type && t->ctype.modifiers & MOD_CHAR)
273 is_char = 1;
275 switch (expr->type) {
276 case EXPR_INITIALIZER: {
277 struct expression *entry;
278 int count = 0;
279 int str_len = 0;
280 FOR_EACH_PTR(expr->expr_list, entry) {
281 count++;
282 switch (entry->type) {
283 case EXPR_INDEX:
284 if (entry->idx_to >= nr)
285 nr = entry->idx_to+1;
286 break;
287 case EXPR_STRING:
288 if (is_char)
289 str_len = entry->string->length;
290 default:
291 nr++;
293 } END_FOR_EACH_PTR(entry);
294 if (count == 1 && str_len)
295 nr = str_len;
296 break;
298 case EXPR_STRING:
299 if (is_char)
300 nr = expr->string->length;
301 default:
302 break;
304 return nr;
307 static struct symbol * examine_node_type(struct symbol *sym)
309 struct symbol *base_type = examine_base_type(sym);
310 int bit_size;
311 unsigned long alignment, modifiers;
313 /* SYM_NODE - figure out what the type of the node was.. */
314 modifiers = sym->ctype.modifiers;
316 bit_size = 0;
317 alignment = 0;
318 if (!base_type)
319 return sym;
321 bit_size = base_type->bit_size;
322 alignment = base_type->ctype.alignment;
324 /* Pick up signedness information into the node */
325 sym->ctype.modifiers |= (MOD_SIGNEDNESS & base_type->ctype.modifiers);
327 if (!sym->ctype.alignment)
328 sym->ctype.alignment = alignment;
330 /* Unsized array? The size might come from the initializer.. */
331 if (bit_size < 0 && base_type->type == SYM_ARRAY && sym->initializer) {
332 struct symbol *node_type = base_type->ctype.base_type;
333 int count = count_array_initializer(node_type, sym->initializer);
335 if (node_type && node_type->bit_size >= 0)
336 bit_size = node_type->bit_size * count;
339 sym->bit_size = bit_size;
340 return sym;
343 static struct symbol *examine_enum_type(struct symbol *sym)
345 struct symbol *base_type = examine_base_type(sym);
347 sym->ctype.modifiers |= (base_type->ctype.modifiers & MOD_SIGNEDNESS);
348 sym->bit_size = bits_in_enum;
349 if (base_type->bit_size > sym->bit_size)
350 sym->bit_size = base_type->bit_size;
351 sym->ctype.alignment = enum_alignment;
352 if (base_type->ctype.alignment > sym->ctype.alignment)
353 sym->ctype.alignment = base_type->ctype.alignment;
354 return sym;
357 static struct symbol *examine_pointer_type(struct symbol *sym)
360 * We need to set the pointer size first, and
361 * examine the thing we point to only afterwards.
362 * That's because this pointer type may end up
363 * being needed for the base type size evalutation.
365 if (!sym->bit_size)
366 sym->bit_size = bits_in_pointer;
367 if (!sym->ctype.alignment)
368 sym->ctype.alignment = pointer_alignment;
369 return sym;
373 * Fill in type size and alignment information for
374 * regular SYM_TYPE things.
376 struct symbol *examine_symbol_type(struct symbol * sym)
378 if (!sym)
379 return sym;
381 /* Already done? */
382 if (sym->examined)
383 return sym;
384 sym->examined = 1;
386 switch (sym->type) {
387 case SYM_FN:
388 case SYM_NODE:
389 return examine_node_type(sym);
390 case SYM_ARRAY:
391 return examine_array_type(sym);
392 case SYM_STRUCT:
393 return examine_struct_union_type(sym, 1);
394 case SYM_UNION:
395 return examine_struct_union_type(sym, 0);
396 case SYM_PTR:
397 return examine_pointer_type(sym);
398 case SYM_ENUM:
399 return examine_enum_type(sym);
400 case SYM_BITFIELD:
401 return examine_bitfield_type(sym);
402 case SYM_BASETYPE:
403 /* Size and alignment had better already be set up */
404 return sym;
405 case SYM_TYPEOF: {
406 struct symbol *base = evaluate_expression(sym->initializer);
407 if (base) {
408 if (is_bitfield_type(base))
409 warning(base->pos, "typeof applied to bitfield type");
410 if (base->type == SYM_NODE)
411 base = base->ctype.base_type;
412 *sym = *base;
413 break;
415 break;
417 case SYM_PREPROCESSOR:
418 sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident));
419 return NULL;
420 case SYM_UNINITIALIZED:
421 sparse_error(sym->pos, "ctype on uninitialized symbol %p", sym);
422 return NULL;
423 case SYM_RESTRICT:
424 examine_base_type(sym);
425 return sym;
426 default:
427 sparse_error(sym->pos, "Examining unknown symbol type %d", sym->type);
428 break;
430 return sym;
433 void check_declaration(struct symbol *sym)
435 int warned = 0;
436 struct symbol *next = sym;
438 while ((next = next->next_id) != NULL) {
439 if (next->namespace != sym->namespace)
440 continue;
441 if (sym->scope == next->scope) {
442 sym->same_symbol = next;
443 return;
445 if (sym->ctype.modifiers & next->ctype.modifiers & MOD_EXTERN) {
446 sym->same_symbol = next;
447 return;
450 if (!Wshadow || warned)
451 continue;
452 if (get_sym_type(next) == SYM_FN)
453 continue;
454 warned = 1;
455 warning(sym->pos, "symbol '%s' shadows an earlier one", show_ident(sym->ident));
456 info(next->pos, "originally declared here");
460 void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns)
462 struct scope *scope;
463 if (sym->id_list) {
464 sparse_error(sym->pos, "internal error: symbol type already bound");
465 return;
467 if (ident->reserved && (ns & (NS_TYPEDEF | NS_STRUCT | NS_LABEL | NS_SYMBOL))) {
468 sparse_error(sym->pos, "Trying to use reserved word '%s' as identifier", show_ident(ident));
469 return;
471 sym->namespace = ns;
472 sym->next_id = ident->symbols;
473 ident->symbols = sym;
474 sym->id_list = &ident->symbols;
475 if (sym->ident && sym->ident != ident)
476 warning(sym->pos, "Symbol '%s' already bound", show_ident(sym->ident));
477 sym->ident = ident;
479 scope = block_scope;
480 if (ns == NS_SYMBOL && toplevel(scope)) {
481 unsigned mod = MOD_ADDRESSABLE | MOD_TOPLEVEL;
482 scope = global_scope;
483 if (sym->ctype.modifiers & MOD_STATIC) {
484 scope = file_scope;
485 mod = MOD_TOPLEVEL;
487 sym->ctype.modifiers |= mod;
489 if (ns == NS_MACRO)
490 scope = file_scope;
491 if (ns == NS_LABEL)
492 scope = function_scope;
493 bind_scope(sym, scope);
496 struct symbol *create_symbol(int stream, const char *name, int type, int namespace)
498 struct token *token = built_in_token(stream, name);
499 struct symbol *sym = alloc_symbol(token->pos, type);
501 bind_symbol(sym, token->ident, namespace);
502 return sym;
505 static int evaluate_to_integer(struct expression *expr)
507 expr->ctype = &int_ctype;
508 return 1;
511 static int evaluate_expect(struct expression *expr)
513 /* Should we evaluate it to return the type of the first argument? */
514 expr->ctype = &int_ctype;
515 return 1;
518 static int arguments_choose(struct expression *expr)
520 struct expression_list *arglist = expr->args;
521 struct expression *arg;
522 int i = 0;
524 FOR_EACH_PTR (arglist, arg) {
525 if (!evaluate_expression(arg))
526 return 0;
527 i++;
528 } END_FOR_EACH_PTR(arg);
529 if (i < 3) {
530 sparse_error(expr->pos,
531 "not enough arguments for __builtin_choose_expr");
532 return 0;
533 } if (i > 3) {
534 sparse_error(expr->pos,
535 "too many arguments for __builtin_choose_expr");
536 return 0;
538 return 1;
541 static int evaluate_choose(struct expression *expr)
543 struct expression_list *list = expr->args;
544 struct expression *arg, *args[3];
545 int n = 0;
547 /* there will be exactly 3; we'd already verified that */
548 FOR_EACH_PTR(list, arg) {
549 args[n++] = arg;
550 } END_FOR_EACH_PTR(arg);
552 *expr = get_expression_value(args[0]) ? *args[1] : *args[2];
554 return 1;
557 static int expand_expect(struct expression *expr, int cost)
559 struct expression *arg = first_ptr_list((struct ptr_list *) expr->args);
561 if (arg)
562 *expr = *arg;
563 return 0;
567 * __builtin_warning() has type "int" and always returns 1,
568 * so that you can use it in conditionals or whatever
570 static int expand_warning(struct expression *expr, int cost)
572 struct expression *arg;
573 struct expression_list *arglist = expr->args;
575 FOR_EACH_PTR (arglist, arg) {
577 * Constant strings get printed out as a warning. By the
578 * time we get here, the EXPR_STRING has been fully
579 * evaluated, so by now it's an anonymous symbol with a
580 * string initializer.
582 * Just for the heck of it, allow any constant string
583 * symbol.
585 if (arg->type == EXPR_SYMBOL) {
586 struct symbol *sym = arg->symbol;
587 if (sym->initializer && sym->initializer->type == EXPR_STRING) {
588 struct string *string = sym->initializer->string;
589 warning(expr->pos, "%*s", string->length-1, string->data);
591 continue;
595 * Any other argument is a conditional. If it's
596 * non-constant, or it is false, we exit and do
597 * not print any warning.
599 if (arg->type != EXPR_VALUE)
600 goto out;
601 if (!arg->value)
602 goto out;
603 } END_FOR_EACH_PTR(arg);
604 out:
605 expr->type = EXPR_VALUE;
606 expr->value = 1;
607 return 0;
611 * Type and storage class keywords need to have the symbols
612 * created for them, so that the parser can have enough semantic
613 * information to do parsing.
615 * "double" == "long float", "long double" == "long long float"
617 static struct sym_init {
618 const char *name;
619 struct symbol *base_type;
620 unsigned int modifiers;
621 struct symbol_op *op;
622 } symbol_init_table[] = {
623 /* Storage class */
624 { "auto", NULL, MOD_AUTO },
625 { "register", NULL, MOD_REGISTER },
626 { "static", NULL, MOD_STATIC },
627 { "extern", NULL, MOD_EXTERN },
629 /* Type specifiers */
630 { "void", &void_ctype, 0 },
631 { "char", NULL, MOD_CHAR },
632 { "short", NULL, MOD_SHORT },
633 { "int", &int_type, 0 },
634 { "long", NULL, MOD_LONG },
635 { "float", &fp_type, 0 },
636 { "double", &fp_type, MOD_LONG },
637 { "signed", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
638 { "__signed", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
639 { "__signed__", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
640 { "unsigned", NULL, MOD_UNSIGNED },
641 { "__label__", &label_ctype, MOD_LABEL | MOD_UNSIGNED },
642 { "_Bool", &bool_ctype, MOD_UNSIGNED },
644 /* Type qualifiers */
645 { "const", NULL, MOD_CONST },
646 { "__const", NULL, MOD_CONST },
647 { "__const__", NULL, MOD_CONST },
648 { "volatile", NULL, MOD_VOLATILE },
649 { "__volatile", NULL, MOD_VOLATILE },
650 { "__volatile__", NULL, MOD_VOLATILE },
652 /* Predeclared types */
653 { "__builtin_va_list", &int_type, 0 },
655 /* Typedef.. */
656 { "typedef", NULL, MOD_TYPEDEF },
658 /* Extended types */
659 { "typeof", NULL, MOD_TYPEOF },
660 { "__typeof", NULL, MOD_TYPEOF },
661 { "__typeof__", NULL, MOD_TYPEOF },
663 #if 0
664 { "attribute", NULL, MOD_ATTRIBUTE },
665 #endif
666 { "__attribute", NULL, MOD_ATTRIBUTE },
667 { "__attribute__", NULL, MOD_ATTRIBUTE },
669 { "struct", NULL, MOD_STRUCTOF },
670 { "union", NULL, MOD_UNIONOF },
671 { "enum", NULL, MOD_ENUMOF },
673 { "inline", NULL, MOD_INLINE },
674 { "__inline", NULL, MOD_INLINE },
675 { "__inline__", NULL, MOD_INLINE },
677 /* Ignored for now.. */
678 { "restrict", NULL, 0 },
679 { "__restrict", NULL, 0 },
681 { NULL, NULL, 0 }
684 static struct symbol_op constant_p_op = {
685 .evaluate = evaluate_to_integer,
686 .expand = expand_constant_p
689 static struct symbol_op safe_p_op = {
690 .evaluate = evaluate_to_integer,
691 .expand = expand_safe_p
694 static struct symbol_op warning_op = {
695 .evaluate = evaluate_to_integer,
696 .expand = expand_warning
699 static struct symbol_op expect_op = {
700 .evaluate = evaluate_expect,
701 .expand = expand_expect
704 static struct symbol_op choose_op = {
705 .evaluate = evaluate_choose,
706 .args = arguments_choose,
710 * Builtin functions
712 static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ };
713 static struct sym_init eval_init_table[] = {
714 { "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op },
715 { "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op },
716 { "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op },
717 { "__builtin_expect", &builtin_fn_type, MOD_TOPLEVEL, &expect_op },
718 { "__builtin_choose_expr", &builtin_fn_type, MOD_TOPLEVEL, &choose_op },
719 { NULL, NULL, 0 }
724 * Abstract types
726 struct symbol int_type,
727 fp_type;
730 * C types (ie actual instances that the abstract types
731 * can map onto)
733 struct symbol bool_ctype, void_ctype, type_ctype,
734 char_ctype, schar_ctype, uchar_ctype,
735 short_ctype, sshort_ctype, ushort_ctype,
736 int_ctype, sint_ctype, uint_ctype,
737 long_ctype, slong_ctype, ulong_ctype,
738 llong_ctype, sllong_ctype, ullong_ctype,
739 float_ctype, double_ctype, ldouble_ctype,
740 string_ctype, ptr_ctype, lazy_ptr_ctype,
741 incomplete_ctype, label_ctype, bad_ctype;
743 struct symbol zero_int;
745 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
746 #define __IDENT(n,str,res) \
747 struct ident n = __INIT_IDENT(str,res)
749 #include "ident-list.h"
751 void init_symbols(void)
753 int stream = init_stream("builtin", -1, includepath);
754 struct sym_init *ptr;
756 #define __IDENT(n,str,res) \
757 hash_ident(&n)
758 #include "ident-list.h"
760 for (ptr = symbol_init_table; ptr->name; ptr++) {
761 struct symbol *sym;
762 sym = create_symbol(stream, ptr->name, SYM_NODE, NS_TYPEDEF);
763 sym->ident->reserved = 1;
764 sym->ctype.base_type = ptr->base_type;
765 sym->ctype.modifiers = ptr->modifiers;
768 builtin_fn_type.variadic = 1;
769 for (ptr = eval_init_table; ptr->name; ptr++) {
770 struct symbol *sym;
771 sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL);
772 sym->ctype.base_type = ptr->base_type;
773 sym->ctype.modifiers = ptr->modifiers;
774 sym->op = ptr->op;
778 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
779 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
780 static const struct ctype_declare {
781 struct symbol *ptr;
782 enum type type;
783 unsigned long modifiers;
784 int *bit_size;
785 int *maxalign;
786 struct symbol *base_type;
787 } ctype_declaration[] = {
788 { &bool_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_bool, &max_int_alignment, &int_type },
789 { &void_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
790 { &type_ctype, SYM_BASETYPE, MOD_TYPE, NULL, NULL, NULL },
791 { &incomplete_ctype,SYM_BASETYPE, 0, NULL, NULL, NULL },
792 { &bad_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
794 { &char_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
795 { &schar_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
796 { &uchar_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
797 { &short_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
798 { &sshort_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
799 { &ushort_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
800 { &int_ctype, SYM_BASETYPE, MOD_SIGNED, &bits_in_int, &max_int_alignment, &int_type },
801 { &sint_ctype, SYM_BASETYPE, MOD_ESIGNED, &bits_in_int, &max_int_alignment, &int_type },
802 { &uint_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_int, &max_int_alignment, &int_type },
803 { &long_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
804 { &slong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
805 { &ulong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
806 { &llong_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
807 { &sllong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
808 { &ullong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
810 { &float_ctype, SYM_BASETYPE, 0, &bits_in_float, &max_fp_alignment, &fp_type },
811 { &double_ctype, SYM_BASETYPE, MOD_LONG, &bits_in_double, &max_fp_alignment, &fp_type },
812 { &ldouble_ctype, SYM_BASETYPE, MOD_LONG | MOD_LONGLONG, &bits_in_longdouble, &max_fp_alignment, &fp_type },
814 { &string_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &char_ctype },
815 { &ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
816 { &label_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
817 { &lazy_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
818 { NULL, }
820 #undef MOD_LL
821 #undef MOD_ESIGNED
823 void init_ctype(void)
825 const struct ctype_declare *ctype;
827 for (ctype = ctype_declaration ; ctype->ptr; ctype++) {
828 struct symbol *sym = ctype->ptr;
829 unsigned long bit_size = ctype->bit_size ? *ctype->bit_size : -1;
830 unsigned long maxalign = ctype->maxalign ? *ctype->maxalign : 0;
831 unsigned long alignment = bit_size >> 3;
833 if (alignment > maxalign)
834 alignment = maxalign;
835 sym->type = ctype->type;
836 sym->bit_size = bit_size;
837 sym->ctype.alignment = alignment;
838 sym->ctype.base_type = ctype->base_type;
839 sym->ctype.modifiers = ctype->modifiers;