- create an error type
[cparser] / type.c
1 #include <config.h>
2
3 #include <stdio.h>
4 #include <assert.h>
5 #include "type_t.h"
6 #include "type_hash.h"
7 #include "adt/error.h"
8
9 static struct obstack   _type_obst;
10 struct obstack         *type_obst = &_type_obst;
11 static FILE            *out;
12 static int              type_visited = 0;
13
14 static void intern_print_type_pre(const type_t *type, bool top);
15 static void intern_print_type_post(const type_t *type, bool top);
16
17 void init_types(void)
18 {
19         obstack_init(type_obst);
20 }
21
22 void exit_types(void)
23 {
24         obstack_free(type_obst, NULL);
25 }
26
27 void type_set_output(FILE *stream)
28 {
29         out = stream;
30 }
31
32 void inc_type_visited(void)
33 {
34         type_visited++;
35 }
36
37 void print_type_qualifiers(type_qualifiers_t qualifiers)
38 {
39         if(qualifiers & TYPE_QUALIFIER_CONST)    fputs("const ",    out);
40         if(qualifiers & TYPE_QUALIFIER_VOLATILE) fputs("volatile ", out);
41         if(qualifiers & TYPE_QUALIFIER_RESTRICT) fputs("restrict ", out);
42 }
43
44 static
45 void print_atomic_type(const atomic_type_t *type)
46 {
47         print_type_qualifiers(type->type.qualifiers);
48
49         const char *s;
50         switch(type->akind) {
51         case ATOMIC_TYPE_INVALID:     s = "INVALIDATOMIC";      break;
52         case ATOMIC_TYPE_VOID:        s = "void";               break;
53         case ATOMIC_TYPE_BOOL:        s = "_Bool";              break;
54         case ATOMIC_TYPE_CHAR:        s = "char";               break;
55         case ATOMIC_TYPE_SCHAR:       s = "signed char";        break;
56         case ATOMIC_TYPE_UCHAR:       s = "unsigned char";      break;
57         case ATOMIC_TYPE_INT:         s = "int";                break;
58         case ATOMIC_TYPE_UINT:        s = "unsigned int";       break;
59         case ATOMIC_TYPE_SHORT:       s = "short";              break;
60         case ATOMIC_TYPE_USHORT:      s = "unsigned short";     break;
61         case ATOMIC_TYPE_LONG:        s = "long";               break;
62         case ATOMIC_TYPE_ULONG:       s = "unsigned long";      break;
63         case ATOMIC_TYPE_LONGLONG:    s = "long long";          break;
64         case ATOMIC_TYPE_ULONGLONG:   s = "unsigned long long"; break;
65         case ATOMIC_TYPE_LONG_DOUBLE: s = "long double";        break;
66         case ATOMIC_TYPE_FLOAT:       s = "float";              break;
67         case ATOMIC_TYPE_DOUBLE:      s = "double";             break;
68         default:                      s = "UNKNOWNATOMIC";      break;
69         }
70         fputs(s, out);
71 }
72
73 static void print_function_type_pre(const function_type_t *type, bool top)
74 {
75         print_type_qualifiers(type->type.qualifiers);
76
77         intern_print_type_pre(type->return_type, false);
78
79         /* don't emit braces if we're the toplevel type... */
80         if(!top)
81                 fputc('(', out);
82 }
83
84 static void print_function_type_post(const function_type_t *type,
85                                      const context_t *context, bool top)
86 {
87         intern_print_type_post(type->return_type, false);
88         /* don't emit braces if we're the toplevel type... */
89         if(!top)
90                 fputc(')', out);
91
92         fputc('(', out);
93
94         int                 first     = 1;
95         if(context == NULL) {
96                 function_parameter_t *parameter = type->parameters;
97                 for( ; parameter != NULL; parameter = parameter->next) {
98                         if(first) {
99                                 first = 0;
100                         } else {
101                                 fputs(", ", out);
102                         }
103                         print_type(parameter->type);
104                 }
105         } else {
106                 declaration_t *parameter = context->declarations;
107                 for( ; parameter != NULL; parameter = parameter->next) {
108                         if(first) {
109                                 first = 0;
110                         } else {
111                                 fputs(", ", out);
112                         }
113                         print_type_ext(parameter->type, parameter->symbol,
114                                        &parameter->context);
115                 }
116         }
117         if(type->variadic) {
118                 if(first) {
119                         first = 0;
120                 } else {
121                         fputs(", ", out);
122                 }
123                 fputs("...", out);
124         }
125         if(first && !type->unspecified_parameters) {
126                 fputs("void", out);
127         }
128         fputc(')', out);
129 }
130
131 static void print_pointer_type_pre(const pointer_type_t *type)
132 {
133         intern_print_type_pre(type->points_to, false);
134         fputs("*", out);
135         print_type_qualifiers(type->type.qualifiers);
136 }
137
138 static void print_pointer_type_post(const pointer_type_t *type)
139 {
140         intern_print_type_post(type->points_to, false);
141 }
142
143 static void print_array_type_pre(const array_type_t *type)
144 {
145         intern_print_type_pre(type->element_type, false);
146 }
147
148 static void print_array_type_post(const array_type_t *type)
149 {
150         fputc('[', out);
151         if(type->is_static) {
152                 fputs("static ", out);
153         }
154         print_type_qualifiers(type->type.qualifiers);
155         if(type->size != NULL) {
156                 print_expression(type->size);
157         }
158         fputc(']', out);
159         intern_print_type_post(type->element_type, false);
160 }
161
162 static void print_bitfield_type_post(const bitfield_type_t *type)
163 {
164         fputs(" : ", out);
165         print_expression(type->size);
166         intern_print_type_post(type->base, false);
167 }
168
169 void print_enum_definition(const declaration_t *declaration)
170 {
171         fputs("{\n", out);
172
173         change_indent(1);
174
175         declaration_t *entry = declaration->next;
176         for( ; entry != NULL && entry->storage_class == STORAGE_CLASS_ENUM_ENTRY;
177                entry = entry->next) {
178
179                 print_indent();
180                 fprintf(out, "%s", entry->symbol->string);
181                 if(entry->init.initializer != NULL) {
182                         fprintf(out, " = ");
183                         print_expression(entry->init.enum_value);
184                 }
185                 fprintf(out, ",\n");
186         }
187
188         change_indent(-1);
189         print_indent();
190         fputs("}", out);
191 }
192
193 static void print_type_enum(const enum_type_t *type)
194 {
195         print_type_qualifiers(type->type.qualifiers);
196         fputs("enum ", out);
197
198         declaration_t *declaration = type->declaration;
199         symbol_t      *symbol      = declaration->symbol;
200         if(symbol != NULL) {
201                 fputs(symbol->string, out);
202         } else {
203                 print_enum_definition(declaration);
204         }
205 }
206
207 void print_compound_definition(const declaration_t *declaration)
208 {
209         fputs("{\n", out);
210         change_indent(1);
211
212         declaration_t *iter = declaration->context.declarations;
213         for( ; iter != NULL; iter = iter->next) {
214                 print_indent();
215                 print_declaration(iter);
216                 fputc('\n', out);
217         }
218
219         change_indent(-1);
220         print_indent();
221         fputs("}", out);
222 }
223
224 static void print_compound_type(const compound_type_t *type)
225 {
226         print_type_qualifiers(type->type.qualifiers);
227
228         if(type->type.kind == TYPE_COMPOUND_STRUCT) {
229                 fputs("struct ", out);
230         } else {
231                 assert(type->type.kind == TYPE_COMPOUND_UNION);
232                 fputs("union ", out);
233         }
234
235         declaration_t *declaration = type->declaration;
236         symbol_t      *symbol      = declaration->symbol;
237         if(symbol != NULL) {
238                 fputs(symbol->string, out);
239         } else {
240                 print_compound_definition(declaration);
241         }
242 }
243
244 static void print_typedef_type_pre(const typedef_type_t *const type)
245 {
246         print_type_qualifiers(type->type.qualifiers);
247         fputs(type->declaration->symbol->string, out);
248 }
249
250 static void print_typeof_type_pre(const typeof_type_t *const type)
251 {
252         fputs("typeof(", out);
253         if(type->expression != NULL) {
254                 assert(type->typeof_type == NULL);
255                 print_expression(type->expression);
256         } else {
257                 print_type(type->typeof_type);
258         }
259         fputc(')', out);
260 }
261
262 static void intern_print_type_pre(const type_t *const type, const bool top)
263 {
264         switch(type->kind) {
265         case TYPE_ERROR:
266                 fputs("<error>", out);
267         case TYPE_INVALID:
268                 fputs("<invalid>", out);
269                 return;
270         case TYPE_ENUM:
271                 print_type_enum(&type->enumt);
272                 return;
273         case TYPE_ATOMIC:
274                 print_atomic_type(&type->atomic);
275                 return;
276         case TYPE_COMPOUND_STRUCT:
277         case TYPE_COMPOUND_UNION:
278                 print_compound_type(&type->compound);
279                 return;
280         case TYPE_BUILTIN:
281                 fputs(type->builtin.symbol->string, out);
282                 return;
283         case TYPE_FUNCTION:
284                 print_function_type_pre(&type->function, top);
285                 return;
286         case TYPE_POINTER:
287                 print_pointer_type_pre(&type->pointer);
288                 return;
289         case TYPE_BITFIELD:
290                 intern_print_type_pre(type->bitfield.base, top);
291                 return;
292         case TYPE_ARRAY:
293                 print_array_type_pre(&type->array);
294                 return;
295         case TYPE_TYPEDEF:
296                 print_typedef_type_pre(&type->typedeft);
297                 return;
298         case TYPE_TYPEOF:
299                 print_typeof_type_pre(&type->typeoft);
300                 return;
301         }
302         fputs("unknown", out);
303 }
304
305 static void intern_print_type_post(const type_t *const type, const bool top)
306 {
307         switch(type->kind) {
308         case TYPE_FUNCTION:
309                 print_function_type_post(&type->function, NULL, top);
310                 return;
311         case TYPE_POINTER:
312                 print_pointer_type_post(&type->pointer);
313                 return;
314         case TYPE_ARRAY:
315                 print_array_type_post(&type->array);
316                 return;
317         case TYPE_BITFIELD:
318                 print_bitfield_type_post(&type->bitfield);
319                 return;
320         case TYPE_ERROR:
321         case TYPE_INVALID:
322         case TYPE_ATOMIC:
323         case TYPE_ENUM:
324         case TYPE_COMPOUND_STRUCT:
325         case TYPE_COMPOUND_UNION:
326         case TYPE_BUILTIN:
327         case TYPE_TYPEOF:
328         case TYPE_TYPEDEF:
329                 break;
330         }
331 }
332
333 void print_type(const type_t *const type)
334 {
335         print_type_ext(type, NULL, NULL);
336 }
337
338 void print_type_ext(const type_t *const type, const symbol_t *symbol,
339                     const context_t *context)
340 {
341         if(type == NULL) {
342                 fputs("nil type", out);
343                 return;
344         }
345
346         intern_print_type_pre(type, true);
347         if(symbol != NULL) {
348                 fputc(' ', out);
349                 fputs(symbol->string, out);
350         }
351         if(type->kind == TYPE_FUNCTION) {
352                 print_function_type_post(&type->function, context, true);
353         } else {
354                 intern_print_type_post(type, true);
355         }
356 }
357
358 static size_t get_type_size(type_t *type)
359 {
360         switch(type->kind) {
361         case TYPE_ATOMIC:          return sizeof(atomic_type_t);
362         case TYPE_COMPOUND_STRUCT:
363         case TYPE_COMPOUND_UNION:  return sizeof(compound_type_t);
364         case TYPE_ENUM:            return sizeof(enum_type_t);
365         case TYPE_FUNCTION:        return sizeof(function_type_t);
366         case TYPE_POINTER:         return sizeof(pointer_type_t);
367         case TYPE_ARRAY:           return sizeof(array_type_t);
368         case TYPE_BUILTIN:         return sizeof(builtin_type_t);
369         case TYPE_TYPEDEF:         return sizeof(typedef_type_t);
370         case TYPE_TYPEOF:          return sizeof(typeof_type_t);
371         case TYPE_BITFIELD:        return sizeof(bitfield_type_t);
372         case TYPE_ERROR:           panic("error type found");
373         case TYPE_INVALID:         panic("invalid type found");
374         }
375         panic("unknown type found");
376 }
377
378 /**
379  * duplicates a type
380  * note that this does not produce a deep copy!
381  */
382 type_t *duplicate_type(type_t *type)
383 {
384         size_t size = get_type_size(type);
385
386         type_t *copy = obstack_alloc(type_obst, size);
387         memcpy(copy, type, size);
388
389         return copy;
390 }
391
392 type_t *get_unqualified_type(type_t *type)
393 {
394         if(type->base.qualifiers == TYPE_QUALIFIER_NONE)
395                 return type;
396
397         type_t *unqualified_type          = duplicate_type(type);
398         unqualified_type->base.qualifiers = TYPE_QUALIFIER_NONE;
399
400         type_t *result = typehash_insert(unqualified_type);
401         if(result != unqualified_type) {
402                 obstack_free(type_obst, unqualified_type);
403         }
404
405         return result;
406 }
407
408 bool type_valid(const type_t *type)
409 {
410         return type->kind != TYPE_INVALID;
411 }
412
413 bool is_type_integer(const type_t *type)
414 {
415         assert(!is_typeref(type));
416
417         if(type->kind == TYPE_ENUM)
418                 return true;
419
420         if(type->kind != TYPE_ATOMIC)
421                 return false;
422
423         switch(type->atomic.akind) {
424         case ATOMIC_TYPE_BOOL:
425         case ATOMIC_TYPE_CHAR:
426         case ATOMIC_TYPE_SCHAR:
427         case ATOMIC_TYPE_UCHAR:
428         case ATOMIC_TYPE_SHORT:
429         case ATOMIC_TYPE_USHORT:
430         case ATOMIC_TYPE_INT:
431         case ATOMIC_TYPE_UINT:
432         case ATOMIC_TYPE_LONG:
433         case ATOMIC_TYPE_ULONG:
434         case ATOMIC_TYPE_LONGLONG:
435         case ATOMIC_TYPE_ULONGLONG:
436                 return true;
437         default:
438                 return false;
439         }
440 }
441
442 bool is_type_floating(const type_t *type)
443 {
444         assert(!is_typeref(type));
445
446         if(type->kind != TYPE_ATOMIC)
447                 return false;
448
449         switch(type->atomic.akind) {
450         case ATOMIC_TYPE_FLOAT:
451         case ATOMIC_TYPE_DOUBLE:
452         case ATOMIC_TYPE_LONG_DOUBLE:
453 #ifdef PROVIDE_COMPLEX
454         case ATOMIC_TYPE_FLOAT_COMPLEX:
455         case ATOMIC_TYPE_DOUBLE_COMPLEX:
456         case ATOMIC_TYPE_LONG_DOUBLE_COMPLEX:
457         case ATOMIC_TYPE_FLOAT_IMAGINARY:
458         case ATOMIC_TYPE_DOUBLE_IMAGINARY:
459         case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY:
460 #endif
461                 return true;
462         default:
463                 return false;
464         }
465 }
466
467 bool is_type_signed(const type_t *type)
468 {
469         assert(!is_typeref(type));
470
471         /* enum types are int for now */
472         if(type->kind == TYPE_ENUM)
473                 return true;
474
475         if(type->kind != TYPE_ATOMIC)
476                 return false;
477
478         switch(type->atomic.akind) {
479         case ATOMIC_TYPE_CHAR:
480         case ATOMIC_TYPE_SCHAR:
481         case ATOMIC_TYPE_SHORT:
482         case ATOMIC_TYPE_INT:
483         case ATOMIC_TYPE_LONG:
484         case ATOMIC_TYPE_LONGLONG:
485         case ATOMIC_TYPE_FLOAT:
486         case ATOMIC_TYPE_DOUBLE:
487         case ATOMIC_TYPE_LONG_DOUBLE:
488 #ifdef PROVIDE_COMPLEX
489         case ATOMIC_TYPE_FLOAT_COMPLEX:
490         case ATOMIC_TYPE_DOUBLE_COMPLEX:
491         case ATOMIC_TYPE_LONG_DOUBLE_COMPLEX:
492         case ATOMIC_TYPE_FLOAT_IMAGINARY:
493         case ATOMIC_TYPE_DOUBLE_IMAGINARY:
494         case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY:
495 #endif
496                 return true;
497
498         case ATOMIC_TYPE_BOOL:
499         case ATOMIC_TYPE_UCHAR:
500         case ATOMIC_TYPE_USHORT:
501         case ATOMIC_TYPE_UINT:
502         case ATOMIC_TYPE_ULONG:
503         case ATOMIC_TYPE_ULONGLONG:
504                 return false;
505
506         case ATOMIC_TYPE_VOID:
507         case ATOMIC_TYPE_INVALID:
508         case ATOMIC_TYPE_LAST:
509                 return false;
510         }
511
512         panic("invalid atomic type found");
513         return false;
514 }
515
516 bool is_type_arithmetic(const type_t *type)
517 {
518         assert(!is_typeref(type));
519
520         if(type->kind == TYPE_BITFIELD)
521                 return true;
522
523         if(is_type_integer(type) || is_type_floating(type))
524                 return true;
525
526         return false;
527 }
528
529 bool is_type_scalar(const type_t *type)
530 {
531         assert(!is_typeref(type));
532
533         switch (type->kind) {
534                 case TYPE_POINTER: return true;
535                 case TYPE_BUILTIN: return is_type_scalar(type->builtin.real_type);
536                 default:            break;
537         }
538
539         return is_type_arithmetic(type);
540 }
541
542 bool is_type_incomplete(const type_t *type)
543 {
544         assert(!is_typeref(type));
545
546         switch(type->kind) {
547         case TYPE_COMPOUND_STRUCT:
548         case TYPE_COMPOUND_UNION: {
549                 const compound_type_t *compound_type = &type->compound;
550                 declaration_t         *declaration   = compound_type->declaration;
551                 return !declaration->init.is_defined;
552         }
553         case TYPE_BITFIELD:
554         case TYPE_FUNCTION:
555                 return true;
556
557         case TYPE_ARRAY:
558                 return type->array.size == NULL;
559
560         case TYPE_ATOMIC:
561                 return type->atomic.akind == ATOMIC_TYPE_VOID;
562
563         case TYPE_POINTER:
564         case TYPE_ENUM:
565         case TYPE_BUILTIN:
566                 return false;
567
568         case TYPE_TYPEDEF:
569         case TYPE_TYPEOF:
570                 panic("is_type_incomplete called without typerefs skipped");
571         case TYPE_ERROR:
572                 panic("error type found");
573         case TYPE_INVALID:
574                 break;
575         }
576
577         panic("invalid type found");
578 }
579
580 static bool function_types_compatible(const function_type_t *func1,
581                                       const function_type_t *func2)
582 {
583         const type_t* const ret1 = skip_typeref(func1->return_type);
584         const type_t* const ret2 = skip_typeref(func2->return_type);
585         if (!types_compatible(ret1, ret2))
586                 return false;
587
588         /* can parameters be compared? */
589         if(func1->unspecified_parameters || func2->unspecified_parameters)
590                 return true;
591
592         if(func1->variadic != func2->variadic)
593                 return false;
594
595         /* TODO: handling of unspecified parameters not correct yet */
596
597         /* all argument types must be compatible */
598         function_parameter_t *parameter1 = func1->parameters;
599         function_parameter_t *parameter2 = func2->parameters;
600         for( ; parameter1 != NULL && parameter2 != NULL;
601                         parameter1 = parameter1->next, parameter2 = parameter2->next) {
602                 type_t *parameter1_type = skip_typeref(parameter1->type);
603                 type_t *parameter2_type = skip_typeref(parameter2->type);
604
605                 parameter1_type = get_unqualified_type(parameter1_type);
606                 parameter2_type = get_unqualified_type(parameter2_type);
607
608                 if(!types_compatible(parameter1_type, parameter2_type))
609                         return false;
610         }
611         /* same number of arguments? */
612         if(parameter1 != NULL || parameter2 != NULL)
613                 return false;
614
615         return true;
616 }
617
618 static bool array_types_compatible(const array_type_t *array1,
619                                    const array_type_t *array2)
620 {
621         type_t *element_type1 = skip_typeref(array1->element_type);
622         type_t *element_type2 = skip_typeref(array2->element_type);
623         if(!types_compatible(element_type1, element_type2))
624                 return false;
625
626         if(array1->size != NULL && array2->size != NULL) {
627                 /* TODO: check if size expression evaluate to the same value
628                  * if they are constant */
629         }
630
631         return true;
632 }
633
634 bool types_compatible(const type_t *type1, const type_t *type2)
635 {
636         assert(!is_typeref(type1));
637         assert(!is_typeref(type2));
638
639         /* shortcut: the same type is always compatible */
640         if(type1 == type2)
641                 return true;
642
643         if(type1->base.qualifiers != type2->base.qualifiers)
644                 return false;
645         if(type1->kind != type2->kind)
646                 return false;
647
648         switch(type1->kind) {
649         case TYPE_FUNCTION:
650                 return function_types_compatible(&type1->function, &type2->function);
651         case TYPE_ATOMIC:
652                 return type1->atomic.akind == type2->atomic.akind;
653         case TYPE_ARRAY:
654                 return array_types_compatible(&type1->array, &type2->array);
655
656         case TYPE_POINTER: {
657                 const type_t *const to1 = skip_typeref(type1->pointer.points_to);
658                 const type_t *const to2 = skip_typeref(type2->pointer.points_to);
659                 return types_compatible(to1, to2);
660         }
661
662         case TYPE_COMPOUND_STRUCT:
663         case TYPE_COMPOUND_UNION:
664         case TYPE_ENUM:
665         case TYPE_BUILTIN:
666                 /* TODO: not implemented */
667                 break;
668
669         case TYPE_BITFIELD:
670                 /* not sure if this makes sense or is even needed, implement it if you
671                  * really need it! */
672                 panic("type compatibility check for bitfield type");
673
674         case TYPE_ERROR:
675                 /* Hmm, the error type should be compatible to all other types */
676                 return true;
677         case TYPE_INVALID:
678                 panic("invalid type found in compatible types");
679         case TYPE_TYPEDEF:
680         case TYPE_TYPEOF:
681                 panic("typerefs not skipped in compatible types?!?");
682         }
683
684         /* TODO: incomplete */
685         return false;
686 }
687
688 bool pointers_compatible(const type_t *type1, const type_t *type2)
689 {
690         assert(!is_typeref(type1));
691         assert(!is_typeref(type2));
692
693         assert(type1->kind == TYPE_POINTER);
694         assert(type2->kind == TYPE_POINTER);
695         /* TODO */
696         return true;
697 }
698
699 /**
700  * Skip all typerefs and return the underlying type.
701  */
702 type_t *skip_typeref(type_t *type)
703 {
704         unsigned qualifiers = TYPE_QUALIFIER_NONE;
705
706         while(true) {
707                 switch(type->kind) {
708                 case TYPE_ERROR:
709                         return type;
710                 case TYPE_TYPEDEF: {
711                         qualifiers |= type->base.qualifiers;
712                         const typedef_type_t *typedef_type = &type->typedeft;
713                         if(typedef_type->resolved_type != NULL) {
714                                 type = typedef_type->resolved_type;
715                                 break;
716                         }
717                         type = typedef_type->declaration->type;
718                         continue;
719                 }
720                 case TYPE_TYPEOF: {
721                         const typeof_type_t *typeof_type = &type->typeoft;
722                         if(typeof_type->typeof_type != NULL) {
723                                 type = typeof_type->typeof_type;
724                         } else {
725                                 type = typeof_type->expression->base.datatype;
726                         }
727                         continue;
728                 }
729                 default:
730                         break;
731                 }
732                 break;
733         }
734
735         if (qualifiers != TYPE_QUALIFIER_NONE) {
736                 type_t *const copy     = duplicate_type(type);
737                 copy->base.qualifiers |= qualifiers;
738
739                 type = typehash_insert(copy);
740                 if (type != copy) {
741                         obstack_free(type_obst, copy);
742                 }
743         }
744
745         return type;
746 }
747
748
749
750 static type_t *identify_new_type(type_t *type)
751 {
752         type_t *result = typehash_insert(type);
753         if(result != type) {
754                 obstack_free(type_obst, type);
755         }
756         return result;
757 }
758
759 type_t *make_atomic_type(atomic_type_kind_t atype, type_qualifiers_t qualifiers)
760 {
761         type_t *type = obstack_alloc(type_obst, sizeof(atomic_type_t));
762         memset(type, 0, sizeof(atomic_type_t));
763
764         type->kind            = TYPE_ATOMIC;
765         type->base.qualifiers = qualifiers;
766         type->atomic.akind    = atype;
767
768         return identify_new_type(type);
769 }
770
771 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers)
772 {
773         type_t *type = obstack_alloc(type_obst, sizeof(pointer_type_t));
774         memset(type, 0, sizeof(pointer_type_t));
775
776         type->kind              = TYPE_POINTER;
777         type->base.qualifiers   = qualifiers;
778         type->pointer.points_to = points_to;
779
780         return identify_new_type(type);
781 }
782
783 static __attribute__((unused))
784 void dbg_type(type_t *type)
785 {
786         FILE *old_out = out;
787         out = stderr;
788         print_type(type);
789         puts("\n");
790         fflush(stderr);
791         out = old_out;
792 }