6 static struct obstack _type_obst;
7 struct obstack *type_obst = &_type_obst;
10 static void intern_print_type_pre(const type_t *type);
11 static void intern_print_type_post(const type_t *type);
15 obstack_init(type_obst);
20 obstack_free(type_obst, NULL);
23 void type_set_output(FILE *stream)
29 void print_type_qualifiers(unsigned qualifiers)
31 if(qualifiers & TYPE_QUALIFIER_CONST) {
34 if(qualifiers & TYPE_QUALIFIER_VOLATILE) {
35 fputs("volatile ", out);
37 if(qualifiers & TYPE_QUALIFIER_RESTRICT) {
38 fputs("restrict ", out);
40 if(qualifiers & TYPE_QUALIFIER_INLINE) {
41 fputs("inline ", out);
46 void print_atomic_type(const atomic_type_t *type)
48 print_type_qualifiers(type->type.qualifiers);
51 case ATOMIC_TYPE_INVALID: fputs("INVALIDATOMIC", out); return;
52 case ATOMIC_TYPE_VOID: fputs("void", out); return;
53 case ATOMIC_TYPE_BOOL: fputs("bool", out); return;
54 case ATOMIC_TYPE_CHAR: fputs("char", out); return;
55 case ATOMIC_TYPE_SCHAR: fputs("signed char", out); return;
56 case ATOMIC_TYPE_UCHAR: fputs("unsigned char", out); return;
57 case ATOMIC_TYPE_INT: fputs("int", out); return;
58 case ATOMIC_TYPE_UINT: fputs("unsigned int", out); return;
59 case ATOMIC_TYPE_SHORT: fputs("short", out); return;
60 case ATOMIC_TYPE_USHORT: fputs("unsigned short", out); return;
61 case ATOMIC_TYPE_LONG: fputs("long", out); return;
62 case ATOMIC_TYPE_ULONG: fputs("unsigned long", out); return;
63 case ATOMIC_TYPE_LONGLONG: fputs("long long", out); return;
64 case ATOMIC_TYPE_ULONGLONG: fputs("unsigned long long", out); return;
65 case ATOMIC_TYPE_LONG_DOUBLE: fputs("long double", out); return;
66 case ATOMIC_TYPE_FLOAT: fputs("float", out); return;
67 case ATOMIC_TYPE_DOUBLE: fputs("double", out); return;
69 fputs("UNKNOWNATOMIC", out);
73 void print_method_type_pre(const method_type_t *type)
75 print_type_qualifiers(type->type.qualifiers);
77 intern_print_type_pre(type->result_type);
79 /* TODO: don't emit braces if we're the toplevel type... */
84 void print_method_type_post(const method_type_t *type)
86 /* TODO: don't emit braces if we're the toplevel type... */
87 intern_print_type_post(type->result_type);
92 declaration_t *parameter = type->parameters;
94 for( ; parameter != NULL; parameter = parameter->next) {
100 print_type(parameter->type, parameter->symbol);
110 if(first && !type->unspecified_parameters) {
117 void print_pointer_type_pre(const pointer_type_t *type)
119 intern_print_type_pre(type->points_to);
121 print_type_qualifiers(type->type.qualifiers);
125 void print_pointer_type_post(const pointer_type_t *type)
127 intern_print_type_post(type->points_to);
131 void print_type_enum(const enum_type_t *type)
133 print_type_qualifiers(type->type.qualifiers);
134 if(type->symbol != NULL) {
135 fprintf(out, "enum %s", type->symbol->string);
137 fprintf(out, "enum {\n");
139 enum_entry_t *entry = type->entries;
140 for( ; entry != NULL; entry = entry->next) {
141 fprintf(out, "\t%s", entry->symbol->string);
142 if(entry->value != NULL) {
144 print_expression(entry->value);
154 void intern_print_type_pre(const type_t *type)
158 fputs("invalid", out);
161 print_type_enum((const enum_type_t*) type);
164 print_atomic_type((const atomic_type_t*) type);
166 case TYPE_COMPOUND_STRUCT:
167 case TYPE_COMPOUND_UNION:
168 print_type_qualifiers(type->qualifiers);
169 if(((const compound_type_t*) type)->symbol != NULL) {
170 fprintf(out, "%s", ((const compound_type_t*) type)->symbol->string);
174 fputs(((builtin_type_t*) type)->symbol->string, out);
177 print_method_type_pre((const method_type_t*) type);
180 print_pointer_type_pre((const pointer_type_t*) type);
183 fputs("unknown", out);
187 void intern_print_type_post(const type_t *type)
191 print_method_type_post((const method_type_t*) type);
194 print_pointer_type_post((const pointer_type_t*) type);
199 case TYPE_COMPOUND_STRUCT:
200 case TYPE_COMPOUND_UNION:
206 void print_type(const type_t *type, const symbol_t *symbol)
209 fputs("nil type", out);
213 intern_print_type_pre(type);
216 fputs(symbol->string, out);
218 intern_print_type_post(type);
221 int type_valid(const type_t *type)
223 return type->type != TYPE_INVALID;
226 int is_type_int(const type_t *type)
228 if(type->type != TYPE_ATOMIC)
231 atomic_type_t *atomic_type = (atomic_type_t*) type;
232 switch(atomic_type->atype) {
233 case ATOMIC_TYPE_CHAR:
234 case ATOMIC_TYPE_SCHAR:
235 case ATOMIC_TYPE_UCHAR:
236 case ATOMIC_TYPE_SHORT:
237 case ATOMIC_TYPE_USHORT:
238 case ATOMIC_TYPE_INT:
239 case ATOMIC_TYPE_UINT:
240 case ATOMIC_TYPE_LONG:
241 case ATOMIC_TYPE_ULONG:
242 case ATOMIC_TYPE_LONGLONG:
243 case ATOMIC_TYPE_ULONGLONG:
250 static __attribute__((unused))
251 void dbg_type(const type_t *type)
255 print_type(type, NULL);