implement MS type extension types
[cparser] / type.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #ifndef TYPE_H
21 #define TYPE_H
22
23 #include <stdio.h>
24 #include <stdbool.h>
25 #include "ast.h"
26 #include "symbol.h"
27
28 /* note that the constant values represent the rank of the types as defined
29  * in ยง 6.3.1 */
30 typedef enum {
31         ATOMIC_TYPE_INVALID = 0,
32         ATOMIC_TYPE_VOID,
33         ATOMIC_TYPE_CHAR,
34         ATOMIC_TYPE_SCHAR,
35         ATOMIC_TYPE_UCHAR,
36         ATOMIC_TYPE_SHORT,
37         ATOMIC_TYPE_USHORT,
38         ATOMIC_TYPE_INT,
39         ATOMIC_TYPE_UINT,
40         ATOMIC_TYPE_LONG,
41         ATOMIC_TYPE_ULONG,
42         ATOMIC_TYPE_LONGLONG,
43         ATOMIC_TYPE_ULONGLONG,
44         ATOMIC_TYPE_FLOAT,
45         ATOMIC_TYPE_DOUBLE,
46         ATOMIC_TYPE_LONG_DOUBLE,
47         ATOMIC_TYPE_BOOL,
48         /* microsoft extensions */
49         ATOMIC_TYPE_INT8,
50         ATOMIC_TYPE_INT16,
51         ATOMIC_TYPE_INT32,
52         ATOMIC_TYPE_INT64,
53         ATOMIC_TYPE_INT128,
54         ATOMIC_TYPE_UINT8,
55         ATOMIC_TYPE_UINT16,
56         ATOMIC_TYPE_UINT32,
57         ATOMIC_TYPE_UINT64,
58         ATOMIC_TYPE_UINT128,
59
60         ATOMIC_TYPE_FLOAT_COMPLEX,
61         ATOMIC_TYPE_DOUBLE_COMPLEX,
62         ATOMIC_TYPE_LONG_DOUBLE_COMPLEX,
63         ATOMIC_TYPE_FLOAT_IMAGINARY,
64         ATOMIC_TYPE_DOUBLE_IMAGINARY,
65         ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
66
67         ATOMIC_TYPE_LAST = ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY
68 } atomic_type_kind_t;
69
70 typedef struct type_base_t           type_base_t;
71 typedef struct atomic_type_t         atomic_type_t;
72 typedef struct pointer_type_t        pointer_type_t;
73 typedef struct function_parameter_t  function_parameter_t;
74 typedef struct function_type_t       function_type_t;
75 typedef struct compound_type_t       compound_type_t;
76 typedef struct enum_type_t           enum_type_t;
77 typedef struct builtin_type_t        builtin_type_t;
78 typedef struct array_type_t          array_type_t;
79 typedef struct typedef_type_t        typedef_type_t;
80 typedef struct bitfield_type_t       bitfield_type_t;
81 typedef struct typeof_type_t         typeof_type_t;
82 typedef union  type_t                type_t;
83
84 void init_types(void);
85 void exit_types(void);
86
87 void print_type(const type_t *type);
88
89 /**
90  * prints a human readable form of @p type. prints an abstract typename
91  * if symbol is NULL
92  */
93 void print_type_ext(const type_t *type, const symbol_t *symbol,
94                     const scope_t *scope);
95
96 void print_type_qualifiers(unsigned qualifiers);
97
98 void print_enum_definition(const declaration_t *declaration);
99 void print_compound_definition(const declaration_t *declaration);
100
101 /**
102  * set output stream for the type printer
103  */
104 void type_set_output(FILE *out);
105
106 void inc_type_visited(void);
107
108 /**
109  * returns true if type contains integer numbers
110  */
111 bool is_type_integer(const type_t *type);
112
113 /**
114  * return true if type contains signed numbers
115  */
116 bool is_type_signed(const type_t *type);
117
118 /**
119  * returns true if type contains floating point numbers
120  */
121 bool is_type_float(const type_t *type);
122
123 /**
124  * returns true if the type is valid. A type is valid if it contains no
125  * unresolved references anymore and is not of TYPE_INVALID.
126  */
127 bool type_valid(const type_t *type);
128
129 /**
130  * returns true if the type is an arithmetic type (6.2.18)
131  */
132 bool is_type_arithmetic(const type_t *type);
133
134 /**
135  * returns true if the type is a scalar type (6.2.21)
136  */
137 bool is_type_scalar(const type_t *type);
138
139 bool is_type_incomplete(const type_t *type);
140
141 bool types_compatible(const type_t *type1, const type_t *type2);
142
143 bool pointers_compatible(const type_t *type1, const type_t *type2);
144
145 type_t *get_unqualified_type(type_t *type);
146 type_t *skip_typeref(type_t *type);
147
148 /**
149  * returns size of an atomic type kind in bytes
150  */
151 unsigned get_atomic_type_size(atomic_type_kind_t kind);
152
153 /**
154  * returns alignment of an atomic type kind in bytes
155  */
156 unsigned get_atomic_type_align(atomic_type_kind_t kind);
157
158 #endif