@@ -530,32 +530,32 @@ algorithm
530530 then
531531 el :: elements;
532532
533- case Equation . FOR ()
534- algorithm
535- // flatten the equations
536- (els1, funcs) := flattenEquations(eq. body, prefix, {}, funcs);
537-
538- // deal with the range
539- if isSome(eq. range) then
540- SOME (e) := eq. range;
541- SOME (de) := DAEUtil . evaluateExp(Expression . toDAE(e), elements);
542- range := match (de)
543- case DAE . ARRAY (array = range) then range;
544- case DAE . RANGE (_, DAE . ICONST (is), SOME (DAE . ICONST (step)), DAE . ICONST (ie))
545- then List . map(ExpressionSimplify . simplifyRange(is, step, ie), DAEExpression . makeIntegerExp);
546- case DAE . RANGE (_, DAE . ICONST (is), _, DAE . ICONST (ie))
547- then if is <= ie
548- then List . map(ExpressionSimplify . simplifyRange(is, 1 , ie), DAEExpression . makeIntegerExp)
549- else List . map(ExpressionSimplify . simplifyRange(is, -1 , ie), DAEExpression . makeIntegerExp);
550- end match;
551- // replace index in elements
552- for i in range loop
553- els := DAEUtil . replaceCrefInDAEElements(els1, DAE . CREF_IDENT (eq. name, Type . toDAE(eq. indexType), {}), i);
554- elements := listAppend(els, elements);
555- end for ;
556- end if ;
557- then
558- elements;
533+ // case Equation.FOR()
534+ // algorithm
535+ // // flatten the equations
536+ // (els1, funcs) := flattenEquations(eq.body, prefix, {}, funcs);
537+ //
538+ // // deal with the range
539+ // if isSome(eq.range) then
540+ // SOME(e) := eq.range;
541+ // SOME(de) := DAEUtil.evaluateExp(Expression.toDAE(e), elements);
542+ // range := match (de)
543+ // case DAE.ARRAY(array = range) then range;
544+ // case DAE.RANGE(_, DAE.ICONST(is), SOME(DAE.ICONST(step)), DAE.ICONST(ie))
545+ // then List.map(ExpressionSimplify.simplifyRange(is, step, ie), DAEExpression.makeIntegerExp);
546+ // case DAE.RANGE(_, DAE.ICONST(is), _, DAE.ICONST(ie))
547+ // then if is <= ie
548+ // then List.map(ExpressionSimplify.simplifyRange(is, 1, ie), DAEExpression.makeIntegerExp)
549+ // else List.map(ExpressionSimplify.simplifyRange(is, -1, ie), DAEExpression.makeIntegerExp);
550+ // end match;
551+ // // replace index in elements
552+ // for i in range loop
553+ // els := DAEUtil.replaceCrefInDAEElements(els1, DAE.CREF_IDENT(eq.name, Type.toDAE(eq.indexType), {}), i);
554+ // elements := listAppend(els, elements);
555+ // end for;
556+ // end if;
557+ // then
558+ // elements;
559559
560560 case Equation . WHEN ()
561561 algorithm
@@ -747,16 +747,9 @@ algorithm
747747
748748 case Statement . FOR ()
749749 algorithm
750- // flatten the list of statements
751- (sts, funcs) := flattenStatements(alg. body, {}, funcs);
752- if isSome(alg. range) then
753- SOME (e) := alg. range;
754- de := Expression . toDAE(e);
755- else
756- de := DAE . SCONST ("NO RANGE GIVEN TODO FIXME" );
757- end if ;
750+ (stmt, funcs) := flattenForStatement(alg, funcs);
758751 then
759- DAE . STMT_FOR ( Type . toDAE(alg . indexType), false , alg . name, alg . index, de, sts, ElementSource . createElementSource(alg . info)) :: stmts;
752+ stmt :: stmts;
760753
761754 case Statement . IF ()
762755 algorithm
@@ -918,14 +911,13 @@ protected
918911 list< tuple< Expression , list< Statement >>> rest;
919912 Option < DAE . Statement > owhenStatement = NONE ();
920913algorithm
921-
922914 head :: rest := whenBranches;
923915 cond1 := Expression . toDAE(Util . tuple21(head));
924916 (stmts1, funcs) := flattenStatements(Util . tuple22(head), {}, funcs);
925917 rest := listReverse(rest);
926918
927919 for b in rest loop
928- cond2 := Expression . toDAE(Util . tuple21(b));
920+ cond2 := Expression . toDAE(Util . tuple21(b));
929921 (stmts2, funcs) := flattenStatements(Util . tuple22(b), {}, funcs);
930922 whenStatement := DAE . STMT_WHEN (cond2, {}, false , stmts2, owhenStatement, ElementSource . createElementSource(info));
931923 owhenStatement := SOME (whenStatement);
@@ -934,6 +926,31 @@ algorithm
934926 whenStatement := DAE . STMT_WHEN (cond1, {}, false , stmts1, owhenStatement, ElementSource . createElementSource(info));
935927end flattenWhenStatement;
936928
929+ function flattenForStatement
930+ input Statement forStmt;
931+ output DAE . Statement forDAE;
932+ input output DAE . FunctionTree funcs;
933+ protected
934+ InstNode iterator;
935+ Type ty;
936+ Binding binding;
937+ Expression range;
938+ list< Statement > body;
939+ list< DAE . Statement > dbody;
940+ SourceInfo info;
941+ algorithm
942+ Statement . FOR (iterator = iterator, body = body, info = info) := forStmt;
943+
944+ (dbody, funcs) := flattenStatements(body, {}, funcs);
945+
946+ Component . ITERATOR (ty = ty, binding = binding) := InstNode . component(iterator);
947+ SOME (range) := Binding . typedExp(binding);
948+
949+ forDAE := DAE . STMT_FOR (Type . toDAE(ty), Type . isArray(ty),
950+ InstNode . name(iterator), 0 , Expression . toDAE(range), dbody,
951+ ElementSource . createElementSource(info));
952+ end flattenForStatement;
953+
937954function applyExpPrefix
938955 input ComponentRef prefix;
939956 input output Expression exp;
0 commit comments