microsoft types are just synonyms for default types
[cparser] / types.c
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 #include "type_t.h"
21 #include "types.h"
22 #include "lang_features.h"
23
24 /** The error type. */
25 type_t *type_error_type;
26
27 type_t *type_char;
28 type_t *type_double;
29 type_t *type_float;
30 type_t *type_int;
31 type_t *type_long_double;
32 type_t *type_long_long;
33 type_t *type_long;
34 type_t *type_short;
35 type_t *type_signed_char;
36 type_t *type_unsigned_int;
37 type_t *type_unsigned_long_long;
38 type_t *type_unsigned_long;
39 type_t *type_void;
40
41 type_t *type_char_ptr;
42 type_t *type_int_ptr;
43 type_t *type_long_long_ptr;
44 type_t *type_long_ptr;
45 type_t *type_short_ptr;
46 type_t *type_signed_char_ptr;
47 type_t *type_void_ptr;
48
49 type_t *type_char_ptr_ptr;
50
51 type_t *type_intmax_t;
52 type_t *type_ptrdiff_t;
53 type_t *type_size_t;
54 type_t *type_ssize_t;
55 type_t *type_uintmax_t;
56 type_t *type_uptrdiff_t;
57 type_t *type_wchar_t;
58 type_t *type_wint_t;
59
60 type_t *type_intmax_t_ptr;
61 type_t *type_ptrdiff_t_ptr;
62 type_t *type_ssize_t_ptr;
63 type_t *type_wchar_t_ptr;
64
65 /* microsoft types */
66 atomic_type_kind_t int8_type_kind            = ATOMIC_TYPE_INVALID;
67 atomic_type_kind_t int16_type_kind           = ATOMIC_TYPE_INVALID;
68 atomic_type_kind_t int32_type_kind           = ATOMIC_TYPE_INVALID;
69 atomic_type_kind_t int64_type_kind           = ATOMIC_TYPE_INVALID;
70 atomic_type_kind_t int128_type_kind          = ATOMIC_TYPE_INVALID;
71 atomic_type_kind_t unsigned_int8_type_kind   = ATOMIC_TYPE_INVALID;
72 atomic_type_kind_t unsigned_int16_type_kind  = ATOMIC_TYPE_INVALID;
73 atomic_type_kind_t unsigned_int32_type_kind  = ATOMIC_TYPE_INVALID;
74 atomic_type_kind_t unsigned_int64_type_kind  = ATOMIC_TYPE_INVALID;
75 atomic_type_kind_t unsigned_int128_type_kind = ATOMIC_TYPE_INVALID;
76
77 type_t *type_int8;
78 type_t *type_int16;
79 type_t *type_int32;
80 type_t *type_int64;
81 type_t *type_unsigned_int8;
82 type_t *type_unsigned_int16;
83 type_t *type_unsigned_int32;
84 type_t *type_unsigned_int64;
85
86
87 void init_basic_types(void)
88 {
89         static const type_base_t error = { TYPE_ERROR, TYPE_QUALIFIER_NONE, 0, { NULL, 0 }, NULL };
90
91         type_error_type         = (type_t*)&error;
92         type_signed_char        = make_atomic_type(ATOMIC_TYPE_SCHAR,       TYPE_QUALIFIER_NONE);
93         type_short              = make_atomic_type(ATOMIC_TYPE_SHORT,       TYPE_QUALIFIER_NONE);
94         type_int                = make_atomic_type(ATOMIC_TYPE_INT,         TYPE_QUALIFIER_NONE);
95         type_unsigned_int       = make_atomic_type(ATOMIC_TYPE_UINT,        TYPE_QUALIFIER_NONE);
96         type_long               = make_atomic_type(ATOMIC_TYPE_LONG,        TYPE_QUALIFIER_NONE);
97         type_unsigned_long      = make_atomic_type(ATOMIC_TYPE_ULONG,       TYPE_QUALIFIER_NONE);
98         type_long_long          = make_atomic_type(ATOMIC_TYPE_LONGLONG,    TYPE_QUALIFIER_NONE);
99         type_unsigned_long_long = make_atomic_type(ATOMIC_TYPE_ULONGLONG,   TYPE_QUALIFIER_NONE);
100         type_long_double        = make_atomic_type(ATOMIC_TYPE_LONG_DOUBLE, TYPE_QUALIFIER_NONE);
101         type_double             = make_atomic_type(ATOMIC_TYPE_DOUBLE,      TYPE_QUALIFIER_NONE);
102         type_float              = make_atomic_type(ATOMIC_TYPE_FLOAT,       TYPE_QUALIFIER_NONE);
103         type_char               = make_atomic_type(ATOMIC_TYPE_CHAR,        TYPE_QUALIFIER_NONE);
104         type_void               = make_atomic_type(ATOMIC_TYPE_VOID,        TYPE_QUALIFIER_NONE);
105
106         /* microsoft types */
107         if(c_mode & _MS) {
108                 int8_type_kind           = find_signed_int_atomic_type_kind_for_size(1);
109                 type_int8                = make_atomic_type(int8_type_kind, TYPE_QUALIFIER_NONE);
110                 int16_type_kind          = find_signed_int_atomic_type_kind_for_size(2);
111                 type_int16               = make_atomic_type(int16_type_kind, TYPE_QUALIFIER_NONE);
112                 int32_type_kind          = find_signed_int_atomic_type_kind_for_size(4);
113                 type_int32               = make_atomic_type(int32_type_kind, TYPE_QUALIFIER_NONE);
114                 int64_type_kind          = find_signed_int_atomic_type_kind_for_size(8);
115                 type_int64               = make_atomic_type(int64_type_kind, TYPE_QUALIFIER_NONE);
116                 unsigned_int8_type_kind  = find_unsigned_int_atomic_type_kind_for_size(1);
117                 type_unsigned_int8       = make_atomic_type(unsigned_int8_type_kind, TYPE_QUALIFIER_NONE);
118                 unsigned_int16_type_kind = find_unsigned_int_atomic_type_kind_for_size(2);
119                 type_unsigned_int16      = make_atomic_type(unsigned_int16_type_kind, TYPE_QUALIFIER_NONE);
120                 unsigned_int32_type_kind = find_unsigned_int_atomic_type_kind_for_size(4);
121                 type_unsigned_int32      = make_atomic_type(unsigned_int32_type_kind, TYPE_QUALIFIER_NONE);
122                 unsigned_int64_type_kind = find_unsigned_int_atomic_type_kind_for_size(8);
123                 type_unsigned_int64      = make_atomic_type(unsigned_int64_type_kind, TYPE_QUALIFIER_NONE);
124         }
125
126         /* pointer types */
127         type_void_ptr           = make_pointer_type(type_void,              TYPE_QUALIFIER_NONE);
128         type_char_ptr           = make_pointer_type(type_char,              TYPE_QUALIFIER_NONE);
129         type_signed_char_ptr    = make_pointer_type(type_signed_char,       TYPE_QUALIFIER_NONE);
130         type_short_ptr          = make_pointer_type(type_short,             TYPE_QUALIFIER_NONE);
131         type_int_ptr            = make_pointer_type(type_int,               TYPE_QUALIFIER_NONE);
132         type_long_ptr           = make_pointer_type(type_long,              TYPE_QUALIFIER_NONE);
133         type_long_long_ptr      = make_pointer_type(type_long_long,         TYPE_QUALIFIER_NONE);
134
135         type_char_ptr_ptr       = make_pointer_type(type_char_ptr,          TYPE_QUALIFIER_NONE);
136 }