Skip to content

Commit 609f8a7

Browse files
niklworsunknown
authored andcommitted
added assert warnings in cpp template
1 parent e1aa8b0 commit 609f8a7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Compiler/Template/CodegenCpp.tpl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11487,7 +11487,7 @@ template whenOperators(list<WhenOperator> whenOps, Context context, Text &varDec
1148711487
MODELICA_TERMINATE(<%msgVar%>);
1148811488
>>
1148911489
case ASSERT(source=SOURCE(info=info)) then
11490-
assertCommon(condition, message, contextSimulationDiscrete, &varDecls, info,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
11490+
assertCommon(condition, message,level, contextSimulationDiscrete, &varDecls, info,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
1149111491
case NORETCALL(__) then
1149211492
let &preExp = buffer ""
1149311493
let expPart = daeExp(exp, contextSimulationDiscrete, &preExp, &varDecls,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
@@ -11818,7 +11818,7 @@ end daeExpRange;
1181811818

1181911819

1182011820

11821-
template assertCommon(Exp condition, Exp message, Context context, Text &varDecls, builtin.SourceInfo info, SimCode simCode,
11821+
template assertCommon(Exp condition, Exp message,Exp level, Context context, Text &varDecls, builtin.SourceInfo info, SimCode simCode,
1182211822
Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation)
1182311823
::=
1182411824
let &preExpCond = buffer ""
@@ -11842,17 +11842,25 @@ template assertCommon(Exp condition, Exp message, Context context, Text &varDecl
1184211842
if(!<%condVar%>)
1184311843
{
1184411844
<%preExpMsg%>
11845-
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,<%msgVar%>);
11845+
<%match level case ENUM_LITERAL(index=2)
11846+
then 'cerr <<"Warning: " << <%msgVar%>;'
11847+
else
11848+
'throw ModelicaSimulationError(MODEL_EQ_SYSTEM,<%msgVar%>);'
11849+
%>
1184611850

1184711851
}
1184811852
>>
1184911853
else
1185011854
<<
1185111855
if(!<%condVar%>)
1185211856
{
11857+
1185311858
<%preExpCond%>
1185411859
<%preExpMsg%>
11855-
throw ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM);
11860+
<%match level case ENUM_LITERAL(index=2)
11861+
then 'cerr <<"Warning: >Assert in model equation";'
11862+
else 'throw ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM);'
11863+
%>
1185611864
}
1185711865
>>
1185811866
%>
@@ -13509,7 +13517,7 @@ template algStmtAssert(DAE.Statement stmt, Context context, Text &varDecls,SimCo
1350913517
::=
1351013518
match stmt
1351113519
case STMT_ASSERT(source=SOURCE(info=info)) then
13512-
assertCommon(cond, msg, context, &varDecls, info,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
13520+
assertCommon(cond, msg, level, context, &varDecls, info,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
1351313521
end algStmtAssert;
1351413522

1351513523

0 commit comments

Comments
 (0)