Skip to content

Commit 9317835

Browse files
committed
fbc: g++ ABI - add tracking for complete and deleting destructors
- internal changes - FB_STRUCTEXT - rename dtor to dtor1 and add dtor0 - SYMBDEFAULTMEMBERS - rename dtor to dtor1 and add dtor0 - symbSetCompDtor() - rename to symbSetCompDtor1() and add symbSetCompDtor0() - symbGetCompDtor() - rename to symbGetCompDtor1() and add symbGetCompDtor0()
1 parent acc219f commit 9317835

13 files changed

+81
-34
lines changed

src/compiler/ast-helper.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function astBuildVarDtorCall overload _
153153
'' UDT var with dtor?
154154
if( symbHasDtor( s ) ) then
155155
if( check_access ) then
156-
if( symbCheckAccess( symbGetCompDtor( symbGetSubtype( s ) ) ) = FALSE ) then
156+
if( symbCheckAccess( symbGetCompDtor1( symbGetSubtype( s ) ) ) = FALSE ) then
157157
errReport( FB_ERRMSG_NOACCESSTODTOR )
158158
end if
159159
end if
@@ -543,7 +543,7 @@ function astBuildDtorCall _
543543
dim as ASTNODE ptr callexpr = any
544544

545545
'' Can be virtual
546-
dtor = symbGetCompDtor( sym )
546+
dtor = symbGetCompDtor1( sym )
547547
if( ignore_virtual ) then
548548
callexpr = astNewCALL( dtor )
549549
else

src/compiler/ast-node-proc.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ sub astProcBegin( byval sym as FBSYMBOL ptr, byval ismain as integer )
500500
astNewVAR( symbGetParamVar( argv ) ) )
501501

502502
'' Destructor?
503-
elseif( symbIsDestructor1( sym ) and enable_implicit_code ) then
503+
elseif( (symbIsDestructor0( sym ) or symbIsDestructor1( sym )) and enable_implicit_code ) then
504504
''
505505
'' If the UDT has a vptr, reset it at the top of destructors,
506506
'' such that the vptr always matches the type of object that
@@ -1296,7 +1296,7 @@ private sub hCallBaseDtor _
12961296
'' Just like derived classes are not responsible for initializing their
12971297
'' base class, they shouldn't be made responsible for cleaning it up.
12981298

1299-
dtor = symbGetCompDtor( symbGetSubtype( base_ ) )
1299+
dtor = symbGetCompDtor1( symbGetSubtype( base_ ) )
13001300
if( dtor = NULL ) then
13011301
exit sub
13021302
end if

src/compiler/parser-decl-struct.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private sub hFieldInit _
183183
end if
184184

185185
'' Does it have a destructor?
186-
defctor = symbGetCompDtor( subtype )
186+
defctor = symbGetCompDtor1( subtype )
187187
if( defctor ) then
188188
'' Check whether we have access
189189
if( symbCheckAccess( defctor ) = FALSE ) then

src/compiler/parser-decl-var.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ private function hFlushInitializer _
11891189
'' object?
11901190
if( has_dtor and (not symbIsRef( sym )) ) then
11911191
'' check visibility
1192-
if( symbCheckAccess( symbGetCompDtor( symbGetSubtype( sym ) ) ) = FALSE ) then
1192+
if( symbCheckAccess( symbGetCompDtor1( symbGetSubtype( sym ) ) ) = FALSE ) then
11931193
errReport( FB_ERRMSG_NOACCESSTODTOR )
11941194
end if
11951195
end if

src/compiler/parser-expr-variable.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private function hMemberId( byval parent as FBSYMBOL ptr ) as FBSYMBOL ptr
246246
case FB_TK_CONSTRUCTOR
247247
res = symbGetCompCtorHead( parent )
248248
case FB_TK_DESTRUCTOR
249-
res = symbGetCompDtor( parent )
249+
res = symbGetCompDtor1( parent )
250250
end select
251251

252252
if( res ) then

src/compiler/parser-proc.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ function cProcHeader _
15561556
case FB_TK_CONSTRUCTOR
15571557
head_proc = symbGetCompCtorHead( parent )
15581558
case FB_TK_DESTRUCTOR
1559-
head_proc = symbGetCompDtor( parent )
1559+
head_proc = symbGetCompDtor1( parent )
15601560
case FB_TK_OPERATOR
15611561
head_proc = symbGetCompOpOvlHead( parent, op )
15621562
end select

src/compiler/parser-quirk-mem.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ sub cOperatorDelete( )
260260

261261
'' check visibility
262262
if( typeHasDtor( typeDeref( dtype ), subtype ) ) then
263-
if( symbCheckAccess( symbGetCompDtor( subtype ) ) = FALSE ) then
263+
if( symbCheckAccess( symbGetCompDtor1( subtype ) ) = FALSE ) then
264264
errReport( FB_ERRMSG_NOACCESSTODTOR )
265265
end if
266266
end if

src/compiler/rtl-array.bas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ function rtlArrayClear( byval arrayexpr as ASTNODE ptr ) as ASTNODE ptr
370370
if( dtype = FB_DATATYPE_STRUCT ) then
371371
subtype = astGetSubtype( arrayexpr )
372372
ctor = symbGetCompDefCtor( subtype )
373-
dtor = symbGetCompDtor( subtype )
373+
dtor = symbGetCompDtor1( subtype )
374374

375375
'' No default ctor, but others? Then the rtlib cannot just clear
376376
'' that array of objects.
@@ -453,7 +453,7 @@ function rtlArrayErase _
453453
if( dtype = FB_DATATYPE_STRUCT ) then
454454
subtype = astGetSubtype( arrayexpr )
455455
ctor = symbGetCompDefCtor( subtype )
456-
dtor = symbGetCompDtor( subtype )
456+
dtor = symbGetCompDtor1( subtype )
457457

458458
'' No default ctor, but others? Then the rtlib cannot just clear
459459
'' that array of objects.
@@ -534,7 +534,7 @@ private sub hGetCtorDtorForRedim _
534534

535535
if( typeGetDtAndPtrOnly( dtype ) = FB_DATATYPE_STRUCT ) then
536536
ctor = symbGetCompDefCtor( subtype )
537-
dtor = symbGetCompDtor( subtype )
537+
dtor = symbGetCompDtor1( subtype )
538538

539539
'' Assuming there aren't any other ctors if there is no default one,
540540
'' because if it were possible to declare such a dynamic array,

src/compiler/symb-comp.bas

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,8 @@ sub symbUdtDeclareDefaultMembers _
559559
default.copyctor = NULL
560560
default.copyctorconst = NULL
561561
default.copyletopconst = NULL
562-
default.dtor = NULL
562+
default.dtor1 = NULL
563+
default.dtor0 = NULL
563564

564565
'' Ctor/inited fields and no ctor yet?
565566
if( (symbGetUDTHasCtorField( udt ) or symbGetUDTHasInitedField( udt )) and _
@@ -618,12 +619,18 @@ sub symbUdtDeclareDefaultMembers _
618619
symbUdtAllocExt( udt )
619620

620621
'' no default dtor explicitly defined?
621-
if( udt->udt.ext->dtor = NULL ) then
622-
'' Complete Dtor
623-
default.dtor = hDeclareProc( udt, INVALID, FB_DATATYPE_INVALID, FB_SYMBATTRIB_NONE, FB_PROCATTRIB_DESTRUCTOR1 )
622+
if( udt->udt.ext->dtor1 = NULL ) then
623+
624+
assert( udt->udt.ext->dtor0 = NULL )
625+
626+
'' Complete dtor
627+
default.dtor1 = hDeclareProc( udt, INVALID, FB_DATATYPE_INVALID, FB_SYMBATTRIB_NONE, FB_PROCATTRIB_DESTRUCTOR1 )
628+
629+
'' Deleting dtor
630+
default.dtor0 = hDeclareProc( udt, INVALID, FB_DATATYPE_INVALID, FB_SYMBATTRIB_NONE, FB_PROCATTRIB_DESTRUCTOR0 )
624631

625632
'' Don't allow the implicit dtor to override a FINAL dtor from the base
626-
symbProcCheckOverridden( default.dtor, TRUE )
633+
symbProcCheckOverridden( default.dtor1, TRUE )
627634
end if
628635
end if
629636

@@ -685,8 +692,12 @@ sub symbUdtImplementDefaultMembers _
685692
hAddCtorBody( udt, default.copyctor, TRUE )
686693
end if
687694

688-
if( default.dtor ) then
689-
hAddCtorBody( udt, default.dtor, FALSE )
695+
if( default.dtor1 ) then
696+
hAddCtorBody( udt, default.dtor1, FALSE )
697+
end if
698+
699+
if( default.dtor0 ) then
700+
hAddCtorBody( udt, default.dtor0, FALSE )
690701
end if
691702

692703
end sub
@@ -733,7 +744,7 @@ end function
733744
function symbCompIsTrivial( byval sym as FBSYMBOL ptr ) as integer
734745
assert( symbIsStruct( sym ) )
735746
function = ((symbGetCompCopyCtor( sym ) = NULL) and _
736-
(symbGetCompDtor( sym ) = NULL) and _
747+
(symbGetCompDtor1( sym ) = NULL) and _
737748
(not symbGetHasRTTI( sym )))
738749
end function
739750

@@ -783,13 +794,24 @@ sub symbCheckCompCtor( byval sym as FBSYMBOL ptr, byval proc as FBSYMBOL ptr )
783794
end if
784795
end sub
785796

786-
sub symbSetCompDtor( byval sym as FBSYMBOL ptr, byval proc as FBSYMBOL ptr )
797+
sub symbSetCompDtor1( byval sym as FBSYMBOL ptr, byval proc as FBSYMBOL ptr )
787798
if( symbIsStruct( sym ) ) then
788799
assert( symbIsDestructor1( proc ) )
789800
symbUdtAllocExt( sym )
790-
if( sym->udt.ext->dtor = NULL ) then
801+
if( sym->udt.ext->dtor1 = NULL ) then
802+
'' Add dtor
803+
sym->udt.ext->dtor1 = proc
804+
end if
805+
end if
806+
end sub
807+
808+
sub symbSetCompDtor0( byval sym as FBSYMBOL ptr, byval proc as FBSYMBOL ptr )
809+
if( symbIsStruct( sym ) ) then
810+
assert( symbIsDestructor0( proc ) )
811+
symbUdtAllocExt( sym )
812+
if( sym->udt.ext->dtor0 = NULL ) then
791813
'' Add dtor
792-
sym->udt.ext->dtor = proc
814+
sym->udt.ext->dtor0 = proc
793815
end if
794816
end if
795817
end sub
@@ -821,11 +843,21 @@ private function symbGetCompCopyCtor( byval sym as FBSYMBOL ptr ) as FBSYMBOL pt
821843
end if
822844
end function
823845

824-
function symbGetCompDtor( byval sym as FBSYMBOL ptr ) as FBSYMBOL ptr
846+
function symbGetCompDtor1( byval sym as FBSYMBOL ptr ) as FBSYMBOL ptr
847+
if( sym ) then
848+
if( symbIsStruct( sym ) ) then
849+
if( sym->udt.ext ) then
850+
function = sym->udt.ext->dtor1
851+
end if
852+
end if
853+
end if
854+
end function
855+
856+
function symbGetCompDtor0( byval sym as FBSYMBOL ptr ) as FBSYMBOL ptr
825857
if( sym ) then
826858
if( symbIsStruct( sym ) ) then
827859
if( sym->udt.ext ) then
828-
function = sym->udt.ext->dtor
860+
function = sym->udt.ext->dtor0
829861
end if
830862
end if
831863
end if

src/compiler/symb-data.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ function typeHasDtor _
322322

323323
select case( typeGet( dtype ) )
324324
case FB_DATATYPE_STRUCT '', FB_DATATYPE_CLASS
325-
function = (symbGetCompDtor( subtype ) <> NULL)
325+
function = (symbGetCompDtor1( subtype ) <> NULL)
326326
end select
327327

328328
end function

0 commit comments

Comments
 (0)