Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / msvcp60 / cxx.h
blobcc3915cdfa50296534e253baaba9fd278709b3fb
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 /* Copied from dlls/msvcrt/cpp.c */
20 #ifdef __i386__ /* thiscall functions are i386-specific */
22 #define THISCALL(func) __thiscall_ ## func
23 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
24 #define __thiscall __stdcall
25 #define DEFINE_THISCALL_WRAPPER(func,args) \
26 extern void THISCALL(func)(void); \
27 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
28 "popl %eax\n\t" \
29 "pushl %ecx\n\t" \
30 "pushl %eax\n\t" \
31 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
32 #else /* __i386__ */
34 #define THISCALL(func) func
35 #define THISCALL_NAME(func) __ASM_NAME(#func)
36 #define __thiscall __cdecl
37 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
39 #endif /* __i386__ */
41 #ifdef _WIN64
43 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
45 #define __ASM_VTABLE(name,funcs) \
46 __asm__(".data\n" \
47 "\t.align 8\n" \
48 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
49 "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
50 __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
51 "\t.quad " THISCALL_NAME(MSVCP_ ## name ## _vector_dtor) "\n" \
52 funcs "\n\t.text")
54 #else
56 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
58 #define __ASM_VTABLE(name,funcs) \
59 __asm__(".data\n" \
60 "\t.align 4\n" \
61 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
62 "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
63 __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
64 "\t.long " THISCALL_NAME(MSVCP_ ## name ## _vector_dtor) "\n" \
65 funcs "\n\t.text")
67 #endif /* _WIN64 */
69 #define DEFINE_RTTI_DATA(name, off, base_classes, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
70 static const type_info name ## _type_info = { \
71 &MSVCP_type_info_vtable, \
72 NULL, \
73 mangled_name \
74 }; \
76 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
77 &name ##_type_info, \
78 base_classes, \
79 { 0, -1, 0}, \
80 64 \
81 }; \
83 static const rtti_base_array name ## _rtti_base_array = { \
84 { \
85 &name ## _rtti_base_descriptor, \
86 cl1, \
87 cl2, \
88 cl3, \
89 cl4, \
90 cl5, \
91 cl6, \
92 cl7, \
93 cl8, \
94 cl9, \
95 } \
96 }; \
98 static const rtti_object_hierarchy name ## _hierarchy = { \
99 0, \
100 0, \
101 base_classes+1, \
102 &name ## _rtti_base_array \
103 }; \
105 const rtti_object_locator name ## _rtti = { \
106 0, \
107 off, \
108 0, \
109 &name ## _type_info, \
110 &name ## _hierarchy \
113 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
114 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
115 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
116 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
117 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
118 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
119 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
120 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
121 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
122 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
123 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
124 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
125 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
126 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
128 #ifdef __i386__
130 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
132 extern void *vtbl_wrapper_0;
133 extern void *vtbl_wrapper_4;
134 extern void *vtbl_wrapper_8;
135 extern void *vtbl_wrapper_12;
136 extern void *vtbl_wrapper_16;
137 extern void *vtbl_wrapper_20;
138 extern void *vtbl_wrapper_24;
139 extern void *vtbl_wrapper_28;
140 extern void *vtbl_wrapper_32;
141 extern void *vtbl_wrapper_36;
142 extern void *vtbl_wrapper_40;
143 extern void *vtbl_wrapper_44;
144 extern void *vtbl_wrapper_48;
145 extern void *vtbl_wrapper_52;
146 extern void *vtbl_wrapper_56;
147 extern void *vtbl_wrapper_60;
149 #else
151 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__cdecl***)type)this)[0][off/4]args
153 #endif
155 /* exception object */
156 typedef void (*vtable_ptr)(void);
157 typedef struct __exception
159 const vtable_ptr *vtable;
160 char *name; /* Name of this exception, always a new copy for each object */
161 int do_free; /* Whether to free 'name' in our dtor */
162 } exception;
164 /* Internal: throws selected exception */
165 typedef enum __exception_type {
166 EXCEPTION_RERAISE,
167 EXCEPTION,
168 EXCEPTION_BAD_ALLOC,
169 EXCEPTION_LOGIC_ERROR,
170 EXCEPTION_LENGTH_ERROR,
171 EXCEPTION_OUT_OF_RANGE,
172 EXCEPTION_INVALID_ARGUMENT,
173 EXCEPTION_RUNTIME_ERROR,
174 EXCEPTION_FAILURE,
175 } exception_type;
176 void throw_exception(exception_type, const char *);
178 /* rtti */
179 typedef struct __type_info
181 const vtable_ptr *vtable;
182 char *name; /* Unmangled name, allocated lazily */
183 char mangled[128]; /* Variable length, but we declare it large enough for static RTTI */
184 } type_info;
186 extern const vtable_ptr MSVCP_type_info_vtable;
188 /* offsets for computing the this pointer */
189 typedef struct
191 int this_offset; /* offset of base class this pointer from start of object */
192 int vbase_descr; /* offset of virtual base class descriptor */
193 int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
194 } this_ptr_offsets;
196 typedef struct _rtti_base_descriptor
198 const type_info *type_descriptor;
199 int num_base_classes;
200 this_ptr_offsets offsets; /* offsets for computing the this pointer */
201 unsigned int attributes;
202 } rtti_base_descriptor;
204 typedef struct _rtti_base_array
206 const rtti_base_descriptor *bases[10]; /* First element is the class itself */
207 } rtti_base_array;
209 typedef struct _rtti_object_hierarchy
211 unsigned int signature;
212 unsigned int attributes;
213 int array_len; /* Size of the array pointed to by 'base_classes' */
214 const rtti_base_array *base_classes;
215 } rtti_object_hierarchy;
217 typedef struct _rtti_object_locator
219 unsigned int signature;
220 int base_class_offset;
221 unsigned int flags;
222 const type_info *type_descriptor;
223 const rtti_object_hierarchy *type_hierarchy;
224 } rtti_object_locator;