6 static struct obstack _type_obst;
7 struct obstack *type_obst = &_type_obst;
11 obstack_init(type_obst);
16 obstack_free(type_obst, NULL);
20 void print_type_qualifiers(FILE *out, const type_t *type)
22 unsigned qualifiers = type->qualifiers;
23 if(qualifiers & TYPE_QUALIFIER_CONST) {
26 if(qualifiers & TYPE_QUALIFIER_VOLATILE) {
27 fputs("volatile ", out);
29 if(qualifiers & TYPE_QUALIFIER_RESTRICT) {
30 fputs("restrict ", out);
32 if(qualifiers & TYPE_QUALIFIER_INLINE) {
33 fputs("inline ", out);
38 void print_atomic_type(FILE *out, const atomic_type_t *type)
40 print_type_qualifiers(out, & type->type);
43 case ATOMIC_TYPE_INVALID: fputs("INVALIDATOMIC", out); break;
44 case ATOMIC_TYPE_BOOL: fputs("bool", out); break;
45 case ATOMIC_TYPE_CHAR: fputs("char", out); break;
46 case ATOMIC_TYPE_SCHAR: fputs("signed char", out); break;
47 case ATOMIC_TYPE_UCHAR: fputs("unsigned char", out); break;
48 case ATOMIC_TYPE_INT: fputs("int", out); break;
49 case ATOMIC_TYPE_UINT: fputs("unsigned int", out); break;
50 case ATOMIC_TYPE_SHORT: fputs("short", out); break;
51 case ATOMIC_TYPE_USHORT: fputs("unsigned short", out); break;
52 case ATOMIC_TYPE_LONG: fputs("long", out); break;
53 case ATOMIC_TYPE_ULONG: fputs("unsigned long", out); break;
54 case ATOMIC_TYPE_LONGLONG: fputs("long long", out); break;
55 case ATOMIC_TYPE_ULONGLONG: fputs("unsigned long long", out); break;
56 case ATOMIC_TYPE_FLOAT: fputs("float", out); break;
57 case ATOMIC_TYPE_DOUBLE: fputs("double", out); break;
58 default: fputs("UNKNOWNATOMIC", out); break;
63 void print_method_type(FILE *out, const method_type_t *type)
65 print_type_qualifiers(out, & type->type);
68 print_type(out, type->result_type);
71 if(type->abi_style != NULL) {
72 fprintf(out, "\"%s\" ", type->abi_style);
74 fputs("method(", out);
75 method_parameter_type_t *param_type = type->parameter_types;
77 while(param_type != NULL) {
83 print_type(out, param_type->type);
84 param_type = param_type->next;
90 void print_pointer_type(FILE *out, const pointer_type_t *type)
92 print_type(out, type->points_to);
94 print_type_qualifiers(out, &type->type);
97 void print_type(FILE *out, const type_t *type)
100 fputs("nil type", out);
106 fputs("invalid", out);
109 print_type_qualifiers(out, type);
113 print_atomic_type(out, (const atomic_type_t*) type);
115 case TYPE_COMPOUND_STRUCT:
116 case TYPE_COMPOUND_UNION:
117 print_type_qualifiers(out, type);
118 if(((const compound_type_t*) type)->symbol != NULL) {
119 fprintf(out, "%s", ((const compound_type_t*) type)->symbol->string);
123 print_method_type(out, (const method_type_t*) type);
126 print_pointer_type(out, (const pointer_type_t*) type);
129 fputs("unknown", out);
132 int type_valid(const type_t *type)
134 return type->type != TYPE_INVALID;
137 int is_type_int(const type_t *type)
139 if(type->type != TYPE_ATOMIC)
142 atomic_type_t *atomic_type = (atomic_type_t*) type;
143 switch(atomic_type->atype) {
144 case ATOMIC_TYPE_CHAR:
145 case ATOMIC_TYPE_SCHAR:
146 case ATOMIC_TYPE_UCHAR:
147 case ATOMIC_TYPE_SHORT:
148 case ATOMIC_TYPE_USHORT:
149 case ATOMIC_TYPE_INT:
150 case ATOMIC_TYPE_UINT:
151 case ATOMIC_TYPE_LONG:
152 case ATOMIC_TYPE_ULONG:
153 case ATOMIC_TYPE_LONGLONG:
154 case ATOMIC_TYPE_ULONGLONG:
161 static __attribute__((unused))
162 void dbg_type(const type_t *type)
164 print_type(stdout,type);