3 /* Copyright (c) 1994 Stanford University
7 This software is provided under the terms described in
8 the "suif_copyright.h" include file. */
10 #include <suif_copyright.h>
12 /* snoot type handling */
18 type_node
*chartype
; /* char */
19 type_node
*doubletype
; /* double */
20 type_node
*floattype
; /* float */
21 type_node
*inttype
; /* signed int */
22 type_node
*longdouble
; /* long double */
23 type_node
*longtype
; /* long */
24 type_node
*longlong
; /* long long */
25 type_node
*shorttype
; /* signed short int */
26 type_node
*signedchar
; /* signed char */
27 type_node
*unsignedchar
; /* unsigned char */
28 type_node
*unsignedlong
; /* unsigned long int */
29 type_node
*unsignedlonglong
; /* unsigned long long int */
30 type_node
*unsignedshort
; /* unsigned short int */
31 type_node
*unsignedtype
; /* unsigned int */
32 type_node
*voidptype
; /* void* */
33 type_node
*voidtype
; /* void */
34 type_node
*booleantype
; /* for internal use */
35 type_node
*size_t_type
; /* whatever size_t is on the target
36 machine, one of unsignedchar,
37 unsignedshort, unsignedtype,
38 unsignedlong, or unsignedlonglong
42 /* Symbol table entries of basic types: */
44 Symbol chartype_sym
; /* char */
45 Symbol doubletype_sym
; /* double */
46 Symbol floattype_sym
; /* float */
47 Symbol inttype_sym
; /* signed int */
48 Symbol longdouble_sym
; /* long double */
49 Symbol longtype_sym
; /* long */
50 Symbol longlong_sym
; /* long long */
51 Symbol shorttype_sym
; /* signed short int */
52 Symbol signedchar_sym
; /* signed char */
53 Symbol unsignedchar_sym
; /* unsigned char */
54 Symbol unsignedlong_sym
; /* unsigned long int */
55 Symbol unsignedlonglong_sym
; /* unsigned long long int */
56 Symbol unsignedshort_sym
; /* unsigned short int */
57 Symbol unsignedtype_sym
; /* unsigned int */
58 Symbol voidtype_sym
; /* void */
60 replacements
*global_replacements
;
62 static base_symtab
*type_symtab
; /* table to put types when there is nothing
65 static void init_base_type(type_node
**the_type_node
, char *name
,
66 type_ops the_op
, boolean is_signed
, int size
,
67 int alignment
, Symbol
*the_symbol
);
68 static boolean
identically_qualified(type_node
*type1
, type_node
*type2
);
69 static boolean
bit_field_annotations_same(type_node
*field1
,
71 static void use_field(struct_type
*the_struct
, char *name
);
72 static Coordinate
*get_source(type_node
*the_type
);
73 static void set_source(type_node
*the_type
, Coordinate source
);
75 /* typeInit - initialize basic types */
80 target
.is_big_endian
= this_target
->is_big_endian
;
81 target
.addressable_size
= this_target
->addressable_size
;
82 target
.char_is_signed
= this_target
->char_is_signed
;
84 for (c_type
= 0; c_type
< num_C_types
; ++c_type
)
86 target
.size
[c_type
] = this_target
->size
[c_type
];
87 target
.align
[c_type
] = this_target
->align
[c_type
];
90 target
.array_align
= this_target
->array_align
;
91 target
.struct_align
= this_target
->struct_align
;
93 target
.ptr_diff_type
= this_target
->ptr_diff_type
;
96 * Sanity check on alignments
99 for (c_type_1
= C_char
; c_type_1
<= C_longlong
; ++c_type_1
)
101 for (int c_type_2
= C_char
; c_type_2
<= C_longlong
; ++c_type_2
)
103 if ((target
.size
[c_type_1
] == target
.size
[c_type_2
]) &&
104 (target
.align
[c_type_1
] != target
.align
[c_type_2
]))
107 "integral types with size %d bits have "
108 "conflicting", target
.size
[c_type_1
]);
110 " alignment requirements of %d and %d bits",
111 target
.align
[c_type_1
], target
.align
[c_type_2
]);
115 for (c_type_1
= C_float
; c_type_1
<= C_longdouble
; ++c_type_1
)
117 for (int c_type_2
= C_float
; c_type_2
<= C_longdouble
; ++c_type_2
)
119 if ((target
.size
[c_type_1
] == target
.size
[c_type_2
]) &&
120 (target
.align
[c_type_1
] != target
.align
[c_type_2
]))
123 "floating point types with size %d bits have "
124 "conflicting", target
.size
[c_type_1
]);
126 " alignment requirements of %d and %d bits",
127 target
.align
[c_type_1
], target
.align
[c_type_2
]);
132 fileset
->globals()->predefine_types();
133 type_symtab
= type_signed
->parent();
135 global_replacements
= new replacements
;
137 init_base_type(&chartype
, "char", TYPE_INT
,
138 target
.char_is_signed
, target
.size
[C_char
],
139 target
.align
[C_char
], &chartype_sym
);
140 init_base_type(&doubletype
, "double", TYPE_FLOAT
,
141 TRUE
, target
.size
[C_double
],
142 target
.align
[C_double
], &doubletype_sym
);
143 init_base_type(&floattype
, "float", TYPE_FLOAT
,
144 TRUE
, target
.size
[C_float
],
145 target
.align
[C_float
], &floattype_sym
);
146 init_base_type(&inttype
, "int", TYPE_INT
,
147 TRUE
, target
.size
[C_int
],
148 target
.align
[C_int
], &inttype_sym
);
149 init_base_type(&longdouble
, "long double", TYPE_FLOAT
,
150 TRUE
, target
.size
[C_longdouble
],
151 target
.align
[C_longdouble
], &longdouble_sym
);
152 init_base_type(&longtype
, "long int", TYPE_INT
,
153 TRUE
, target
.size
[C_long
],
154 target
.align
[C_long
], &longtype_sym
);
155 init_base_type(&longlong
, "long long int", TYPE_INT
,
156 TRUE
, target
.size
[C_longlong
],
157 target
.align
[C_longlong
], &longlong_sym
);
158 init_base_type(&shorttype
, "short", TYPE_INT
,
159 TRUE
, target
.size
[C_short
],
160 target
.align
[C_short
], &shorttype_sym
);
161 init_base_type(&signedchar
, "signed char", TYPE_INT
,
162 TRUE
, target
.size
[C_char
],
163 target
.align
[C_char
], &signedchar_sym
);
164 init_base_type(&unsignedchar
, "unsigned char", TYPE_INT
,
165 FALSE
, target
.size
[C_char
],
166 target
.align
[C_char
], &unsignedchar_sym
);
167 init_base_type(&unsignedlong
, "unsigned long int", TYPE_INT
,
168 FALSE
, target
.size
[C_long
],
169 target
.align
[C_long
], &unsignedlong_sym
);
170 init_base_type(&unsignedlonglong
, "unsigned long long int", TYPE_INT
,
171 FALSE
, target
.size
[C_longlong
],
172 target
.align
[C_longlong
], &unsignedlonglong_sym
);
173 init_base_type(&unsignedshort
, "unsigned short int", TYPE_INT
,
174 FALSE
, target
.size
[C_short
],
175 target
.align
[C_short
], &unsignedshort_sym
);
176 init_base_type(&unsignedtype
, "unsigned int", TYPE_INT
,
177 FALSE
, target
.size
[C_int
],
178 target
.align
[C_int
], &unsignedtype_sym
);
179 init_base_type(&voidtype
, "void", TYPE_VOID
,
183 /* In some places, type_ptr_diff is used as an expression result
184 * type, but other pieces assume that expression result types that
185 * are integers will be exactly one of the standard C types. So
186 * we can't just rely on what predefine_types() to set
187 * type_ptr_diff; we have to set it here to one of the standard C
188 * integer types we just created. */
189 switch (target
.ptr_diff_type
)
192 type_ptr_diff
= signedchar
;
195 type_ptr_diff
= shorttype
;
198 type_ptr_diff
= inttype
;
201 type_ptr_diff
= longtype
;
204 type_ptr_diff
= longlong
;
210 voidptype
= voidtype
->ptr_to();
212 booleantype
= new base_type(TYPE_INT
, type_signed
->size(), TRUE
);
213 immed_list
*new_immed_list
= new immed_list
;
214 new_immed_list
->append(immed("boolean"));
215 booleantype
->append_annote(k_type_name
, new_immed_list
);
216 booleantype
= type_symtab
->install_type(booleantype
);
219 * We assume that size_t is the unsigned version of ptrdiff_t.
220 * This isn't technically required by the ANSI standard, but it's
221 * likely to be true on almost any real back-end C compiler, and
222 * even if it's not, it is very unlikely that the difference will
225 switch (target
.ptr_diff_type
)
228 size_t_type
= unsignedchar
;
231 size_t_type
= unsignedshort
;
234 size_t_type
= unsignedtype
;
237 size_t_type
= unsignedlong
;
240 size_t_type
= unsignedlonglong
;
247 * BUILTIN in config.h only seems to handle builin expressions
248 * and this is a built-in type.
250 Coordinate c
= { "", 0, 0 };
251 deftype(string("__builtin_va_list"), chartype
->ptr_to(), &c
);
255 static void init_base_type(type_node
**the_type_node
, char *name
,
256 type_ops the_op
, boolean is_signed
, int size
,
257 int alignment
, Symbol
*the_symbol
)
259 *the_symbol
= install(string(name
), &types
, 1);
260 *the_type_node
= new base_type(the_op
, size
, is_signed
);
261 immed_list
*new_immed_list
= new immed_list
;
262 new_immed_list
->append(immed(name
));
263 (*the_type_node
)->append_annote(k_type_name
, new_immed_list
);
264 *the_type_node
= type_symtab
->install_type(*the_type_node
);
265 (*the_symbol
)->type
= *the_type_node
;
266 assert((alignment
== 0) || (size
% alignment
== 0));
268 type_node
*merged_version
= new base_type(the_op
, size
, is_signed
);
269 merged_version
= type_symtab
->install_type(merged_version
);
270 global_replacements
->oldtypes
.append(*the_type_node
);
271 global_replacements
->newtypes
.append(merged_version
);
274 /* array - construct the type `array 0..n-1 of ty' */
275 extern type_node
*build_array(type_node
*ty
, int n
)
281 error("illegal type `array of %t'\n", ty
);
282 return build_array(inttype
, n
);
285 if ((level
> GLOBAL
) && isarray(ty
) && (ty
->size() == 0))
286 error("missing array size\n");
289 if (ty
->unqual() == voidtype
)
290 error("illegal type `array of %t'\n", ty
);
292 warning("declaring type `array of %t' is undefined\n", ty
);
294 else if (n
> INT_MAX
/ ty
->size())
296 error("size of `array of %t' exceeds %d bytes\n", ty
, INT_MAX
);
300 base_symtab
*the_symtab
= ty
->parent();
301 assert(the_symtab
!= NULL
);
302 array_bound upper_bound
= unknown_bound
;
304 upper_bound
= array_bound(n
- 1);
305 type_node
*new_type
= new array_type(ty
, array_bound(0), upper_bound
);
306 return the_symtab
->install_type(new_type
);
309 /* atop - convert ty from `array of ty' to `pointer to ty' */
310 extern type_node
*atop(type_node
*ty
)
313 return base_from_array(ty
)->ptr_to();
314 error("type error: %s\n", "array expected");
318 /* composite - return the composite type of ty1 & ty2, or NULL if ty1 & ty2 are
320 extern type_node
*composite(type_node
*ty1
, type_node
*ty2
)
322 if ((ty1
== NULL
) || (ty2
== NULL
))
326 if ((ty1
->op() != ty2
->op()) &&
327 ((!ty1
->is_modifier()) || (!ty2
->is_modifier())))
336 if (!identically_qualified(ty1
, ty2
))
338 type_node
*new_type
= composite(ty1
->unqual(), ty2
->unqual());
339 if (new_type
== NULL
)
342 new_type
= qual(CONST
, new_type
);
343 if (ty1
->is_volatile())
344 new_type
= qual(VOLATILE
, new_type
);
349 type_node
*new_type
=
350 composite(base_from_pointer(ty1
), base_from_pointer(ty2
));
351 if (new_type
== NULL
)
353 return new_type
->ptr_to();
357 type_node
*new_type
=
358 composite(base_from_array(ty1
), base_from_array(ty2
));
359 if (new_type
== NULL
)
362 array_type
*old_array1
= (array_type
*)ty1
;
363 array_type
*old_array2
= (array_type
*)ty2
;
365 if (!old_array1
->are_bounds_unknown())
366 upper_bound
= old_array1
->upper_bound().constant() + 1;
367 if (!old_array2
->are_bounds_unknown())
369 if ((upper_bound
!= 0) &&
370 (upper_bound
!= old_array2
->upper_bound().constant() + 1))
374 upper_bound
= old_array2
->upper_bound().constant() + 1;
376 return build_array(new_type
, upper_bound
);
380 func_type
*old_func1
= (func_type
*)ty1
;
381 func_type
*old_func2
= (func_type
*)ty2
;
382 type_node
*new_type
=
383 composite(old_func1
->return_type(),
384 old_func2
->return_type());
385 if (new_type
== NULL
)
388 unsigned num_args
= 0;
389 boolean args_unknown
= TRUE
;
390 boolean varargs
= FALSE
;
391 if (old_func1
->args_known() && old_func2
->args_known())
393 num_args
= old_func1
->num_args();
394 if (num_args
!= old_func2
->num_args())
396 args_unknown
= FALSE
;
397 varargs
= old_func1
->has_varargs();
398 if (varargs
!= old_func2
->has_varargs())
401 else if (old_func1
->args_known() && !old_func2
->args_known())
405 else if (old_func2
->args_known() && !old_func1
->args_known())
410 base_symtab
*the_symtab
= fileset
->globals();
412 boolean vis
= the_symtab
->make_type_visible(new_type
);
414 func_type
*new_func
= new func_type(new_type
, num_args
, varargs
);
418 new_func
->set_args_unknown();
422 new_func
->set_args_known();
423 for (unsigned arg_num
= 0; arg_num
< num_args
; ++arg_num
)
425 type_node
*arg1_type
= old_func1
->arg_type(arg_num
);
426 type_node
*arg2_type
= old_func2
->arg_type(arg_num
);
427 type_node
*new_arg
= composite(arg1_type
->unqual(),
428 arg2_type
->unqual());
434 if (isconst(arg1_type
) || isconst(arg2_type
))
435 new_arg
= qual(CONST
, new_arg
);
436 if (isvolatile(arg1_type
) || isvolatile(arg2_type
))
437 new_arg
= qual(VOLATILE
, new_arg
);
439 vis
= the_symtab
->make_type_visible(new_arg
);
441 new_func
->set_arg_type(arg_num
, new_arg
);
445 return the_symtab
->install_type(new_func
);
453 /* deftype - define name to be equivalent to type ty */
454 extern Symbol
deftype(char *name
, type_node
*ty
, Coordinate
*pos
)
456 Symbol p
= lookup(name
, identifiers
);
458 if ((p
!= NULL
) && (p
->scope
== level
))
459 error("redeclaration of `%s'\n", name
);
460 p
= install(name
, &identifiers
, level
< LOCAL
);
464 if (option_keep_typedef_info
)
466 base_symtab
*current_symtab
= get_current_symtab();
467 var_sym
*typedef_var
= current_symtab
->new_var(type_signed
, name
);
468 if (current_symtab
->is_file())
470 current_symtab
->define_var(typedef_var
,
471 get_alignment(type_signed
));
473 typedef_var
->append_annote(k_typedef_name
, new immed_list(ty
));
478 /* deref - dereference ty, type *ty */
479 extern type_node
*deref(type_node
*ty
)
482 return base_from_pointer(ty
);
484 error("type error: %s\n", "pointer expected");
488 /* eqtype - is ty1==ty2? handles arrays & functions; return ret if ty1==ty2,
489 but one is incomplete */
490 extern boolean
eqtype(type_node
*ty1
, type_node
*ty2
, boolean ret
)
494 if ((ty1
== NULL
) || (ty2
== NULL
))
497 if ((ty1
->op() != ty2
->op()) &&
498 ((!ty1
->is_modifier()) || (!ty2
->is_modifier())))
506 if (!identically_qualified(ty1
, ty2
))
508 return eqtype(ty1
->unqual(), ty2
->unqual(), ret
);
510 return eqtype(base_from_pointer(ty1
), base_from_pointer(ty2
), ret
);
513 array_type
*old_array1
= (array_type
*)ty1
;
514 array_type
*old_array2
= (array_type
*)ty2
;
516 if (!eqtype(old_array1
->elem_type(), old_array2
->elem_type(), ret
))
518 if (old_array1
->upper_bound() == old_array2
->upper_bound())
520 if (old_array1
->are_bounds_unknown() !=
521 old_array2
->are_bounds_unknown())
529 func_type
*old_func1
= (func_type
*)ty1
;
530 func_type
*old_func2
= (func_type
*)ty2
;
531 if (!eqtype(old_func1
->return_type(), old_func2
->return_type(),
537 if (old_func1
->args_known() && old_func2
->args_known())
539 unsigned num_args
= old_func1
->num_args();
540 if (num_args
!= old_func2
->num_args())
542 if (old_func1
->has_varargs() != old_func2
->has_varargs())
544 for (unsigned arg_num
= 0; arg_num
< num_args
; ++arg_num
)
546 if (!eqtype(old_func1
->arg_type(arg_num
)->unqual(),
547 old_func2
->arg_type(arg_num
)->unqual(), ret
))
554 else if (old_func1
->args_known() && !old_func2
->args_known())
556 func_type
*temp_func
= old_func1
;
557 old_func1
= old_func2
;
558 old_func2
= temp_func
;
560 if (!old_func2
->args_known())
563 if (old_func2
->has_varargs())
564 return (old_func2
->num_args() == 0);
566 unsigned num_args
= old_func2
->num_args();
567 for (unsigned arg_num
= 0; arg_num
< num_args
; ++arg_num
)
569 type_node
*arg_type
= old_func2
->arg_type(arg_num
)->unqual();
570 if ((promote(arg_type
) != arg_type
) || (arg_type
== floattype
))
582 /* fieldref - find field name of type ty, return entry */
583 Field
fieldref(char *name
, type_node
*ty
)
585 static struct field the_field
;
588 assert(ty
->is_struct());
589 struct_type
*the_struct
= (struct_type
*)ty
;
590 unsigned num_fields
= the_struct
->num_fields();
591 for (unsigned field_num
= 0; field_num
< num_fields
; ++field_num
)
593 if (field_is_bit_fields(the_struct
, field_num
))
595 struct field
*bit_fields
= bit_field_list(the_struct
, field_num
);
596 while (bit_fields
!= NULL
)
598 if (strcmp(bit_fields
->name
, name
) == 0)
600 the_field
= *bit_fields
;
601 the_field
.link
= NULL
;
602 while (bit_fields
!= NULL
)
604 struct field
*old_field
= bit_fields
;
605 bit_fields
= bit_fields
->link
;
608 the_field
.offset
= the_struct
->offset(field_num
);
609 the_field
.block_name
= the_struct
->field_name(field_num
);
610 the_field
.block_type
= the_struct
->field_type(field_num
);
611 use_field(the_struct
, name
);
615 struct field
*old_field
= bit_fields
;
616 bit_fields
= bit_fields
->link
;
622 if (strcmp(the_struct
->field_name(field_num
), name
) == 0)
624 the_field
.name
= the_struct
->field_name(field_num
);
625 the_field
.type
= the_struct
->field_type(field_num
);
626 the_field
.offset
= the_struct
->offset(field_num
);
629 the_field
.block_name
= the_struct
->field_name(field_num
);
630 the_field
.block_type
= the_struct
->field_type(field_num
);
631 the_field
.link
= NULL
;
632 use_field(the_struct
, name
);
640 /* freturn - for `function returning ty', return ty */
641 extern type_node
*freturn(type_node
*ty
)
646 func_type
*the_func
= (func_type
*)ty
;
647 return the_func
->return_type();
649 error("type error: %s\n", "function expected");
653 /* func - construct the type `function (void) returning ty' */
654 extern func_type
*func(type_node
*ty
)
657 if (isarray(ty
) || isfunc(ty
))
658 error("illegal return type `%t'\n", ty
);
660 base_symtab
*the_symtab
= ty
->parent();
661 assert(the_symtab
!= NULL
);
662 func_type
*new_type
= new func_type(ty
);
663 return (func_type
*)(the_symtab
->install_type(new_type
));
666 /* hasproto - true iff ty has no function types or they all have prototypes */
667 extern boolean
hasproto(type_node
*ty
)
675 modifier_type
*the_modifier
= (modifier_type
*)ty
;
676 return hasproto(the_modifier
->base());
680 ptr_type
*the_pointer
= (ptr_type
*)ty
;
681 return hasproto(the_pointer
->ref_type());
685 array_type
*the_array
= (array_type
*)ty
;
686 return hasproto(the_array
->elem_type());
690 func_type
*the_func
= (func_type
*)ty
;
691 return (hasproto(the_func
->return_type()) &&
692 the_func
->args_known());
699 /* newfield - install a new field in ty with type fty */
700 extern Field
newfield(const char *name
, struct field
**field_list
,
701 type_node
*fty
, struct_type
*to_fill
)
703 Field p
, *q
= field_list
;
706 name
= gen_internal_name();
707 for (p
= *q
; p
!= NULL
; q
= &p
->link
, p
= *q
)
709 if (strcmp(p
->name
, name
) == 0)
710 error("duplicate field name `%s' in `%t'\n", name
, to_fill
);
712 #ifndef DEAL_WITH_GCC_BRAIN_DAMAGE
713 *q
= p
= new struct field
;
716 // gcc version 2.6.3 gets a parse error on the code above. The code
717 // looks like it should be perfectly legal, and both gcc 2.5.8 and
718 // the IRIX 5.3 C++ compiler have no problem with it, so I'm inclined
719 // to think the problem is caused by brain damage in the g++
720 // front-end. A work-around follows.
722 *q
= p
= (struct field
*)operator new(sizeof(struct field
));
729 p
->block_name
= NULL
;
730 p
->block_type
= NULL
;
734 assert(to_fill
!= NULL
);
735 if (get_field_table(to_fill
) == NULL
)
736 set_field_table(to_fill
, table(0, level
));
737 Table field_table
= get_field_table(to_fill
);
738 install(name
, &field_table
, 1)->src
= src
;
739 set_field_table(to_fill
, field_table
);
744 /* newstruct - install a new structure/union/enum depending on op and return
745 its symbol table entry */
746 Symbol
newstruct(int op
, const char *tag
)
748 assert((op
== ENUM
) || (op
== STRUCT
) || (op
== UNION
));
749 if ((tag
== NULL
) || (*tag
== '\0')) /* anonymous structure/union/enum */
750 tag
= gen_internal_name();
751 Symbol p
= lookup(tag
, types
);
753 ((p
->scope
== level
) || ((p
->scope
== PARAM
) && (level
== PARAM
+1))))
755 if ((((p
->type
->op() == TYPE_ENUM
) && (op
== ENUM
)) ||
756 ((p
->type
->op() == TYPE_STRUCT
) && (op
== STRUCT
)) ||
757 ((p
->type
->op() == TYPE_UNION
) && (op
== UNION
))) && !p
->defined
)
761 error("redeclaration of `%s'\n", tag
);
763 p
= install(tag
, &types
, 1);
766 p
->type
= new enum_type(tag
, inttype
->size(), TRUE
, 0);
770 p
->type
= new struct_type((op
== STRUCT
) ? TYPE_STRUCT
: TYPE_UNION
,
773 set_source(p
->type
, src
);
775 base_symtab
*the_symtab
= get_current_symtab();
776 if (the_symtab
->is_file())
777 the_symtab
= the_symtab
->parent();
778 p
->type
= the_symtab
->install_type(p
->type
);
784 /* outtype - output type ty */
785 extern void outtype(void (*s_printer
)(const char *to_print
, void *data
),
786 void (*c_printer
)(int to_print
, void *data
), void *data
,
790 (*s_printer
)(chartype_sym
->name
, data
);
791 else if (ty
== doubletype
)
792 (*s_printer
)(doubletype_sym
->name
, data
);
793 else if (ty
== floattype
)
794 (*s_printer
)(floattype_sym
->name
, data
);
795 else if (ty
== inttype
)
796 (*s_printer
)(inttype_sym
->name
, data
);
797 else if (ty
== longdouble
)
798 (*s_printer
)(longdouble_sym
->name
, data
);
799 else if (ty
== longtype
)
800 (*s_printer
)(longtype_sym
->name
, data
);
801 else if (ty
== longlong
)
802 (*s_printer
)(longlong_sym
->name
, data
);
803 else if (ty
== shorttype
)
804 (*s_printer
)(shorttype_sym
->name
, data
);
805 else if (ty
== signedchar
)
806 (*s_printer
)(signedchar_sym
->name
, data
);
807 else if (ty
== unsignedchar
)
808 (*s_printer
)(unsignedchar_sym
->name
, data
);
809 else if (ty
== unsignedlong
)
810 (*s_printer
)(unsignedlong_sym
->name
, data
);
811 else if (ty
== unsignedlonglong
)
812 (*s_printer
)(unsignedlonglong_sym
->name
, data
);
813 else if (ty
== unsignedshort
)
814 (*s_printer
)(unsignedshort_sym
->name
, data
);
815 else if (ty
== unsignedtype
)
816 (*s_printer
)(unsignedtype_sym
->name
, data
);
817 else if (ty
== voidtype
)
818 (*s_printer
)(voidtype_sym
->name
, data
);
824 (*s_printer
)(voidtype_sym
->name
, data
);
829 gprint(s_printer
, c_printer
, data
, "%k ", CONST
);
830 if (ty
->is_volatile())
831 gprint(s_printer
, c_printer
, data
, "%k ", VOLATILE
);
832 gprint(s_printer
, c_printer
, data
, "%t", ty
->unqual());
840 if (ty
->op() == TYPE_ENUM
)
842 enum_type
*the_enum
= (enum_type
*)ty
;
843 ty_name
= the_enum
->name();
848 struct_type
*the_struct
= (struct_type
*)ty
;
849 ty_name
= the_struct
->name();
850 op
= (ty
->op() == TYPE_STRUCT
) ? STRUCT
: UNION
;
853 (*s_printer
)("incomplete ", data
);
854 assert(ty_name
!= NULL
);
855 if ((*ty_name
>= '1') && (*ty_name
<= '9'))
857 Symbol p
= findtype(ty
);
860 gprint(s_printer
, c_printer
, data
, "%k", op
);
861 Coordinate
*location
= get_source(ty
);
862 if (location
!= NULL
)
864 gprint(s_printer
, c_printer
, data
,
865 " defined at %w", location
);
870 (*s_printer
)(p
->name
, data
);
875 gprint(s_printer
, c_printer
, data
, "%k %s", op
, ty_name
);
878 Coordinate
*location
= get_source(ty
);
879 if (location
!= NULL
)
881 gprint(s_printer
, c_printer
, data
,
882 " defined at %w", location
);
889 gprint(s_printer
, c_printer
, data
, "pointer to %t",
890 base_from_pointer(ty
));
894 func_type
*the_func
= (func_type
*)ty
;
895 gprint(s_printer
, c_printer
, data
, "%t function",
896 the_func
->return_type());
897 if (the_func
->args_known())
899 if (the_func
->num_args() == 0)
901 if (the_func
->has_varargs())
902 gprint(s_printer
, c_printer
, data
, "(...)");
904 gprint(s_printer
, c_printer
, data
, "(void)");
908 gprint(s_printer
, c_printer
, data
, "(%t",
909 the_func
->arg_type(0));
910 unsigned num_args
= the_func
->num_args();
911 for (unsigned arg_num
= 1; arg_num
< num_args
;
914 gprint(s_printer
, c_printer
, data
, ", %t",
915 the_func
->arg_type(arg_num
));
917 if (the_func
->has_varargs())
918 gprint(s_printer
, c_printer
, data
, ", ...");
919 gprint(s_printer
, c_printer
, data
, ")");
926 array_type
*the_array
= (array_type
*)ty
;
927 if (!the_array
->are_bounds_unknown())
929 gprint(s_printer
, c_printer
, data
, "array %d",
930 the_array
->upper_bound().constant() + 1);
931 while ((the_array
->elem_type() != NULL
) &&
932 isarray(the_array
->elem_type()) &&
933 (!((array_type
*)(the_array
->elem_type()))
934 ->are_bounds_unknown()))
936 the_array
= (array_type
*)(the_array
->elem_type());
937 gprint(s_printer
, c_printer
, data
, ", %d",
938 the_array
->upper_bound().constant() + 1);
943 (*s_printer
)("incomplete array", data
);
945 if (the_array
->elem_type() != NULL
)
947 gprint(s_printer
, c_printer
, data
, " of %t",
948 the_array
->elem_type());
958 /* printdecl - output a C declaration for symbol p of type ty */
959 void printdecl(Symbol p
, type_node
*ty
)
964 fprint(stderr
, "%s;\n", typestring(ty
, p
->name
));
968 fprint(stderr
, "%k %s;\n", p
->sclass
, typestring(ty
, p
->name
));
977 /* printproto - output a prototype declaration for function p */
978 void printproto(Symbol p
, Symbol callee
[])
981 type_node
*p_type
= p
->type
;
982 assert(p_type
->is_func());
983 func_type
*the_func
= (func_type
*)p_type
;
984 if (the_func
->args_known())
986 printdecl(p
, the_func
);
991 for (num_args
= 0; callee
[num_args
] != NULL
; ++num_args
)
993 func_type
*temp_func
=
994 new func_type(freturn(the_func
), num_args
, FALSE
);
995 for (unsigned arg_num
= 0; arg_num
< num_args
; ++arg_num
)
996 temp_func
->set_arg_type(arg_num
, callee
[arg_num
]->type
);
997 printdecl(p
, temp_func
);
1002 /* qual - construct the type `op ty' where op is CONST or VOLATILE */
1003 extern type_node
*qual(int op
, type_node
*ty
)
1006 base_symtab
*the_symtab
= ty
->parent();
1007 assert(the_symtab
!= NULL
);
1009 type_ops suif_type_op
;
1011 suif_type_op
= TYPE_CONST
;
1012 else if (op
== VOLATILE
)
1013 suif_type_op
= TYPE_VOLATILE
;
1017 type_node
*new_type
;
1020 assert(ty
== ty
->unqual());
1021 assert(ty
->is_array());
1022 array_type
*old_array
= (array_type
*)ty
;
1023 new_type
= new array_type(qual(op
, old_array
->elem_type()),
1024 old_array
->lower_bound(),
1025 old_array
->upper_bound());
1027 else if (isfunc(ty
))
1029 warning("qualified function type ignored\n");
1032 else if ((isconst(ty
) && (op
== CONST
)) ||
1033 (isvolatile(ty
) && (op
== VOLATILE
)))
1035 error("illegal type `%k %t'\n", op
, ty
);
1040 new_type
= new modifier_type(suif_type_op
, ty
);
1043 return the_symtab
->install_type(new_type
);
1046 /* typestring - return ty as C declaration for str, which may be "" */
1047 extern const char *typestring(type_node
*ty
, const char *str
)
1050 const char *name
= NULL
;
1052 name
= chartype_sym
->name
;
1053 else if (ty
== doubletype
)
1054 name
= doubletype_sym
->name
;
1055 else if (ty
== floattype
)
1056 name
= floattype_sym
->name
;
1057 else if (ty
== inttype
)
1058 name
= inttype_sym
->name
;
1059 else if (ty
== longdouble
)
1060 name
= longdouble_sym
->name
;
1061 else if (ty
== longtype
)
1062 name
= longtype_sym
->name
;
1063 else if (ty
== longlong
)
1064 name
= longlong_sym
->name
;
1065 else if (ty
== shorttype
)
1066 name
= shorttype_sym
->name
;
1067 else if (ty
== signedchar
)
1068 name
= signedchar_sym
->name
;
1069 else if (ty
== unsignedchar
)
1070 name
= unsignedchar_sym
->name
;
1071 else if (ty
== unsignedlong
)
1072 name
= unsignedlong_sym
->name
;
1073 else if (ty
== unsignedlonglong
)
1074 name
= unsignedlonglong_sym
->name
;
1075 else if (ty
== unsignedshort
)
1076 name
= unsignedshort_sym
->name
;
1077 else if (ty
== unsignedtype
)
1078 name
= unsignedtype_sym
->name
;
1079 else if (ty
== voidtype
)
1080 name
= voidtype_sym
->name
;
1083 return ((*str
!= 0) ? stringf("%s %s", name
, str
) : name
);
1090 type_node
*unqualled
= ty
->unqual();
1092 if (ty
->is_volatile())
1093 quals
= stringf("%k %s", VOLATILE
, quals
);
1095 quals
= stringf("%k %s", CONST
, quals
);
1096 if (isptr(unqualled
))
1097 return typestring(unqualled
, stringf("%s%s", quals
, str
));
1099 return stringf("%s%s", quals
, typestring(unqualled
, str
));
1105 Symbol p
= findtype(ty
);
1108 return ((*str
!= 0) ?
1109 stringf("%s %s", p
->name
, str
) : p
->name
);
1114 if (ty
->op() == TYPE_ENUM
)
1116 enum_type
*the_enum
= (enum_type
*)ty
;
1117 name
= the_enum
->name();
1122 struct_type
*the_struct
= (struct_type
*)ty
;
1123 name
= the_struct
->name();
1124 op
= (ty
->op() == TYPE_STRUCT
) ? STRUCT
: UNION
;
1126 assert(name
!= NULL
);
1127 if ((*name
>= '1') && (*name
<= '9'))
1128 warning("unnamed %k in prototype\n", op
);
1131 return stringf("%k %s %s", op
, name
, str
);
1133 return stringf("%k %s", op
, name
);
1138 if ((base_from_pointer(ty
)->unqual()->size() !=
1139 target
.size
[C_char
]) &&
1140 ((p
= findtype(ty
)) != NULL
))
1142 return ((*str
!= 0) ?
1143 stringf("%s %s", p
->name
, str
) : p
->name
);
1145 type_node
*base_type
= base_from_pointer(ty
);
1146 str
= stringf((isarray(base_type
) || isfunc(base_type
)) ?
1147 "(*%s)" : "*%s", str
);
1148 return typestring(base_type
, str
);
1152 Symbol p
= findtype(ty
);
1155 return ((*str
!= 0) ?
1156 stringf("%s %s", p
->name
, str
) : p
->name
);
1159 func_type
*the_func
= (func_type
*)ty
;
1160 if (!the_func
->args_known())
1162 str
= stringf("%s()", str
);
1163 return typestring(the_func
->return_type(), str
);
1167 if (the_func
->num_args() == 0)
1169 if (the_func
->has_varargs())
1170 str
= stringf("%s(...)", str
);
1172 str
= stringf("%s(void)", str
);
1176 str
= stringf("%s(%s", str
,
1177 typestring(the_func
->arg_type(0), ""));
1178 unsigned num_args
= the_func
->num_args();
1179 for (unsigned arg_num
= 1; arg_num
< num_args
; ++arg_num
)
1181 str
= stringf("%s, %s", str
,
1182 typestring(the_func
->arg_type(arg_num
),
1185 if (the_func
->has_varargs())
1186 str
= stringf("%s, ...", str
);
1187 str
= stringf("%s)", str
);
1189 return typestring(the_func
->return_type(), str
);
1194 Symbol p
= findtype(ty
);
1197 return ((*str
!= 0) ?
1198 stringf("%s %s", p
->name
, str
) : p
->name
);
1201 array_type
*the_array
= (array_type
*)ty
;
1202 if (!the_array
->are_bounds_unknown())
1204 str
= stringf("%s[%d]", str
,
1205 the_array
->upper_bound().constant() + 1);
1206 return typestring(the_array
->elem_type(), str
);
1210 str
= stringf("%s[]", str
);
1211 return typestring(the_array
->elem_type(), str
);
1222 extern type_node
*base_from_enum(type_node
*the_type
)
1224 assert(the_type
!= NULL
);
1225 type_node
*unqualled
= the_type
->unqual();
1226 assert(unqualled
!= NULL
);
1227 assert(unqualled
->is_enum());
1228 enum_type
*the_enum
= (enum_type
*)unqualled
;
1229 boolean is_signed
= the_enum
->is_signed();
1230 int the_size
= the_enum
->size();
1233 if (the_size
== inttype
->size())
1235 if (the_size
== signedchar
->size())
1237 if (the_size
== shorttype
->size())
1239 if (the_size
== longtype
->size())
1241 if (the_size
== longlong
->size())
1246 if (the_size
== unsignedtype
->size())
1247 return unsignedtype
;
1248 if (the_size
== unsignedchar
->size())
1249 return unsignedchar
;
1250 if (the_size
== unsignedshort
->size())
1251 return unsignedshort
;
1252 if (the_size
== unsignedlong
->size())
1253 return unsignedlong
;
1254 if (the_size
== unsignedlonglong
->size())
1255 return unsignedlonglong
;
1258 base_symtab
*the_symtab
= the_type
->parent();
1259 assert(the_symtab
!= NULL
);
1260 type_node
*new_type
= new base_type(TYPE_INT
, the_size
, is_signed
);
1261 return the_symtab
->install_type(new_type
);
1264 extern type_node
*base_from_pointer(type_node
*the_type
)
1266 assert(the_type
!= NULL
);
1267 type_node
*unqualled
= the_type
->unqual();
1268 assert(unqualled
!= NULL
);
1269 assert(unqualled
->is_ptr());
1270 ptr_type
*the_pointer
= (ptr_type
*)unqualled
;
1271 return the_pointer
->ref_type();
1274 extern type_node
*base_from_array(type_node
*the_type
)
1276 assert(the_type
!= NULL
);
1277 type_node
*unqualled
= the_type
->unqual();
1278 assert(unqualled
!= NULL
);
1279 assert(unqualled
->is_array());
1280 array_type
*the_array
= (array_type
*)unqualled
;
1281 return the_array
->elem_type();
1286 * See ANSI/ISO 9899-1990, sections 6.1.2.6, 6.5.2, 6.5.3, and 6.5.4
1289 extern boolean
compatible_types(type_node
*type1
, type_node
*type2
)
1291 if (!identically_qualified(type1
, type2
))
1294 type_node
*t1
= type1
->unqual();
1295 type_node
*t2
= type2
->unqual();
1301 * ANSI/ISO 9899-1990, section 6.5.4.1, ``Semantics'', paragraph 2
1303 if (t2
->op() == TYPE_ENUM
)
1305 type_node
*temp_type
= t2
;
1318 if (t2
->op() != TYPE_PTR
)
1322 * ANSI/ISO 9899-1990, section 6.5.4.1, ``Semantics'',
1325 return (compatible_types(base_from_pointer(t1
),
1326 base_from_pointer(t2
)));
1330 if (t2
->op() != TYPE_ARRAY
)
1334 * ANSI/ISO 9899-1990, section 6.5.4.2, ``Semantics'',
1337 array_type
*array1
= (array_type
*)t1
;
1338 array_type
*array2
= (array_type
*)t2
;
1339 if ((!array1
->are_bounds_unknown()) &&
1340 (!array2
->are_bounds_unknown()))
1342 array_bound upper1
= array1
->upper_bound();
1343 array_bound upper2
= array2
->upper_bound();
1344 if (upper1
!= upper2
)
1347 return compatible_types(array1
->elem_type(), array2
->elem_type());
1351 if (t2
->op() != TYPE_FUNC
)
1355 * ANSI/ISO 9899-1990, sectifon 6.5.4.3, ``Semantics'',
1358 func_type
*function1
= (func_type
*)t1
;
1359 func_type
*function2
= (func_type
*)t2
;
1361 if (!compatible_types(function1
->return_type(),
1362 function2
->return_type()))
1367 if (!(function2
->args_known()))
1369 func_type
*temp_function
= function2
;
1370 function2
= function1
;
1371 function1
= temp_function
;
1374 if (function1
->args_known())
1376 if (function1
->has_varargs() != function2
->has_varargs())
1379 unsigned num_args
= function1
->num_args();
1380 if (function2
->num_args() != num_args
)
1383 for (unsigned arg_num
= 0; arg_num
< num_args
; ++arg_num
)
1385 type_node
*arg1
= function1
->arg_type(arg_num
);
1386 type_node
*arg2
= function2
->arg_type(arg_num
);
1387 if (!compatible_types(arg1
->unqual(), arg2
->unqual()))
1393 else if (function2
->args_known())
1395 if (function2
->has_varargs())
1398 unsigned num_args
= function2
->num_args();
1400 for (unsigned arg_num
= 0; arg_num
< num_args
; ++arg_num
)
1402 type_node
*arg
= function2
->arg_type(arg_num
);
1403 if (!compatible_types(arg
->unqual(),
1404 promote(arg
->unqual())))
1420 if (t1
->op() != t2
->op())
1423 boolean is_union
= (t1
->op() == TYPE_UNION
);
1425 struct_type
*struct1
= (struct_type
*)t1
;
1426 struct_type
*struct2
= (struct_type
*)t2
;
1428 unsigned num_fields
= struct1
->num_fields();
1429 if (struct2
->num_fields() != num_fields
)
1432 for (unsigned field_num
= 0; field_num
< num_fields
; ++field_num
)
1434 const char *name1
= struct1
->field_name(field_num
);
1435 type_node
*field1
= struct1
->field_type(field_num
);
1437 unsigned field_2_num
;
1440 field_2_num
= struct2
->find_field_by_name(name1
);
1441 if (field_2_num
== (unsigned)-1)
1446 field_2_num
= field_num
;
1449 if (strcmp(struct2
->field_name(field_2_num
), name1
) != 0)
1452 if (field_is_bit_fields(struct1
, field_num
))
1454 if (!field_is_bit_fields(struct2
, field_num
))
1456 if (!bit_field_annotations_same(
1457 struct2
->field_type(field_2_num
), field1
))
1464 if (field_is_bit_fields(struct2
, field_num
))
1466 if (!compatible_types(struct2
->field_type(field_2_num
),
1479 * ANSI/ISO 9899-1990, section 6.5.4.1, ``Semantics'',
1482 if (t2
->op() != TYPE_ENUM
)
1484 if (compatible_types(base_from_enum(t1
), t2
))
1488 warning("compatibility between `%t' and `%t' is "
1489 "compiler-dependent\n", t1
, t2
);
1496 enum_type
*enum1
= (enum_type
*)t1
;
1497 enum_type
*enum2
= (enum_type
*)t2
;
1499 unsigned num_values
= enum1
->num_values();
1500 if (enum2
->num_values() != num_values
)
1503 for (unsigned value_num
= 0; value_num
< num_values
; ++value_num
)
1505 const char *value_name
= enum1
->member(value_num
);
1506 int value_value
= enum1
->value(value_num
);
1507 int value_2_num
= enum2
->find_member_by_value(value_value
);
1508 if (value_2_num
== -1)
1510 if (strcmp(enum2
->member(value_2_num
), value_name
) != 0)
1512 if (enum2
->value(value_2_num
) != value_value
)
1523 static boolean
identically_qualified(type_node
*type1
, type_node
*type2
)
1525 return ((type1
->is_const() == type2
->is_const()) &&
1526 (type1
->is_volatile() == type2
->is_volatile()));
1529 static boolean
bit_field_annotations_same(type_node
*field1
,
1532 immed_list
*list1
= (immed_list
*)(field1
->peek_annote(k_bit_field_info
));
1533 immed_list
*list2
= (immed_list
*)(field2
->peek_annote(k_bit_field_info
));
1534 if ((list1
== NULL
) && (list2
== NULL
))
1536 if ((list1
== NULL
) || (list2
== NULL
))
1538 immed_list_iter
iter1(list1
);
1539 immed_list_iter
iter2(list2
);
1540 while ((!iter1
.is_empty()) && (!iter2
.is_empty()))
1542 immed value1
= iter1
.step();
1543 immed value2
= iter2
.step();
1544 if (value1
!= value2
)
1547 return (iter1
.is_empty() == iter2
.is_empty());
1550 extern array_type
*make_array(type_node
*element_type
)
1552 assert(element_type
!= NULL
);
1553 base_symtab
*the_symtab
= element_type
->parent();
1554 assert(the_symtab
!= NULL
);
1555 array_type
*new_type
= new array_type(element_type
, array_bound(0));
1556 return (array_type
*)(the_symtab
->install_type(new_type
));
1559 extern boolean
has_constant_in_fields(type_node
*the_type
)
1561 if (the_type
->is_const())
1564 type_node
*unqualled
= the_type
->unqual();
1565 if (!unqualled
->is_struct())
1568 struct_type
*the_struct
= (struct_type
*)unqualled
;
1569 int num_fields
= the_struct
->num_fields();
1570 for (int field_num
= 0; field_num
< num_fields
; ++field_num
)
1572 if (has_constant_in_fields(the_struct
->field_type(field_num
)))
1578 extern type_node
*create_function_type(type_node
*return_type
,
1579 type_node
**arguments
)
1581 assert(return_type
!= NULL
);
1583 func_type
*result
= new func_type(return_type
);
1584 if (arguments
== NULL
)
1586 result
->set_args_unknown();
1590 result
->set_args_known();
1591 unsigned num_args
= 0;
1592 type_node
**current_arg
= arguments
;
1593 while (*current_arg
!= NULL
)
1595 if (*current_arg
== voidtype
)
1598 result
->set_varargs(TRUE
);
1604 result
->set_num_args(num_args
);
1605 for (unsigned arg_num
= 0; arg_num
< num_args
; ++arg_num
)
1606 result
->set_arg_type(arg_num
, arguments
[arg_num
]);
1612 extern boolean
field_is_bit_fields(struct_type
*the_struct
,
1615 assert(the_struct
!= NULL
);
1616 assert(the_struct
->num_fields() > field_num
);
1617 type_node
*field_type
= the_struct
->field_type(field_num
);
1618 assert(field_type
!= NULL
);
1619 return (field_type
->peek_annote(k_bit_field_info
) != NULL
);
1622 extern struct field
*bit_field_list(struct_type
*the_struct
,
1625 assert(the_struct
!= NULL
);
1626 assert(the_struct
->num_fields() > field_num
);
1627 type_node
*field_type
= the_struct
->field_type(field_num
);
1628 assert(field_type
!= NULL
);
1630 immed_list
*descriptor
=
1631 (immed_list
*)(field_type
->peek_annote(k_bit_field_info
));
1632 if (descriptor
== NULL
)
1635 struct field
*result
= NULL
;
1636 struct field
**next_position
= &result
;
1637 immed_list_iter
the_iter(descriptor
);
1638 while (!the_iter
.is_empty())
1640 #ifndef DEAL_WITH_GCC_BRAIN_DAMAGE
1641 *next_position
= new struct field
;
1644 // gcc version 2.6.3 gets a parse error on the code above. The code
1645 // looks like it should be perfectly legal, and both gcc 2.5.8 and
1646 // the IRIX 5.3 C++ compiler have no problem with it, so I'm inclined
1647 // to think the problem is caused by brain damage in the g++
1648 // front-end. A work-around follows.
1650 *next_position
= (struct field
*)operator new(sizeof(struct field
));
1653 immed type_value
= the_iter
.step();
1654 assert(type_value
.is_string());
1655 const char *type_string
= type_value
.string();
1656 boolean is_volatile
= FALSE
;
1657 boolean is_constant
= FALSE
;
1659 if (strcmp(type_string
, "volatile") == 0)
1662 assert(!the_iter
.is_empty());
1663 type_value
= the_iter
.step();
1664 assert(type_value
.is_string());
1665 type_string
= type_value
.string();
1668 if (strcmp(type_string
, "const") == 0)
1671 assert(!the_iter
.is_empty());
1672 type_value
= the_iter
.step();
1673 assert(type_value
.is_string());
1674 type_string
= type_value
.string();
1677 if (strcmp(type_string
, "int") == 0)
1678 (*next_position
)->type
= inttype
;
1679 else if (strcmp(type_string
, "unsigned") == 0)
1680 (*next_position
)->type
= unsignedtype
;
1684 assert(!the_iter
.is_empty());
1685 immed name_value
= the_iter
.step();
1686 assert(name_value
.is_string());
1687 (*next_position
)->name
= name_value
.string();
1689 assert(!the_iter
.is_empty());
1690 immed from_value
= the_iter
.step();
1691 assert(from_value
.is_integer());
1692 (*next_position
)->from
= from_value
.integer();
1694 assert(!the_iter
.is_empty());
1695 immed to_value
= the_iter
.step();
1696 assert(to_value
.is_integer());
1697 (*next_position
)->to
= to_value
.integer();
1699 (*next_position
)->offset
= 0;
1700 (*next_position
)->link
= NULL
;
1702 next_position
= &((*next_position
)->link
);
1707 extern Table
get_field_table(struct_type
*the_struct
)
1709 assert(the_struct
!= NULL
);
1710 return (Table
)(the_struct
->peek_annote(k_field_table
));
1713 extern void set_field_table(struct_type
*the_struct
, Table new_table
)
1715 assert(the_struct
!= NULL
);
1716 the_struct
->append_annote(k_field_table
, new_table
);
1720 * This function expects an integer or pointer type and returns an unsigned
1721 * integer type of the same size.
1723 extern type_node
*unsigned_int_version(type_node
*original_type
)
1725 if (original_type
->op() == TYPE_INT
)
1727 base_type
*the_base
= (base_type
*)original_type
;
1728 if (!the_base
->is_signed())
1729 return original_type
;
1731 else if (original_type
->op() != TYPE_PTR
)
1733 return original_type
;
1735 type_node
*new_type
= new base_type(TYPE_INT
,
1736 original_type
->size(), FALSE
);
1737 return original_type
->parent()->install_type(new_type
);
1740 static void use_field(struct_type
*the_struct
, char *name
)
1744 Table field_table
= get_field_table(the_struct
);
1745 assert(field_table
!= NULL
);
1746 Symbol q
= lookup(name
, field_table
);
1752 static Coordinate
*get_source(type_node
*the_type
)
1754 assert(the_type
!= NULL
);
1755 immed_list
*immeds
=
1756 (immed_list
*)(the_type
->peek_annote(k_type_source_coordinates
));
1757 return immeds_to_coordinate(immeds
);
1760 static void set_source(type_node
*the_type
, Coordinate source
)
1762 assert(the_type
!= NULL
);
1763 immed_list
*immeds
= coordinate_to_immeds(source
);
1764 the_type
->append_annote(k_type_source_coordinates
, immeds
);