replaced the different type types by one union type saving a lot of casts (and adding...
[cparser] / type_t.h
1 #ifndef TYPE_T_H
2 #define TYPE_T_H
3
4 #include <stdbool.h>
5
6 #include <libfirm/firm_types.h>
7
8 #include "type.h"
9 #include "symbol.h"
10 #include "token_t.h"
11 #include "ast_t.h"
12 #include "adt/obst.h"
13
14 struct obstack *type_obst;
15
16 typedef enum {
17         TYPE_INVALID,
18         TYPE_ATOMIC,
19         TYPE_COMPOUND_STRUCT,
20         TYPE_COMPOUND_UNION,
21         TYPE_ENUM,
22         TYPE_FUNCTION,
23         TYPE_POINTER,
24         TYPE_ARRAY,
25         TYPE_BUILTIN,
26         TYPE_TYPEDEF,
27         TYPE_TYPEOF
28 } type_type_t;
29
30 /* note that the constant values represent the rank of the types as defined
31  * in ยง 6.3.1 */
32 typedef enum {
33         ATOMIC_TYPE_INVALID = 0,
34         ATOMIC_TYPE_VOID,
35         ATOMIC_TYPE_CHAR,
36         ATOMIC_TYPE_SCHAR,
37         ATOMIC_TYPE_UCHAR,
38         ATOMIC_TYPE_SHORT,
39         ATOMIC_TYPE_USHORT,
40         ATOMIC_TYPE_INT,
41         ATOMIC_TYPE_UINT,
42         ATOMIC_TYPE_LONG,
43         ATOMIC_TYPE_ULONG,
44         ATOMIC_TYPE_LONGLONG,
45         ATOMIC_TYPE_ULONGLONG,
46         ATOMIC_TYPE_FLOAT,
47         ATOMIC_TYPE_DOUBLE,
48         ATOMIC_TYPE_LONG_DOUBLE,
49         ATOMIC_TYPE_BOOL,
50 #ifdef PROVIDE_COMPLEX
51         ATOMIC_TYPE_FLOAT_COMPLEX,
52         ATOMIC_TYPE_DOUBLE_COMPLEX,
53         ATOMIC_TYPE_LONG_DOUBLE_COMPLEX,
54         ATOMIC_TYPE_FLOAT_IMAGINARY,
55         ATOMIC_TYPE_DOUBLE_IMAGINARY,
56         ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
57 #endif
58 } atomic_type_type_t;
59
60 typedef enum {
61         TYPE_QUALIFIER_NONE     = 0,
62         TYPE_QUALIFIER_CONST    = 1 << 0,
63         TYPE_QUALIFIER_RESTRICT = 1 << 1,
64         TYPE_QUALIFIER_VOLATILE = 1 << 2,
65 } type_qualifier_t;
66
67 typedef unsigned int type_qualifiers_t;
68
69 struct function_parameter_t {
70         type_t               *type;
71         function_parameter_t *next;
72 };
73
74 struct type_t {
75         type_type_t       type;
76         type_qualifiers_t qualifiers;
77
78         union {
79                 /* if type == TYPE_ATOMIC */
80                 struct {
81                         atomic_type_type_t  atype;
82                 } atomic_type;
83                 /* if type == TYPE_COMPOUND_STRUCT or type == TYPE_COMPOUND_UNION */
84                 struct {
85                         /** the declaration of the compound type, its context field
86                          * contains the compound entries. */
87                         declaration_t *declaration;
88                 } compound_type;
89                 /* if type == TYPE_ENUM */
90                 struct {
91                         /** the declaration of the enum type. You can find the enum entries by
92                          * walking the declaration->next list until you don't find
93                          * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
94                         declaration_t *declaration;
95                 } enum_type;
96                 /* if type == TYPE_FUNCTION */
97                 struct  {
98                         type_t               *result_type;
99                         function_parameter_t *parameters;
100                         bool                  variadic;
101                         bool                  unspecified_parameters;
102                 } function_type;
103                 /* if type == TYPE_POINTER */
104                 struct {
105                         type_t  *points_to;
106                 } pointer_type;
107                 /* if type == TYPE_ARRAY */
108                 struct {
109                         type_t       *element_type;
110                         bool          is_static;
111                         bool          is_variable;
112                         expression_t *size;
113                 } array_type;
114                 /* if type == TYPE_BUILTIN */
115                 struct {
116                         symbol_t *symbol;
117                         type_t   *real_type;
118                 } builtin_type;
119                 /* if type == TYPE_TYPEDEF */
120                 struct {
121                         declaration_t *declaration;
122                         type_t        *resolved_type;
123                 } typedef_type;
124                 /* if type == TYPE_TYPEOF */
125                 struct {
126                         expression_t *expression;
127                         type_t       *typeof_type;
128                         type_t       *resolved_type;
129                 } typeof_type;
130         } v;
131
132         ir_type          *firm_type;
133 };
134
135 type_t *make_atomic_type(atomic_type_type_t type, type_qualifiers_t qualifiers);
136 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
137
138 #endif