Skip to content

Commit df424ed

Browse files
committed
fbc: remove implementation of the deleting destructor (g++ compatibility)
- the deleting destructor was being automatically generated (implementation) even when the class (UDT) was being declared only - add tests for (simplified) virtual destructor and method in tests/cpp/derived.bmk - add method test for class test in tests/cpp/class.bmk
1 parent a1e9e16 commit df424ed

File tree

10 files changed

+769
-28
lines changed

10 files changed

+769
-28
lines changed

src/compiler/ast-node-proc.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,14 @@ function astProcEnd( byval callrtexit as integer ) as integer
673673
res = (symbCheckLabels(symbGetProcSymbTbHead(parser.currproc)) = 0)
674674

675675
if( res ) then
676-
'' Complete Destructor?
676+
'' Complete Destructor? (D1)
677677
if( symbIsDestructor1( sym ) and enable_implicit_code ) then
678678
'' Call destructors, behind the exit label, so they'll
679679
'' always be called, even with early returns.
680680
hCallDtors( sym )
681681
end if
682682

683-
'' Deleting Destructor?
683+
'' Deleting Destructor? (D0)
684684
if( symbIsDestructor0( sym ) and enable_implicit_code ) then
685685
hCallDeleteDtor( sym )
686686
end if

src/compiler/parser-proc.bas

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,9 +1482,7 @@ function cProcHeader _
14821482
'' except for the destructor type
14831483
dim dtor0 as FBSYMBOL ptr = symbPreAddProc( NULL )
14841484
symbAddProcInstanceParam( parent, dtor0 )
1485-
pattrib and= not FB_PROCATTRIB_DESTRUCTOR1
1486-
pattrib or= FB_PROCATTRIB_DESTRUCTOR0
1487-
dtor0 = symbAddCtor( dtor0, NULL, attrib, pattrib, mode )
1485+
dtor0 = symbAddCtor( dtor0, NULL, attrib, ((pattrib and not FB_PROCATTRIB_DESTRUCTOR1) or FB_PROCATTRIB_DESTRUCTOR0), mode )
14881486
end if
14891487
end if
14901488

@@ -1848,7 +1846,7 @@ sub cProcStmtBegin( byval attrib as FB_SYMBATTRIB, byval pattrib as FB_PROCATTRI
18481846
stk->proc.endlabel = astGetProcExitlabel( ast.proc.curr )
18491847
end sub
18501848

1851-
'' ProcStmtEnd = END (SUB | FUNCTION) .
1849+
'' ProcStmtEnd = END (SUB | FUNCTION | OPERATOR | CONSTRUCTOR | DESTRUCTOR | PROPERTY) .
18521850
sub cProcStmtEnd( )
18531851
dim as FB_CMPSTMTSTK ptr stk = any
18541852
dim as FBSYMBOL ptr proc_res = any
@@ -1894,7 +1892,7 @@ sub cProcStmtEnd( )
18941892
end if
18951893
end if
18961894

1897-
'' always finish
1895+
'' always finish
18981896
astProcEnd( FALSE )
18991897

19001898
'' Close namespace again if cProcHeader() opened it

src/compiler/symb-comp.bas

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -628,21 +628,17 @@ sub symbUdtDeclareDefaultMembers _
628628
'' Complete dtor
629629
default.dtor1 = hDeclareProc( udt, INVALID, FB_DATATYPE_INVALID, FB_SYMBATTRIB_NONE, FB_PROCATTRIB_DESTRUCTOR1 )
630630

631+
'' c++? we may need other dtors too...
631632
if( symbGetMangling( udt ) = FB_MANGLING_CPP ) then
632633
'' Deleting dtor
633634
default.dtor0 = hDeclareProc( udt, INVALID, FB_DATATYPE_INVALID, FB_SYMBATTRIB_NONE, FB_PROCATTRIB_DESTRUCTOR0 )
634635
end if
635636

636637
'' Don't allow the implicit dtor to override a FINAL dtor from the base
637638
symbProcCheckOverridden( default.dtor1, TRUE )
638-
end if
639-
end if
640639

641-
if( symbGetMangling( udt ) = FB_MANGLING_CPP ) then
642-
if( default.dtor0 = NULL ) then
643-
'' deleting dtor will be implicitly declared if the complete dtor was explicitly declared
644-
default.dtor0 = symbGetCompDtor0( udt )
645640
end if
641+
646642
end if
647643

648644
end sub
@@ -810,7 +806,7 @@ sub symbSetCompDtor1( byval sym as FBSYMBOL ptr, byval proc as FBSYMBOL ptr )
810806
assert( symbIsDestructor1( proc ) )
811807
symbUdtAllocExt( sym )
812808
if( sym->udt.ext->dtor1 = NULL ) then
813-
'' Add dtor
809+
'' Add deleting dtor (D1)
814810
sym->udt.ext->dtor1 = proc
815811
end if
816812
end if
@@ -821,7 +817,7 @@ sub symbSetCompDtor0( byval sym as FBSYMBOL ptr, byval proc as FBSYMBOL ptr )
821817
assert( symbIsDestructor0( proc ) )
822818
symbUdtAllocExt( sym )
823819
if( sym->udt.ext->dtor0 = NULL ) then
824-
'' Add dtor
820+
'' Add complete dtor (D0)
825821
sym->udt.ext->dtor0 = proc
826822
end if
827823
end if
@@ -1076,11 +1072,11 @@ private sub hInsertImported _
10761072
if( ns <> NULL ) then
10771073
symbGetCompExt( ns )->cnt += 1
10781074
if( symbGetCompExt( ns )->cnt = 1 ) then
1079-
'' add to import hash tb list
1080-
symbHashListInsertNamespace( ns, _
1081-
symbGetCompSymbTb( ns ).head )
1082-
end if
1083-
end if
1075+
'' add to import hash tb list
1076+
symbHashListInsertNamespace( ns, _
1077+
symbGetCompSymbTb( ns ).head )
1078+
end if
1079+
end if
10841080

10851081
imp_ = symbGetImportNext( imp_ )
10861082
loop

src/compiler/symb-proc.bas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,10 @@ add_proc:
932932
'' There can always only be one complete dtor, so there is no
933933
'' need to do a lookup and/or overload checks.
934934
overridden = symbGetCompDtor1( parent->udt.base->subtype )
935+
elseif( symbIsDestructor0( proc ) ) then
936+
'' There can always only be deleting dtor, so there is no
937+
'' need to do a lookup and/or overload checks.
938+
overridden = symbGetCompDtor0( parent->udt.base->subtype )
935939
elseif( symbIsOperator( proc ) ) then
936940
'' Get the corresponding operator from the base
937941
'' (actually a chain of overloads for that particular operator)

src/compiler/symb.bi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,10 +2504,10 @@ declare sub symbProcRecalcRealType( byval proc as FBSYMBOL ptr )
25042504

25052505
#define symbIsConstructor(s) ((s->pattrib and FB_PROCATTRIB_CONSTRUCTOR) <> 0)
25062506

2507-
#define symbIsDestructor0(s) ((s->pattrib and FB_PROCATTRIB_DESTRUCTOR0) <> 0)
2508-
25092507
#define symbIsDestructor1(s) ((s->pattrib and FB_PROCATTRIB_DESTRUCTOR1) <> 0)
25102508

2509+
#define symbIsDestructor0(s) ((s->pattrib and FB_PROCATTRIB_DESTRUCTOR0) <> 0)
2510+
25112511
#define symbIsOperator(s) ((s->pattrib and FB_PROCATTRIB_OPERATOR) <> 0)
25122512

25132513
#define symbIsProperty(s) ((s->pattrib and FB_PROCATTRIB_PROPERTY) <> 0)

tests/cpp/class-cpp.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class UDT
6969
UDT();
7070
UDT( UDT const& rhs );
7171
UDT( int const& rhs );
72-
~UDT();
72+
~UDT();
73+
void method( int const& rhs );
7374

7475
// assignment
7576
UDT& operator=( UDT const& rhs );
@@ -140,6 +141,20 @@ UDT::~UDT()
140141
}
141142
}
142143

144+
// sub UDT.method( byref rhs as const long )
145+
void UDT::method( int const& rhs )
146+
{
147+
if( initial ) {
148+
ptr1 = this;
149+
ptr2 = &rhs;
150+
setMsg( "void UDT::method( int const& rhs )" );
151+
val1 = value;
152+
val2 = rhs;
153+
val3 = rhs;
154+
}
155+
value = rhs;
156+
}
157+
143158
// operator UDT.let( byref rhs as const UDT )
144159
UDT& UDT::operator=( UDT const& rhs )
145160
{

tests/cpp/class-fbc.bas

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ extern "c++"
5656
declare constructor thiscall ( byref rhs as const UDT )
5757
declare constructor thiscall ( byref rhs as const long )
5858
declare destructor thiscall ()
59+
declare sub method thiscall ( byref rhs as const long )
5960
declare operator let thiscall ( byref rhs as const UDT )
60-
/' declare operator thiscall +( byref rhs as const long ) as UDT '/
61-
/' declare operator thiscall -( byref rhs as const long ) as UDT '/
61+
'' !!! TODO !!! member operators
62+
'' !!! TODO !!! declare operator + thiscall ( byref rhs as const long ) as UDT
63+
'' !!! TODO !!! declare operator - thiscall ( byref rhs as const long ) as UDT
6264

6365
end type
6466

@@ -123,6 +125,17 @@ scope
123125
assert( b.value = 2 )
124126
end scope
125127

128+
DLOG( sub UDT.method( byref rhs as const long ) )
129+
scope
130+
dim a1 as long = 1, a2 as long = 2
131+
resetChecks()
132+
dim b as UDT = a1
133+
checkResults( @b, @a1, -1, 1, 1, "UDT::UDT( int const& rhs )" )
134+
b.method( a2 )
135+
checkResults( @b, @a2, 1, 2, 2, "void UDT::method( int const& rhs )" )
136+
assert( b.value = a2 )
137+
end scope
138+
126139
DLOG( operator UDT.let( byref rhs as const UDT ) )
127140
scope
128141
dim a as UDT = 2
@@ -137,8 +150,8 @@ end scope
137150
'' disable results for ctor/dtor/copy-ctor/let
138151
setInitial( 0 )
139152

140-
/'
141-
'' !!! TODO !!!
153+
/'
154+
!!! TODO !!!
142155
DLOG( operator UDT.+( byref rhs as const long ) )
143156
scope
144157
dim as UDT a = 3
@@ -149,7 +162,6 @@ scope
149162
checkResults( @a, @b, 3, 11, 14, "UDT::operator+( int rhs )" )
150163
end scope
151164

152-
'' !!! TODO !!!
153165
DLOG( operator UDT.-( byref rhs as const long ) as UDT )
154166
scope
155167
dim as UDT a = 17

0 commit comments

Comments
 (0)