Skip to content

Commit

Permalink
[NF] further fix discrete real check
Browse files Browse the repository at this point in the history
 - adds record support
 - fixes ticket #6045
  • Loading branch information
kabdelhak authored and adrpo committed Jul 6, 2020
1 parent fa6d1f2 commit fd2d61b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFVerifyModel.mo
Expand Up @@ -43,6 +43,8 @@ protected
import Equation = NFEquation;
import Expression = NFExpression;
import ExpandExp = NFExpandExp;
import NFInstNode.InstNode;
import Record = NFRecord;
import Variable = NFVariable;
import Algorithm = NFAlgorithm;
import Statement = NFStatement;
Expand Down Expand Up @@ -421,6 +423,7 @@ protected
Expression lhs;
Type ty;
ComponentRef cref;
InstNode cls;
list<Equation> body;
list<Equation.Branch> branches;

Expand All @@ -433,6 +436,9 @@ protected
hashTable := BaseHashTable.add((ComponentRef.stripSubscriptsAll(cref), 0), hashTable);
then hashTable;

case Equation.CREF_EQUALITY(lhs = cref as ComponentRef.CREF(ty = ty as Type.COMPLEX(cls = cls))) guard(Type.isRecord(ty))
then checkDiscreteRealRecord(cref, cls, hashTable);

// traverse nested if equations. It suffices if the variable is defined in ANY branch.
case Equation.IF(branches = branches)
algorithm
Expand Down Expand Up @@ -528,6 +534,7 @@ protected
Type ty;
ComponentRef cref;
list<Expression> elements;
InstNode cls;

// only add if it is a real variable, we cannot check for discrete here
// since only the variable has variablity information
Expand All @@ -538,6 +545,9 @@ protected
hashTable := BaseHashTable.add((ComponentRef.stripSubscriptsAll(cref), 0), hashTable);
then hashTable;

case Expression.CREF(ty = ty as Type.COMPLEX(cls = cls), cref = cref) guard(Type.isRecord(ty))
then checkDiscreteRealRecord(cref, cls, hashTable);

case Expression.TUPLE(elements = elements)
algorithm
for element in elements loop
Expand All @@ -550,5 +560,23 @@ protected
end match;
end checkDiscreteRealExp;

function checkDiscreteRealRecord
input ComponentRef cref;
input InstNode cls;
input output HashTable hashTable;
protected
ComponentRef element;
list<InstNode> inputs;
algorithm
// remove all subscripts to handle arrays
hashTable := BaseHashTable.add((ComponentRef.stripSubscriptsAll(cref), 0), hashTable);
// also add all record elements
(inputs, _, _) := Record.collectRecordParams(cls);
for node in inputs loop
element := ComponentRef.prefixCref(node, InstNode.getType(node), {}, cref);
hashTable := BaseHashTable.add((ComponentRef.stripSubscriptsAll(element), 0), hashTable);
end for;
end checkDiscreteRealRecord;

annotation(__OpenModelica_Interface="frontend");
end NFVerifyModel;

0 comments on commit fd2d61b

Please sign in to comment.