Skip to content

Commit f19bfb1

Browse files
committed
fbc: formatting and comments for calling conventions in tests/cpp
1 parent c215885 commit f19bfb1

File tree

4 files changed

+69
-64
lines changed

4 files changed

+69
-64
lines changed

tests/cpp/class-cpp.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// implementation for class-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+
17
#define NULL 0
28
static const void * ptr1 = NULL; // this/lhs address
39
static const void * ptr2 = NULL; // rhs address
@@ -51,12 +57,14 @@ int getVal3() {
5157
return val3;
5258
}
5359

60+
// simple UDT class to test with and
61+
// we declare same on fbc side
62+
5463
class UDT
5564
{
5665
public:
5766

5867
int value;
59-
void* self;
6068

6169
UDT();
6270
UDT( UDT const& rhs );
@@ -80,7 +88,6 @@ UDT operator-( int const& lhs, UDT const& rhs );
8088
// constructor UDT()
8189
UDT::UDT()
8290
{
83-
self = this;
8491
if( initial ) {
8592
ptr1 = this;
8693
ptr2 = NULL;
@@ -95,7 +102,6 @@ UDT::UDT()
95102
// constructor UDT( byref rhs as const UDT )
96103
UDT::UDT( UDT const& rhs )
97104
{
98-
self = this;
99105
if( initial ) {
100106
ptr1 = this;
101107
ptr2 = &rhs;
@@ -110,7 +116,6 @@ UDT::UDT( UDT const& rhs )
110116
// constructor UDT( byref rhs as const long )
111117
UDT::UDT( int const& rhs )
112118
{
113-
self = this;
114119
if( initial ) {
115120
ptr1 = this;
116121
ptr2 = &rhs;
@@ -150,6 +155,7 @@ UDT& UDT::operator=( UDT const& rhs )
150155
return *this;
151156
}
152157

158+
/*
153159
// !!! TODO !!!: operator UDT.+( byref rhs as const long )
154160
UDT& UDT::operator+( int const& rhs )
155161
{
@@ -177,6 +183,7 @@ UDT& UDT::operator-( int const& rhs )
177183
value -= rhs;
178184
return *this;
179185
}
186+
*/
180187

181188
// operator +( byref lhs as const UDT, byref rhs as const UDT ) as UDT
182189
UDT operator+( UDT const& lhs, UDT const& rhs )
@@ -229,4 +236,3 @@ UDT operator-( int const& lhs, UDT const& rhs )
229236

230237
return UDT(lhs - rhs.value);
231238
}
232-

tests/cpp/class-fbc.bas

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,18 @@
22

33
'' test mapping of mangling between c++ class and fbc type
44

5+
'' helper macro to track progress
56
#define DLOG( msg ) '' print #msg
67

7-
/'
8-
#undef assert
9-
#macro assert( expr )
10-
if( (expr) = 0 ) then
11-
'' filename.ext(###): assertion failed at PROC: EXPR
12-
print __FILE__; "("; __LINE__; "): assertion failed at "; __FUNCTION__; ": "; #expr
13-
end if
14-
#endmacro
15-
'/
16-
178
#if ENABLE_CHECK_BUGS
189
#define DOTEST
1910
#else
11+
'' thiscall is not supported in -gen gas
2012
#if __FB_BACKEND__ <> "gas"
2113
#define DOTEST
2214
#endif
2315
#endif
2416

25-
#ifdef DOTEST
26-
2717
'' !!! TODO !!! this default should be handled in fbc
2818
#if defined(__FB_WIN32__) and not defined(__FB_64BIT__)
2919
#define thiscall __thiscall
@@ -36,47 +26,54 @@
3626
#endif
3727

3828
extern "c++"
29+
'' getters to retrieve call information
30+
'' from the c++ side
31+
declare sub setInitial( byval flag as long )
32+
declare sub resetChecks()
33+
declare function getPtr1() as any ptr
34+
declare function getPtr2() as any ptr
35+
declare function getMsg1() as zstring ptr
36+
declare function getVal1() as long
37+
declare function getVal2() as long
38+
declare function getVal3() as long
39+
end extern
40+
41+
extern "c++"
42+
'' simple UDT to test with and we
43+
'' declare the same on c++ side
44+
45+
type UDT
46+
value as long
3947

40-
declare sub setInitial( byval flag as long )
41-
declare sub resetChecks()
42-
declare function getPtr1() as any ptr
43-
declare function getPtr2() as any ptr
44-
declare function getMsg1() as zstring ptr
45-
declare function getVal1() as long
46-
declare function getVal2() as long
47-
declare function getVal3() as long
48-
49-
type UDT
50-
value as long
51-
self as any ptr
52-
53-
declare constructor thiscall ()
54-
declare constructor thiscall ( byref rhs as const UDT )
55-
declare constructor thiscall ( byref rhs as const long )
56-
declare destructor thiscall ()
57-
declare operator let thiscall ( byref rhs as const UDT )
58-
/' declare operator thiscall +( byref rhs as const long ) as UDT '/
59-
/' declare operator thiscall -( byref rhs as const long ) as UDT '/
60-
61-
end type
62-
63-
'' global operators
64-
declare operator +( byref lhs as const UDT, byref rhs as const UDT ) as UDT
65-
declare operator -( byref lhs as const UDT, byref rhs as const UDT ) as UDT
66-
declare operator +( byref lhs as const long, byref rhs as const UDT ) as UDT
67-
declare operator -( byref lhs as const long, byref rhs as const UDT ) as UDT
48+
declare constructor thiscall ()
49+
declare constructor thiscall ( byref rhs as const UDT )
50+
declare constructor thiscall ( byref rhs as const long )
51+
declare destructor thiscall ()
52+
declare operator let thiscall ( byref rhs as const UDT )
53+
/' declare operator thiscall +( byref rhs as const long ) as UDT '/
54+
/' declare operator thiscall -( byref rhs as const long ) as UDT '/
55+
56+
end type
57+
58+
'' global operators
59+
declare operator +( byref lhs as const UDT, byref rhs as const UDT ) as UDT
60+
declare operator -( byref lhs as const UDT, byref rhs as const UDT ) as UDT
61+
declare operator +( byref lhs as const long, byref rhs as const UDT ) as UDT
62+
declare operator -( byref lhs as const long, byref rhs as const UDT ) as UDT
6863

6964
end extern
7065

7166
#macro checkResults( p1, p2, v1, v2, v3, m1 )
67+
assert( m1 = *getMsg1() )
7268
assert( p1 = getPtr1() )
7369
assert( p2 = getPtr2() )
7470
assert( v1 = getVal1() )
7571
assert( v2 = getVal2() )
7672
assert( v3 = getVal3() )
77-
assert( m1 = *getMsg1() )
7873
#endmacro
7974

75+
#ifdef DOTEST
76+
8077
'' enable results for ctor/dtor/copy-ctor/let
8178
setInitial( 1 )
8279

@@ -152,7 +149,7 @@ scope
152149
dim as UDT b = 11
153150
dim as UDT c
154151
resetChecks()
155-
c = a + b
152+
c = (a + b)
156153
checkResults( @a, @b, 3, 11, 14, "UDT operator+( UDT const& lhs, UDT const& rhs )" )
157154
end scope
158155

@@ -186,5 +183,4 @@ scope
186183
checkResults( @a, @b, 17, 5, 12, "UDT operator-( int const& lhs, UDT const& rhs )" )
187184
end scope
188185

189-
#endif
190-
186+
#endif '' DOTEST

tests/cpp/this-cpp.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
// implementation for this-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+
17
static void * ptr1 = 0;
28
static void * ptr2 = 0;
39
static void * ptr3 = 0;
410

5-
6-
// global getters:
7-
// we can retrieve argument information passed
8-
// by calling the getters
9-
1011
void resetChecks() {
1112
ptr1 = ptr2 = ptr3 = 0;
1213
}
@@ -69,6 +70,7 @@ void UDT_DEFAULT::loadpointer3( void* arg1, void* arg2 ) {
6970
// thiscall calling convention in c++
7071
// Normally, __attribute__((thiscall)) will generate warnings on
7172
// linux x86_64 so we should pass '-Wno-attributes' to gcc/g++
73+
// or later disable emitting the attribute in gcc backend.
7274

7375
class UDT_THISCALL {
7476
public:

tests/cpp/this-fbc.bas

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#if ENABLE_CHECK_BUGS
88
#define DOTEST
99
#else
10+
'' thiscall is not supported in -gen gas
1011
#if __FB_BACKEND__ <> "gas"
1112
#define DOTEST
1213
#endif
@@ -15,11 +16,13 @@
1516
#ifdef DOTEST
1617

1718
extern "c++"
18-
19-
declare sub resetChecks()
20-
declare function getPtr1() as any ptr
21-
declare function getPtr2() as any ptr
22-
declare function getPtr3() as any ptr
19+
'' getters to retrieve call information
20+
'' from the c++ side
21+
declare sub resetChecks()
22+
declare function getPtr1() as any ptr
23+
declare function getPtr2() as any ptr
24+
declare function getPtr3() as any ptr
25+
end extern
2326

2427
'' default calling convention
2528
'' on the cpp side, we are not explicitly specifying calling
@@ -32,6 +35,8 @@ declare function getPtr3() as any ptr
3235
#define thiscall
3336
#endif
3437

38+
extern "c++"
39+
3540
type UDT_DEFAULT
3641

3742
value as long
@@ -212,8 +217,4 @@ end scope
212217
'' check results of destructor called
213218
checkResults( p1, 0, 0 )
214219

215-
#else
216-
#if ENABLE_CHECK_BUGS
217-
assert( 0 )
218-
#endif
219-
#endif
220+
#endif '' DOTEST

0 commit comments

Comments
 (0)