Skip to content

Commit

Permalink
Add a warning for StateSelect.always/never
Browse files Browse the repository at this point in the history
If a non-state variable has StateSelect.always or a state variable has
StateSelect.never, we now give a warning during the SimCode phase.

This resolves ticket:3689.

Belonging to [master]:
  - OpenModelica/OMCompiler#2191
  - OpenModelica/OpenModelica-testsuite#867
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Mar 5, 2018
1 parent be2bc89 commit c5d63e7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
10 changes: 10 additions & 0 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -1271,6 +1271,16 @@ algorithm
end match;
end isPreCref;

public function isPreviousCref
input DAE.ComponentRef cr;
output Boolean b;
algorithm
b := match(cr)
case(DAE.CREF_QUAL(ident=DAE.previousNamePrefix)) then true;
else false;
end match;
end isPreviousCref;

public function isStartCref
input DAE.ComponentRef cr;
output Boolean b;
Expand Down
41 changes: 28 additions & 13 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -8292,19 +8292,19 @@ algorithm
SimCode.SparsityPattern sparsityT;
case(SOME(dmd)) algorithm
print("\ndaeMode: \n" + UNDERLINE + "\n");
str := "residual Equations:\n"+UNDERLINE+"\n";
print(str);
dumpSimEqSystemLst(List.flatten(dmd.daeEquations),"\n");
dumpVarLst(dmd.residualVars,"residualVars("+intString(listLength(dmd.residualVars))+")");
dumpVarLst(dmd.algebraicVars,"algebraicDAEVars("+intString(listLength(dmd.algebraicVars))+")");
dumpVarLst(dmd.auxiliaryVars,"auxVars("+intString(listLength(dmd.auxiliaryVars))+")");
if isSome(dmd.sparsityPattern) then
str := "Sparsity Pattern:\n"+UNDERLINE+"\n";
print(str);
SimCode.JAC_MATRIX(sparsityT=sparsityT) := Util.getOption(dmd.sparsityPattern);
dumpSparsePatternInt(sparsityT);
end if;
then ();
str := "residual Equations:\n"+UNDERLINE+"\n";
print(str);
dumpSimEqSystemLst(List.flatten(dmd.daeEquations),"\n");
dumpVarLst(dmd.residualVars,"residualVars("+intString(listLength(dmd.residualVars))+")");
dumpVarLst(dmd.algebraicVars,"algebraicDAEVars("+intString(listLength(dmd.algebraicVars))+")");
dumpVarLst(dmd.auxiliaryVars,"auxVars("+intString(listLength(dmd.auxiliaryVars))+")");
if isSome(dmd.sparsityPattern) then
str := "Sparsity Pattern:\n"+UNDERLINE+"\n";
print(str);
SimCode.JAC_MATRIX(sparsityT=sparsityT) := Util.getOption(dmd.sparsityPattern);
dumpSparsePatternInt(sparsityT);
end if;
then ();
case(NONE()) then ();
end match;
end dumpSimCodeDAEmodeDataString;
Expand Down Expand Up @@ -8941,6 +8941,13 @@ algorithm
varType = tp,
source = source)), _, vars)
equation
_ = match BackendVariable.varStateSelect(dlowVar)
case DAE.NEVER()
algorithm
Error.addSourceMessage(Error.STATE_STATESELECT_NEVER, {ComponentReference.printComponentRefStr(cr)}, source.info);
then ();
else ();
end match;
commentStr = unparseCommentOptionNoAnnotationNoQuote(comment);
(unit, displayUnit) = extractVarUnit(dae_var_attr);
isProtected = getProtected(dae_var_attr);
Expand Down Expand Up @@ -8971,6 +8978,14 @@ algorithm
varType = tp,
source = source)), _, vars)
equation
_ = match BackendVariable.varStateSelect(dlowVar)
case DAE.ALWAYS()
guard valueEq(kind, BackendDAE.VARIABLE()) and not ComponentReference.isPreviousCref(cr) /* TODO: Why are clocked variables continuous and not discrete? */
algorithm
Error.addSourceMessage(Error.NON_STATE_STATESELECT_ALWAYS, {ComponentReference.printComponentRefStr(cr)}, source.info);
then ();
else ();
end match;
commentStr = unparseCommentOptionNoAnnotationNoQuote(comment);
(unit, displayUnit) = extractVarUnit(dae_var_attr);
isProtected = getProtected(dae_var_attr);
Expand Down
8 changes: 6 additions & 2 deletions Compiler/Util/Error.mo
Expand Up @@ -935,9 +935,9 @@ public constant Message EQN_NO_SPACE_TO_SOLVE = MESSAGE(581, SYMBOLIC(), WARNING
Util.gettext("Equation %s (size: %s) %s is not big enough to solve for enough variables.\n Remaining unsolved variables are: %s\n Already solved: %s\n Equations used to solve those variables:%s"));
public constant Message VAR_NO_REMAINING_EQN = MESSAGE(582, SYMBOLIC(), WARNING(),
Util.gettext("Variable %s does not have any remaining equation to be solved in.\n The original equations were:%s"));
public constant Message MOVING_PARAMETER_BINDING_TO_INITIAL_EQ_SECTION = MESSAGE(582, TRANSLATION(), NOTIFICATION(),
public constant Message MOVING_PARAMETER_BINDING_TO_INITIAL_EQ_SECTION = MESSAGE(583, TRANSLATION(), NOTIFICATION(),
Util.gettext("Moving binding to initial equation section and setting fixed attribute of %s to false."));
public constant Message MIXED_DETERMINED = MESSAGE(583, SYMBOLIC(), ERROR(),
public constant Message MIXED_DETERMINED = MESSAGE(584, SYMBOLIC(), ERROR(),
Util.gettext("The given system is mixed-determined. [index > %s]\nPlease checkout the option \"--maxMixedDeterminedIndex\"."));
public constant Message STACK_OVERFLOW_DETAILED = MESSAGE(584, SCRIPTING(), ERROR(),
Util.gettext("Stack overflow occurred while evaluating %s:\n%s"));
Expand All @@ -953,6 +953,10 @@ public constant Message NF_CAT_FIRST_ARG_EVAL = MESSAGE(589, TRANSLATION(), ERRO
Util.gettext("The first argument of cat must be possible to evaluate during compile-time. Expression %s has variability %s."));
public constant Message COMMA_OPERATOR_DIFFERENT_SIZES = MESSAGE(590, TRANSLATION(), ERROR(),
Util.gettext("Arguments of concatenation comma operator have different sizes for the first dimension: %s has dimension %s and %s has dimension %s."));
public constant Message NON_STATE_STATESELECT_ALWAYS = MESSAGE(591, SYMBOLIC(), WARNING(),
Util.gettext("Variable %s has attribute stateSelect=StateSelect.always, but was selected as a continuous variable."));
public constant Message STATE_STATESELECT_NEVER = MESSAGE(592, SYMBOLIC(), WARNING(),
Util.gettext("Variable %s has attribute stateSelect=StateSelect.never, but was selected as a state"));

public constant Message MATCH_SHADOWING = MESSAGE(5001, TRANSLATION(), ERROR(),
Util.gettext("Local variable '%s' shadows another variable."));
Expand Down

0 comments on commit c5d63e7

Please sign in to comment.