kernel, db: ignore calls to (struct file_operations)->open()
[smatch.git] / symbol.c
blobebba56deaf944904158035eee5657d4082ba55c3
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 NULL;
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 sym->endpos.type = 0;
66 sym->ctype.attribute = &null_attr;
67 return sym;
70 struct struct_union_info {
71 unsigned long max_align;
72 unsigned long bit_size;
73 int align_size;
77 * Unions are fairly easy to lay out ;)
79 static void lay_out_union(struct symbol *sym, struct struct_union_info *info)
81 examine_symbol_type(sym);
83 // Unnamed bitfields do not affect alignment.
84 if (sym->ident || !is_bitfield_type(sym)) {
85 if (sym->ctype.alignment > info->max_align)
86 info->max_align = sym->ctype.alignment;
89 if (sym->bit_size > info->bit_size)
90 info->bit_size = sym->bit_size;
92 sym->offset = 0;
95 static int bitfield_base_size(struct symbol *sym)
97 if (sym->type == SYM_NODE)
98 sym = sym->ctype.base_type;
99 if (sym->type == SYM_BITFIELD)
100 sym = sym->ctype.base_type;
101 return sym->bit_size;
105 * Structures are a bit more interesting to lay out
107 static void lay_out_struct(struct symbol *sym, struct struct_union_info *info)
109 unsigned long bit_size, align_bit_mask;
110 int base_size;
112 examine_symbol_type(sym);
114 // Unnamed bitfields do not affect alignment.
115 if (sym->ident || !is_bitfield_type(sym)) {
116 if (sym->ctype.alignment > info->max_align)
117 info->max_align = sym->ctype.alignment;
120 bit_size = info->bit_size;
121 base_size = sym->bit_size;
124 * Unsized arrays cause us to not align the resulting
125 * structure size
127 if (base_size < 0) {
128 info->align_size = 0;
129 base_size = 0;
132 align_bit_mask = bytes_to_bits(sym->ctype.alignment) - 1;
135 * Bitfields have some very special rules..
137 if (is_bitfield_type (sym)) {
138 unsigned long bit_offset = bit_size & align_bit_mask;
139 int room = bitfield_base_size(sym) - bit_offset;
140 // Zero-width fields just fill up the unit.
141 int width = base_size ? : (bit_offset ? room : 0);
143 if (width > room) {
144 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
145 bit_offset = 0;
147 sym->offset = bits_to_bytes(bit_size - bit_offset);
148 sym->bit_offset = bit_offset;
149 sym->ctype.base_type->bit_offset = bit_offset;
150 info->bit_size = bit_size + width;
151 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
153 return;
157 * Otherwise, just align it right and add it up..
159 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
160 sym->offset = bits_to_bytes(bit_size);
162 info->bit_size = bit_size + base_size;
163 // warning (sym->pos, "regular: offset=%d", sym->offset);
166 static struct symbol * examine_struct_union_type(struct symbol *sym, int advance)
168 struct struct_union_info info = {
169 .max_align = 1,
170 .bit_size = 0,
171 .align_size = 1
173 unsigned long bit_size, bit_align;
174 void (*fn)(struct symbol *, struct struct_union_info *);
175 struct symbol *member;
177 fn = advance ? lay_out_struct : lay_out_union;
178 FOR_EACH_PTR(sym->symbol_list, member) {
179 fn(member, &info);
180 } END_FOR_EACH_PTR(member);
182 if (!sym->ctype.alignment)
183 sym->ctype.alignment = info.max_align;
184 bit_size = info.bit_size;
185 if (info.align_size) {
186 bit_align = bytes_to_bits(sym->ctype.alignment)-1;
187 bit_size = (bit_size + bit_align) & ~bit_align;
189 sym->bit_size = bit_size;
190 return sym;
193 static struct symbol *examine_base_type(struct symbol *sym)
195 struct symbol *base_type;
197 /* Check the base type */
198 base_type = examine_symbol_type(sym->ctype.base_type);
199 if (!base_type || base_type->type == SYM_PTR)
200 return base_type;
201 sym->ctype.modifiers |= base_type->ctype.modifiers & MOD_PTRINHERIT;
203 merge_attr(&sym->ctype, &base_type->ctype);
205 if (base_type->type == SYM_NODE) {
206 base_type = base_type->ctype.base_type;
207 sym->ctype.base_type = base_type;
209 return base_type;
212 static struct symbol * examine_array_type(struct symbol *sym)
214 struct symbol *base_type = examine_base_type(sym);
215 unsigned long bit_size, alignment;
217 if (!base_type)
218 return sym;
219 bit_size = base_type->bit_size * get_expression_value(sym->array_size);
220 if (!sym->array_size || sym->array_size->type != EXPR_VALUE)
221 bit_size = -1;
222 alignment = base_type->ctype.alignment;
223 if (!sym->ctype.alignment)
224 sym->ctype.alignment = alignment;
225 sym->bit_size = bit_size;
226 return sym;
229 static struct symbol *examine_bitfield_type(struct symbol *sym)
231 struct symbol *base_type = examine_base_type(sym);
232 unsigned long bit_size, alignment, modifiers;
234 if (!base_type)
235 return sym;
236 bit_size = base_type->bit_size;
237 if (sym->bit_size > bit_size)
238 warning(sym->pos, "impossible field-width, %d, for this type", sym->bit_size);
240 alignment = base_type->ctype.alignment;
241 if (!sym->ctype.alignment)
242 sym->ctype.alignment = alignment;
243 modifiers = base_type->ctype.modifiers;
245 /* Bitfields are unsigned, unless the base type was explicitly signed */
246 if (!(modifiers & MOD_EXPLICITLY_SIGNED))
247 modifiers = (modifiers & ~MOD_SIGNED) | MOD_UNSIGNED;
248 sym->ctype.modifiers |= modifiers & MOD_SIGNEDNESS;
249 return sym;
253 * "typeof" will have to merge the types together
255 void merge_type(struct symbol *sym, struct symbol *base_type)
257 sym->ctype.modifiers |= (base_type->ctype.modifiers & ~MOD_STORAGE);
258 merge_attr(&sym->ctype, &base_type->ctype);
259 sym->ctype.base_type = base_type->ctype.base_type;
260 if (sym->ctype.base_type->type == SYM_NODE)
261 merge_type(sym, sym->ctype.base_type);
264 static int count_array_initializer(struct symbol *t, struct expression *expr)
266 int nr = 0;
267 int is_char = 0;
270 * Arrays of character types are special; they can be initialized by
271 * string literal _or_ by string literal in braces. The latter means
272 * that with T x[] = {<string literal>} number of elements in x depends
273 * on T - if it's a character type, we get the length of string literal
274 * (including NUL), otherwise we have one element here.
276 if (t->ctype.base_type == &int_type && t->ctype.modifiers & MOD_CHAR)
277 is_char = 1;
279 switch (expr->type) {
280 case EXPR_INITIALIZER: {
281 struct expression *entry;
282 int count = 0;
283 int str_len = 0;
284 FOR_EACH_PTR(expr->expr_list, entry) {
285 count++;
286 switch (entry->type) {
287 case EXPR_INDEX:
288 if (entry->idx_to >= nr)
289 nr = entry->idx_to+1;
290 break;
291 case EXPR_STRING:
292 if (is_char)
293 str_len = entry->string->length;
294 default:
295 nr++;
297 } END_FOR_EACH_PTR(entry);
298 if (count == 1 && str_len)
299 nr = str_len;
300 break;
302 case EXPR_STRING:
303 if (is_char)
304 nr = expr->string->length;
305 default:
306 break;
308 return nr;
311 static struct symbol * examine_node_type(struct symbol *sym)
313 struct symbol *base_type = examine_base_type(sym);
314 int bit_size;
315 unsigned long alignment;
317 /* SYM_NODE - figure out what the type of the node was.. */
318 bit_size = 0;
319 alignment = 0;
320 if (!base_type)
321 return sym;
323 bit_size = base_type->bit_size;
324 alignment = base_type->ctype.alignment;
326 /* Pick up signedness information into the node */
327 sym->ctype.modifiers |= (MOD_SIGNEDNESS & base_type->ctype.modifiers);
329 if (!sym->ctype.alignment)
330 sym->ctype.alignment = alignment;
332 /* Unsized array? The size might come from the initializer.. */
333 if (bit_size < 0 && base_type->type == SYM_ARRAY && sym->initializer) {
334 struct symbol *node_type = base_type->ctype.base_type;
335 int count = count_array_initializer(node_type, sym->initializer);
337 if (node_type && node_type->bit_size >= 0)
338 bit_size = node_type->bit_size * count;
341 sym->bit_size = bit_size;
342 return sym;
345 static struct symbol *examine_enum_type(struct symbol *sym)
347 struct symbol *base_type = examine_base_type(sym);
349 sym->ctype.modifiers |= (base_type->ctype.modifiers & MOD_SIGNEDNESS);
350 sym->bit_size = bits_in_enum;
351 if (base_type->bit_size > sym->bit_size)
352 sym->bit_size = base_type->bit_size;
353 sym->ctype.alignment = enum_alignment;
354 if (base_type->ctype.alignment > sym->ctype.alignment)
355 sym->ctype.alignment = base_type->ctype.alignment;
356 return sym;
359 static struct symbol *examine_pointer_type(struct symbol *sym)
362 * We need to set the pointer size first, and
363 * examine the thing we point to only afterwards.
364 * That's because this pointer type may end up
365 * being needed for the base type size evaluation.
367 if (!sym->bit_size)
368 sym->bit_size = bits_in_pointer;
369 if (!sym->ctype.alignment)
370 sym->ctype.alignment = pointer_alignment;
371 return sym;
375 * Fill in type size and alignment information for
376 * regular SYM_TYPE things.
378 struct symbol *examine_symbol_type(struct symbol * sym)
380 if (!sym)
381 return sym;
383 /* Already done? */
384 if (sym->examined)
385 return sym;
386 sym->examined = 1;
388 switch (sym->type) {
389 case SYM_FN:
390 case SYM_NODE:
391 return examine_node_type(sym);
392 case SYM_ARRAY:
393 return examine_array_type(sym);
394 case SYM_STRUCT:
395 return examine_struct_union_type(sym, 1);
396 case SYM_UNION:
397 return examine_struct_union_type(sym, 0);
398 case SYM_PTR:
399 return examine_pointer_type(sym);
400 case SYM_ENUM:
401 return examine_enum_type(sym);
402 case SYM_BITFIELD:
403 return examine_bitfield_type(sym);
404 case SYM_BASETYPE:
405 /* Size and alignment had better already be set up */
406 return sym;
407 case SYM_TYPEOF: {
408 struct symbol *base = evaluate_expression(sym->initializer);
409 if (base) {
410 if (is_bitfield_type(base))
411 warning(base->pos, "typeof applied to bitfield type");
412 if (base->type == SYM_NODE)
413 base = base->ctype.base_type;
414 sym->type = SYM_NODE;
415 sym->ctype.modifiers = 0;
416 sym->ctype.base_type = base;
417 return examine_node_type(sym);
419 break;
421 case SYM_PREPROCESSOR:
422 sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident));
423 return NULL;
424 case SYM_UNINITIALIZED:
425 // sparse_error(sym->pos, "ctype on uninitialized symbol %p", sym);
426 return NULL;
427 case SYM_RESTRICT:
428 examine_base_type(sym);
429 return sym;
430 case SYM_FOULED:
431 examine_base_type(sym);
432 return sym;
433 default:
434 sparse_error(sym->pos, "Examining unknown symbol type %d", sym->type);
435 break;
437 return sym;
440 const char* get_type_name(enum type type)
442 const char *type_lookup[] = {
443 [SYM_UNINITIALIZED] = "uninitialized",
444 [SYM_PREPROCESSOR] = "preprocessor",
445 [SYM_BASETYPE] = "basetype",
446 [SYM_NODE] = "node",
447 [SYM_PTR] = "pointer",
448 [SYM_FN] = "function",
449 [SYM_ARRAY] = "array",
450 [SYM_STRUCT] = "struct",
451 [SYM_UNION] = "union",
452 [SYM_ENUM] = "enum",
453 [SYM_TYPEDEF] = "typedef",
454 [SYM_TYPEOF] = "typeof",
455 [SYM_MEMBER] = "member",
456 [SYM_BITFIELD] = "bitfield",
457 [SYM_LABEL] = "label",
458 [SYM_RESTRICT] = "restrict",
459 [SYM_FOULED] = "fouled",
460 [SYM_KEYWORD] = "keyword",
461 [SYM_BAD] = "bad"};
463 if (type <= SYM_BAD)
464 return type_lookup[type];
465 else
466 return NULL;
469 struct symbol *examine_pointer_target(struct symbol *sym)
471 return examine_base_type(sym);
474 static struct symbol_list *restr, *fouled;
476 void create_fouled(struct symbol *type)
478 if (type->bit_size < bits_in_int) {
479 struct symbol *new = alloc_symbol(type->pos, type->type);
480 *new = *type;
481 new->bit_size = bits_in_int;
482 new->type = SYM_FOULED;
483 new->ctype.base_type = type;
484 add_symbol(&restr, type);
485 add_symbol(&fouled, new);
489 struct symbol *befoul(struct symbol *type)
491 struct symbol *t1, *t2;
492 while (type->type == SYM_NODE)
493 type = type->ctype.base_type;
494 PREPARE_PTR_LIST(restr, t1);
495 PREPARE_PTR_LIST(fouled, t2);
496 for (;;) {
497 if (t1 == type)
498 return t2;
499 if (!t1)
500 break;
501 NEXT_PTR_LIST(t1);
502 NEXT_PTR_LIST(t2);
504 FINISH_PTR_LIST(t2);
505 FINISH_PTR_LIST(t1);
506 return NULL;
509 void check_declaration(struct symbol *sym)
511 int warned = 0;
512 struct symbol *next = sym;
514 while ((next = next->next_id) != NULL) {
515 if (next->namespace != sym->namespace)
516 continue;
517 if (sym->scope == next->scope) {
518 sym->same_symbol = next;
519 return;
521 if (sym->ctype.modifiers & next->ctype.modifiers & MOD_EXTERN) {
522 if ((sym->ctype.modifiers ^ next->ctype.modifiers) & MOD_INLINE)
523 continue;
524 sym->same_symbol = next;
525 return;
528 if (!Wshadow || warned)
529 continue;
530 if (get_sym_type(next) == SYM_FN)
531 continue;
532 warned = 1;
533 warning(sym->pos, "symbol '%s' shadows an earlier one", show_ident(sym->ident));
534 info(next->pos, "originally declared here");
538 void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns)
540 struct scope *scope;
541 if (sym->bound) {
542 sparse_error(sym->pos, "internal error: symbol type already bound");
543 return;
545 if (ident->reserved && (ns & (NS_TYPEDEF | NS_STRUCT | NS_LABEL | NS_SYMBOL))) {
546 sparse_error(sym->pos, "Trying to use reserved word '%s' as identifier", show_ident(ident));
547 return;
549 sym->namespace = ns;
550 sym->next_id = ident->symbols;
551 ident->symbols = sym;
552 if (sym->ident && sym->ident != ident)
553 warning(sym->pos, "Symbol '%s' already bound", show_ident(sym->ident));
554 sym->ident = ident;
555 sym->bound = 1;
557 scope = block_scope;
558 if (ns == NS_SYMBOL && toplevel(scope)) {
559 unsigned mod = MOD_ADDRESSABLE | MOD_TOPLEVEL;
561 scope = global_scope;
562 if (sym->ctype.modifiers & MOD_STATIC ||
563 is_extern_inline(sym)) {
564 scope = file_scope;
565 mod = MOD_TOPLEVEL;
567 sym->ctype.modifiers |= mod;
569 if (ns == NS_MACRO)
570 scope = file_scope;
571 if (ns == NS_LABEL)
572 scope = function_scope;
573 bind_scope(sym, scope);
576 struct symbol *create_symbol(int stream, const char *name, int type, int namespace)
578 struct token *token = built_in_token(stream, name);
579 struct symbol *sym = alloc_symbol(token->pos, type);
581 bind_symbol(sym, token->ident, namespace);
582 return sym;
585 static int evaluate_to_integer(struct expression *expr)
587 expr->ctype = &int_ctype;
588 return 1;
591 static int evaluate_expect(struct expression *expr)
593 /* Should we evaluate it to return the type of the first argument? */
594 expr->ctype = &int_ctype;
595 return 1;
598 static int arguments_choose(struct expression *expr)
600 struct expression_list *arglist = expr->args;
601 struct expression *arg;
602 int i = 0;
604 FOR_EACH_PTR (arglist, arg) {
605 if (!evaluate_expression(arg))
606 return 0;
607 i++;
608 } END_FOR_EACH_PTR(arg);
609 if (i < 3) {
610 sparse_error(expr->pos,
611 "not enough arguments for __builtin_choose_expr");
612 return 0;
613 } if (i > 3) {
614 sparse_error(expr->pos,
615 "too many arguments for __builtin_choose_expr");
616 return 0;
618 return 1;
621 static int evaluate_choose(struct expression *expr)
623 struct expression_list *list = expr->args;
624 struct expression *arg, *args[3];
625 int n = 0;
627 /* there will be exactly 3; we'd already verified that */
628 FOR_EACH_PTR(list, arg) {
629 args[n++] = arg;
630 } END_FOR_EACH_PTR(arg);
632 *expr = get_expression_value(args[0]) ? *args[1] : *args[2];
634 return 1;
637 static int expand_expect(struct expression *expr, int cost)
639 struct expression *arg = first_ptr_list((struct ptr_list *) expr->args);
641 if (arg)
642 *expr = *arg;
643 return 0;
647 * __builtin_warning() has type "int" and always returns 1,
648 * so that you can use it in conditionals or whatever
650 static int expand_warning(struct expression *expr, int cost)
652 struct expression *arg;
653 struct expression_list *arglist = expr->args;
655 FOR_EACH_PTR (arglist, arg) {
657 * Constant strings get printed out as a warning. By the
658 * time we get here, the EXPR_STRING has been fully
659 * evaluated, so by now it's an anonymous symbol with a
660 * string initializer.
662 * Just for the heck of it, allow any constant string
663 * symbol.
665 if (arg->type == EXPR_SYMBOL) {
666 struct symbol *sym = arg->symbol;
667 if (sym->initializer && sym->initializer->type == EXPR_STRING) {
668 struct string *string = sym->initializer->string;
669 warning(expr->pos, "%*s", string->length-1, string->data);
671 continue;
675 * Any other argument is a conditional. If it's
676 * non-constant, or it is false, we exit and do
677 * not print any warning.
679 if (arg->type != EXPR_VALUE)
680 goto out;
681 if (!arg->value)
682 goto out;
683 } END_FOR_EACH_PTR(arg);
684 out:
685 expr->type = EXPR_VALUE;
686 expr->value = 1;
687 expr->taint = 0;
688 return 0;
691 static struct symbol_op constant_p_op = {
692 .evaluate = evaluate_to_integer,
693 .expand = expand_constant_p
696 static struct symbol_op safe_p_op = {
697 .evaluate = evaluate_to_integer,
698 .expand = expand_safe_p
701 static struct symbol_op warning_op = {
702 .evaluate = evaluate_to_integer,
703 .expand = expand_warning
706 static struct symbol_op expect_op = {
707 .evaluate = evaluate_expect,
708 .expand = expand_expect
711 static struct symbol_op choose_op = {
712 .evaluate = evaluate_choose,
713 .args = arguments_choose,
717 * Builtin functions
719 static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ };
720 static struct sym_init {
721 const char *name;
722 struct symbol *base_type;
723 unsigned int modifiers;
724 struct symbol_op *op;
725 } eval_init_table[] = {
726 { "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op },
727 { "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op },
728 { "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op },
729 { "__builtin_expect", &builtin_fn_type, MOD_TOPLEVEL, &expect_op },
730 { "__builtin_choose_expr", &builtin_fn_type, MOD_TOPLEVEL, &choose_op },
731 { NULL, NULL, 0 }
735 * Default empty attribute
737 struct attribute null_attr = {};
740 * Abstract types
742 struct symbol int_type,
743 fp_type;
746 * C types (i.e. actual instances that the abstract types
747 * can map onto)
749 struct symbol bool_ctype, void_ctype, type_ctype,
750 char_ctype, schar_ctype, uchar_ctype,
751 short_ctype, sshort_ctype, ushort_ctype,
752 int_ctype, sint_ctype, uint_ctype,
753 long_ctype, slong_ctype, ulong_ctype,
754 llong_ctype, sllong_ctype, ullong_ctype,
755 lllong_ctype, slllong_ctype, ulllong_ctype,
756 float_ctype, double_ctype, ldouble_ctype,
757 string_ctype, ptr_ctype, lazy_ptr_ctype,
758 incomplete_ctype, label_ctype, bad_ctype,
759 null_ctype;
761 struct symbol zero_int;
763 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
764 #define __IDENT(n,str,res) \
765 struct ident n = __INIT_IDENT(str,res)
767 #include "ident-list.h"
769 void init_symbols(void)
771 int stream = init_stream("builtin", -1, includepath);
772 struct sym_init *ptr;
774 #define __IDENT(n,str,res) \
775 hash_ident(&n)
776 #include "ident-list.h"
778 init_parser(stream);
780 builtin_fn_type.variadic = 1;
781 builtin_fn_type.ctype.attribute = &null_attr;
782 for (ptr = eval_init_table; ptr->name; ptr++) {
783 struct symbol *sym;
784 sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL);
785 sym->ctype.base_type = ptr->base_type;
786 sym->ctype.modifiers = ptr->modifiers;
787 sym->ctype.attribute = &null_attr;
788 sym->op = ptr->op;
792 #ifdef __CHAR_UNSIGNED__
793 #define CHAR_SIGNEDNESS MOD_UNSIGNED
794 #else
795 #define CHAR_SIGNEDNESS MOD_SIGNED
796 #endif
798 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
799 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
800 #define MOD_LLL MOD_LONGLONGLONG
801 static const struct ctype_declare {
802 struct symbol *ptr;
803 enum type type;
804 unsigned long modifiers;
805 int *bit_size;
806 int *maxalign;
807 struct symbol *base_type;
808 } ctype_declaration[] = {
809 { &bool_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_bool, &max_int_alignment, &int_type },
810 { &void_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
811 { &type_ctype, SYM_BASETYPE, MOD_TYPE, NULL, NULL, NULL },
812 { &incomplete_ctype,SYM_BASETYPE, 0, NULL, NULL, NULL },
813 { &bad_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
815 { &char_ctype, SYM_BASETYPE, CHAR_SIGNEDNESS | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
816 { &schar_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
817 { &uchar_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
818 { &short_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
819 { &sshort_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
820 { &ushort_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
821 { &int_ctype, SYM_BASETYPE, MOD_SIGNED, &bits_in_int, &max_int_alignment, &int_type },
822 { &sint_ctype, SYM_BASETYPE, MOD_ESIGNED, &bits_in_int, &max_int_alignment, &int_type },
823 { &uint_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_int, &max_int_alignment, &int_type },
824 { &long_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
825 { &slong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
826 { &ulong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
827 { &llong_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
828 { &sllong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
829 { &ullong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
830 { &lllong_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LLL, &bits_in_longlonglong, &max_int_alignment, &int_type },
831 { &slllong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LLL, &bits_in_longlonglong, &max_int_alignment, &int_type },
832 { &ulllong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LLL, &bits_in_longlonglong, &max_int_alignment, &int_type },
834 { &float_ctype, SYM_BASETYPE, 0, &bits_in_float, &max_fp_alignment, &fp_type },
835 { &double_ctype, SYM_BASETYPE, MOD_LONG, &bits_in_double, &max_fp_alignment, &fp_type },
836 { &ldouble_ctype, SYM_BASETYPE, MOD_LONG | MOD_LONGLONG, &bits_in_longdouble, &max_fp_alignment, &fp_type },
838 { &string_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &char_ctype },
839 { &ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
840 { &null_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
841 { &label_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
842 { &lazy_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
843 { NULL, }
845 #undef MOD_LLL
846 #undef MOD_LL
847 #undef MOD_ESIGNED
849 void init_ctype(void)
851 const struct ctype_declare *ctype;
853 for (ctype = ctype_declaration ; ctype->ptr; ctype++) {
854 struct symbol *sym = ctype->ptr;
855 unsigned long bit_size = ctype->bit_size ? *ctype->bit_size : -1;
856 unsigned long maxalign = ctype->maxalign ? *ctype->maxalign : 0;
857 unsigned long alignment = bits_to_bytes(bit_size + bits_in_char - 1);
859 if (alignment > maxalign)
860 alignment = maxalign;
861 sym->type = ctype->type;
862 sym->bit_size = bit_size;
863 sym->ctype.alignment = alignment;
864 sym->ctype.base_type = ctype->base_type;
865 sym->ctype.modifiers = ctype->modifiers;
866 sym->ctype.attribute = &null_attr;