Skip to content

Commit 48d5066

Browse files
committed
fbc: add tests for c++ mangling/call conventions for procedures
- test fbc default, cdecl, and stdcall calling conventions - test in extern "c" and extern "c++" blocks
1 parent c92048f commit 48d5066

File tree

3 files changed

+512
-0
lines changed

3 files changed

+512
-0
lines changed

tests/cpp/call-cpp.cpp

Lines changed: 345 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,345 @@
1+
// implementation for call-fbc.bas
2+
3+
// each operation records call information
4+
// in static variables, and we use getters
5+
// to retrieve it back to fbc side
6+
7+
#define NULL 0
8+
static const void * ptr1 = NULL;
9+
static const void * ptr2 = NULL;
10+
static const void * ptr3 = NULL;
11+
static char msg1[100]; // check message
12+
13+
void setMsg( const char* msg ) {
14+
char *s = msg1;
15+
while( *msg )
16+
*s++ = *msg++;
17+
*s = *msg;
18+
}
19+
20+
void resetChecks() {
21+
ptr1 = NULL;
22+
ptr2 = NULL;
23+
ptr3 = NULL;
24+
setMsg( "" );
25+
}
26+
27+
const void* getPtr1() {
28+
return ptr1;
29+
}
30+
31+
const void* getPtr2() {
32+
return ptr2;
33+
}
34+
35+
const void* getPtr3() {
36+
return ptr3;
37+
}
38+
39+
char* getMsg1() {
40+
return msg1;
41+
}
42+
43+
class UDT
44+
{
45+
public:
46+
int value;
47+
};
48+
49+
extern "C" {
50+
void sub1_c_default( UDT const& a );
51+
void sub1_c_cdecl( UDT const& a ) __attribute__((cdecl));
52+
void sub1_c_stdcall( UDT const& a ) __attribute__((stdcall));
53+
UDT func1_c_default( UDT const& a );
54+
UDT func1_c_cdecl( UDT const& a ) __attribute__((cdecl));
55+
UDT func1_c_stdcall( UDT const& a ) __attribute__((stdcall));
56+
57+
void sub2_c_default( UDT const& a, UDT const& b );
58+
void sub2_c_cdecl( UDT const& a, UDT const& b ) __attribute__((cdecl));
59+
void sub2_c_stdcall( UDT const& a, UDT const& b ) __attribute__((stdcall));
60+
UDT func2_c_default( UDT const& a, UDT const& b );
61+
UDT func2_c_cdecl( UDT const& a, UDT const& b ) __attribute__((cdecl));
62+
UDT func2_c_stdcall( UDT const& a, UDT const& b ) __attribute__((stdcall));
63+
64+
void sub3_c_default( UDT const& a, UDT const& b, UDT const& c );
65+
void sub3_c_cdecl( UDT const& a, UDT const& b, UDT const& c ) __attribute__((cdecl));
66+
void sub3_c_stdcall( UDT const& a, UDT const& b, UDT const& c ) __attribute__((stdcall));
67+
UDT func3_c_default( UDT const& a, UDT const& b, UDT const& c );
68+
UDT func3_c_cdecl( UDT const& a, UDT const& b, UDT const& c ) __attribute__((cdecl));
69+
UDT func3_c_stdcall( UDT const& a, UDT const& b, UDT const& c ) __attribute__((stdcall));
70+
}
71+
72+
void sub1_cpp_default( UDT const& a );
73+
void sub1_cpp_cdecl( UDT const& a ) __attribute__((cdecl));
74+
void sub1_cpp_stdcall( UDT const& a ) __attribute__((stdcall));
75+
UDT func1_cpp_default( UDT const& a );
76+
UDT func1_cpp_cdecl( UDT const& a ) __attribute__((cdecl));
77+
UDT func1_cpp_stdcall( UDT const& a ) __attribute__((stdcall));
78+
79+
void sub2_cpp_default( UDT const& a, UDT const& b );
80+
void sub2_cpp_cdecl( UDT const& a, UDT const& b ) __attribute__((cdecl));
81+
void sub2_cpp_stdcall( UDT const& a, UDT const& b ) __attribute__((stdcall));
82+
UDT func2_cpp_default( UDT const& a, UDT const& b );
83+
UDT func2_cpp_cdecl( UDT const& a, UDT const& b ) __attribute__((cdecl));
84+
UDT func2_cpp_stdcall( UDT const& a, UDT const& b ) __attribute__((stdcall));
85+
86+
void sub3_cpp_default( UDT const& a, UDT const& b, UDT const& c );
87+
void sub3_cpp_cdecl( UDT const& a, UDT const& b, UDT const& c ) __attribute__((cdecl));
88+
void sub3_cpp_stdcall( UDT const& a, UDT const& b, UDT const& c ) __attribute__((stdcall));
89+
UDT func3_cpp_default( UDT const& a, UDT const& b, UDT const& c );
90+
UDT func3_cpp_cdecl( UDT const& a, UDT const& b, UDT const& c ) __attribute__((cdecl));
91+
UDT func3_cpp_stdcall( UDT const& a, UDT const& b, UDT const& c ) __attribute__((stdcall));
92+
93+
extern "C" {
94+
void sub1_c_default( UDT const& a ) {
95+
ptr1 = &a;
96+
setMsg( "sub1_c_default" );
97+
}
98+
99+
void sub1_c_cdecl( UDT const& a ) {
100+
ptr1 = &a;
101+
setMsg( "sub1_c_cdecl" );
102+
}
103+
104+
void sub1_c_stdcall( UDT const& a ) {
105+
ptr1 = &a;
106+
setMsg( "sub1_c_stdcall" );
107+
}
108+
109+
UDT func1_c_default( UDT const& a ) {
110+
UDT ret = {0};
111+
ptr1 = &a;
112+
setMsg( "func1_c_default" );
113+
return ret;
114+
}
115+
116+
UDT func1_c_cdecl( UDT const& a ) {
117+
UDT ret = {0};
118+
ptr1 = &a;
119+
setMsg( "func1_c_cdecl" );
120+
return ret;
121+
}
122+
123+
UDT func1_c_stdcall( UDT const& a ) {
124+
UDT ret = {0};
125+
ptr1 = &a;
126+
setMsg( "func1_c_stdcall" );
127+
return ret;
128+
}
129+
130+
void sub2_c_default( UDT const& a, UDT const& b ) {
131+
ptr1 = &a;
132+
ptr2 = &b;
133+
setMsg( "sub2_c_default" );
134+
}
135+
136+
void sub2_c_cdecl( UDT const& a, UDT const& b ) {
137+
ptr1 = &a;
138+
ptr2 = &b;
139+
setMsg( "sub2_c_cdecl" );
140+
}
141+
142+
void sub2_c_stdcall( UDT const& a, UDT const& b ) {
143+
ptr1 = &a;
144+
ptr2 = &b;
145+
setMsg( "sub2_c_stdcall" );
146+
}
147+
148+
UDT func2_c_default( UDT const& a, UDT const& b ) {
149+
UDT ret = {0};
150+
ptr1 = &a;
151+
ptr2 = &b;
152+
setMsg( "func2_c_default" );
153+
return ret;
154+
}
155+
156+
UDT func2_c_cdecl( UDT const& a, UDT const& b ) {
157+
UDT ret = {0};
158+
ptr1 = &a;
159+
ptr2 = &b;
160+
setMsg( "func2_c_cdecl" );
161+
return ret;
162+
}
163+
164+
UDT func2_c_stdcall( UDT const& a, UDT const& b ) {
165+
UDT ret = {0};
166+
ptr1 = &a;
167+
ptr2 = &b;
168+
setMsg( "func2_c_stdcall" );
169+
return ret;
170+
}
171+
172+
void sub3_c_default( UDT const& a, UDT const& b, UDT const& c ) {
173+
ptr1 = &a;
174+
ptr2 = &b;
175+
ptr3 = &c;
176+
setMsg( "sub3_c_default" );
177+
}
178+
179+
void sub3_c_cdecl( UDT const& a, UDT const& b, UDT const& c ) {
180+
ptr1 = &a;
181+
ptr2 = &b;
182+
ptr3 = &c;
183+
setMsg( "sub3_c_cdecl" );
184+
}
185+
186+
void sub3_c_stdcall( UDT const& a, UDT const& b, UDT const& c ) {
187+
ptr1 = &a;
188+
ptr2 = &b;
189+
ptr3 = &c;
190+
setMsg( "sub3_c_stdcall" );
191+
}
192+
193+
UDT func3_c_default( UDT const& a, UDT const& b, UDT const& c ) {
194+
UDT ret = {0};
195+
ptr1 = &a;
196+
ptr2 = &b;
197+
ptr3 = &c;
198+
setMsg( "func3_c_default" );
199+
return ret;
200+
}
201+
202+
UDT func3_c_cdecl( UDT const& a, UDT const& b, UDT const& c ) {
203+
UDT ret = {0};
204+
ptr1 = &a;
205+
ptr2 = &b;
206+
ptr3 = &c;
207+
setMsg( "func3_c_cdecl" );
208+
return ret;
209+
}
210+
211+
UDT func3_c_stdcall( UDT const& a, UDT const& b, UDT const& c ) {
212+
UDT ret = {0};
213+
ptr1 = &a;
214+
ptr2 = &b;
215+
ptr3 = &c;
216+
setMsg( "func3_c_stdcall" );
217+
return ret;
218+
}
219+
} // extern "C"
220+
221+
void sub1_cpp_default( UDT const& a ) {
222+
ptr1 = &a;
223+
setMsg( "sub1_cpp_default" );
224+
}
225+
226+
void sub1_cpp_cdecl( UDT const& a ) {
227+
ptr1 = &a;
228+
setMsg( "sub1_cpp_cdecl" );
229+
}
230+
231+
void sub1_cpp_stdcall( UDT const& a ) {
232+
ptr1 = &a;
233+
setMsg( "sub1_cpp_stdcall" );
234+
}
235+
236+
UDT func1_cpp_default( UDT const& a ) {
237+
UDT ret = {0};
238+
ptr1 = &a;
239+
setMsg( "func1_cpp_default" );
240+
return ret;
241+
}
242+
243+
UDT func1_cpp_cdecl( UDT const& a ) {
244+
UDT ret = {0};
245+
ptr1 = &a;
246+
setMsg( "func1_cpp_cdecl" );
247+
return ret;
248+
}
249+
250+
UDT func1_cpp_stdcall( UDT const& a ) {
251+
UDT ret = {0};
252+
ptr1 = &a;
253+
setMsg( "func1_cpp_stdcall" );
254+
return ret;
255+
}
256+
257+
void sub2_cpp_default( UDT const& a, UDT const& b ) {
258+
ptr1 = &a;
259+
ptr2 = &b;
260+
setMsg( "sub2_cpp_default" );
261+
}
262+
263+
void sub2_cpp_cdecl( UDT const& a, UDT const& b ) {
264+
ptr1 = &a;
265+
ptr2 = &b;
266+
setMsg( "sub2_cpp_cdecl" );
267+
}
268+
269+
void sub2_cpp_stdcall( UDT const& a, UDT const& b ) {
270+
ptr1 = &a;
271+
ptr2 = &b;
272+
setMsg( "sub2_cpp_stdcall" );
273+
}
274+
275+
UDT func2_cpp_default( UDT const& a, UDT const& b ) {
276+
UDT ret = {0};
277+
ptr1 = &a;
278+
ptr2 = &b;
279+
setMsg( "func2_cpp_default" );
280+
return ret;
281+
}
282+
283+
UDT func2_cpp_cdecl( UDT const& a, UDT const& b ) {
284+
UDT ret = {0};
285+
ptr1 = &a;
286+
ptr2 = &b;
287+
setMsg( "func2_cpp_cdecl" );
288+
return ret;
289+
}
290+
291+
UDT func2_cpp_stdcall( UDT const& a, UDT const& b ) {
292+
UDT ret = {0};
293+
ptr1 = &a;
294+
ptr2 = &b;
295+
setMsg( "func2_cpp_stdcall" );
296+
return ret;
297+
}
298+
299+
void sub3_cpp_default( UDT const& a, UDT const& b, UDT const& c ) {
300+
ptr1 = &a;
301+
ptr2 = &b;
302+
ptr3 = &c;
303+
setMsg( "sub3_cpp_default" );
304+
}
305+
306+
void sub3_cpp_cdecl( UDT const& a, UDT const& b, UDT const& c ) {
307+
ptr1 = &a;
308+
ptr2 = &b;
309+
ptr3 = &c;
310+
setMsg( "sub3_cpp_cdecl" );
311+
}
312+
313+
void sub3_cpp_stdcall( UDT const& a, UDT const& b, UDT const& c ) {
314+
ptr1 = &a;
315+
ptr2 = &b;
316+
ptr3 = &c;
317+
setMsg( "sub3_cpp_stdcall" );
318+
}
319+
320+
UDT func3_cpp_default( UDT const& a, UDT const& b, UDT const& c ) {
321+
UDT ret = {0};
322+
ptr1 = &a;
323+
ptr2 = &b;
324+
ptr3 = &c;
325+
setMsg( "func3_cpp_default" );
326+
return ret;
327+
}
328+
329+
UDT func3_cpp_cdecl( UDT const& a, UDT const& b, UDT const& c ) {
330+
UDT ret = {0};
331+
ptr1 = &a;
332+
ptr2 = &b;
333+
ptr3 = &c;
334+
setMsg( "func3_cpp_cdecl" );
335+
return ret;
336+
}
337+
338+
UDT func3_cpp_stdcall( UDT const& a, UDT const& b, UDT const& c ) {
339+
UDT ret = {0};
340+
ptr1 = &a;
341+
ptr2 = &b;
342+
ptr3 = &c;
343+
setMsg( "func3_cpp_stdcall" );
344+
return ret;
345+
}

0 commit comments

Comments
 (0)