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

Commit

Permalink
[NF] support range based on enumeration type
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - #2867
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Jan 13, 2019
1 parent 1871ad3 commit 2be04fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Compiler/NFFrontEnd/NFEvalFunction.mo
Expand Up @@ -488,6 +488,8 @@ function evaluateStatement
input Statement stmt;
output FlowControl ctrl;
algorithm
// adrpo: we really need some error handling here to detect which statement cannot be evaluated
// try
ctrl := match stmt
case Statement.ASSIGNMENT() then evaluateAssignment(stmt.lhs, stmt.rhs);
case Statement.FOR() then evaluateFor(stmt.iterator, stmt.range, stmt.body, stmt.source);
Expand All @@ -504,6 +506,10 @@ algorithm
fail();

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

function evaluateAssignment
Expand Down
13 changes: 13 additions & 0 deletions Compiler/NFFrontEnd/NFRangeIterator.mo
Expand Up @@ -135,6 +135,19 @@ public
then
ARRAY_RANGE(values);

// enumeration type based range
case Expression.TYPENAME(ty = Type.ARRAY(elementType = ty as Type.ENUMERATION(literals = literals)))
algorithm
values := {};
istep := 0;

for l in literals loop
istep := istep + 1;
values := Expression.ENUM_LITERAL(ty, l, istep) :: values;
end for;
then
ARRAY_RANGE(values);

else INVALID_RANGE(exp);

end match;
Expand Down

0 comments on commit 2be04fd

Please sign in to comment.