15 byval n
as ASTNODE
ptr, _
16 byval old_sym
as FBSYMBOL
ptr, _
17 byval new_sym
as FBSYMBOL
ptr _
21 listInit( @ast.dtorlist, 64,
len( AST_DTORLIST_ITEM ), LIST_FLAGS_NOCLEAR )
22 with( ast.dtorlistscopes )
27 ast.dtorlistcookies = 0
28 ast.flushdtorlist = TRUE
32 with( ast.dtorlistscopes )
34 deallocate( .cookies )
46 byval l as ASTNODE
ptr, _
47 byval r
as ASTNODE
ptr _
52 if( (
l = NULL)
or (r = NULL) )
then
59 if(
l->
class <> r->
class )
then
63 if( astGetFullType(
l ) <> astGetFullType( r ) )
then
67 if(
l->subtype <> r->subtype )
then
71 select case as const l->
class
72 case AST_NODECLASS_VAR
73 if(
l->sym <> r->sym )
then
77 if(
l->var_.ofs <> r->var_.ofs )
then
81 case AST_NODECLASS_FIELD
82 if(
l->sym <> r->sym )
then
86 case AST_NODECLASS_CONST
87 select case( typeGetClass(
l->dtype ) )
88 case FB_DATACLASS_FPOINT
89 if(
l->
val.f <> r->
val.f )
then
93 case FB_DATACLASS_INTEGER
94 if(
l->
val.i <> r->
val.i )
then
100 case AST_NODECLASS_DEREF
101 if(
l->
ptr.ofs <> r->
ptr.ofs )
then
105 case AST_NODECLASS_IDX
106 if(
l->idx.ofs <> r->idx.ofs )
then
110 if(
l->idx.mult <> r->idx.mult )
then
114 case AST_NODECLASS_BOP
115 if(
l->op.op <> r->op.op )
then
119 if(
l->op.options <> r->op.options )
then
123 if(
l->op.ex <> r->op.ex )
then
127 case AST_NODECLASS_UOP
128 if(
l->op.op <> r->op.op )
then
132 if(
l->op.options <> r->op.options )
then
136 case AST_NODECLASS_ADDROF
137 if(
l->sym <> r->sym )
then
141 if(
l->op.op <> r->op.op )
then
145 case AST_NODECLASS_OFFSET
146 if(
l->sym <> r->sym )
then
150 if(
l->ofs.ofs <> r->ofs.ofs )
then
154 case AST_NODECLASS_CONV
157 case AST_NODECLASS_CALL, AST_NODECLASS_BRANCH, _
158 AST_NODECLASS_LOAD, AST_NODECLASS_ASSIGN, _
200 byval l as ASTNODE
ptr, _
201 byval r
as ASTNODE
ptr _
206 if( (
l = NULL)
or (r = NULL) )
then
213 if(
l->
class <> r->
class )
then
217 if(
l->dtype <> r->dtype )
then
221 if(
l->subtype <> r->subtype )
then
225 if( typeGetDtOnly(
l->dtype ) = FB_DATATYPE_FUNCTION )
then
226 if(
symbIsEqual(
l->subtype, r->subtype ) = FALSE )
then
234 select case as const(
l->
class )
235 case AST_NODECLASS_LINK
236 if(
l->link.ret_left <> r->link.ret_left )
then
240 case AST_NODECLASS_VAR
244 if(
l->sym <> r->sym )
then
245 if( symbIsTemp(
l->sym ) = FALSE )
then
248 if( symbIsTemp( r->sym ) = FALSE )
then
253 if(
l->var_.ofs <> r->var_.ofs )
then
257 case AST_NODECLASS_FIELD
258 if(
l->sym <> r->sym )
then
259 if( symbIsTemp(
l->sym ) = FALSE )
then
262 if( symbIsTemp( r->sym ) = FALSE )
then
267 case AST_NODECLASS_CONST
268 if( typeGetClass(
l->dtype ) = FB_DATACLASS_FPOINT )
then
269 if(
l->
val.f <> r->
val.f )
then
273 assert( typeGetClass(
l->dtype ) = FB_DATACLASS_INTEGER )
274 if(
l->
val.i <> r->
val.i )
then
279 case AST_NODECLASS_DEREF
280 if(
l->
ptr.ofs <> r->
ptr.ofs )
then
284 case AST_NODECLASS_IDX
285 if(
l->idx.ofs <> r->idx.ofs )
then
289 if(
l->idx.mult <> r->idx.mult )
then
293 case AST_NODECLASS_BOP, AST_NODECLASS_UOP
294 if(
l->op.op <> r->op.op )
then
298 if(
l->op.options <> r->op.options )
then
302 case AST_NODECLASS_ADDROF
303 if(
l->sym <> r->sym )
then
304 if( symbIsTemp(
l->sym ) = FALSE )
then
307 if( symbIsTemp( r->sym ) = FALSE )
then
312 if(
l->op.op <> r->op.op )
then
316 case AST_NODECLASS_OFFSET
317 if(
l->sym <> r->sym )
then
318 if( symbIsTemp(
l->sym ) = FALSE )
then
321 if( symbIsTemp( r->sym ) = FALSE )
then
326 if(
l->ofs.ofs <> r->ofs.ofs )
then
330 case AST_NODECLASS_CALL
331 if(
l->sym <> r->sym )
then
350 byval class_
as integer, _
351 byval n
as ASTNODE
ptr _
354 dim as ASTNODE
ptr m =
any
361 if( n->
class = class_ )
then
383 byval sym
as FBSYMBOL
ptr, _
384 byval n
as ASTNODE
ptr _
387 dim as FBSYMBOL
ptr s =
any
393 select case as const n->
class
394 case AST_NODECLASS_VAR, AST_NODECLASS_IDX, AST_NODECLASS_FIELD, _
395 AST_NODECLASS_ADDROF, AST_NODECLASS_OFFSET
397 s = astGetSymbol( n )
405 if (symbIsParamBydescOrByref(s))
then
411 case AST_NODECLASS_DEREF
416 if( n->
l <> NULL )
then
422 if( n->r <> NULL )
then
435 byval n
as ASTNODE
ptr, _
436 byval old_sym
as FBSYMBOL
ptr, _
437 byval new_sym
as FBSYMBOL
ptr _
444 if( n->sym = old_sym )
then
451 select case as const n->
class
452 case AST_NODECLASS_BOP, AST_NODECLASS_UOP, _
453 AST_NODECLASS_BRANCH, AST_NODECLASS_LOOP
454 if( n->op.ex = old_sym )
then
458 case AST_NODECLASS_IIF
459 if( n->
iif.falselabel = old_sym )
then
460 n->
iif.falselabel = new_sym
463 case AST_NODECLASS_CALL
470 if( n->
l <> NULL )
then
474 if( n->r <> NULL )
then
482 byval n
as ASTNODE
ptr, _
483 byval oldsubtype
as FBSYMBOL
ptr, _
484 byval newdtype
as integer, _
485 byval newsubtype
as FBSYMBOL
ptr _
488 if( (typeGetDtOnly( n->dtype ) = FB_DATATYPE_FWDREF)
and _
489 (n->subtype = oldsubtype) )
then
490 n->dtype =
typeMerge( n->dtype, newdtype )
491 n->subtype = newsubtype
514 if( symbIsConstant( expr->sym ) )
then
519 return (astIsCONST( expr )
or typeIsConst( astGetFullType( expr ) ))
525 byval n
as ASTNODE
ptr _
528 dim as FBSYMBOL
ptr s =
any
532 if( astIsVAR( n ) )
then
533 s = astGetSymbol( n )
535 if( symbGetIsLiteral( s ) )
then
549 byval dtype
as integer, _
550 byval n
as ASTNODE
ptr _
553 dim as integer result =
any
554 dim as double dval =
any
555 dim as single sval =
any
556 dim as longint lval =
any
571 select case as const( typeGetDtAndPtrOnly( dtype ) )
580 case FB_DATATYPE_SINGLE
587 select case abs( dval )
588 case 0.0, 2e-45
to 3e+38
594 #define IS_INFINITY_OR_ZERO(x) ( (x) + (x) = (x) )
596 if IS_INFINITY_OR_ZERO( sval )
then
597 result = IS_INFINITY_OR_ZERO( dval )
603 case FB_DATATYPE_BITFIELD
607 select case as const( typeGetSizeType( dtype ) )
608 case FB_SIZETYPE_INT8, FB_SIZETYPE_UINT8
609 lval = astConstGetAsInt64( n )
610 result = ((lval >= -128)
and (lval <= 255))
612 case FB_SIZETYPE_INT16, FB_SIZETYPE_UINT16
613 lval = astConstGetAsInt64( n )
614 result = ((lval >= -32768)
and (lval <= 65535))
616 case FB_SIZETYPE_INT32, FB_SIZETYPE_UINT32
617 lval = astConstGetAsInt64( n )
618 result = ((lval >= -2147483648ll)
and (lval <= 4294967295ll))
620 case FB_SIZETYPE_INT64, FB_SIZETYPE_UINT64
623 if( typeGetClass( n->dtype ) = FB_DATACLASS_FPOINT )
then
625 result = ((dval >= -9223372036854775808ull)
and _
626 (dval <= 18446744073709551615ull))
632 if( (result = FALSE)
and ast.warn_convoverflow )
then
640 byval pdtype
as integer, _
641 byval psubtype
as FBSYMBOL
ptr, _
642 byval expr
as ASTNODE
ptr, _
643 byval strictcheck
as integer _
646 dim as integer edtype =
any
650 edtype = astGetFullType( expr )
653 if( typeIsPtr( edtype ) = FALSE )
then
655 if( astIsCONST( expr ) )
then
656 if( typeGetClass( edtype ) = FB_DATACLASS_INTEGER )
then
664 if( strictcheck )
then
665 if( typeGetPtrConstMask( edtype ) <> _
666 typeGetPtrConstMask( pdtype ) )
then
672 if( typeGetDtAndPtrOnly( pdtype ) <> typeGetDtAndPtrOnly( edtype ) )
then
675 dim as integer pdtype_np =
any, edtype_np =
any
676 pdtype_np = typeGetDtOnly( pdtype )
677 edtype_np = typeGetDtOnly( edtype )
680 if( pdtype_np = FB_DATATYPE_VOID )
then
682 elseif( edtype_np = FB_DATATYPE_VOID )
then
687 if( typeGetPtrCnt( pdtype ) <> typeGetPtrCnt( edtype ) )
then
692 if( (pdtype_np <= FB_DATATYPE_DOUBLE)
and _
693 (edtype_np <= FB_DATATYPE_DOUBLE) )
then
694 if( typeGetSize( pdtype_np ) = typeGetSize( edtype_np ) )
then
695 if( typeGetClass( pdtype_np ) = typeGetClass( edtype_np ) )
then
705 function =
symbIsEqual( astGetSubType( expr ), psubtype )
714 dim as ASTNODE
ptr l =
any, r =
any
722 select case as const astGetDataType( n )
723 case FB_DATATYPE_STRING, FB_DATATYPE_FIXSTR, _
742 if( n->
class = AST_NODECLASS_BOP )
then
743 if( n->op.op = AST_OP_ADD )
then
746 dim as integer ldtype = astGetDataType(
l ), rdtype = astGetDataType( r )
747 if( astGetDataType( n ) <> FB_DATATYPE_WCHAR )
then
762 byval expr
as ASTNODE
ptr, _
763 byval label
as FBSYMBOL
ptr, _
764 byval is_inverse
as integer, _
765 byval is_iif
as integer _
768 dim as ASTNODE
ptr n =
any, parentlink =
any, m =
any
769 dim as integer dtype =
any, call_dtors =
any
770 dim as FBSYMBOL
ptr temp =
any
772 if( expr = NULL )
then
780 dtype = astGetDataType( expr )
783 if( typeGetClass( dtype ) = FB_DATACLASS_STRING )
then
788 select case as const dtype
789 case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
791 if( astIsDEREF( expr ) = FALSE )
then
796 case FB_DATATYPE_STRUCT
797 dim as FB_ERRMSG err_num =
any
798 dim as FBSYMBOL
ptr ovlProc =
any
802 if( ovlProc = NULL )
then
805 if( ovlProc = NULL )
then
807 if( ovlProc = NULL )
then
808 if( expr->subtype )
then
811 " """ & *symbGetName( expr->subtype ) &
".cast()""" )
816 errReport( FB_ERRMSG_NOMATCHINGPROC, TRUE )
823 dtype = astGetDataType( expr )
852 call_dtors =
not (is_iif
or astDTorListIsEmpty( ))
854 if( call_dtors = FALSE )
then
858 while( n->
class = AST_NODECLASS_LINK )
860 if( n->link.ret_left )
then
867 select case( n->
class )
868 case AST_NODECLASS_CONST
874 assert( is_iif = FALSE )
875 assert( call_dtors = FALSE )
891 case AST_NODECLASS_BOP
894 select case as const( n->op.op )
895 case AST_OP_EQ, AST_OP_NE, AST_OP_GT, _
896 AST_OP_LT, AST_OP_GE, AST_OP_LE
901 assert( call_dtors = FALSE )
905 if( is_inverse = FALSE )
then
910 case AST_OP_ADD, AST_OP_SUB, AST_OP_SHL, AST_OP_SHR, _
911 AST_OP_AND, AST_OP_OR, AST_OP_XOR, AST_OP_IMP
915 assert( call_dtors = FALSE )
917 dim as integer doopt =
any
919 if( typeGetClass( dtype ) = FB_DATACLASS_INTEGER )
then
920 doopt = irGetOption( IR_OPT_CPUBOPFLAGS )
922 select case as const dtype
923 case FB_DATATYPE_LONGINT, FB_DATATYPE_ULONGINT
925 doopt = irGetOption( IR_OPT_64BITCPUREGS )
929 doopt = irGetOption( IR_OPT_FPUBOPFLAGS )
935 n =
astNewBRANCH(
iif( is_inverse, AST_OP_JNE, AST_OP_JEQ ), label, n )
951 if( parentlink )
then
952 if( parentlink->link.ret_left )
then
973 case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
974 dtype =
typeRemap( dtype, expr->subtype )
977 if( call_dtors )
then
991 astNewBOP(
iif( is_inverse, AST_OP_NE, AST_OP_EQ ), _
993 label, AST_OPOPT_NONE ) )
1002 function hHasDtor(
byval sym
as FBSYMBOL
ptr )
as integer
1003 assert( symbIsVar( sym ) )
1009 select case( symbGetType( sym ) )
1010 case FB_DATATYPE_STRING
1013 case typeAddrOf( FB_DATATYPE_WCHAR )
1014 if( symbGetIsWstring( sym ) )
then
1023 dim as AST_DTORLIST_ITEM
ptr i =
any
1025 print "-------------- dtorlist: ------------------"
1028 print " ";
symbDump( i->sym );
" cookie: ";i->cookie;
" refcount: ";i->refcount;
" has dtor? ";
hHasDtor( i->sym )
1035 dim as AST_DTORLIST_ITEM
ptr n =
any
1044 with( ast.dtorlistscopes )
1047 if( .count > 0 )
then
1048 n->cookie = .cookies[.count-1]
1058 dim as AST_DTORLIST_ITEM
ptr i =
any
1068 if( i->sym = sym )
then
1078 dim as AST_DTORLIST_ITEM
ptr i =
any
1088 if( i->sym = sym )
then
1089 assert( i->refcount > 0 )
1092 if( i->refcount <= 0 )
then
1104 dim as AST_DTORLIST_ITEM
ptr n =
any, p =
any
1105 dim as ASTNODE
ptr t =
any
1116 assert(
iif( cookie = 0, n->cookie = 0, TRUE ) )
1119 if( n->cookie = cookie )
then
1127 if( cookie = 0 )
then
1128 ast.dtorlistcookies = 0
1135 dim as AST_DTORLIST_ITEM
ptr n =
any
1143 if( n->sym = sym )
then
1156 if( cookie = 0 )
then
1158 ast.dtorlistcookies += 1
1159 cookie = ast.dtorlistcookies
1163 with( ast.dtorlistscopes )
1165 if( .count = .room )
then
1167 .cookies =
xreallocate( .cookies,
sizeof( *.cookies ) * .room )
1169 .cookies[.count] = cookie
1178 with( ast.dtorlistscopes )
1179 assert( .count > 0 )
1180 function = .cookies[.count-1]
1186 dim as AST_DTORLIST_ITEM
ptr i =
any
1191 if( i->cookie = cookie )
then
1205 byval n
as ASTNODE
ptr, _
1206 byval dtype
as integer, _
1207 byval subtype
as FBSYMBOL
ptr _
1211 if( astIsTYPEINI( n ) )
then
1217 assert( typeGetDtAndPtrOnly( n->dtype ) = typeGetDtAndPtrOnly( dtype ) )
1218 assert( n->subtype = subtype )
1222 astGetFullType( n ) = dtype
1223 n->subtype = subtype
1225 select case n->
class
1226 case AST_NODECLASS_LINK
1227 if( n->link.ret_left )
then
1233 case AST_NODECLASS_FIELD
1236 case AST_NODECLASS_CALLCTOR
1246 case AST_NODECLASS_IIF
1258 select case( typeGetDtAndPtrOnly( n->dtype ) )
1259 case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR, FB_DATATYPE_FIXSTR
1261 function = symbGetLen( n->sym )
1267 function = symbIsLocal( sym )
and (
not symbIsStatic( sym ))
1273 select case( astGetClass( expr ) )
1274 case AST_NODECLASS_VAR
1280 case AST_NODECLASS_IDX
1283 if( symbIsParamBydesc( expr->sym ) = FALSE )
then
1287 case AST_NODECLASS_CALL
1294 case AST_NODECLASS_FIELD
1295 if( astIsDEREF( expr->
l ) )
then
1296 if( astIsBOP( expr->
l->
l, AST_OP_ADD ) )
then
1297 if( astGetClass( expr->
l->
l->
l ) = AST_NODECLASS_ADDROF )
then