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

Commit c5d63e7

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Add a warning for StateSelect.always/never
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]: - #2191 - OpenModelica/OpenModelica-testsuite#867
1 parent be2bc89 commit c5d63e7

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

Compiler/FrontEnd/ComponentReference.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,16 @@ algorithm
12711271
end match;
12721272
end isPreCref;
12731273

1274+
public function isPreviousCref
1275+
input DAE.ComponentRef cr;
1276+
output Boolean b;
1277+
algorithm
1278+
b := match(cr)
1279+
case(DAE.CREF_QUAL(ident=DAE.previousNamePrefix)) then true;
1280+
else false;
1281+
end match;
1282+
end isPreviousCref;
1283+
12741284
public function isStartCref
12751285
input DAE.ComponentRef cr;
12761286
output Boolean b;

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8292,19 +8292,19 @@ algorithm
82928292
SimCode.SparsityPattern sparsityT;
82938293
case(SOME(dmd)) algorithm
82948294
print("\ndaeMode: \n" + UNDERLINE + "\n");
8295-
str := "residual Equations:\n"+UNDERLINE+"\n";
8296-
print(str);
8297-
dumpSimEqSystemLst(List.flatten(dmd.daeEquations),"\n");
8298-
dumpVarLst(dmd.residualVars,"residualVars("+intString(listLength(dmd.residualVars))+")");
8299-
dumpVarLst(dmd.algebraicVars,"algebraicDAEVars("+intString(listLength(dmd.algebraicVars))+")");
8300-
dumpVarLst(dmd.auxiliaryVars,"auxVars("+intString(listLength(dmd.auxiliaryVars))+")");
8301-
if isSome(dmd.sparsityPattern) then
8302-
str := "Sparsity Pattern:\n"+UNDERLINE+"\n";
8303-
print(str);
8304-
SimCode.JAC_MATRIX(sparsityT=sparsityT) := Util.getOption(dmd.sparsityPattern);
8305-
dumpSparsePatternInt(sparsityT);
8306-
end if;
8307-
then ();
8295+
str := "residual Equations:\n"+UNDERLINE+"\n";
8296+
print(str);
8297+
dumpSimEqSystemLst(List.flatten(dmd.daeEquations),"\n");
8298+
dumpVarLst(dmd.residualVars,"residualVars("+intString(listLength(dmd.residualVars))+")");
8299+
dumpVarLst(dmd.algebraicVars,"algebraicDAEVars("+intString(listLength(dmd.algebraicVars))+")");
8300+
dumpVarLst(dmd.auxiliaryVars,"auxVars("+intString(listLength(dmd.auxiliaryVars))+")");
8301+
if isSome(dmd.sparsityPattern) then
8302+
str := "Sparsity Pattern:\n"+UNDERLINE+"\n";
8303+
print(str);
8304+
SimCode.JAC_MATRIX(sparsityT=sparsityT) := Util.getOption(dmd.sparsityPattern);
8305+
dumpSparsePatternInt(sparsityT);
8306+
end if;
8307+
then ();
83088308
case(NONE()) then ();
83098309
end match;
83108310
end dumpSimCodeDAEmodeDataString;
@@ -8941,6 +8941,13 @@ algorithm
89418941
varType = tp,
89428942
source = source)), _, vars)
89438943
equation
8944+
_ = match BackendVariable.varStateSelect(dlowVar)
8945+
case DAE.NEVER()
8946+
algorithm
8947+
Error.addSourceMessage(Error.STATE_STATESELECT_NEVER, {ComponentReference.printComponentRefStr(cr)}, source.info);
8948+
then ();
8949+
else ();
8950+
end match;
89448951
commentStr = unparseCommentOptionNoAnnotationNoQuote(comment);
89458952
(unit, displayUnit) = extractVarUnit(dae_var_attr);
89468953
isProtected = getProtected(dae_var_attr);
@@ -8971,6 +8978,14 @@ algorithm
89718978
varType = tp,
89728979
source = source)), _, vars)
89738980
equation
8981+
_ = match BackendVariable.varStateSelect(dlowVar)
8982+
case DAE.ALWAYS()
8983+
guard valueEq(kind, BackendDAE.VARIABLE()) and not ComponentReference.isPreviousCref(cr) /* TODO: Why are clocked variables continuous and not discrete? */
8984+
algorithm
8985+
Error.addSourceMessage(Error.NON_STATE_STATESELECT_ALWAYS, {ComponentReference.printComponentRefStr(cr)}, source.info);
8986+
then ();
8987+
else ();
8988+
end match;
89748989
commentStr = unparseCommentOptionNoAnnotationNoQuote(comment);
89758990
(unit, displayUnit) = extractVarUnit(dae_var_attr);
89768991
isProtected = getProtected(dae_var_attr);

Compiler/Util/Error.mo

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,9 @@ public constant Message EQN_NO_SPACE_TO_SOLVE = MESSAGE(581, SYMBOLIC(), WARNING
935935
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"));
936936
public constant Message VAR_NO_REMAINING_EQN = MESSAGE(582, SYMBOLIC(), WARNING(),
937937
Util.gettext("Variable %s does not have any remaining equation to be solved in.\n The original equations were:%s"));
938-
public constant Message MOVING_PARAMETER_BINDING_TO_INITIAL_EQ_SECTION = MESSAGE(582, TRANSLATION(), NOTIFICATION(),
938+
public constant Message MOVING_PARAMETER_BINDING_TO_INITIAL_EQ_SECTION = MESSAGE(583, TRANSLATION(), NOTIFICATION(),
939939
Util.gettext("Moving binding to initial equation section and setting fixed attribute of %s to false."));
940-
public constant Message MIXED_DETERMINED = MESSAGE(583, SYMBOLIC(), ERROR(),
940+
public constant Message MIXED_DETERMINED = MESSAGE(584, SYMBOLIC(), ERROR(),
941941
Util.gettext("The given system is mixed-determined. [index > %s]\nPlease checkout the option \"--maxMixedDeterminedIndex\"."));
942942
public constant Message STACK_OVERFLOW_DETAILED = MESSAGE(584, SCRIPTING(), ERROR(),
943943
Util.gettext("Stack overflow occurred while evaluating %s:\n%s"));
@@ -953,6 +953,10 @@ public constant Message NF_CAT_FIRST_ARG_EVAL = MESSAGE(589, TRANSLATION(), ERRO
953953
Util.gettext("The first argument of cat must be possible to evaluate during compile-time. Expression %s has variability %s."));
954954
public constant Message COMMA_OPERATOR_DIFFERENT_SIZES = MESSAGE(590, TRANSLATION(), ERROR(),
955955
Util.gettext("Arguments of concatenation comma operator have different sizes for the first dimension: %s has dimension %s and %s has dimension %s."));
956+
public constant Message NON_STATE_STATESELECT_ALWAYS = MESSAGE(591, SYMBOLIC(), WARNING(),
957+
Util.gettext("Variable %s has attribute stateSelect=StateSelect.always, but was selected as a continuous variable."));
958+
public constant Message STATE_STATESELECT_NEVER = MESSAGE(592, SYMBOLIC(), WARNING(),
959+
Util.gettext("Variable %s has attribute stateSelect=StateSelect.never, but was selected as a state"));
956960

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

0 commit comments

Comments
 (0)