29 declare sub hCallCtors(
byval n
as ASTNODE
ptr,
byval sym as FBSYMBOL
ptr )
43 ast.globinst.ctorcnt = 0
44 ast.globinst.dtorcnt = 0
51 ast.globinst.dtorcnt = 0
52 ast.globinst.ctorcnt = 0
63 dim as ASTNODE
ptr n =
any
65 n =
astNewNode( AST_NODECLASS_PROC, FB_DATATYPE_INVALID, NULL )
68 if( ast.
proc.tail <> NULL )
then
69 ast.
proc.tail->
next = n
74 n->prev = ast.
proc.tail
86 if( n->prev <> NULL )
then
87 n->prev->
next = n->
next
89 ast.
proc.head = n->
next
92 if( n->
next <> NULL )
then
93 n->
next->prev = n->prev
95 ast.
proc.tail = n->prev
104 byval p as ASTNODE
ptr, _
105 byval doemit
as integer _
108 dim as ASTNODE
ptr n =
any, nxt =
any
109 dim as FBSYMBOL
ptr sym =
any
124 parser.
scope =
iif(
p->block.
proc.ismain, FB_MAINSCOPE, FB_MAINSCOPE+1 )
125 parser.currproc =
sym
126 parser.currblock =
sym
132 if( ast.doemit )
then
133 symbSetProcIsEmitted(
sym )
135 irEmitPROCBEGIN(
sym,
p->block.initlabel )
143 do while( n <> NULL )
151 if( ast.doemit )
then
152 irEmitPROCEND(
sym,
p->block.initlabel,
p->block.exitlabel )
155 irProcAllocStaticVars( symbGetProcSymbTbHead(
sym ) )
176 dim as ASTNODE
ptr n =
any
177 dim as integer doemit =
any
178 dim as FBSYMBOL
ptr sym =
any
195 if( symbGetIsParsed(
sym ) )
then
198 if( symbIsPrivate(
sym ) )
then
200 if( symbGetIsAccessed(
sym ) = FALSE )
then
204 elseif( symbGetIsModLevelProc(
sym ) )
then
218 function astUpdate(
byval n
as ASTNODE
ptr )
as ASTNODE
ptr
224 if( astIsCALL( n ) )
then
225 if( n->
call.isrtl )
then
226 if( astGetFullType( n ) <> FB_DATATYPE_VOID )
then
257 if( ast.flushdtorlist )
then
264 function astAdd(
byval n
as ASTNODE
ptr )
as ASTNODE
ptr
271 if( ast.
proc.curr->r <> NULL )
then
272 ast.
proc.curr->r->
next = n
276 n->prev = ast.
proc.curr->r
285 dim as ASTNODE
ptr i =
any
302 byval n
as ASTNODE
ptr, _
303 byval ref
as ASTNODE
ptr _
318 if( ref->
next->prev )
then
322 assert( ast.
proc.curr->r = ref )
329 n->
next = ast.
proc.curr->l
330 if( ast.
proc.curr->l )
then
331 ast.
proc.curr->l->prev = n
333 assert( ast.
proc.curr->r = NULL )
345 byval n
as ASTNODE
ptr _
348 dim as ASTNODE
ptr last =
any
354 last = ast.
proc.curr->block.
proc.decl_last
355 if( last = NULL )
then
356 last = ast.
proc.curr->l
359 ast.flushdtorlist = FALSE
361 if( last = NULL )
then
367 ast.flushdtorlist = TRUE
369 ast.
proc.curr->block.
proc.decl_last = n
374 dim as ASTNODE
ptr i =
any
376 assert(
proc->
class = AST_NODECLASS_PROC )
381 select case( i->
class )
382 case AST_NODECLASS_NOP, AST_NODECLASS_LABEL, _
383 AST_NODECLASS_DECL, AST_NODECLASS_LIT, _
384 AST_NODECLASS_DATASTMT, AST_NODECLASS_DBG _
397 dim as ASTNODE
ptr n =
any
406 sym->
proc.ext->dbg.incfile = env.inf.incfile
411 parser.
scope =
iif( ismain, FB_MAINSCOPE, FB_MAINSCOPE+1 )
412 parser.currproc =
sym
413 parser.currblock =
sym
420 n->block.exitlabel =
symbAddLabel( NULL, FB_SYMBOPT_NONE )
423 n->block.
proc.ismain = ismain
425 n->block.inistmt = parser.stmt.cnt
426 n->block.breaklist.head = NULL
427 n->block.breaklist.tail = NULL
428 n->block.
proc.decl_last = NULL
434 if( symbIsNaked(
sym ) = FALSE )
then
439 if( symbGetType(
sym ) <> FB_DATATYPE_VOID )
then
451 sym->
proc.ext->stmtnum = parser.stmt.cnt
454 if( symbGetIsMainProc(
sym ) )
then
455 dim as FBSYMBOL
ptr argc =
any, argv =
any
457 assert( symbGetProcParams(
sym ) = 2 )
458 argc = symbGetProcHeadParam(
sym )
459 argv = symbGetProcTailParam(
sym )
475 byval head_node
as ASTNODE
ptr, _
476 byval sym as FBSYMBOL
ptr _
481 if( env.clopt.extraerrchk )
then
492 if( .lastfun <> NULL )
then
497 if( .lastmod <> NULL )
then
502 if( .lasthnd <> NULL )
then
514 byval head_node
as ASTNODE
ptr, _
515 byval sym as FBSYMBOL
ptr _
518 dim as FBSYMBOL
ptr res =
any, defctor =
any
521 if( symbProcReturnsByref(
sym )
or _
522 (symbGetType(
sym ) <> FB_DATATYPE_STRUCT) )
then
536 if( (
not symbGetProcStatAssignUsed(
sym ))
and symbGetProcStatReturnUsed(
sym ) )
then
542 if( defctor = NULL )
then
549 errReport( FB_ERRMSG_RESULTHASNODEFCTOR )
555 if( res = NULL )
then
567 byval head_node
as ASTNODE
ptr _
571 if( env.clopt.profile )
then
572 if( env.clopt.target <> FB_COMPTARGET_DOS )
then
581 function astProcEnd(
byval callrtexit
as integer )
as integer
582 static as integer rec_cnt = 0
583 dim as integer res =
any, do_flush =
any, enable_implicit_code =
any
584 dim as FBSYMBOL
ptr sym =
any
585 dim as ASTNODE
ptr n =
any
590 n->block.endstmt = parser.stmt.cnt
598 enable_implicit_code =
not symbIsNaked(
sym )
602 if( symbIsConstructor(
sym )
and enable_implicit_code )
then
604 if( symbGetIsCtorInited(
sym ) = FALSE )
then
605 symbSetIsCtorInited(
sym )
622 if( symbIsDestructor(
sym )
and enable_implicit_code )
then
629 if( n->block.breaklist.head <> NULL )
then
636 dim as ASTNODE
ptr head_node = n->l
638 if( enable_implicit_code )
then
645 if( callrtexit )
then
646 if( n->block.
proc.ismain )
then
651 if( enable_implicit_code )
then
653 if( symbGetType(
sym ) <> FB_DATATYPE_VOID )
then
665 symbSetIsParsed(
sym )
668 if( rec_cnt = 1 )
then
669 if( n->block.
proc.ismain = FALSE )
then
671 if( symbIsPrivate(
sym ) = FALSE )
then
693 if( env.clopt.vectorize >= FB_VECTORIZE_NORMAL )
then
699 if( n->block.
proc.ismain = FALSE )
then
708 ast.currblock = ast.
proc.head
710 parser.
scope = FB_MAINSCOPE
711 parser.currproc = env.main.
proc
712 parser.currblock = env.main.
proc
722 dim as integer i =
any
723 dim as FBSYMBOL
ptr p =
any
728 if( symbGetType(
proc ) = FB_DATATYPE_STRUCT )
then
737 p = symbGetProcLastParam(
proc )
738 do while(
p <> NULL )
739 if(
p->param.mode <> FB_PARAMMODE_VARARG )
then
741 if(
p->param.
var = NULL )
then
747 p = symbGetProcPrevParam(
proc,
p )
755 dim as FBSYMBOL
ptr s =
any
756 dim as ASTNODE
ptr n =
any
764 if( (symbGetType(
proc ) = FB_DATATYPE_STRING)
and _
765 (
not symbProcReturnsByref(
proc )) )
then
768 if( env.clopt.backend = FB_BACKEND_GCC )
then
774 symbGetProcRealSubtype(
proc ) ), _
775 symbGetProcRealType(
proc ), TRUE )
782 dim as ASTNODE
ptr n =
any, nxt =
any
792 if( n->
class <> AST_NODECLASS_LABEL )
then
800 if( n->
class <> AST_NODECLASS_LABEL )
then
814 byval is_ctor
as integer, _
815 byval this_
as FBSYMBOL
ptr, _
816 byval fld
as FBSYMBOL
ptr _
819 dim as FBSYMBOL
ptr cnt =
any, label =
any, iter =
any, subtype =
any
820 dim as ASTNODE
ptr fldexpr =
any, tree =
any
821 dim as integer dtype =
any
822 dim as longint elements =
any
825 if( fld <> NULL )
then
826 dtype = symbGetType( fld )
827 subtype = symbGetSubtype( fld )
828 elements = symbGetArrayElements( fld )
830 dtype = symbGetType( this_ )
831 subtype = symbGetSubtype( this_ )
832 elements = symbGetArrayElements( this_ )
840 if( fld <> NULL )
then
854 fldexpr =
astBuildVarField( this_, NULL, (elements - 1) * symbGetLen( subtype ) )
882 byval this_
as FBSYMBOL
ptr, _
883 byval fld
as FBSYMBOL
ptr _
887 if( symbGetDontInit( fld ) )
then
896 if( (symbGetArrayDimensions( fld ) = 0)
or _
897 (symbGetArrayElements( fld ) = 1) )
then
909 if( symbGetType( fld ) = FB_DATATYPE_BITFIELD )
then
915 astNewCONSTi( symbGetLen( fld ) * symbGetArrayElements( fld ) ) )
921 byval this_
as FBSYMBOL
ptr, _
922 byval base_fld
as FBSYMBOL
ptr, _
923 byval pfinalfield
as FBSYMBOL
ptr ptr _
926 dim as FBSYMBOL
ptr fld =
any
927 dim as longint bytes =
any, lgt =
any, base_ofs =
any
932 base_ofs = symbGetOfs( base_fld )
935 lgt = (symbGetLen( fld ) * symbGetArrayElements( fld )) + _
936 (symbGetOfs( fld ) - base_ofs)
937 if( lgt > bytes )
then
942 if( fld = NULL )
then
945 loop while( symbGetIsUnionField( fld ) )
957 byval parent as FBSYMBOL
ptr, _
958 byval proc as FBSYMBOL
ptr _
961 dim as FBSYMBOL
ptr fld =
any, this_ =
any
962 dim as ASTNODE
ptr tree = NULL
964 this_ = symbGetParamVar( symbGetProcHeadParam(
proc ) )
967 fld = symbGetCompSymbTb(
parent ).head
968 do while( fld <> NULL )
970 if( symbIsField( fld ) )
then
972 if( fld <>
parent->udt.
base )
then
974 if( symbGetIsUnionField( fld ) )
then
980 if( symbGetTypeIniTree( fld ) = NULL )
then
986 this_, AST_INIOPT_ISINI ) )
1000 byval parent as FBSYMBOL
ptr, _
1001 byval proc as FBSYMBOL
ptr _
1004 dim as ASTNODE
ptr initree =
any
1005 dim as FBSYMBOL
ptr base_ =
any, this_ =
any, subtype =
any, defctor =
any
1010 if( base_ = NULL )
then
1014 this_ = symbGetParamVar( symbGetProcHeadParam(
proc ) )
1019 proc->
proc.ext->base_initree = NULL
1023 subtype = symbGetSubtype( base_ )
1031 errReport( FB_ERRMSG_NOACCESSTOBASEDEFCTOR )
1044 byval parent as FBSYMBOL
ptr, _
1045 byval proc as FBSYMBOL
ptr _
1049 if( symbGetHasRTTI(
parent ) = FALSE )
then
1054 assert(
parent->udt.ext->vtable )
1056 var this_ = symbGetParamVar( symbGetProcHeadParam(
proc ) )
1062 astNewCONV( typeAddrOf( FB_DATATYPE_VOID ), NULL, _
1067 dim as ASTNODE
ptr tree =
any
1068 dim as FBSYMBOL
ptr parent =
any
1092 byval this_
as FBSYMBOL
ptr, _
1093 byval fld
as FBSYMBOL
ptr _
1096 if( symbGetType( fld ) = FB_DATATYPE_STRING )
then
1102 if( (symbGetArrayDimensions( fld ) = 0)
or _
1103 (symbGetArrayElements( fld ) = 1) )
then
1112 if( (symbGetArrayDimensions( fld ) = 0)
or _
1113 (symbGetArrayElements( fld ) = 1) )
then
1126 byval parent as FBSYMBOL
ptr, _
1127 byval proc as FBSYMBOL
ptr _
1130 dim as FBSYMBOL
ptr fld =
any, this_ =
any
1132 this_ = symbGetParamVar( symbGetProcHeadParam(
proc ) )
1135 fld = symbGetCompSymbTb(
parent ).tail
1136 do while( fld <> NULL )
1139 if( symbIsField( fld ) )
then
1141 if( fld <>
parent->udt.
base )
Then
1153 byval parent as FBSYMBOL
ptr, _
1154 byval proc as FBSYMBOL
ptr _
1157 dim as FBSYMBOL
ptr base_ =
any, dtor =
any, this_ =
any
1162 if( base_ = NULL )
then
1176 if( dtor = NULL )
then
1183 errReport( FB_ERRMSG_NOACCESSTOBASEDTOR )
1188 if( symbIsAbstract( dtor ) )
then
1192 this_ = symbGetParamVar( symbGetProcHeadParam(
proc ) )
1199 dim as FBSYMBOL
ptr parent =
any
1212 byval sym as FBSYMBOL
ptr, _
1213 byval initree as ASTNODE
ptr _
1223 if( symbIsDynamic(
sym ) )
then
1227 if( (symbGetArrayDimensions(
sym ) = 0)
or _
1228 (symbGetArrayElements(
sym ) = 1) )
then
1238 dim as TLIST
ptr dtorlist =
any
1239 dim as FB_DTORWRAPPER
ptr wrap =
any
1240 dim as ASTNODE
ptr n =
any
1242 dtorlist =
proc->
proc.ext->statdtor
1244 if( dtorlist = NULL )
then
1250 do while( wrap <> NULL )
1269 deallocate(
proc->
proc.ext->statdtor )
1276 byval sym as FBSYMBOL
ptr _
1279 dim as TLIST
ptr dtorlist =
any
1280 dim as FB_DTORWRAPPER
ptr wrap =
any
1281 dim as FBSYMBOL
ptr proc =
any
1283 dtorlist = parser.currproc->
proc.ext->statdtor
1286 if( dtorlist = NULL )
then
1288 parser.currproc->
proc.ext->statdtor = dtorlist
1290 listInit( dtorlist, 16,
len( FB_DTORWRAPPER ), LIST_FLAGS_NOCLEAR )
1297 FB_SYMBATTRIB_PRIVATE, FB_FUNCMODE_CDECL, FB_SYMBOPT_DECLARING )
1303 symbSetCantUndef(
sym )
1312 byval sym as FBSYMBOL
ptr, _
1313 byval initree as ASTNODE
ptr, _
1327 symbSetCantUndef(
sym )
1330 ast.globinst.ctorcnt += 1
1334 ast.globinst.dtorcnt += 1
1340 dim as FBSYMBOL
ptr proc =
any
1344 iif( is_ctor, @FB_GLOBCTORNAME, @FB_GLOBDTORNAME ), _
1345 FB_DATATYPE_VOID, NULL, FB_SYMBATTRIB_PRIVATE, _
1346 FB_FUNCMODE_CDECL, FB_SYMBOPT_DECLARING )
1353 symbSetIsAccessed(
proc )
1354 symbSetIsParsed(
proc )
1361 dim as FBSYMBOL
ptr sym =
any
1364 if( ast.globinst.ctorcnt > 0 )
then
1372 if( inst->
initree <> NULL )
then
1385 if( ast.globinst.dtorcnt > 0 )
then