18 #define CREATEFAKEID( ) _
19 astNewVAR( symbAddTempVar( FB_DATATYPE_INTEGER ) )
23 byval parent as FBSYMBOL
ptr, _
25 byval inst_expr
as ASTNODE
ptr, _
26 byval second_arg
as ASTNODE
ptr, _
27 byval third_arg
as ASTNODE
ptr =
NULL _
32 byval op as integer, _
33 byval lhs
as FB_CMPSTMT_FORELM
ptr, _
34 byval rhs
as FB_CMPSTMT_FORELM
ptr, _
35 byval ex
as FBSYMBOL
ptr _
40 byval op as integer, _
41 byval lhs
as FB_CMPSTMT_FORELM
ptr, _
42 byval rhs
as FB_CMPSTMT_FORELM
ptr _
48 byval v
as FB_CMPSTMT_FORELM
ptr _
59 if( v->sym <>
NULL )
then
72 byval stk
as FB_CMPSTMTSTK
ptr _
75 dim as ASTNODE
ptr proc =
any, step_expr =
NULL
78 if( stk->
for.explicit_step )
then
87 if( proc <>
NULL )
then
96 byval stk
as FB_CMPSTMTSTK
ptr _
99 dim as ASTNODE
ptr proc =
any, step_expr =
NULL
102 if( stk->
for.explicit_step )
then
111 if( proc <>
NULL )
then
120 byval stk
as FB_CMPSTMTSTK
ptr _
123 dim as ASTNODE
ptr proc =
any, step_expr =
NULL
126 if( stk->
for.explicit_step )
then
136 if( proc <>
NULL )
then
150 byval stk
as FB_CMPSTMTSTK
ptr _
154 hFlushSelfBOP( AST_OP_ADD_SELF, @stk->
for.cnt, @stk->
for.stp )
161 byval stk
as FB_CMPSTMTSTK
ptr _
165 if( stk->
for.ispos.sym =
NULL )
then
167 hFlushBOP(
iif( stk->
for.ispos.value.i, AST_OP_LE, AST_OP_GE ), _
168 @stk->
for.cnt, @stk->
for.
end, stk->
for.inilabel )
183 hFlushBOP( AST_OP_GE, @stk->
for.cnt, @stk->
for.
end, stk->
for.inilabel )
195 hFlushBOP( AST_OP_LE, @stk->
for.cnt, @stk->
for.
end, stk->
for.inilabel )
206 byval dtype
as integer, _
207 byval subtype
as FBSYMBOL
ptr =
NULL _
210 dim as FBSYMBOL
ptr s =
any
211 dim as integer options =
any
218 if( fbLangOptIsSet( FB_LANG_OPT_SCOPE ) = FALSE )
then
219 options
or= FB_SYMBOPT_UNSCOPE
225 if( options
and FB_SYMBOPT_UNSCOPE )
then
236 byval dtype
as integer, _
237 byval subtype
as FBSYMBOL
ptr, _
238 byval expr
as ASTNODE
ptr _
250 if( expr =
NULL )
then
251 select case as const typeGet( dtype )
253 case FB_DATATYPE_STRUCT
256 errReport( FB_ERRMSG_UDTINFORNEEDSOPERATORS, TRUE, _
257 astGetOpId( AST_OP_ASSIGN ) )
271 byval op as integer, _
272 byval lhs
as FB_CMPSTMT_FORELM
ptr, _
273 byval rhs
as FB_CMPSTMT_FORELM
ptr, _
274 byval ex
as FBSYMBOL
ptr _
280 dim as ASTNODE
ptr lhs_expr =
any, rhs_expr =
any, expr =
any
288 expr =
astNewBOP(
op, lhs_expr, rhs_expr, ex, AST_OPOPT_NONE )
291 if( expr =
NULL )
then
293 errReport( FB_ERRMSG_UDTINFORNEEDSOPERATORS, TRUE, astGetOpId(
op ) )
298 if( lhs->dtype = FB_DATATYPE_STRUCT )
then
303 if( expr =
NULL )
then
305 errReport( FB_ERRMSG_UDTINFORNEEDSOPERATORS, TRUE, astGetOpId(
op ) )
318 byval lhs_dtype
as integer, _
319 byval lhs_subtype
as FBSYMBOL
ptr, _
320 byval rhs
as FB_CMPSTMT_FORELM
ptr _
323 dim as longint length =
any
330 if( typeIsPtr( lhs_dtype ) )
then
332 if( length <= 0 )
then
338 if( rhs->sym <>
NULL )
then
345 astNewVAR( rhs->sym, 0, FB_DATATYPE_INTEGER ), _
367 byval op as integer, _
368 byval lhs
as FB_CMPSTMT_FORELM
ptr, _
369 byval rhs
as FB_CMPSTMT_FORELM
ptr _
374 dim as ASTNODE
ptr lhs_expr =
any, rhs_expr =
any, expr =
any
377 rhs_expr =
hStepExpression( lhs->dtype, symbGetSubtype( lhs->sym ), rhs )
383 if( expr =
NULL )
then
385 errReport( FB_ERRMSG_UDTINFORNEEDSOPERATORS, TRUE, astGetOpId(
op ) )
394 function hCallCtor(
byval sym
as FBSYMBOL
ptr )
as integer
395 dim as ASTNODE
ptr expr =
cInitializer( sym, FB_INIOPT_ISINI )
396 if( expr =
NULL )
then
401 if( expr =
NULL )
then
411 byval stk
as FB_CMPSTMTSTK
ptr, _
412 byref isconst
as integer, _
413 byval dtype
as integer, _
414 byval subtype
as FBSYMBOL
ptr, _
416 byval idexpr
as ASTNODE
ptr _
430 if( expr =
NULL )
then
431 errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
437 if( astIsCONST( expr )
and ((flags
and FOR_ISUDT) = 0) )
then
440 if( expr =
NULL )
then
447 stk->
for.cnt.value = *astConstGetVal( expr )
454 if( expr =
NULL )
then
458 errReport( FB_ERRMSG_UDTINFORNEEDSOPERATORS, TRUE, @
"let" )
466 if(
hCallCtor( stk->
for.cnt.sym ) = FALSE )
then
467 errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
475 byval stk
as FB_CMPSTMTSTK
ptr, _
476 byref isconst
as integer, _
477 byval dtype
as integer, _
478 byval subtype
as FBSYMBOL
ptr, _
497 if( expr =
NULL )
then
498 errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
504 if( astIsCONST( expr )
and ((flags
and FOR_ISUDT) = 0) )
then
506 if( expr =
NULL )
then
513 stk->
for.
end.sym =
NULL
514 stk->
for.
end.dtype = dtype
518 stk->
for.
end.value = *astConstGetVal( expr )
526 stk->
for.
end.sym =
hStoreTemp( dtype, subtype, expr )
527 stk->
for.
end.dtype = symbGetType( stk->
for.
end.sym )
535 stk->
for.
end.dtype = symbGetType( stk->
for.
end.sym )
538 if(
hCallCtor( stk->
for.
end.sym ) = FALSE )
then
547 byval dtype
as integer, _
548 byval expr
as ASTNODE
ptr _
552 if( typeIsSigned( dtype ) = FALSE )
then
563 byval stk
as FB_CMPSTMTSTK
ptr, _
564 byref isconst
as integer, _
565 byval dtype
as integer, _
566 byval subtype
as FBSYMBOL
ptr, _
571 stk->
for.explicit_step = FALSE
574 stk->
for.explicit_step = TRUE
577 dim as integer iscomplex = FALSE
580 dim as ASTNODE
ptr expr =
any
582 if( stk->
for.explicit_step )
then
584 if( expr =
NULL )
then
585 errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
597 if( typeIsSigned( astGetFullType( expr ) ) )
then
607 if( astIsCONST( expr )
and ((flags
and FOR_ISUDT) = 0) )
then
609 if( expr =
NULL )
then
619 stk->
for.stp.sym =
NULL
620 if( typeIsPtr( dtype ) )
then
621 stk->
for.stp.dtype = FB_DATATYPE_LONG
623 stk->
for.stp.dtype = dtype
627 stk->
for.stp.value = *astConstGetVal( expr )
636 dim as integer tmp_dtype = dtype
637 dim as FBSYMBOL
ptr tmp_subtype = subtype
640 if( typeIsPtr( dtype ) )
then
641 tmp_dtype = FB_DATATYPE_LONG
646 stk->
for.stp.sym =
hStoreTemp( tmp_dtype, tmp_subtype, expr )
647 stk->
for.stp.dtype = symbGetType( stk->
for.stp.sym )
654 if( stk->
for.explicit_step )
then
657 stk->
for.stp.dtype = symbGetType( stk->
for.stp.sym )
660 if(
hCallCtor( stk->
for.stp.sym ) = FALSE )
then
666 if( typeIsSigned( dtype ) = FALSE
and ((flags
and FOR_ISUDT) = 0) )
then
669 stk->
for.ispos.sym =
NULL
670 stk->
for.ispos.dtype = FB_DATATYPE_INTEGER
671 stk->
for.ispos.value.i = -1
674 elseif( iscomplex
and ((flags
and FOR_ISUDT) = 0) )
then
675 dim as FB_CMPSTMT_FORELM cmp
676 cmp.dtype = stk->
for.stp.dtype
679 stk->
for.ispos.dtype = FB_DATATYPE_INTEGER
682 dim as ASTNODE
ptr rhs =
astNewBOP( AST_OP_GE, _
687 if( rhs =
NULL )
then
698 stk->
for.ispos.sym =
NULL
705 dim as FBSYMBOL
ptr sym =
any
711 dim as FBSYMCHAIN
ptr chain_ =
any
712 dim as FBSYMBOL
ptr base_parent =
any
714 chain_ =
cIdentifier( base_parent, FB_IDOPT_ISDECL
or FB_IDOPT_DEFAULT )
718 if( outerscopenode =
NULL )
then
722 dim as ASTNODE
ptr idexpr =
any, expr =
any
727 if( sym =
NULL )
then
729 idexpr = CREATEFAKEID( )
737 errReport( FB_ERRMSG_EXPECTEDSCALAR, TRUE )
740 idexpr = CREATEFAKEID( )
745 if( idexpr =
NULL )
then
748 idexpr = CREATEFAKEID( )
751 if( astIsVAR( idexpr ) = FALSE )
then
752 errReport( FB_ERRMSG_EXPECTEDSCALAR, TRUE )
755 idexpr = CREATEFAKEID( )
759 dim as integer dtype = astGetDataType( idexpr )
760 dim as FBSYMBOL
ptr subtype = astGetSubType( idexpr )
762 if( typeIsConst( astGetFullType( idexpr ) ) )
then
763 errReport( FB_ERRMSG_CONSTANTCANTBECHANGED )
766 select case as const dtype
767 case FB_DATATYPE_BYTE
to FB_DATATYPE_DOUBLE
769 case FB_DATATYPE_STRUCT
777 if( typeIsPtr( dtype ) = FALSE )
then
778 errReport( FB_ERRMSG_EXPECTEDSCALAR, TRUE )
781 idexpr = CREATEFAKEID( )
782 dtype = astGetDataType( idexpr )
790 stk->
for.cnt.sym = astGetSymbol( idexpr )
791 stk->
for.cnt.dtype = dtype
793 dim as integer isconst = 0
796 hForAssign( stk, isconst, dtype, subtype, flags, idexpr )
799 hForTo( stk, isconst, dtype, subtype, flags )
802 hForStep( stk, isconst, dtype, subtype, flags )
805 dim as FBSYMBOL
ptr il =
any, tl =
any, el =
any, cl =
any
818 stk->
for.endlabel = el
827 if( isconst = 3 )
then
828 expr =
astNewBOP(
iif( stk->
for.ispos.value.i, AST_OP_LE, AST_OP_GE ), _
829 astNewCONST( @stk->
for.cnt.value, stk->
for.cnt.dtype ), _
830 astNewCONST( @stk->
for.
end.value, stk->
for.
end.dtype ) )
845 stk->
for.outerscopenode = outerscopenode
846 stk->
for.testlabel = tl
847 stk->
for.inilabel = il
848 stk->
for.cmplabel = cl
854 byval parent as FBSYMBOL
ptr, _
855 byval op as AST_OP, _
856 byval inst_expr
as ASTNODE
ptr, _
857 byval second_arg
as ASTNODE
ptr, _
858 byval third_arg
as ASTNODE
ptr _
861 dim as FBSYMBOL
ptr sym =
any
866 if( sym =
NULL )
then
867 errReport( FB_ERRMSG_UDTINFORNEEDSOPERATORS, _
874 dim as FB_ERRMSG err_num =
any
875 if( second_arg =
NULL )
then
878 dim as FB_CALL_ARG args(0
to 1) =
any
879 dim as integer params = 1
887 if(
op = AST_OP_NEXT )
then
888 if( third_arg <>
NULL )
then
889 args(0).
next = @args(1)
902 if( sym =
NULL )
then
904 if( err_num <> FB_ERRMSG_OK )
then
909 dim as string op_version = *astGetOpId(
op ) +
" (with"
910 select case as const op
911 case AST_OP_FOR, AST_OP_STEP
913 if( second_arg =
NULL )
then
918 if( third_arg =
NULL )
then
922 op_version +=
" step)"
923 errReport( FB_ERRMSG_UDTINFORNEEDSOPERATORS, TRUE,
strptr(op_version) )
928 function =
astBuildCall( sym, inst_expr, second_arg, third_arg )
933 if( stk->scopenode <>
NULL )
then
941 select case symbGetType( stk->
for.cnt.sym )
942 case FB_DATATYPE_STRUCT
967 if( stk->
for.outerscopenode <>
NULL )
then
974 dim as FB_CMPSTMTSTK
ptr stk =
any
982 if( stk =
NULL )
then
997 dim as FBSYMCHAIN
ptr chain_ =
any
998 dim as FBSYMBOL
ptr base_parent =
any
999 chain_ =
cIdentifier( base_parent, FB_IDOPT_ISDECL
or FB_IDOPT_DEFAULT )
1002 dim as ASTNODE
ptr idexpr =
cVariable( chain_ )
1004 if( idexpr =
NULL )
then
1008 if( idexpr->sym <> stk->
for.cnt.sym )
then
1009 errReport( FB_ERRMSG_FORNEXTVARIABLEMISMATCH )
1012 if( fbPdCheckIsSet( FB_PDCHECK_NEXTVAR ) )
then
1013 errReportWarn( FB_WARNINGMSG_NEXTVARMEANINGLESS, *symbGetName(idexpr->sym) )