Skip to content

Commit

Permalink
[NF] update discrete real check
Browse files Browse the repository at this point in the history
 - correct support for array element types
  • Loading branch information
kabdelhak authored and adrpo committed Sep 11, 2020
1 parent e2dd3e1 commit 2f08035
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFType.mo
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ public
end match;
end isReal;

function isRealRecursive
input Type ty;
output Boolean isReal;
algorithm
isReal := match ty
case REAL() then true;
case ARRAY() then isRealRecursive(ty.elementType);
else false;
end match;
end isRealRecursive;

function isBoolean
input Type ty;
output Boolean isBool;
Expand Down
7 changes: 4 additions & 3 deletions OMCompiler/Compiler/NFFrontEnd/NFVerifyModel.mo
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ protected
for variable in flatModel.variables loop
// check variability and not type for discrete variables
// remove all subscripts to handle arrays
if Variable.variability(variable) == Variability.DISCRETE and Type.isReal(variable.ty) and not BaseHashTable.hasKey(ComponentRef.stripSubscriptsAll(variable.name), hashTable) then
variable.name := ComponentRef.stripSubscriptsAll(variable.name);
if Variable.variability(variable) == Variability.DISCRETE and Type.isRealRecursive(variable.ty) and not BaseHashTable.hasKey(variable.name, hashTable) then
illegal_discrete_vars := variable :: illegal_discrete_vars;
end if;
end for;
Expand Down Expand Up @@ -430,7 +431,7 @@ protected
case Equation.EQUALITY(lhs = lhs) then checkDiscreteRealExp(lhs, hashTable);
case Equation.ARRAY_EQUALITY(lhs = lhs) then checkDiscreteRealExp(lhs, hashTable);

case Equation.CREF_EQUALITY(lhs = cref as ComponentRef.CREF(ty = ty)) guard(Type.isReal(ty))
case Equation.CREF_EQUALITY(lhs = cref as ComponentRef.CREF(ty = ty)) guard(Type.isRealRecursive(ty))
algorithm
// remove all subscripts to handle arrays
hashTable := BaseHashTable.add((ComponentRef.stripSubscriptsAll(cref), 0), hashTable);
Expand Down Expand Up @@ -539,7 +540,7 @@ protected
// only add if it is a real variable, we cannot check for discrete here
// since only the variable has variablity information
// Type.isDiscrete does always return false for REAL
case Expression.CREF(ty = ty, cref = cref) guard(Type.isReal(ty))
case Expression.CREF(ty = ty, cref = cref) guard(Type.isRealRecursive(ty))
algorithm
// remove all subscripts to handle arrays
hashTable := BaseHashTable.add((ComponentRef.stripSubscriptsAll(cref), 0), hashTable);
Expand Down

0 comments on commit 2f08035

Please sign in to comment.