filter trigraphs in advance and simplify lexer code because of that
[cparser] / type_t.h
1 #ifndef TYPE_T_H
2 #define TYPE_T_H
3
4 #include "type.h"
5 #include "symbol.h"
6 #include "token_t.h"
7 #include "ast_t.h"
8 #include "adt/obst.h"
9
10 struct obstack *type_obst;
11
12 typedef enum {
13         TYPE_INVALID,
14         TYPE_ATOMIC,
15         TYPE_COMPOUND_STRUCT,
16         TYPE_COMPOUND_UNION,
17         TYPE_ENUM,
18         TYPE_METHOD,
19         TYPE_POINTER,
20         TYPE_BUILTIN
21 } type_type_t;
22
23 typedef enum {
24         ATOMIC_TYPE_INVALID,
25         ATOMIC_TYPE_VOID,
26         ATOMIC_TYPE_CHAR,
27         ATOMIC_TYPE_SCHAR,
28         ATOMIC_TYPE_UCHAR,
29         ATOMIC_TYPE_SHORT,
30         ATOMIC_TYPE_USHORT,
31         ATOMIC_TYPE_INT,
32         ATOMIC_TYPE_UINT,
33         ATOMIC_TYPE_LONG,
34         ATOMIC_TYPE_ULONG,
35         ATOMIC_TYPE_LONGLONG,
36         ATOMIC_TYPE_ULONGLONG,
37         ATOMIC_TYPE_FLOAT,
38         ATOMIC_TYPE_DOUBLE,
39         ATOMIC_TYPE_LONG_DOUBLE,
40         ATOMIC_TYPE_BOOL,
41 #ifdef PROVIDE_COMPLEX
42         ATOMIC_TYPE_FLOAT_COMPLEX,
43         ATOMIC_TYPE_DOUBLE_COMPLEX,
44         ATOMIC_TYPE_LONG_DOUBLE_COMPLEX,
45 #endif
46 #ifdef PROVIDE_IMAGINARY
47         ATOMIC_TYPE_FLOAT_IMAGINARY,
48         ATOMIC_TYPE_DOUBLE_IMAGINARY,
49         ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
50 #endif
51 } atomic_type_type_t;
52
53 typedef enum {
54         TYPE_QUALIFIER_CONST    = 1 << 0,
55         TYPE_QUALIFIER_RESTRICT = 1 << 1,
56         TYPE_QUALIFIER_VOLATILE = 1 << 2,
57         TYPE_QUALIFIER_INLINE   = 1 << 3,
58 } type_qualifier_t;
59
60 struct type_t {
61         type_type_t  type;
62         unsigned     qualifiers;
63 };
64
65 struct atomic_type_t {
66         type_t              type;
67         atomic_type_type_t  atype;
68 };
69
70 struct builtin_type_t {
71         type_t    type;
72         symbol_t *symbol;
73 };
74
75 struct enum_type_t {
76         type_t             type;
77         symbol_t          *symbol;
78         source_position_t  source_position;
79         enum_type_t       *next;
80         declaration_t     *entries_begin;
81         declaration_t     *entries_end;
82         int                defined;
83 };
84
85 struct pointer_type_t {
86         type_t   type;
87         type_t  *points_to;
88 };
89
90 struct method_parameter_t {
91         type_t             *type;
92         method_parameter_t *next;
93 };
94
95 struct method_type_t {
96         type_t              type;
97         type_t             *result_type;
98         method_parameter_t *parameters;
99         int                 variadic;
100         int                 unspecified_parameters;
101 };
102
103 struct compound_type_t {
104         type_t             type;
105         symbol_t          *symbol;
106         context_t          context;
107         source_position_t  source_position;
108         int                defined;
109         compound_type_t   *next;
110 };
111
112 type_t *make_atomic_type(atomic_type_type_t type, unsigned qualifiers);
113 type_t *make_pointer_type(type_t *points_to, unsigned qualifiers);
114
115 #endif