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

Commit 2be04fd

Browse files
adrpoOpenModelica-Hudson
authored andcommitted
[NF] support range based on enumeration type
Belonging to [master]: - #2867
1 parent 1871ad3 commit 2be04fd

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Compiler/NFFrontEnd/NFEvalFunction.mo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ function evaluateStatement
488488
input Statement stmt;
489489
output FlowControl ctrl;
490490
algorithm
491+
// adrpo: we really need some error handling here to detect which statement cannot be evaluated
492+
// try
491493
ctrl := match stmt
492494
case Statement.ASSIGNMENT() then evaluateAssignment(stmt.lhs, stmt.rhs);
493495
case Statement.FOR() then evaluateFor(stmt.iterator, stmt.range, stmt.body, stmt.source);
@@ -504,6 +506,10 @@ algorithm
504506
fail();
505507

506508
end match;
509+
//else
510+
// Error.assertion(false, getInstanceName() + " failed to evaluate statement " + Statement.toString(stmt) + "\n", sourceInfo());
511+
// fail();
512+
//end try;
507513
end evaluateStatement;
508514

509515
function evaluateAssignment

Compiler/NFFrontEnd/NFRangeIterator.mo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ public
135135
then
136136
ARRAY_RANGE(values);
137137

138+
// enumeration type based range
139+
case Expression.TYPENAME(ty = Type.ARRAY(elementType = ty as Type.ENUMERATION(literals = literals)))
140+
algorithm
141+
values := {};
142+
istep := 0;
143+
144+
for l in literals loop
145+
istep := istep + 1;
146+
values := Expression.ENUM_LITERAL(ty, l, istep) :: values;
147+
end for;
148+
then
149+
ARRAY_RANGE(values);
150+
138151
else INVALID_RANGE(exp);
139152

140153
end match;

0 commit comments

Comments
 (0)