17 for i
as integer = 0
to AST_OPCODES-1
18 symb.globOpOvlTb(i).head = NULL
29 assert( symbIsStruct( udt ) )
30 if( udt->udt.ext = NULL )
then
31 udt->udt.ext =
xcallocate(
sizeof( FB_STRUCTEXT ) )
41 byval udt
as FBSYMBOL
ptr, _
43 byval add_rhs
as integer, _
44 byval attrib
as FB_SYMBATTRIB _
47 dim as FBSYMBOL
ptr proc =
any
59 assert( symbIsStruct( udt ) )
61 FB_PARAMMODE_BYREF, FB_SYMBATTRIB_NONE )
64 attrib
or= FB_SYMBATTRIB_METHOD
65 attrib
or= FB_SYMBATTRIB_PRIVATE
68 if(
op = INVALID )
then
70 FB_FUNCMODE_CDECL, FB_SYMBOPT_DECLARING )
74 FB_FUNCMODE_CDECL, FB_SYMBOPT_DECLARING )
93 if( udt->udt.ext->vtableelements = 0 )
then
94 udt->udt.ext->vtableelements = 2
99 static as FBARRAYDIM dTB(0)
100 dim as ASTNODE
ptr initree =
any, rttibase =
any
101 dim as FBSYMBOL
ptr rtti =
any, fld =
any
106 rtti =
symbAddVar( NULL, NULL, FB_DATATYPE_STRUCT, symb.rtti.fb_rtti, 0, 0, dTB(), _
107 FB_SYMBATTRIB_CONST
or FB_SYMBATTRIB_STATIC
or FB_SYMBATTRIB_SHARED, _
108 FB_SYMBOPT_PRESERVECASE )
109 rtti->stats
or= FB_SYMBSTATS_RTTITABLE
111 udt->udt.ext->rtti = rtti
114 initree =
astTypeIniBegin( FB_DATATYPE_STRUCT, symb.rtti.fb_rtti, FALSE, 0 )
127 if( udt->udt.
base )
then
130 rttibase =
astNewCONSTi( 0, typeAddrOf( FB_DATATYPE_VOID ) )
137 symbSetTypeIniTree( rtti, initree )
138 symbSetIsInitialized( rtti )
142 static as FBARRAYDIM dTB(0)
143 dim as ASTNODE
ptr initree =
any, basevtableinitree =
any
144 dim as FBSYMBOL
ptr member =
any, rtti =
any, vtable =
any
145 dim as integer i =
any, basevtableelements =
any
153 assert( udt->udt.ext->vtableelements >= 2 )
158 dTB(0).upper = udt->udt.ext->vtableelements - 1
159 vtable =
symbAddVar( NULL, NULL, typeAddrOf( FB_DATATYPE_VOID ), NULL, 0, 1, dTB(), _
160 FB_SYMBATTRIB_CONST
or FB_SYMBATTRIB_STATIC
or FB_SYMBATTRIB_SHARED, _
161 FB_SYMBOPT_PRESERVECASE )
162 vtable->stats
or= FB_SYMBSTATS_VTABLE
174 assert( symbIsField( udt->udt.
base ) )
175 assert( symbGetType( udt->udt.
base ) = FB_DATATYPE_STRUCT )
176 assert( symbIsStruct( udt->udt.
base->subtype ) )
177 basevtableelements = udt->udt.
base->subtype->udt.ext->vtableelements
179 if( basevtableelements > 2 )
then
180 assert( symbIsVar( udt->udt.
base->subtype->udt.ext->vtable ) )
181 basevtableinitree = udt->udt.
base->subtype->udt.ext->vtable->var_.initree
183 basevtableinitree = NULL
187 initree =
astTypeIniBegin( typeAddrOf( FB_DATATYPE_VOID ), NULL, FALSE, 0 )
194 rtti = udt->udt.ext->rtti
200 if( basevtableinitree )
then
204 assert( basevtableelements > 2 )
205 i += (basevtableelements - 2)
213 while( i <= dTB(0).upper )
222 symbSetTypeIniTree( vtable, initree )
223 symbSetIsInitialized( vtable )
236 member = symbGetCompSymbTb( udt ).head
239 if( symbIsProc( member ) )
then
241 if( (i > 0)
and (
not symbIsAbstract( member )) )
then
245 member = member->
next
248 udt->udt.ext->vtable = vtable
265 byval udt
as FBSYMBOL
ptr, _
266 byval proc as FBSYMBOL
ptr, _
267 byval is_copyctor
as integer _
270 dim as FBSYMBOL
ptr this_ =
any, src =
any
276 if( is_copyctor )
then
277 this_ = symbGetParamVar( symbGetProcHeadParam(
proc ) )
278 src = symbGetParamVar( symbGetProcTailParam(
proc ) )
286 symbSetCantUndef( udt )
292 byval fld
as FBSYMBOL
ptr, _
293 byval dstexpr
as ASTNODE
ptr, _
294 byval srcexpr
as ASTNODE
ptr _
297 dim as FBSYMBOL
ptr cnt, label, dst, src, subtype
299 subtype = symbGetSubtype( fld )
330 byval this_
as FBSYMBOL
ptr, _
331 byval rhs
as FBSYMBOL
ptr, _
332 byval base_fld
as FBSYMBOL
ptr _
335 dim as FBSYMBOL
ptr fld =
any
336 dim as longint bytes =
any, lgt =
any, base_ofs =
any
341 base_ofs = symbGetOfs( base_fld )
344 lgt = (symbGetLen( fld ) * symbGetArrayElements( fld )) + _
345 (symbGetOfs( fld ) - base_ofs)
346 if( lgt > bytes )
then
351 if( fld = NULL )
then
354 loop while( symbGetIsUnionField( fld ) )
367 byval udt
as FBSYMBOL
ptr, _
368 byval letproc
as FBSYMBOL
ptr _
371 dim as FBSYMBOL
ptr fld =
any, this_ =
any, rhs =
any
372 dim as ASTNODE
ptr dstexpr =
any, srcexpr =
any
376 this_ = symbGetParamVar( symbGetProcHeadParam( letproc ) )
377 rhs = symbGetParamVar( symbGetProcTailParam( letproc ) )
380 fld = symbGetCompSymbTb( udt ).head
382 if( symbIsField( fld ) )
then
384 if( symbGetIsUnionField( fld ) )
then
393 if( (symbGetArrayDimensions( fld ) = 0)
or _
394 (symbGetArrayElements( fld ) = 1) )
then
408 symbSetCantUndef( udt )
414 dim as FBSYMBOL
ptr defctor =
any, copyctor =
any, letop =
any, dtor =
any
415 dim as integer base_without_defaultctor =
any
432 if( udt->udt.
base )
then
433 assert( symbIsField( udt->udt.
base ) )
434 assert( symbGetType( udt->udt.
base ) = FB_DATATYPE_STRUCT )
435 assert( symbIsStruct( udt->udt.
base->subtype ) )
439 base_without_defaultctor = FALSE
448 if( (symbGetUDTHasCtorField( udt )
or symbGetUDTHasInitedField( udt ))
and _
450 if( base_without_defaultctor )
then
455 errReport( FB_ERRMSG_NEEDEXPLICITDEFCTOR )
458 defctor =
hDeclareProc( udt, INVALID, FALSE, FB_SYMBATTRIB_OVERLOADED
or FB_SYMBATTRIB_CONSTRUCTOR )
462 if( symbGetUDTHasCtorField( udt ) )
then
465 letop =
hDeclareProc( udt, AST_OP_ASSIGN, TRUE, FB_SYMBATTRIB_OVERLOADED
or FB_SYMBATTRIB_OPERATOR )
473 if( base_without_defaultctor )
then
476 errReport( FB_ERRMSG_NEEDEXPLICITCOPYCTOR )
478 copyctor =
hDeclareProc( udt, INVALID, TRUE, FB_SYMBATTRIB_OVERLOADED
or FB_SYMBATTRIB_CONSTRUCTOR )
484 if( symbGetUDTHasDtorField( udt ) )
then
488 dtor =
hDeclareProc( udt, INVALID, FALSE, FB_SYMBATTRIB_DESTRUCTOR )
511 if( symbGetHasRTTI( udt ) )
then
517 if( udt <> symb.rtti.fb_object )
then
550 byval parent as FBSYMBOL
ptr, _
551 byval proc as FBSYMBOL
ptr _
554 dim as FBSYMBOL
ptr param, subtype
558 param = symbGetProcTailParam(
proc )
559 if( symbGetParamMode( param ) = FB_PARAMMODE_BYREF )
then
560 subtype = symbGetSubtype( param )
562 if( subtype = NULL )
then
567 if( symbGetClass( subtype ) = FB_SYMBCLASS_FWDREF )
then
569 if( symbGetType( param ) = FB_DATATYPE_FWDREF )
then
571 if( subtype->hash.index =
parent->hash.index )
then
579 if( subtype =
parent )
then
580 select case symbGetClass(
parent )
581 case FB_SYMBCLASS_STRUCT
582 function = ( symbGetType( param ) = FB_DATATYPE_STRUCT )
584 case FB_SYMBCLASS_CLASS
600 (
not symbGetHasRTTI(
sym )))
604 if( symbIsStruct(
sym ) )
then
605 assert( symbIsConstructor(
proc ) )
608 if(
sym->udt.ext->ctorhead = NULL )
then
616 if( symbIsStruct(
sym ) )
then
617 select case( symbGetProcParams(
proc ) )
626 if(
sym->udt.ext->copyctor = NULL )
then
634 if(
sym->udt.ext->defctor = NULL )
then
635 if( symbGetProcOptParams(
proc ) = symbGetProcParams(
proc ) - 1 )
then
643 if( symbIsStruct(
sym ) )
then
644 assert( symbIsDestructor(
proc ) )
646 if(
sym->udt.ext->dtor = NULL )
then
655 if( symbIsStruct(
sym ) )
then
656 if(
sym->udt.ext )
then
657 function =
sym->udt.ext->ctorhead
665 if( symbIsStruct(
sym ) )
then
666 if(
sym->udt.ext )
then
667 function =
sym->udt.ext->defctor
675 if( symbIsStruct(
sym ) )
then
676 if(
sym->udt.ext )
then
677 function =
sym->udt.ext->copyctor
685 if( symbIsStruct(
sym ) )
then
686 if(
sym->udt.ext )
then
687 function =
sym->udt.ext->dtor
694 if( symbIsStruct(
sym ) )
then
705 if( symbIsStruct(
sym ) )
then
706 if(
sym->udt.ext )
then
707 function =
sym->udt.ext->clone
716 byval sym as FBSYMBOL
ptr, _
721 if( astGetOpIsSelf(
op ) )
then
722 select case symbGetClass(
sym )
723 case FB_SYMBCLASS_STRUCT
724 if(
sym->udt.ext = NULL )
then
728 function = symbGetUDTOpOvlTb(
sym)(
op - AST_OP_SELFBASE)
730 case FB_SYMBCLASS_ENUM
733 case FB_SYMBCLASS_CLASS
740 function = symb.globOpOvlTb(
op).head
748 byval sym as FBSYMBOL
ptr, _
749 byval proc as FBSYMBOL
ptr _
752 dim as AST_OP
op = symbGetProcOpOvl(
proc )
755 if( astGetOpIsSelf(
op ) )
then
756 if( symbIsStruct(
sym ) )
then
758 symbGetUDTOpOvlTb(
sym)(
op - AST_OP_SELFBASE) =
proc
762 if(
op = AST_OP_ASSIGN )
then
767 symb.globOpOvlTb(
op).head =
proc
775 assert( symbGetHasRTTI( udt ) )
781 function = udt->udt.ext->vtableelements
782 udt->udt.ext->vtableelements += 1
786 assert( symbIsStruct( udt ) )
787 if( udt->udt.ext )
then
788 function = udt->udt.ext->abstractcount
815 byval sym as FBSYMBOL
ptr, _
816 byval lasttb
as FBHASHTB
ptr, _
817 byval base_ns
as FBSYMBOL
ptr _
820 dim as FBHASHTB
ptr hashtb =
any
824 dim as FBSYMBOL
ptr ns = symbGetNamespace(
sym )
825 do until(
ns = base_ns )
828 if( symbGetCompExt(
ns ) = NULL )
then
829 symbGetCompExt(
ns ) = symbCompAllocExt( )
832 symbGetCompExt(
ns )->cnt += 1
833 if( symbGetCompExt(
ns )->cnt <> 1 )
then
844 ns = symbGetNamespace(
ns )
852 byval sym as FBSYMBOL
ptr, _
853 byval base_ns
as FBSYMBOL
ptr _
858 dim as FBSYMBOL
ptr ns = symbGetNamespace(
sym )
859 do until(
ns = base_ns )
860 symbGetCompExt(
ns )->cnt -= 1
865 if( symbGetCompExt(
ns )->cnt <> 0 )
then
868 symbGetCompSymbTb(
ns ).head )
871 ns = symbGetNamespace(
ns )
879 byval sym as FBSYMBOL
ptr _
882 if( symbGetCompExt(
sym ) = NULL )
then
886 dim as FBSYMBOL
ptr imp_ = symbGetCompImportHead(
sym )
887 do while( imp_ <> NULL )
888 dim as FBSYMBOL
ptr ns = symbGetImportNamespc( imp_ )
890 if(
ns <> NULL )
then
891 symbGetCompExt(
ns )->cnt += 1
892 if( symbGetCompExt(
ns )->cnt = 1 )
then
895 symbGetCompSymbTb(
ns ).head )
899 imp_ = symbGetImportNext( imp_ )
907 byval sym as FBSYMBOL
ptr _
910 if( symbGetCompExt(
sym ) = NULL )
then
914 dim as FBSYMBOL
ptr imp_ = symbGetCompImportHead(
sym )
915 do while( imp_ <> NULL )
916 dim as FBSYMBOL
ptr ns = symbGetImportNamespc( imp_ )
918 if(
ns <> NULL )
then
919 symbGetCompExt(
ns )->cnt -= 1
920 if( symbGetCompExt(
ns )->cnt = 0 )
then
926 imp_ = symbGetImportNext( imp_ )
934 byval sym as FBSYMBOL
ptr, _
935 byval insert_chain
as integer _
939 dim as FBHASHTB
ptr hashtb =
any
940 dim as FBSYMBOLTB
ptr symbtb =
any
945 n->
symtb = symbGetCurrentSymTb( )
946 n->
hashtb = symbGetCurrentHashTb( )
948 if( symbGetClass(
sym ) = FB_SYMBCLASS_PROC )
then
949 symbtb = @symbGetProcSymbTb(
sym )
952 symbtb = @symbGetCompSymbTb(
sym )
956 symbSetCurrentSymTb( symbtb )
959 n->
ns = symbGetCurrentNamespc( )
960 symbSetCurrentNamespc(
sym )
962 symbSetCurrentHashTb(
hashtb )
964 if( symbGetCompExt(
sym ) = NULL )
then
965 symbGetCompExt(
sym ) = symbCompAllocExt( )
968 symbGetCompExt(
sym )->cnt += 1
969 if( symbGetCompExt(
sym )->cnt <> 1 )
then
977 if( insert_chain )
then
990 byval remove_chain
as integer _
994 dim as FBHASHTB
ptr hashtb =
any
995 dim as FBSYMBOL
ptr sym =
any
1001 if( symbGetClass(
sym ) = FB_SYMBCLASS_PROC )
then
1007 symbSetCurrentSymTb( n->
symtb )
1009 if(
hashtb <> NULL )
then
1013 if( remove_chain )
then
1017 symbGetCompExt(
sym )->cnt -= 1
1022 if( symbGetCompExt(
sym )->cnt <> 0 )
then
1025 symbGetCompSymbTb(
sym ).head )
1028 symbSetCurrentHashTb( n->
hashtb )
1030 symbSetCurrentNamespc( n->
ns )
1044 byval imp_
as FBSYMBOL
ptr _
1047 dim as FBSYMBOL
ptr ns = symbGetExportNamespc( imp_ )
1049 if( symbGetCompExt(
ns ) = NULL )
then
1050 symbGetCompExt(
ns ) = symbCompAllocExt( )
1053 if( symbGetCompExt(
ns )->implist.tail <> NULL )
then
1054 symbGetCompExt(
ns )->implist.tail->nsimp.imp_next = imp_
1056 symbGetCompExt(
ns )->implist.head = imp_
1059 imp_->nsimp.imp_prev = symbGetCompExt(
ns )->implist.tail
1060 imp_->nsimp.imp_next = NULL
1062 symbGetCompExt(
ns )->implist.tail = imp_
1069 byval imp_
as FBSYMBOL
ptr _
1072 dim as FBSYMBOL
ptr ns = symbGetExportNamespc( imp_ )
1074 if( imp_->nsimp.imp_prev = NULL )
then
1075 symbGetCompExt(
ns )->implist.head = imp_->nsimp.imp_next
1077 imp_->nsimp.imp_prev->nsimp.imp_next = imp_->nsimp.imp_next
1080 if( imp_->nsimp.imp_next = NULL )
then
1081 symbGetCompExt(
ns )->implist.tail = imp_->nsimp.imp_prev
1083 imp_->nsimp.imp_next->nsimp.imp_prev = imp_->nsimp.imp_prev
1091 byval imp_
as FBSYMBOL
ptr _
1094 dim as FBSYMBOL
ptr ns = symbGetImportNamespc( imp_ )
1096 if( symbGetCompExt(
ns ) = NULL )
then
1097 symbGetCompExt(
ns ) = symbCompAllocExt( )
1100 if( symbGetCompExt(
ns )->explist.tail <> NULL )
then
1101 symbGetCompExt(
ns )->explist.tail->nsimp.exp_next = imp_
1103 symbGetCompExt(
ns )->explist.head = imp_
1106 imp_->nsimp.exp_prev = symbGetCompExt(
ns )->explist.tail
1107 imp_->nsimp.exp_next = NULL
1109 symbGetCompExt(
ns )->explist.tail = imp_
1116 byval imp_
as FBSYMBOL
ptr _
1119 dim as FBSYMBOL
ptr ns = symbGetImportNamespc( imp_ )
1121 if( imp_->nsimp.exp_prev = NULL )
then
1122 symbGetCompExt(
ns )->explist.head = imp_->nsimp.exp_next
1124 imp_->nsimp.exp_prev->nsimp.exp_next = imp_->nsimp.exp_next
1127 if( imp_->nsimp.exp_next = NULL )
then
1128 symbGetCompExt(
ns )->explist.tail = imp_->nsimp.exp_prev
1130 imp_->nsimp.exp_next->nsimp.exp_prev = imp_->nsimp.exp_prev
1138 byval sym as FBSYMBOL
ptr _
1141 if( symbGetCompExt(
sym ) = NULL )
then
1148 dim as FBSYMBOL
ptr exp_ = symbGetCompExportHead(
sym )
1149 do while( exp_ <> NULL )
1153 dim as FBSYMBOL
ptr nxt = symbGetExportNext( exp_ )
1157 symbGetImportNamespc( exp_ ) = NULL
1169 dim as FBSYMBOL
ptr rttitype =
any, objtype =
any, objrtti =
any, ctor =
any
1171 static as FBARRAYDIM dTB(0)
1174 rttitype =
symbStructBegin( NULL, NULL,
"$fb_RTTI",
"$fb_RTTI", FALSE, 0, NULL, 0 )
1175 symb.rtti.fb_rtti = rttitype
1178 symbAddField( rttitype,
"stdlibvtable", 0, dTB(), typeAddrOf( FB_DATATYPE_VOID ), NULL, 0, 0 )
1181 symbAddField( rttitype,
"id", 0, dTB(), typeAddrOf( FB_DATATYPE_CHAR ), NULL, 0, 0 )
1184 symbAddField( rttitype,
"rttibase", 0, dTB(), typeAddrOf( FB_DATATYPE_STRUCT ), rttitype, 0, 0 )
1190 dim as const zstring ptr ptypename =
any
1191 if( fbLangIsSet( FB_LANG_QB ) )
then
1192 ptypename = @
"__OBJECT"
1194 ptypename = @
"OBJECT"
1196 objtype =
symbStructBegin( NULL, NULL, ptypename,
"$fb_Object", FALSE, 0, NULL, 0 )
1197 symb.rtti.fb_object = objtype
1198 symbSetHasRTTI( objtype )
1199 symbSetIsUnique( objtype )
1203 symbAddField( objtype,
"$vptr", 0, dTB(), typeAddrOf( FB_DATATYPE_VOID ), NULL, 0, 0 )
1208 symbAddCtor( ctor, NULL, FB_SYMBATTRIB_METHOD
or FB_SYMBATTRIB_CONSTRUCTOR _
1209 or FB_SYMBATTRIB_OVERLOADED, FB_FUNCMODE_CDECL )
1215 objrtti =
symbAddVar( NULL,
"__fb_ZTS6Object", FB_DATATYPE_STRUCT, symb.rtti.fb_rtti, 0, 0, dTB(), _
1216 FB_SYMBATTRIB_EXTERN
or FB_SYMBATTRIB_SHARED, FB_SYMBOPT_PRESERVECASE )
1220 objtype->udt.ext->rtti = objrtti