kernel32/tests/pipe: Enable compilation with long types.
[wine.git] / dlls / msvcrt / cxx.h
blobcacbb1524b616549dbd5d3b5181ca5e43d72df4b
1 /*
2 * Copyright 2012 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "cppexcept.h"
21 #ifdef _WIN64
23 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
25 #define __ASM_VTABLE(name,funcs) \
26 __asm__(".data\n" \
27 "\t.balign 8\n" \
28 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
29 "\t.globl " __ASM_NAME(#name "_vtable") "\n" \
30 __ASM_NAME(#name "_vtable") ":\n" \
31 funcs "\n\t.text")
33 #else
35 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
37 #define __ASM_VTABLE(name,funcs) \
38 __asm__(".data\n" \
39 "\t.balign 4\n" \
40 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
41 "\t.globl " __ASM_NAME(#name "_vtable") "\n" \
42 __ASM_NAME(#name "_vtable") ":\n" \
43 funcs "\n\t.text")
45 #endif /* _WIN64 */
47 #ifndef __x86_64__
49 #define DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
50 static type_info name ## _type_info = { \
51 &type_info_vtable, \
52 NULL, \
53 mangled_name \
54 }; \
56 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
57 &name ##_type_info, \
58 base_classes_no, \
59 { 0, -1, 0}, \
60 64 \
63 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
64 DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
66 static const rtti_base_array name ## _rtti_base_array = { \
67 { \
68 &name ## _rtti_base_descriptor, \
69 cl1, \
70 cl2, \
71 cl3, \
72 cl4, \
73 cl5, \
74 cl6, \
75 cl7, \
76 cl8, \
77 cl9, \
78 } \
79 }; \
81 static const rtti_object_hierarchy name ## _hierarchy = { \
82 0, \
83 0, \
84 base_classes_no+1, \
85 &name ## _rtti_base_array \
86 }; \
88 const rtti_object_locator name ## _rtti = { \
89 0, \
90 off, \
91 0, \
92 &name ## _type_info, \
93 &name ## _hierarchy \
96 #else
98 #define __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
99 static type_info name ## _type_info = { \
100 &type_info_vtable, \
101 NULL, \
102 mangled_name \
103 }; \
105 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
106 0xdeadbeef, \
107 base_classes_no, \
108 { 0, -1, 0}, \
109 64 \
112 #define DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
113 __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
115 static void init_ ## name ## _rtti(char *base) \
117 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
120 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
121 __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
123 static rtti_base_array name ## _rtti_base_array = { \
125 0xdeadbeef, \
126 0xdeadbeef, \
127 0xdeadbeef, \
128 0xdeadbeef, \
129 0xdeadbeef, \
130 0xdeadbeef, \
131 0xdeadbeef, \
132 0xdeadbeef, \
133 0xdeadbeef, \
134 0xdeadbeef, \
136 }; \
138 static rtti_object_hierarchy name ## _hierarchy = { \
139 0, \
140 0, \
141 base_classes_no+1, \
142 0xdeadbeef \
143 }; \
145 rtti_object_locator name ## _rtti = { \
146 1, \
147 off, \
148 0, \
149 0xdeadbeef, \
150 0xdeadbeef, \
151 0xdeadbeef \
154 static void init_ ## name ## _rtti(char *base) \
156 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
157 name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
158 name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
159 name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
160 name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
161 name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
162 name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
163 name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
164 name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
165 name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
166 name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
167 name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
168 name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
169 name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
170 name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
173 #endif
175 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
176 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
177 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
178 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
179 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
180 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
181 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
182 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
183 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
184 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
185 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
186 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
187 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
188 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
190 #ifndef __x86_64__
192 typedef struct _rtti_base_descriptor
194 const type_info *type_descriptor;
195 int num_base_classes;
196 this_ptr_offsets offsets; /* offsets for computing the this pointer */
197 unsigned int attributes;
198 } rtti_base_descriptor;
200 typedef struct _rtti_base_array
202 const rtti_base_descriptor *bases[10]; /* First element is the class itself */
203 } rtti_base_array;
205 typedef struct _rtti_object_hierarchy
207 unsigned int signature;
208 unsigned int attributes;
209 int array_len; /* Size of the array pointed to by 'base_classes' */
210 const rtti_base_array *base_classes;
211 } rtti_object_hierarchy;
213 typedef struct _rtti_object_locator
215 unsigned int signature;
216 int base_class_offset;
217 unsigned int flags;
218 const type_info *type_descriptor;
219 const rtti_object_hierarchy *type_hierarchy;
220 } rtti_object_locator;
222 #else
224 typedef struct
226 unsigned int type_descriptor;
227 int num_base_classes;
228 this_ptr_offsets offsets; /* offsets for computing the this pointer */
229 unsigned int attributes;
230 } rtti_base_descriptor;
232 typedef struct
234 unsigned int bases[10]; /* First element is the class itself */
235 } rtti_base_array;
237 typedef struct
239 unsigned int signature;
240 unsigned int attributes;
241 int array_len; /* Size of the array pointed to by 'base_classes' */
242 unsigned int base_classes;
243 } rtti_object_hierarchy;
245 typedef struct
247 unsigned int signature;
248 int base_class_offset;
249 unsigned int flags;
250 unsigned int type_descriptor;
251 unsigned int type_hierarchy;
252 unsigned int object_locator;
253 } rtti_object_locator;
255 #endif
257 #ifdef __ASM_USE_THISCALL_WRAPPER
259 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
261 extern void *vtbl_wrapper_0;
262 extern void *vtbl_wrapper_4;
263 extern void *vtbl_wrapper_8;
264 extern void *vtbl_wrapper_12;
265 extern void *vtbl_wrapper_16;
266 extern void *vtbl_wrapper_20;
267 extern void *vtbl_wrapper_24;
268 extern void *vtbl_wrapper_28;
269 extern void *vtbl_wrapper_32;
270 extern void *vtbl_wrapper_36;
271 extern void *vtbl_wrapper_40;
272 extern void *vtbl_wrapper_44;
273 extern void *vtbl_wrapper_48;
275 #else
277 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__thiscall***)type)this)[0][off/4]args
279 #endif
281 exception* __thiscall exception_ctor(exception*, const char**);
283 extern const vtable_ptr type_info_vtable;
285 #define CREATE_TYPE_INFO_VTABLE \
286 DEFINE_THISCALL_WRAPPER(type_info_vector_dtor,8) \
287 void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags) \
289 if (flags & 2) \
291 /* we have an array, with the number of elements stored before the first object */ \
292 INT_PTR i, *ptr = (INT_PTR *)_this - 1; \
294 for (i = *ptr - 1; i >= 0; i--) free(_this[i].name); \
295 free(ptr); \
297 else \
299 free(_this->name); \
300 if (flags & 1) free(_this); \
302 return _this; \
305 DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" ) \
307 __ASM_BLOCK_BEGIN(type_info_vtables) \
308 __ASM_VTABLE(type_info, \
309 VTABLE_ADD_FUNC(type_info_vector_dtor)); \
310 __ASM_BLOCK_END