18 byval dtype
as integer, _
19 byval subtype
as FBSYMBOL
ptr, _
20 byval is_local
as integer, _
21 byval ofs
as longint _
24 dim as ASTNODE
ptr n =
any
34 dim as integer add_scope = FALSE
35 if( is_local = FALSE )
then
36 if( symbIsScope( parser.currblock ) )
then
37 add_scope =
not astIsTYPEINI( parser.currblock->scp.backnode )
56 byval tree
as ASTNODE
ptr, _
57 byval is_initializer
as integer _
60 dim as ASTNODE
ptr n =
any, p =
any, l =
any, r =
any
61 dim as longint ofs =
any
62 dim as FBSYMBOL
ptr sym =
any
68 if( is_initializer = FALSE )
then
77 if( n->
class = AST_NODECLASS_TYPEINI_ASSIGN )
then
80 if( astIsTYPEINI( l ) )
then
98 do while( n->r <> NULL )
102 n->typeini.ofs += ofs
114 if( tree->typeini.scp <> NULL )
then
123 byval tree
as ASTNODE
ptr, _
124 byval class_
as AST_NODECLASS, _
125 byval dtype
as FB_DATATYPE, _
126 byval subtype
as FBSYMBOL
ptr _
127 )
as ASTNODE
ptr static
133 if( tree->r <> NULL )
then
147 byval tree
as ASTNODE
ptr, _
148 byval bytes
as longint _
151 dim as ASTNODE
ptr n =
any
154 AST_NODECLASS_TYPEINI_PAD, _
155 FB_DATATYPE_INVALID, _
158 n->typeini.bytes = bytes
159 n->typeini.ofs = tree->typeini.ofs
168 byval tree
as ASTNODE
ptr, _
169 byval expr
as ASTNODE
ptr, _
170 byval sym
as FBSYMBOL
ptr _
173 dim as ASTNODE
ptr n =
any
176 AST_NODECLASS_TYPEINI_ASSIGN, _
177 symbGetFullType( sym ), _
178 symbGetSubtype( sym ) )
182 n->typeini.ofs = tree->typeini.ofs
184 tree->typeini.ofs += symbGetLen( sym )
193 byval tree
as ASTNODE
ptr, _
194 byval sym
as FBSYMBOL
ptr, _
195 byval procexpr
as ASTNODE
ptr _
198 dim as ASTNODE
ptr n =
any
201 AST_NODECLASS_TYPEINI_CTORCALL, _
202 symbGetFullType( sym ), _
203 symbGetSubtype( sym ) )
206 n->typeini.ofs = tree->typeini.ofs
209 tree->typeini.ofs += symbGetLen( sym )
217 byval tree
as ASTNODE
ptr, _
218 byval sym
as FBSYMBOL
ptr, _
219 byval elements
as longint _
222 dim as ASTNODE
ptr n =
any
225 AST_NODECLASS_TYPEINI_CTORLIST, _
226 symbGetFullType( sym ), _
227 symbGetSubtype( sym ) )
230 n->typeini.ofs = tree->typeini.ofs
231 n->typeini.elements = elements
233 tree->typeini.ofs += symbGetLen( sym ) * elements
241 byval tree
as ASTNODE
ptr, _
242 byval sym
as FBSYMBOL
ptr _
245 dim as ASTNODE
ptr n =
any
248 AST_NODECLASS_TYPEINI_SCOPEINI, _
249 FB_DATATYPE_INVALID, _
261 byval tree
as ASTNODE
ptr, _
262 byval sym
as FBSYMBOL
ptr _
265 dim as ASTNODE
ptr n =
any
268 AST_NODECLASS_TYPEINI_SCOPEEND, _
269 FB_DATATYPE_INVALID, _
286 byval tree
as ASTNODE
ptr, _
287 byval source
as ASTNODE
ptr, _
288 byval beginindex
as integer _
291 dim as integer i =
any
293 assert( astIsTYPEINI( source ) )
296 assert( source->
class = AST_NODECLASS_TYPEINI_SCOPEINI )
300 while( source->
class = AST_NODECLASS_TYPEINI_ASSIGN )
301 if( i >= beginindex )
then
308 assert( source->
class = AST_NODECLASS_TYPEINI_SCOPEEND )
313 byval tree
as ASTNODE
ptr, _
314 byval element
as integer, _
315 byval expr
as ASTNODE
ptr _
324 dim as integer i =
any
326 assert( astIsTYPEINI( tree ) )
329 assert( tree->
class = AST_NODECLASS_TYPEINI_SCOPEINI )
333 while( tree->
class = AST_NODECLASS_TYPEINI_ASSIGN )
334 if( i = element )
then
350 byval flush_tree
as ASTNODE
ptr, _
351 byval n
as ASTNODE
ptr, _
352 byval basesym
as FBSYMBOL
ptr _
355 dim as FBSYMBOL
ptr fld =
any
356 dim as longint ofs = n->typeini.ofs
359 if( fld <> NULL )
then
360 if( symbIsField( fld ) = FALSE )
then
366 ofs -= symbGetOfs( fld )
377 function = flush_tree
384 byval flush_tree
as ASTNODE
ptr, _
385 byval n
as ASTNODE
ptr, _
386 byval basesym
as FBSYMBOL
ptr _
389 dim as FBSYMBOL
ptr subtype =
any, fld =
any
390 dim as ASTNODE
ptr fldexpr =
any
391 dim as integer dtype =
any
392 dim as longint elements =
any
395 if( fld <> NULL )
then
396 if( symbIsField( fld ) = FALSE )
then
401 dtype = astGetDataType( n )
403 elements = n->typeini.elements
408 if( elements > 1 )
then
409 dim as FBSYMBOL
ptr cnt, label, iter
433 function = flush_tree
440 byval tree
as ASTNODE
ptr, _
441 byval basesym
as FBSYMBOL
ptr, _
442 byval do_deref
as integer _
445 dim as ASTNODE
ptr n =
any, nxt =
any, flush_tree =
any, lside =
any
446 dim as FBSYMBOL
ptr bitfield =
any
447 dim as integer dtype =
any
451 do while( n <> NULL )
454 select case as const n->
class
455 case AST_NODECLASS_TYPEINI_ASSIGN
469 if( symbIsParamInstance( basesym ) )
then
478 assert( typeIsPtr( symbGetType( basesym ) ) )
490 if( n->sym = basesym )
then
491 assert( typeIsPtr( dtype ) )
492 dtype = typeDeref( dtype )
498 lside =
astNewVAR( basesym, n->typeini.ofs, astGetFullType( n ), n->subtype )
503 if( symbIsField( n->sym ) )
then
509 if( astGetDataType( lside ) = FB_DATATYPE_BITFIELD )
then
510 bitfield = astGetSubType( lside )
511 assert( symbIsBitfield( bitfield ) )
512 assert( typeGetClass( symbGetType( bitfield ) ) = FB_DATACLASS_INTEGER )
515 if( bitfield->bitfld.bitpos = 0 )
then
519 astNewCONSTi( typeGetSize( symbGetType( bitfield ) ) ) ) )
528 lside =
astNewASSIGN( lside, n->l, AST_OPOPT_ISINI
or AST_OPOPT_DONTCHKPTR )
529 assert( lside <> NULL )
532 case AST_NODECLASS_TYPEINI_PAD
534 if( symbIsParamInstance( basesym ) )
then
540 assert( typeIsPtr( symbGetFullType( basesym ) ) )
544 lside =
astNewVAR( basesym, n->typeini.ofs )
551 case AST_NODECLASS_TYPEINI_CTORCALL
552 flush_tree =
hCallCtor( flush_tree, n, basesym )
554 case AST_NODECLASS_TYPEINI_CTORLIST
563 function = flush_tree
569 byval n
as ASTNODE
ptr, _
570 byval basesym
as FBSYMBOL
ptr _
573 dim as ASTNODE
ptr expr =
any
574 dim as integer edtype =
any, sdtype =
any
575 dim as FBSYMBOL
ptr sym =
any, litsym =
any
581 edtype = astGetDataType( expr )
582 sdtype = symbGetType( sym )
586 case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
591 if( litsym = NULL )
then
593 if( astIsOFFSET( expr ) )
then
594 irEmitVARINIOFS( astGetSymbol( expr ), expr->ofs.ofs )
598 if( edtype <> sdtype )
then
599 expr =
astNewCONV( symbGetFullType( sym ), symbGetSubtype( sym ), expr, AST_CONVOPT_DONTCHKPTR )
600 assert( expr <> NULL )
603 assert( astIsCONST( expr ) )
604 if( typeGetClass( sdtype ) = FB_DATACLASS_FPOINT )
then
605 irEmitVARINIf( sym, astConstGetFloat( expr ) )
607 irEmitVARINIi( sym, astConstGetInt( expr ) )
614 if( sdtype <> FB_DATATYPE_WCHAR )
then
617 if( edtype <> FB_DATATYPE_WCHAR )
then
619 irEmitVARINISTR( symbGetStrLen( sym ) - 1, _
620 symbGetVarLitText( litsym ), _
621 symbGetStrLen( litsym ) - 1 )
624 irEmitVARINISTR( symbGetStrLen( sym ) - 1, _
625 str( *symbGetVarLitTextW( litsym ) ), _
626 symbGetWstrLen( litsym ) - 1 )
634 if( edtype <> FB_DATATYPE_WCHAR )
then
636 irEmitVARINIWSTR( symbGetWstrLen( sym ) - 1, _
637 wstr( *symbGetVarLitText( litsym ) ), _
638 symbGetStrLen( litsym ) - 1 )
641 irEmitVARINIWSTR( symbGetWstrLen( sym ) - 1, _
642 symbGetVarLitTextW( litsym ), _
643 symbGetWstrLen( litsym ) - 1 )
660 byval tree
as ASTNODE
ptr, _
661 byval basesym
as FBSYMBOL
ptr _
664 dim as ASTNODE
ptr n =
any, nxt =
any
668 irEmitVARINIBEGIN( basesym )
671 do while( n <> NULL )
674 select case as const n->
class
675 case AST_NODECLASS_TYPEINI_PAD
676 irEmitVARINIPAD( n->typeini.bytes )
678 case AST_NODECLASS_TYPEINI_SCOPEINI
679 irEmitVARINISCOPEBEGIN( )
681 case AST_NODECLASS_TYPEINI_SCOPEEND
682 irEmitVARINISCOPEEND( )
692 irEmitVARINIEND( basesym )
700 byval tree
as ASTNODE
ptr, _
701 byval basesym
as FBSYMBOL
ptr, _
702 byval options
as AST_INIOPT _
708 assert( tree <> NULL )
710 if( tree = NULL )
then return NULL
713 if( (options
and AST_INIOPT_ISINI) = 0 )
then
714 ast.typeinicount -= 1
717 if( (options
and AST_INIOPT_ISSTATIC) <> 0 )
then
721 function =
hFlushTree( tree, basesym, ((options
and AST_INIOPT_DODEREF) <> 0) )
731 byval n
as ASTNODE
ptr _
734 dim as FBSYMBOL
ptr sym =
any, litsym =
any
735 dim as ASTNODE
ptr expr =
any
736 dim as integer sdtype =
any, edtype =
any
741 sdtype = symbGetType( sym )
742 edtype = astGetDataType( expr )
747 case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
752 if( litsym = NULL )
then
757 errReport( FB_ERRMSG_EXPECTEDCONST, TRUE )
759 errReport( FB_ERRMSG_INVALIDDATATYPES, TRUE )
764 errReport( FB_ERRMSG_INVALIDDATATYPES, TRUE )
769 if( symbIsField( sym ) )
then
770 if( symbGetType( sym ) = FB_DATATYPE_BITFIELD )
then
771 errReport( FB_ERRMSG_INVALIDDATATYPES, TRUE )
777 if( astIsOFFSET( expr ) )
then
779 if( (typeGetClass( sdtype ) <> FB_DATACLASS_INTEGER)
or _
780 (typeGetSize( sdtype ) <> env.pointersize) )
then
781 errReport( FB_ERRMSG_INVALIDDATATYPES, TRUE )
786 if( astIsCONST( expr ) = FALSE )
then
787 errReport( FB_ERRMSG_EXPECTEDCONST, TRUE )
796 errReport( FB_ERRMSG_INVALIDDATATYPES, TRUE )
801 if( sdtype = FB_DATATYPE_STRING )
then
802 errReport( FB_ERRMSG_CANTINITDYNAMICSTRINGS, TRUE )
815 byval tree
as ASTNODE
ptr _
818 dim as ASTNODE
ptr n =
any
823 do while( n <> NULL )
826 case AST_NODECLASS_TYPEINI_ASSIGN
831 case AST_NODECLASS_TYPEINI_CTORCALL, AST_NODECLASS_TYPEINI_CTORLIST
844 byval n
as ASTNODE
ptr, _
845 byval ignoreattrib
as integer _
853 static as integer reclevel
854 if( reclevel = 0 )
then
855 assert( astIsTYPEINI( n ) )
876 if( astIsVAR( n ) )
then
881 if( symbIsLocal( n->sym )
and _
882 ((symbGetAttrib( n->sym )
and ignoreattrib) = 0) )
then
902 byval n
as ASTNODE
ptr, _
903 byval parent as ASTNODE
ptr _
906 dim as ASTNODE
ptr expr =
any
907 dim as FBSYMBOL
ptr sym =
any
913 if( astIsTYPEINI( n ) )
then
946 dim as integer count =
any
951 if( astIsTYPEINI( n ) )
then
964 dim as ASTNODE
ptr tempvarinitcode =
any
965 dim as ASTNODE treeparent =
any
971 if( ast.typeinicount <= 0 )
then
979 astInitNode( (@treeparent), AST_NODECLASS_NOP, FB_DATATYPE_INVALID, NULL )
986 tempvarinitcode =
hWalk( tree, @treeparent )
992 function =
astNewLINK( tempvarinitcode, treeparent.l, FALSE )
999 dim as ASTNODE
ptr clonetree =
any
1001 assert( astIsTYPEINI( tree ) )
1005 if( tree->typeini.scp )
then
1009 function = clonetree
1015 assert( astIsTYPEINI( tree ) )
1020 if( tree->l->r )
then
1025 if( tree->l->
class <> AST_NODECLASS_TYPEINI_ASSIGN )
then
1031 if( (astGetDataType( tree ) <> astGetDataType( tree->l ))
or _
1032 (tree->subtype <> tree->l->subtype) )
then
1036 function = tree->l->l
1039 ast.typeinicount -= 1
1044 assert( astIsTYPEINI( tree ) )
1046 if( tree->typeini.scp )
then
1048 tree->typeini.scp = NULL