Once again, remember that basic blocks may not have any instructions.
[smatch.git] / symbol.c
blobd705350cdd7d2c17c5249a91e7ac7bc65eb70e76
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 "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 symbol *alloc_symbol(struct position pos, int type)
57 struct symbol *sym = __alloc_symbol(0);
58 sym->type = type;
59 sym->pos = pos;
60 return sym;
63 struct struct_union_info {
64 unsigned long max_align;
65 unsigned long bit_size;
66 int align_size;
70 * Unions are fairly easy to lay out ;)
72 static void lay_out_union(struct symbol *sym, struct struct_union_info *info)
74 examine_symbol_type(sym);
76 // Unnamed bitfields do not affect alignment.
77 if (sym->ident || !is_bitfield_type(sym)) {
78 if (sym->ctype.alignment > info->max_align)
79 info->max_align = sym->ctype.alignment;
82 if (sym->bit_size > info->bit_size)
83 info->bit_size = sym->bit_size;
85 sym->offset = 0;
88 static int bitfield_base_size(struct symbol *sym)
90 if (sym->type == SYM_NODE)
91 sym = sym->ctype.base_type;
92 if (sym->type == SYM_BITFIELD)
93 sym = sym->ctype.base_type;
94 return sym->bit_size;
98 * Structures are a bit more interesting to lay out
100 static void lay_out_struct(struct symbol *sym, struct struct_union_info *info)
102 unsigned long bit_size, align_bit_mask;
103 int base_size;
105 examine_symbol_type(sym);
107 // Unnamed bitfields do not affect alignment.
108 if (sym->ident || !is_bitfield_type(sym)) {
109 if (sym->ctype.alignment > info->max_align)
110 info->max_align = sym->ctype.alignment;
113 bit_size = info->bit_size;
114 base_size = sym->bit_size;
117 * Unsized arrays cause us to not align the resulting
118 * structure size
120 if (base_size < 0) {
121 info->align_size = 0;
122 base_size = 0;
125 align_bit_mask = (sym->ctype.alignment << 3) - 1;
128 * Bitfields have some very special rules..
130 if (is_bitfield_type (sym)) {
131 unsigned long bit_offset = bit_size & align_bit_mask;
132 int room = bitfield_base_size(sym) - bit_offset;
133 // Zero-width fields just fill up the unit.
134 int width = base_size ? : (bit_offset ? room : 0);
136 if (width > room) {
137 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
138 bit_offset = 0;
140 sym->offset = (bit_size - bit_offset) >> 3;
141 sym->bit_offset = bit_offset;
142 sym->ctype.base_type->bit_offset = bit_offset;
143 info->bit_size = bit_size + width;
144 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
146 return;
150 * Otherwise, just align it right and add it up..
152 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
153 sym->offset = bit_size >> 3;
155 info->bit_size = bit_size + base_size;
156 // warning (sym->pos, "regular: offset=%d", sym->offset);
159 static struct symbol * examine_struct_union_type(struct symbol *sym, int advance)
161 struct struct_union_info info = {
162 .max_align = 1,
163 .bit_size = 0,
164 .align_size = 1
166 unsigned long bit_size, bit_align;
167 void (*fn)(struct symbol *, struct struct_union_info *);
168 struct symbol *member;
170 fn = advance ? lay_out_struct : lay_out_union;
171 FOR_EACH_PTR(sym->symbol_list, member) {
172 fn(member, &info);
173 } END_FOR_EACH_PTR(member);
175 if (!sym->ctype.alignment)
176 sym->ctype.alignment = info.max_align;
177 bit_size = info.bit_size;
178 if (info.align_size) {
179 bit_align = (sym->ctype.alignment << 3)-1;
180 bit_size = (bit_size + bit_align) & ~bit_align;
182 sym->bit_size = bit_size;
183 return sym;
186 static struct symbol *examine_base_type(struct symbol *sym)
188 struct symbol *base_type;
190 /* Check the basetype */
191 base_type = sym->ctype.base_type;
192 if (base_type) {
193 base_type = examine_symbol_type(base_type);
195 /* "typeof" can cause this */
196 if (base_type && base_type->type == SYM_NODE)
197 merge_type(sym, base_type);
199 return base_type;
202 static struct symbol * examine_array_type(struct symbol *sym)
204 struct symbol *base_type = examine_base_type(sym);
205 unsigned long bit_size, alignment;
207 if (!base_type)
208 return sym;
209 bit_size = base_type->bit_size * get_expression_value(sym->array_size);
210 if (!sym->array_size || sym->array_size->type != EXPR_VALUE)
211 bit_size = -1;
212 alignment = base_type->ctype.alignment;
213 if (!sym->ctype.alignment)
214 sym->ctype.alignment = alignment;
215 sym->bit_size = bit_size;
216 return sym;
219 static struct symbol *examine_bitfield_type(struct symbol *sym)
221 struct symbol *base_type = examine_base_type(sym);
222 unsigned long bit_size, alignment, modifiers;
224 if (!base_type)
225 return sym;
226 bit_size = base_type->bit_size;
227 if (sym->bit_size > bit_size)
228 warning(sym->pos, "impossible field-width, %d, for this type", sym->bit_size);
230 alignment = base_type->ctype.alignment;
231 if (!sym->ctype.alignment)
232 sym->ctype.alignment = alignment;
233 modifiers = base_type->ctype.modifiers;
235 /* Bitfields are unsigned, unless the base type was explicitly signed */
236 if (!(modifiers & MOD_EXPLICITLY_SIGNED))
237 modifiers = (modifiers & ~MOD_SIGNED) | MOD_UNSIGNED;
238 sym->ctype.modifiers |= modifiers & MOD_SIGNEDNESS;
239 return sym;
243 * "typeof" will have to merge the types together
245 void merge_type(struct symbol *sym, struct symbol *base_type)
247 sym->ctype.as |= base_type->ctype.as;
248 sym->ctype.modifiers |= (base_type->ctype.modifiers & ~MOD_STORAGE);
249 sym->ctype.in_context += base_type->ctype.in_context;
250 sym->ctype.out_context += base_type->ctype.out_context;
251 sym->ctype.base_type = base_type->ctype.base_type;
254 static int count_array_initializer(struct expression *expr)
256 int nr = 0;
258 switch (expr->type) {
259 case EXPR_STRING:
260 nr = expr->string->length;
261 break;
262 case EXPR_INITIALIZER: {
263 struct expression *entry;
264 FOR_EACH_PTR(expr->expr_list, entry) {
265 switch (entry->type) {
266 case EXPR_STRING:
267 nr += entry->string->length;
268 break;
269 case EXPR_INDEX:
270 if (entry->idx_to > nr)
271 nr = entry->idx_to;
272 break;
273 default:
274 nr++;
276 } END_FOR_EACH_PTR(entry);
277 break;
279 default:
280 break;
282 return nr;
285 static struct symbol * examine_node_type(struct symbol *sym)
287 struct symbol *base_type = examine_base_type(sym);
288 int bit_size;
289 unsigned long alignment, modifiers;
291 /* SYM_NODE - figure out what the type of the node was.. */
292 modifiers = sym->ctype.modifiers;
294 bit_size = 0;
295 alignment = 0;
296 if (!base_type)
297 return sym;
299 bit_size = base_type->bit_size;
300 alignment = base_type->ctype.alignment;
302 /* Pick up signedness information into the node */
303 sym->ctype.modifiers |= (MOD_SIGNEDNESS & base_type->ctype.modifiers);
305 if (!sym->ctype.alignment)
306 sym->ctype.alignment = alignment;
308 /* Unsized array? The size might come from the initializer.. */
309 if (bit_size < 0 && base_type->type == SYM_ARRAY && sym->initializer) {
310 int count = count_array_initializer(sym->initializer);
311 struct symbol *node_type = base_type->ctype.base_type;
313 if (node_type && node_type->bit_size >= 0)
314 bit_size = node_type->bit_size * count;
317 sym->bit_size = bit_size;
318 return sym;
321 static struct symbol *examine_enum_type(struct symbol *sym)
323 struct symbol *base_type = examine_base_type(sym);
325 if (!base_type || base_type == &bad_ctype) {
326 warning(sym->pos, "invalid enum type");
327 sym->bit_size = -1;
328 return sym;
330 sym->ctype.modifiers |= (base_type->ctype.modifiers & MOD_SIGNEDNESS);
331 sym->bit_size = bits_in_enum;
332 if (base_type->bit_size > sym->bit_size)
333 sym->bit_size = base_type->bit_size;
334 sym->ctype.alignment = enum_alignment;
335 if (base_type->ctype.alignment > sym->ctype.alignment)
336 sym->ctype.alignment = base_type->ctype.alignment;
337 return sym;
340 static struct symbol *examine_pointer_type(struct symbol *sym)
343 * We need to set the pointer size first, and
344 * examine the thing we point to only afterwards.
345 * That's because this pointer type may end up
346 * being needed for the base type size evalutation.
348 if (!sym->bit_size)
349 sym->bit_size = bits_in_pointer;
350 if (!sym->ctype.alignment)
351 sym->ctype.alignment = pointer_alignment;
352 examine_base_type(sym);
353 return sym;
357 * Fill in type size and alignment information for
358 * regular SYM_TYPE things.
360 struct symbol *examine_symbol_type(struct symbol * sym)
362 if (!sym)
363 return sym;
365 /* Already done? */
366 if (sym->examined)
367 return sym;
368 sym->examined = 1;
370 switch (sym->type) {
371 case SYM_FN:
372 case SYM_NODE:
373 return examine_node_type(sym);
374 case SYM_ARRAY:
375 return examine_array_type(sym);
376 case SYM_STRUCT:
377 return examine_struct_union_type(sym, 1);
378 case SYM_UNION:
379 return examine_struct_union_type(sym, 0);
380 case SYM_PTR:
381 return examine_pointer_type(sym);
382 case SYM_ENUM:
383 return examine_enum_type(sym);
384 case SYM_BITFIELD:
385 return examine_bitfield_type(sym);
386 case SYM_BASETYPE:
387 /* Size and alignment had better already be set up */
388 return sym;
389 case SYM_TYPEOF: {
390 struct symbol *base = evaluate_expression(sym->initializer);
391 if (base) {
392 if (is_bitfield_type(base))
393 warning(base->pos, "typeof applied to bitfield type");
394 if (base->type == SYM_NODE)
395 base = base->ctype.base_type;
396 sym->type = SYM_NODE;
397 sym->ctype.base_type = base;
398 sym->bit_size = base->bit_size;
400 break;
402 case SYM_PREPROCESSOR:
403 warning(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident));
404 return NULL;
405 case SYM_UNINITIALIZED:
406 warning(sym->pos, "ctype on uninitialized symbol %p", sym);
407 return NULL;
408 case SYM_RESTRICT:
409 examine_base_type(sym);
410 return sym;
411 default:
412 warning(sym->pos, "Examining unknown symbol type %d", sym->type);
413 break;
415 return sym;
418 void check_declaration(struct symbol *sym)
420 struct symbol *next = sym;
422 while ((next = next->next_id) != NULL) {
423 if (next->namespace != sym->namespace)
424 continue;
425 if (sym->scope == next->scope) {
426 sym->same_symbol = next;
427 return;
429 if (sym->ctype.modifiers & next->ctype.modifiers & MOD_EXTERN) {
430 sym->same_symbol = next;
431 return;
433 #if 0
434 // This may make sense from a warning standpoint:
435 // consider top-level symbols to clash with everything
436 // (but the scoping rules will mean that we actually
437 // _use_ the innermost version)
438 if (toplevel(next->scope)) {
439 sym->same_symbol = next;
440 return;
442 #endif
446 void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns)
448 struct scope *scope;
449 if (sym->id_list) {
450 warning(sym->pos, "internal error: symbol type already bound");
451 return;
453 if (ident->reserved && (ns & (NS_TYPEDEF | NS_STRUCT | NS_LABEL | NS_SYMBOL))) {
454 warning(sym->pos, "Trying to use reserved word '%s' as identifier", show_ident(ident));
455 return;
457 sym->namespace = ns;
458 sym->next_id = ident->symbols;
459 ident->symbols = sym;
460 sym->id_list = &ident->symbols;
461 if (sym->ident && sym->ident != ident)
462 warning(sym->pos, "Symbol '%s' already bound", show_ident(sym->ident));
463 sym->ident = ident;
465 scope = block_scope;
466 if (ns == NS_SYMBOL && toplevel(scope)) {
467 sym->ctype.modifiers |= MOD_TOPLEVEL | MOD_ADDRESSABLE;
468 if (sym->ctype.modifiers & MOD_STATIC)
469 scope = file_scope;
471 if (ns == NS_LABEL)
472 scope = function_scope;
473 bind_scope(sym, scope);
476 struct symbol *create_symbol(int stream, const char *name, int type, int namespace)
478 struct token *token = built_in_token(stream, name);
479 struct symbol *sym = alloc_symbol(token->pos, type);
481 bind_symbol(sym, token->ident, namespace);
482 return sym;
485 static int evaluate_to_integer(struct expression *expr)
487 expr->ctype = &int_ctype;
488 return 1;
492 * __builtin_warning() has type "int" and always returns 1,
493 * so that you can use it in conditionals or whatever
495 static int expand_warning(struct expression *expr, int cost)
497 struct expression *arg;
498 struct expression_list *arglist = expr->args;
500 FOR_EACH_PTR (arglist, arg) {
502 * Constant strings get printed out as a warning. By the
503 * time we get here, the EXPR_STRING has been fully
504 * evaluated, so by now it's an anonymous symbol with a
505 * string initializer.
507 * Just for the heck of it, allow any constant string
508 * symbol.
510 if (arg->type == EXPR_SYMBOL) {
511 struct symbol *sym = arg->symbol;
512 if (sym->initializer && sym->initializer->type == EXPR_STRING) {
513 struct string *string = sym->initializer->string;
514 warning(expr->pos, "%*s", string->length-1, string->data);
516 continue;
520 * Any other argument is a conditional. If it's
521 * non-constant, or it is false, we exit and do
522 * not print any warning.
524 if (arg->type != EXPR_VALUE)
525 goto out;
526 if (!arg->value)
527 goto out;
528 } END_FOR_EACH_PTR(arg);
529 out:
530 expr->type = EXPR_VALUE;
531 expr->value = 1;
532 return 0;
536 * Type and storage class keywords need to have the symbols
537 * created for them, so that the parser can have enough semantic
538 * information to do parsing.
540 * "double" == "long float", "long double" == "long long float"
542 struct sym_init {
543 const char *name;
544 struct symbol *base_type;
545 unsigned int modifiers;
546 struct symbol_op *op;
547 } symbol_init_table[] = {
548 /* Storage class */
549 { "auto", NULL, MOD_AUTO },
550 { "register", NULL, MOD_REGISTER },
551 { "static", NULL, MOD_STATIC },
552 { "extern", NULL, MOD_EXTERN },
554 /* Type specifiers */
555 { "void", &void_ctype, 0 },
556 { "char", NULL, MOD_CHAR },
557 { "short", NULL, MOD_SHORT },
558 { "int", &int_type, 0 },
559 { "long", NULL, MOD_LONG },
560 { "float", &fp_type, 0 },
561 { "double", &fp_type, MOD_LONG },
562 { "signed", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
563 { "__signed", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
564 { "__signed__", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
565 { "unsigned", NULL, MOD_UNSIGNED },
566 { "__label__", &label_ctype, MOD_LABEL | MOD_UNSIGNED },
567 { "_Bool", &bool_ctype, MOD_UNSIGNED },
569 /* Type qualifiers */
570 { "const", NULL, MOD_CONST },
571 { "__const", NULL, MOD_CONST },
572 { "__const__", NULL, MOD_CONST },
573 { "volatile", NULL, MOD_VOLATILE },
574 { "__volatile", NULL, MOD_VOLATILE },
575 { "__volatile__", NULL, MOD_VOLATILE },
577 /* Predeclared types */
578 { "__builtin_va_list", &int_type, 0 },
580 /* Typedef.. */
581 { "typedef", NULL, MOD_TYPEDEF },
583 /* Extended types */
584 { "typeof", NULL, MOD_TYPEOF },
585 { "__typeof", NULL, MOD_TYPEOF },
586 { "__typeof__", NULL, MOD_TYPEOF },
588 #if 0
589 { "attribute", NULL, MOD_ATTRIBUTE },
590 #endif
591 { "__attribute", NULL, MOD_ATTRIBUTE },
592 { "__attribute__", NULL, MOD_ATTRIBUTE },
594 { "struct", NULL, MOD_STRUCTOF },
595 { "union", NULL, MOD_UNIONOF },
596 { "enum", NULL, MOD_ENUMOF },
598 { "inline", NULL, MOD_INLINE },
599 { "__inline", NULL, MOD_INLINE },
600 { "__inline__", NULL, MOD_INLINE },
602 /* Ignored for now.. */
603 { "restrict", NULL, 0 },
604 { "__restrict", NULL, 0 },
606 { NULL, NULL, 0 }
609 static struct symbol_op constant_p_op = {
610 .evaluate = evaluate_to_integer,
611 .expand = expand_constant_p
614 static struct symbol_op safe_p_op = {
615 .evaluate = evaluate_to_integer,
616 .expand = expand_safe_p
619 static struct symbol_op warning_op = {
620 .evaluate = evaluate_to_integer,
621 .expand = expand_warning
625 * Builtin functions
627 static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ };
628 static struct sym_init eval_init_table[] = {
629 { "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op },
630 { "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op },
631 { "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op },
632 { NULL, NULL, 0 }
637 * Abstract types
639 struct symbol int_type,
640 fp_type;
643 * C types (ie actual instances that the abstract types
644 * can map onto)
646 struct symbol bool_ctype, void_ctype, type_ctype,
647 char_ctype, schar_ctype, uchar_ctype,
648 short_ctype, sshort_ctype, ushort_ctype,
649 int_ctype, sint_ctype, uint_ctype,
650 long_ctype, slong_ctype, ulong_ctype,
651 llong_ctype, sllong_ctype, ullong_ctype,
652 float_ctype, double_ctype, ldouble_ctype,
653 string_ctype, ptr_ctype, lazy_ptr_ctype,
654 incomplete_ctype, label_ctype, bad_ctype;
657 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
658 #define __IDENT(n,str,res) \
659 struct ident n = __INIT_IDENT(str,res)
661 #include "ident-list.h"
663 void init_symbols(void)
665 int stream = init_stream("builtin", -1, includepath);
666 struct sym_init *ptr;
668 #define __IDENT(n,str,res) \
669 hash_ident(&n)
670 #include "ident-list.h"
672 for (ptr = symbol_init_table; ptr->name; ptr++) {
673 struct symbol *sym;
674 sym = create_symbol(stream, ptr->name, SYM_NODE, NS_TYPEDEF);
675 sym->ident->reserved = 1;
676 sym->ctype.base_type = ptr->base_type;
677 sym->ctype.modifiers = ptr->modifiers;
680 builtin_fn_type.variadic = 1;
681 for (ptr = eval_init_table; ptr->name; ptr++) {
682 struct symbol *sym;
683 sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL);
684 sym->ctype.base_type = ptr->base_type;
685 sym->ctype.modifiers = ptr->modifiers;
686 sym->op = ptr->op;
690 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
691 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
692 static const struct ctype_declare {
693 struct symbol *ptr;
694 enum type type;
695 unsigned long modifiers;
696 int *bit_size;
697 int *maxalign;
698 struct symbol *base_type;
699 } ctype_declaration[] = {
700 { &bool_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_bool, &max_int_alignment, &int_type },
701 { &void_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
702 { &type_ctype, SYM_BASETYPE, MOD_TYPE, NULL, NULL, NULL },
703 { &incomplete_ctype,SYM_BASETYPE, 0, NULL, NULL, NULL },
704 { &bad_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
706 { &char_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
707 { &schar_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
708 { &uchar_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
709 { &short_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
710 { &sshort_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
711 { &ushort_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
712 { &int_ctype, SYM_BASETYPE, MOD_SIGNED, &bits_in_int, &max_int_alignment, &int_type },
713 { &sint_ctype, SYM_BASETYPE, MOD_ESIGNED, &bits_in_int, &max_int_alignment, &int_type },
714 { &uint_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_int, &max_int_alignment, &int_type },
715 { &long_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
716 { &slong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
717 { &ulong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
718 { &llong_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
719 { &sllong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
720 { &ullong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
722 { &float_ctype, SYM_BASETYPE, 0, &bits_in_float, &max_fp_alignment, &fp_type },
723 { &double_ctype, SYM_BASETYPE, MOD_LONG, &bits_in_double, &max_fp_alignment, &fp_type },
724 { &ldouble_ctype, SYM_BASETYPE, MOD_LONG | MOD_LONGLONG, &bits_in_longdouble, &max_fp_alignment, &fp_type },
726 { &string_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &char_ctype },
727 { &ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
728 { &label_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
729 { &lazy_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
730 { NULL, }
732 #undef MOD_LL
733 #undef MOD_ESIGNED
735 void init_ctype(void)
737 const struct ctype_declare *ctype;
739 for (ctype = ctype_declaration ; ctype->ptr; ctype++) {
740 struct symbol *sym = ctype->ptr;
741 unsigned long bit_size = ctype->bit_size ? *ctype->bit_size : -1;
742 unsigned long maxalign = ctype->maxalign ? *ctype->maxalign : 0;
743 unsigned long alignment = bit_size >> 3;
745 if (alignment > maxalign)
746 alignment = maxalign;
747 sym->type = ctype->type;
748 sym->bit_size = bit_size;
749 sym->ctype.alignment = alignment;
750 sym->ctype.base_type = ctype->base_type;
751 sym->ctype.modifiers = ctype->modifiers;