Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 6d27fdf

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fix SimplifyExp.simplifySubscriptedExp.
- Make SimplifyExp.simplifySubscriptedExp handle slices too. - Added Equation.toString for debug output. Belonging to [master]: - #2617
1 parent 62dcbfd commit 6d27fdf

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

Compiler/NFFrontEnd/NFEquation.mo

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public
5151
Variability conditionVar;
5252
list<Equation> body;
5353
end BRANCH;
54+
55+
function toString
56+
input Branch branch;
57+
output String str;
58+
algorithm
59+
str := Expression.toString(branch.condition) + " then\n" + toStringList(branch.body);
60+
end toString;
5461
end Branch;
5562

5663
record EQUALITY
@@ -518,5 +525,66 @@ public
518525
end match;
519526
end foldExp;
520527

528+
function toString
529+
input Equation eq;
530+
output String str;
531+
algorithm
532+
str := match eq
533+
local
534+
String s1, s2;
535+
536+
case EQUALITY()
537+
then Expression.toString(eq.lhs) + " = " + Expression.toString(eq.rhs);
538+
539+
case CREF_EQUALITY()
540+
then ComponentRef.toString(eq.lhs) + " = " + ComponentRef.toString(eq.rhs);
541+
542+
case ARRAY_EQUALITY()
543+
then Expression.toString(eq.lhs) + " = " + Expression.toString(eq.rhs);
544+
545+
case CONNECT()
546+
then "connect(" + Expression.toString(eq.lhs) + ", " + Expression.toString(eq.rhs) + ")";
547+
548+
case FOR()
549+
algorithm
550+
s1 := if isSome(eq.range) then " in " + Expression.toString(Util.getOption(eq.range)) else "";
551+
s2 := toStringList(eq.body);
552+
then
553+
"for " + InstNode.name(eq.iterator) + s1 + " loop\n" + s2 + "end for";
554+
555+
case IF()
556+
then "if " + Branch.toString(listHead(eq.branches)) +
557+
List.toString(listRest(eq.branches), Branch.toString, "", "elseif ", "\nelseif ", "", false) +
558+
"\nend if";
559+
560+
case WHEN()
561+
then "when " + Branch.toString(listHead(eq.branches)) +
562+
List.toString(listRest(eq.branches), Branch.toString, "", "elsewhen ", "\nelsewhen ", "", false) +
563+
"\nend when";
564+
565+
case ASSERT()
566+
then "assert(" + Expression.toString(eq.condition) + ", " +
567+
Expression.toString(eq.message) + ", " + Expression.toString(eq.level) + ")";
568+
569+
case TERMINATE()
570+
then "terminate( " + Expression.toString(eq.message) + ")";
571+
572+
case REINIT()
573+
then "reinit(" + Expression.toString(eq.cref) + ", " + Expression.toString(eq.reinitExp) + ")";
574+
575+
case NORETCALL()
576+
then Expression.toString(eq.exp);
577+
578+
else "#UNKNOWN EQUATION#";
579+
end match;
580+
end toString;
581+
582+
function toStringList
583+
input list<Equation> eql;
584+
output String str;
585+
algorithm
586+
str := List.toString(eql, toString, "", " ", "\n ", "", false) + "\n";
587+
end toStringList;
588+
521589
annotation(__OpenModelica_Interface="frontend");
522590
end NFEquation;

Compiler/NFFrontEnd/NFSimplifyExp.mo

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,13 @@ algorithm
388388
subscriptedExp := simplify(e);
389389

390390
for s in subs loop
391-
subscriptedExp := Expression.applyIndexSubscript(simplify(s), subscriptedExp);
391+
s := simplify(s);
392+
393+
if Type.isArray(Expression.typeOf(s)) then
394+
subscriptedExp := Expression.applySliceSubscript(s, subscriptedExp);
395+
else
396+
subscriptedExp := Expression.applyIndexSubscript(s, subscriptedExp);
397+
end if;
392398
end for;
393399
end simplifySubscriptedExp;
394400

0 commit comments

Comments
 (0)