Skip to content

Commit 5407d98

Browse files
committed
internal: Split symbStructAddBase() from symbStructBegin()
This could be used to allow adding multiple bases (multiple inheritance, or at least interfaces...) in the future, by calling symbStructAddBase() repeatedly.
1 parent 46c2f30 commit 5407d98

File tree

6 files changed

+39
-30
lines changed

6 files changed

+39
-30
lines changed

src/compiler/ast-node-data.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private sub hCreateDataDesc( )
268268
static as FBARRAYDIM dTB(0)
269269

270270
'' Using FIELD = 1, to pack it as done by the rtlib
271-
ast.data.desc = symbStructBegin( NULL, NULL, NULL, "__FB_DATADESC$", NULL, FALSE, 1, NULL, 0, 0 )
271+
ast.data.desc = symbStructBegin( NULL, NULL, NULL, "__FB_DATADESC$", NULL, FALSE, 1, FALSE, 0, 0 )
272272

273273
'' type as short
274274
symbAddField( ast.data.desc, "type", 0, dTB(), _

src/compiler/parser-decl-struct.bas

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,15 @@ private function hTypeAdd _
631631

632632
dim as FBSYMBOL ptr s = any
633633

634-
s = symbStructBegin( NULL, NULL, parent, id, id_alias, isunion, align, baseSubtype, 0, 0 )
634+
s = symbStructBegin( NULL, NULL, parent, id, id_alias, isunion, align, (baseSubtype <> NULL), 0, 0 )
635635
if( s = NULL ) then
636636
errReportEx( FB_ERRMSG_DUPDEFINITION, id )
637637
'' error recovery: create a fake symbol
638-
s = symbStructBegin( NULL, NULL, parent, symbUniqueLabel( ), NULL, isunion, align, NULL, 0, 0 )
638+
s = symbStructBegin( NULL, NULL, parent, symbUniqueLabel( ), NULL, isunion, align, (baseSubtype <> NULL), 0, 0 )
639+
end if
640+
641+
if( baseSubtype ) then
642+
symbStructAddBase( s, baseSubtype )
639643
end if
640644

641645
'' Comment? SttSeparator

src/compiler/symb-comp.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ sub symbCompRTTIInit( )
13151315
'' type fb_RTTI$
13161316
'' (using fb_RTTI$ instead of $fb_RTTI to prevent gdb/stabs confusion,
13171317
'' where leading $ has special meaning)
1318-
rttitype = symbStructBegin( NULL, NULL, NULL, "fb_RTTI$", "fb_RTTI$", FALSE, 0, NULL, 0, 0 )
1318+
rttitype = symbStructBegin( NULL, NULL, NULL, "fb_RTTI$", "fb_RTTI$", FALSE, 0, FALSE, 0, 0 )
13191319
symb.rtti.fb_rtti = rttitype
13201320

13211321
'' stdlibvtable as any ptr
@@ -1338,7 +1338,7 @@ sub symbCompRTTIInit( )
13381338
ptypename = @"OBJECT"
13391339
end if
13401340
'' (using fb_Object$ instead of $fb_Object - ditto)
1341-
objtype = symbStructBegin( NULL, NULL, NULL, ptypename, "fb_Object$", FALSE, 0, NULL, 0, 0 )
1341+
objtype = symbStructBegin( NULL, NULL, NULL, ptypename, "fb_Object$", FALSE, 0, FALSE, 0, 0 )
13421342
symb.rtti.fb_object = objtype
13431343
symbSetHasRTTI( objtype )
13441344
symbSetIsUnique( objtype )

src/compiler/symb-struct.bas

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function symbStructBegin _
2424
byval id_alias as const zstring ptr, _
2525
byval isunion as integer, _
2626
byval align as integer, _
27-
byval base_ as FBSYMBOL ptr, _
27+
byval is_derived as integer, _
2828
byval attrib as integer, _
2929
byval options as integer _
3030
) as FBSYMBOL ptr
@@ -84,35 +84,38 @@ function symbStructBegin _
8484
s->udt.retdtype = FB_DATATYPE_INVALID
8585
s->udt.dbg.typenum = INVALID
8686
s->udt.ext = NULL
87+
s->udt.base = NULL
8788

88-
'' extending another UDT?
89-
if( base_ <> NULL ) then
90-
static as FBARRAYDIM dTB(0 to 0)
91-
92-
'' (using base$ instead of $base to prevent gdb/stabs confusion,
93-
'' where leading $ has special meaning)
94-
s->udt.base = symbAddField( s, "base$", 0, dTB(), FB_DATATYPE_STRUCT, base_, 0, 0, 0 )
95-
89+
if( is_derived ) then
9690
symbSetIsUnique( s )
9791
symbNestBegin( s, FALSE )
98-
symbNamespaceImportEx( base_, s )
99-
100-
if( symbGetHasRTTI( base_ ) ) then
101-
symbSetHasRTTI( s )
102-
103-
'' inherit the vtable elements and abstracts counts
104-
assert( base_->udt.ext->vtableelements >= 2 )
105-
symbUdtAllocExt( s )
106-
s->udt.ext->vtableelements = base_->udt.ext->vtableelements
107-
s->udt.ext->abstractcount = base_->udt.ext->abstractcount
108-
end if
109-
else
110-
s->udt.base = NULL
11192
end if
11293

11394
function = s
11495
end function
11596

97+
sub symbStructAddBase( byval s as FBSYMBOL ptr, byval base_ as FBSYMBOL ptr )
98+
static as FBARRAYDIM dTB(0 to 0)
99+
100+
assert( s->udt.base = NULL )
101+
102+
'' (using base$ instead of $base to prevent gdb/stabs confusion,
103+
'' where leading $ has special meaning)
104+
s->udt.base = symbAddField( s, "base$", 0, dTB(), FB_DATATYPE_STRUCT, base_, 0, 0, 0 )
105+
106+
symbNamespaceImportEx( base_, s )
107+
108+
if( symbGetHasRTTI( base_ ) ) then
109+
symbSetHasRTTI( s )
110+
111+
'' inherit the vtable elements and abstracts counts
112+
assert( base_->udt.ext->vtableelements >= 2 )
113+
symbUdtAllocExt( s )
114+
s->udt.ext->vtableelements = base_->udt.ext->vtableelements
115+
s->udt.ext->abstractcount = base_->udt.ext->abstractcount
116+
end if
117+
end sub
118+
116119
function typeCalcNaturalAlign _
117120
( _
118121
byval dtype as integer, _

src/compiler/symb-var.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ sub symbVarInit( )
1919
static as FBARRAYDIM dTB(0)
2020

2121
'' type FBARRAYDIM
22-
symb.fbarraydim = symbStructBegin( NULL, NULL, NULL, "__FB_ARRAYDIMTB$", NULL, FALSE, 0, NULL, 0, 0 )
22+
symb.fbarraydim = symbStructBegin( NULL, NULL, NULL, "__FB_ARRAYDIMTB$", NULL, FALSE, 0, FALSE, 0, 0 )
2323

2424
'' elements as integer
2525
symbAddField( symb.fbarraydim, "elements", 0, dTB(), _
@@ -187,7 +187,7 @@ function symbAddArrayDescriptorType _
187187
'' descriptor type, e.g. in hMangleUdtId().
188188
''
189189
attrib or= FB_SYMBATTRIB_DESCRIPTOR
190-
sym = symbStructBegin( symtb, hashtb, NULL, id, aliasid, FALSE, 0, NULL, attrib, FB_SYMBOPT_PRESERVECASE )
190+
sym = symbStructBegin( symtb, hashtb, NULL, id, aliasid, FALSE, 0, FALSE, attrib, FB_SYMBOPT_PRESERVECASE )
191191
assert( sym )
192192
dTB(0).lower = 0
193193
dTB(0).upper = 0

src/compiler/symb.bi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,11 +1168,13 @@ declare function symbStructBegin _
11681168
byval id_alias as const zstring ptr, _
11691169
byval isunion as integer, _
11701170
byval align as integer, _
1171-
byval base_ as FBSYMBOL ptr, _
1171+
byval is_derived as integer, _
11721172
byval attrib as integer, _
11731173
byval options as integer _
11741174
) as FBSYMBOL ptr
11751175

1176+
declare sub symbStructAddBase( byval struct as FBSYMBOL ptr, byval base_ as FBSYMBOL ptr )
1177+
11761178
declare function typeCalcNaturalAlign _
11771179
( _
11781180
byval dtype as integer, _

0 commit comments

Comments
 (0)