Get comparison sizes right.
[smatch.git] / symbol.c
blob68de5e1a7a837b7452f08dbfed8cf5cd41ff28b0
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 symbol *alloc_symbol(struct position pos, int type)
58 struct symbol *sym = __alloc_symbol(0);
59 sym->type = type;
60 sym->pos = pos;
61 return sym;
64 struct struct_union_info {
65 unsigned long max_align;
66 unsigned long bit_size;
67 int align_size;
71 * Unions are fairly easy to lay out ;)
73 static void lay_out_union(struct symbol *sym, struct struct_union_info *info)
75 examine_symbol_type(sym);
77 // Unnamed bitfields do not affect alignment.
78 if (sym->ident || !is_bitfield_type(sym)) {
79 if (sym->ctype.alignment > info->max_align)
80 info->max_align = sym->ctype.alignment;
83 if (sym->bit_size > info->bit_size)
84 info->bit_size = sym->bit_size;
86 sym->offset = 0;
89 static int bitfield_base_size(struct symbol *sym)
91 if (sym->type == SYM_NODE)
92 sym = sym->ctype.base_type;
93 if (sym->type == SYM_BITFIELD)
94 sym = sym->ctype.base_type;
95 return sym->bit_size;
99 * Structures are a bit more interesting to lay out
101 static void lay_out_struct(struct symbol *sym, struct struct_union_info *info)
103 unsigned long bit_size, align_bit_mask;
104 int base_size;
106 examine_symbol_type(sym);
108 // Unnamed bitfields do not affect alignment.
109 if (sym->ident || !is_bitfield_type(sym)) {
110 if (sym->ctype.alignment > info->max_align)
111 info->max_align = sym->ctype.alignment;
114 bit_size = info->bit_size;
115 base_size = sym->bit_size;
118 * Unsized arrays cause us to not align the resulting
119 * structure size
121 if (base_size < 0) {
122 info->align_size = 0;
123 base_size = 0;
126 align_bit_mask = (sym->ctype.alignment << 3) - 1;
129 * Bitfields have some very special rules..
131 if (is_bitfield_type (sym)) {
132 unsigned long bit_offset = bit_size & align_bit_mask;
133 int room = bitfield_base_size(sym) - bit_offset;
134 // Zero-width fields just fill up the unit.
135 int width = base_size ? : (bit_offset ? room : 0);
137 if (width > room) {
138 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
139 bit_offset = 0;
141 sym->offset = (bit_size - bit_offset) >> 3;
142 sym->bit_offset = bit_offset;
143 sym->ctype.base_type->bit_offset = bit_offset;
144 info->bit_size = bit_size + width;
145 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
147 return;
151 * Otherwise, just align it right and add it up..
153 bit_size = (bit_size + align_bit_mask) & ~align_bit_mask;
154 sym->offset = bit_size >> 3;
156 info->bit_size = bit_size + base_size;
157 // warning (sym->pos, "regular: offset=%d", sym->offset);
160 static struct symbol * examine_struct_union_type(struct symbol *sym, int advance)
162 struct struct_union_info info = {
163 .max_align = 1,
164 .bit_size = 0,
165 .align_size = 1
167 unsigned long bit_size, bit_align;
168 void (*fn)(struct symbol *, struct struct_union_info *);
169 struct symbol *member;
171 fn = advance ? lay_out_struct : lay_out_union;
172 FOR_EACH_PTR(sym->symbol_list, member) {
173 fn(member, &info);
174 } END_FOR_EACH_PTR(member);
176 if (!sym->ctype.alignment)
177 sym->ctype.alignment = info.max_align;
178 bit_size = info.bit_size;
179 if (info.align_size) {
180 bit_align = (sym->ctype.alignment << 3)-1;
181 bit_size = (bit_size + bit_align) & ~bit_align;
183 sym->bit_size = bit_size;
184 return sym;
187 static struct symbol *examine_base_type(struct symbol *sym)
189 struct symbol *base_type;
191 /* Check the basetype */
192 base_type = sym->ctype.base_type;
193 if (base_type) {
194 base_type = examine_symbol_type(base_type);
196 /* "typeof" can cause this */
197 if (base_type && base_type->type == SYM_NODE)
198 merge_type(sym, base_type);
200 return base_type;
203 static struct symbol * examine_array_type(struct symbol *sym)
205 struct symbol *base_type = examine_base_type(sym);
206 unsigned long bit_size, alignment;
208 if (!base_type)
209 return sym;
210 bit_size = base_type->bit_size * get_expression_value(sym->array_size);
211 if (!sym->array_size || sym->array_size->type != EXPR_VALUE)
212 bit_size = -1;
213 alignment = base_type->ctype.alignment;
214 if (!sym->ctype.alignment)
215 sym->ctype.alignment = alignment;
216 sym->bit_size = bit_size;
217 return sym;
220 static struct symbol *examine_bitfield_type(struct symbol *sym)
222 struct symbol *base_type = examine_base_type(sym);
223 unsigned long bit_size, alignment, modifiers;
225 if (!base_type)
226 return sym;
227 bit_size = base_type->bit_size;
228 if (sym->bit_size > bit_size)
229 warning(sym->pos, "impossible field-width, %d, for this type", sym->bit_size);
231 alignment = base_type->ctype.alignment;
232 if (!sym->ctype.alignment)
233 sym->ctype.alignment = alignment;
234 modifiers = base_type->ctype.modifiers;
236 /* Bitfields are unsigned, unless the base type was explicitly signed */
237 if (!(modifiers & MOD_EXPLICITLY_SIGNED))
238 modifiers = (modifiers & ~MOD_SIGNED) | MOD_UNSIGNED;
239 sym->ctype.modifiers |= modifiers & MOD_SIGNEDNESS;
240 return sym;
244 * "typeof" will have to merge the types together
246 void merge_type(struct symbol *sym, struct symbol *base_type)
248 sym->ctype.as |= base_type->ctype.as;
249 sym->ctype.modifiers |= (base_type->ctype.modifiers & ~MOD_STORAGE);
250 sym->ctype.in_context += base_type->ctype.in_context;
251 sym->ctype.out_context += base_type->ctype.out_context;
252 sym->ctype.base_type = base_type->ctype.base_type;
255 static int count_array_initializer(struct expression *expr)
257 int nr = 0;
259 switch (expr->type) {
260 case EXPR_STRING:
261 nr = expr->string->length;
262 break;
263 case EXPR_INITIALIZER: {
264 struct expression *entry;
265 FOR_EACH_PTR(expr->expr_list, entry) {
266 switch (entry->type) {
267 case EXPR_STRING:
268 nr += entry->string->length;
269 break;
270 case EXPR_INDEX:
271 if (entry->idx_to > nr)
272 nr = entry->idx_to;
273 break;
274 default:
275 nr++;
277 } END_FOR_EACH_PTR(entry);
278 break;
280 default:
281 break;
283 return nr;
286 static struct symbol * examine_node_type(struct symbol *sym)
288 struct symbol *base_type = examine_base_type(sym);
289 int bit_size;
290 unsigned long alignment, modifiers;
292 /* SYM_NODE - figure out what the type of the node was.. */
293 modifiers = sym->ctype.modifiers;
295 bit_size = 0;
296 alignment = 0;
297 if (!base_type)
298 return sym;
300 bit_size = base_type->bit_size;
301 alignment = base_type->ctype.alignment;
303 /* Pick up signedness information into the node */
304 sym->ctype.modifiers |= (MOD_SIGNEDNESS & base_type->ctype.modifiers);
306 if (!sym->ctype.alignment)
307 sym->ctype.alignment = alignment;
309 /* Unsized array? The size might come from the initializer.. */
310 if (bit_size < 0 && base_type->type == SYM_ARRAY && sym->initializer) {
311 int count = count_array_initializer(sym->initializer);
312 struct symbol *node_type = base_type->ctype.base_type;
314 if (node_type && node_type->bit_size >= 0)
315 bit_size = node_type->bit_size * count;
318 sym->bit_size = bit_size;
319 return sym;
322 static struct symbol *examine_enum_type(struct symbol *sym)
324 struct symbol *base_type = examine_base_type(sym);
326 if (!base_type || base_type == &bad_ctype) {
327 warning(sym->pos, "invalid enum type");
328 sym->bit_size = -1;
329 return sym;
331 sym->ctype.modifiers |= (base_type->ctype.modifiers & MOD_SIGNEDNESS);
332 sym->bit_size = bits_in_enum;
333 if (base_type->bit_size > sym->bit_size)
334 sym->bit_size = base_type->bit_size;
335 sym->ctype.alignment = enum_alignment;
336 if (base_type->ctype.alignment > sym->ctype.alignment)
337 sym->ctype.alignment = base_type->ctype.alignment;
338 return sym;
341 static struct symbol *examine_pointer_type(struct symbol *sym)
344 * We need to set the pointer size first, and
345 * examine the thing we point to only afterwards.
346 * That's because this pointer type may end up
347 * being needed for the base type size evalutation.
349 if (!sym->bit_size)
350 sym->bit_size = bits_in_pointer;
351 if (!sym->ctype.alignment)
352 sym->ctype.alignment = pointer_alignment;
353 examine_base_type(sym);
354 return sym;
358 * Fill in type size and alignment information for
359 * regular SYM_TYPE things.
361 struct symbol *examine_symbol_type(struct symbol * sym)
363 if (!sym)
364 return sym;
366 /* Already done? */
367 if (sym->examined)
368 return sym;
369 sym->examined = 1;
371 switch (sym->type) {
372 case SYM_FN:
373 case SYM_NODE:
374 return examine_node_type(sym);
375 case SYM_ARRAY:
376 return examine_array_type(sym);
377 case SYM_STRUCT:
378 return examine_struct_union_type(sym, 1);
379 case SYM_UNION:
380 return examine_struct_union_type(sym, 0);
381 case SYM_PTR:
382 return examine_pointer_type(sym);
383 case SYM_ENUM:
384 return examine_enum_type(sym);
385 case SYM_BITFIELD:
386 return examine_bitfield_type(sym);
387 case SYM_BASETYPE:
388 /* Size and alignment had better already be set up */
389 return sym;
390 case SYM_TYPEOF: {
391 struct symbol *base = evaluate_expression(sym->initializer);
392 if (base) {
393 if (is_bitfield_type(base))
394 warning(base->pos, "typeof applied to bitfield type");
395 if (base->type == SYM_NODE)
396 base = base->ctype.base_type;
397 sym->type = SYM_NODE;
398 sym->ctype.base_type = base;
399 sym->bit_size = base->bit_size;
401 break;
403 case SYM_PREPROCESSOR:
404 warning(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident));
405 return NULL;
406 case SYM_UNINITIALIZED:
407 warning(sym->pos, "ctype on uninitialized symbol %p", sym);
408 return NULL;
409 case SYM_RESTRICT:
410 examine_base_type(sym);
411 return sym;
412 default:
413 warning(sym->pos, "Examining unknown symbol type %d", sym->type);
414 break;
416 return sym;
419 void check_declaration(struct symbol *sym)
421 struct symbol *next = sym;
423 while ((next = next->next_id) != NULL) {
424 if (next->namespace != sym->namespace)
425 continue;
426 if (sym->scope == next->scope) {
427 sym->same_symbol = next;
428 return;
430 if (sym->ctype.modifiers & next->ctype.modifiers & MOD_EXTERN) {
431 sym->same_symbol = next;
432 return;
434 #if 0
435 // This may make sense from a warning standpoint:
436 // consider top-level symbols to clash with everything
437 // (but the scoping rules will mean that we actually
438 // _use_ the innermost version)
439 if (toplevel(next->scope)) {
440 sym->same_symbol = next;
441 return;
443 #endif
447 void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns)
449 struct scope *scope;
450 if (sym->id_list) {
451 warning(sym->pos, "internal error: symbol type already bound");
452 return;
454 if (ident->reserved && (ns & (NS_TYPEDEF | NS_STRUCT | NS_LABEL | NS_SYMBOL))) {
455 warning(sym->pos, "Trying to use reserved word '%s' as identifier", show_ident(ident));
456 return;
458 sym->namespace = ns;
459 sym->next_id = ident->symbols;
460 ident->symbols = sym;
461 sym->id_list = &ident->symbols;
462 if (sym->ident && sym->ident != ident)
463 warning(sym->pos, "Symbol '%s' already bound", show_ident(sym->ident));
464 sym->ident = ident;
466 scope = block_scope;
467 if (ns == NS_SYMBOL && toplevel(scope)) {
468 sym->ctype.modifiers |= MOD_TOPLEVEL | MOD_ADDRESSABLE;
469 if (sym->ctype.modifiers & MOD_STATIC)
470 scope = file_scope;
472 if (ns == NS_LABEL)
473 scope = function_scope;
474 bind_scope(sym, scope);
477 struct symbol *create_symbol(int stream, const char *name, int type, int namespace)
479 struct token *token = built_in_token(stream, name);
480 struct symbol *sym = alloc_symbol(token->pos, type);
482 bind_symbol(sym, token->ident, namespace);
483 return sym;
486 static int evaluate_to_integer(struct expression *expr)
488 expr->ctype = &int_ctype;
489 return 1;
493 * __builtin_warning() has type "int" and always returns 1,
494 * so that you can use it in conditionals or whatever
496 static int expand_warning(struct expression *expr, int cost)
498 struct expression *arg;
499 struct expression_list *arglist = expr->args;
501 FOR_EACH_PTR (arglist, arg) {
503 * Constant strings get printed out as a warning. By the
504 * time we get here, the EXPR_STRING has been fully
505 * evaluated, so by now it's an anonymous symbol with a
506 * string initializer.
508 * Just for the heck of it, allow any constant string
509 * symbol.
511 if (arg->type == EXPR_SYMBOL) {
512 struct symbol *sym = arg->symbol;
513 if (sym->initializer && sym->initializer->type == EXPR_STRING) {
514 struct string *string = sym->initializer->string;
515 warning(expr->pos, "%*s", string->length-1, string->data);
517 continue;
521 * Any other argument is a conditional. If it's
522 * non-constant, or it is false, we exit and do
523 * not print any warning.
525 if (arg->type != EXPR_VALUE)
526 goto out;
527 if (!arg->value)
528 goto out;
529 } END_FOR_EACH_PTR(arg);
530 out:
531 expr->type = EXPR_VALUE;
532 expr->value = 1;
533 return 0;
537 * Type and storage class keywords need to have the symbols
538 * created for them, so that the parser can have enough semantic
539 * information to do parsing.
541 * "double" == "long float", "long double" == "long long float"
543 struct sym_init {
544 const char *name;
545 struct symbol *base_type;
546 unsigned int modifiers;
547 struct symbol_op *op;
548 } symbol_init_table[] = {
549 /* Storage class */
550 { "auto", NULL, MOD_AUTO },
551 { "register", NULL, MOD_REGISTER },
552 { "static", NULL, MOD_STATIC },
553 { "extern", NULL, MOD_EXTERN },
555 /* Type specifiers */
556 { "void", &void_ctype, 0 },
557 { "char", NULL, MOD_CHAR },
558 { "short", NULL, MOD_SHORT },
559 { "int", &int_type, 0 },
560 { "long", NULL, MOD_LONG },
561 { "float", &fp_type, 0 },
562 { "double", &fp_type, MOD_LONG },
563 { "signed", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
564 { "__signed", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
565 { "__signed__", NULL, MOD_SIGNED | MOD_EXPLICITLY_SIGNED },
566 { "unsigned", NULL, MOD_UNSIGNED },
567 { "__label__", &label_ctype, MOD_LABEL | MOD_UNSIGNED },
568 { "_Bool", &bool_ctype, MOD_UNSIGNED },
570 /* Type qualifiers */
571 { "const", NULL, MOD_CONST },
572 { "__const", NULL, MOD_CONST },
573 { "__const__", NULL, MOD_CONST },
574 { "volatile", NULL, MOD_VOLATILE },
575 { "__volatile", NULL, MOD_VOLATILE },
576 { "__volatile__", NULL, MOD_VOLATILE },
578 /* Predeclared types */
579 { "__builtin_va_list", &int_type, 0 },
581 /* Typedef.. */
582 { "typedef", NULL, MOD_TYPEDEF },
584 /* Extended types */
585 { "typeof", NULL, MOD_TYPEOF },
586 { "__typeof", NULL, MOD_TYPEOF },
587 { "__typeof__", NULL, MOD_TYPEOF },
589 #if 0
590 { "attribute", NULL, MOD_ATTRIBUTE },
591 #endif
592 { "__attribute", NULL, MOD_ATTRIBUTE },
593 { "__attribute__", NULL, MOD_ATTRIBUTE },
595 { "struct", NULL, MOD_STRUCTOF },
596 { "union", NULL, MOD_UNIONOF },
597 { "enum", NULL, MOD_ENUMOF },
599 { "inline", NULL, MOD_INLINE },
600 { "__inline", NULL, MOD_INLINE },
601 { "__inline__", NULL, MOD_INLINE },
603 /* Ignored for now.. */
604 { "restrict", NULL, 0 },
605 { "__restrict", NULL, 0 },
607 { NULL, NULL, 0 }
610 static struct symbol_op constant_p_op = {
611 .evaluate = evaluate_to_integer,
612 .expand = expand_constant_p
615 static struct symbol_op safe_p_op = {
616 .evaluate = evaluate_to_integer,
617 .expand = expand_safe_p
620 static struct symbol_op warning_op = {
621 .evaluate = evaluate_to_integer,
622 .expand = expand_warning
626 * Builtin functions
628 static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ };
629 static struct sym_init eval_init_table[] = {
630 { "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op },
631 { "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op },
632 { "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op },
633 { NULL, NULL, 0 }
638 * Abstract types
640 struct symbol int_type,
641 fp_type;
644 * C types (ie actual instances that the abstract types
645 * can map onto)
647 struct symbol bool_ctype, void_ctype, type_ctype,
648 char_ctype, schar_ctype, uchar_ctype,
649 short_ctype, sshort_ctype, ushort_ctype,
650 int_ctype, sint_ctype, uint_ctype,
651 long_ctype, slong_ctype, ulong_ctype,
652 llong_ctype, sllong_ctype, ullong_ctype,
653 float_ctype, double_ctype, ldouble_ctype,
654 string_ctype, ptr_ctype, lazy_ptr_ctype,
655 incomplete_ctype, label_ctype, bad_ctype;
658 #define __INIT_IDENT(str, res) { .len = sizeof(str)-1, .name = str, .reserved = res }
659 #define __IDENT(n,str,res) \
660 struct ident n = __INIT_IDENT(str,res)
662 #include "ident-list.h"
664 void init_symbols(void)
666 int stream = init_stream("builtin", -1, includepath);
667 struct sym_init *ptr;
669 #define __IDENT(n,str,res) \
670 hash_ident(&n)
671 #include "ident-list.h"
673 for (ptr = symbol_init_table; ptr->name; ptr++) {
674 struct symbol *sym;
675 sym = create_symbol(stream, ptr->name, SYM_NODE, NS_TYPEDEF);
676 sym->ident->reserved = 1;
677 sym->ctype.base_type = ptr->base_type;
678 sym->ctype.modifiers = ptr->modifiers;
681 builtin_fn_type.variadic = 1;
682 for (ptr = eval_init_table; ptr->name; ptr++) {
683 struct symbol *sym;
684 sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL);
685 sym->ctype.base_type = ptr->base_type;
686 sym->ctype.modifiers = ptr->modifiers;
687 sym->op = ptr->op;
691 #define MOD_ESIGNED (MOD_SIGNED | MOD_EXPLICITLY_SIGNED)
692 #define MOD_LL (MOD_LONG | MOD_LONGLONG)
693 static const struct ctype_declare {
694 struct symbol *ptr;
695 enum type type;
696 unsigned long modifiers;
697 int *bit_size;
698 int *maxalign;
699 struct symbol *base_type;
700 } ctype_declaration[] = {
701 { &bool_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_bool, &max_int_alignment, &int_type },
702 { &void_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
703 { &type_ctype, SYM_BASETYPE, MOD_TYPE, NULL, NULL, NULL },
704 { &incomplete_ctype,SYM_BASETYPE, 0, NULL, NULL, NULL },
705 { &bad_ctype, SYM_BASETYPE, 0, NULL, NULL, NULL },
707 { &char_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
708 { &schar_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
709 { &uchar_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_CHAR, &bits_in_char, &max_int_alignment, &int_type },
710 { &short_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
711 { &sshort_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
712 { &ushort_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_SHORT, &bits_in_short, &max_int_alignment, &int_type },
713 { &int_ctype, SYM_BASETYPE, MOD_SIGNED, &bits_in_int, &max_int_alignment, &int_type },
714 { &sint_ctype, SYM_BASETYPE, MOD_ESIGNED, &bits_in_int, &max_int_alignment, &int_type },
715 { &uint_ctype, SYM_BASETYPE, MOD_UNSIGNED, &bits_in_int, &max_int_alignment, &int_type },
716 { &long_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
717 { &slong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
718 { &ulong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LONG, &bits_in_long, &max_int_alignment, &int_type },
719 { &llong_ctype, SYM_BASETYPE, MOD_SIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
720 { &sllong_ctype, SYM_BASETYPE, MOD_ESIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
721 { &ullong_ctype, SYM_BASETYPE, MOD_UNSIGNED | MOD_LL, &bits_in_longlong, &max_int_alignment, &int_type },
723 { &float_ctype, SYM_BASETYPE, 0, &bits_in_float, &max_fp_alignment, &fp_type },
724 { &double_ctype, SYM_BASETYPE, MOD_LONG, &bits_in_double, &max_fp_alignment, &fp_type },
725 { &ldouble_ctype, SYM_BASETYPE, MOD_LONG | MOD_LONGLONG, &bits_in_longdouble, &max_fp_alignment, &fp_type },
727 { &string_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &char_ctype },
728 { &ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
729 { &label_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
730 { &lazy_ptr_ctype, SYM_PTR, 0, &bits_in_pointer, &pointer_alignment, &void_ctype },
731 { NULL, }
733 #undef MOD_LL
734 #undef MOD_ESIGNED
736 void init_ctype(void)
738 const struct ctype_declare *ctype;
740 for (ctype = ctype_declaration ; ctype->ptr; ctype++) {
741 struct symbol *sym = ctype->ptr;
742 unsigned long bit_size = ctype->bit_size ? *ctype->bit_size : -1;
743 unsigned long maxalign = ctype->maxalign ? *ctype->maxalign : 0;
744 unsigned long alignment = bit_size >> 3;
746 if (alignment > maxalign)
747 alignment = maxalign;
748 sym->type = ctype->type;
749 sym->bit_size = bit_size;
750 sym->ctype.alignment = alignment;
751 sym->ctype.base_type = ctype->base_type;
752 sym->ctype.modifiers = ctype->modifiers;