Skip to content

Commit

Permalink
Remove when initial() from dynamic system
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Apr 10, 2017
1 parent 3d4461d commit 639c7bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
8 changes: 4 additions & 4 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -5418,7 +5418,7 @@ template equationWhen(SimEqSystem eq, Context context, Text &varDecls, Text &aux
::=
match eq
case SES_WHEN(whenStmtLst = whenStmtLst, conditions=conditions, elseWhen=NONE()) then
let helpIf = if intGt(listLength(conditions), 0) then (conditions |> e => '(<%cref(e)%> && !<%crefPre(e)%> /* edge */)';separator=" || ") else '0'
let helpIf = if not listEmpty(conditions) then (conditions |> e => '(<%cref(e)%> && !<%crefPre(e)%> /* edge */)';separator=" || ") else '0'
let assign = whenOperators(whenStmtLst, context, &varDecls, auxFunction)
<<
if(<%helpIf%>)
Expand All @@ -5427,7 +5427,7 @@ template equationWhen(SimEqSystem eq, Context context, Text &varDecls, Text &aux
}
>>
case SES_WHEN(whenStmtLst = whenStmtLst, conditions=conditions, elseWhen=SOME(elseWhenEq)) then
let helpIf = if intGt(listLength(conditions), 0) then (conditions |> e => '(<%cref(e)%> && !<%crefPre(e)%> /* edge */)';separator=" || ") else '0'
let helpIf = if not listEmpty(conditions) then (conditions |> e => '(<%cref(e)%> && !<%crefPre(e)%> /* edge */)';separator=" || ") else '0'
let assign = whenOperators(whenStmtLst, context, &varDecls, auxFunction)
let elseWhen = equationElseWhen(elseWhenEq,context,varDecls,&auxFunction)
<<
Expand All @@ -5447,7 +5447,7 @@ case SES_WHEN(whenStmtLst = whenStmtLst, conditions=conditions, elseWhen=NONE())
let helpIf = (conditions |> e => '(<%cref(e)%> && !<%crefPre(e)%> /* edge */)';separator=" || ")
let assign = whenOperators(whenStmtLst, context, &varDecls, auxFunction)

if intGt(listLength(conditions), 0) then
if not listEmpty(conditions) then
<<
else if(<%helpIf%>)
{
Expand All @@ -5458,7 +5458,7 @@ case SES_WHEN(whenStmtLst = whenStmtLst, conditions=conditions, elseWhen=SOME(el
let helpIf = (conditions |> e => '(<%cref(e)%> && !<%crefPre(e)%> /* edge */)';separator=" || ")
let assign = whenOperators(whenStmtLst, context, &varDecls, auxFunction)
let elseWhen = equationElseWhen(elseWhenEq, context, varDecls, auxFunction)
let body = if intGt(listLength(conditions), 0) then
let body = if not listEmpty(conditions) then
<<
else if(<%helpIf%>)
{
Expand Down
28 changes: 6 additions & 22 deletions Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -3190,27 +3190,13 @@ template algStmtWhen(DAE.Statement when, Context context, Text &varDecls, Text &
case SIMULATION_CONTEXT(__) then
match when
case STMT_WHEN(__) then
let initial_condition = if initialCall then
'initial()'
else
'0'
let if_conditions = (conditions |> e => ' || (<%cref(e)%> && !<%crefPre(e)%> /* edge */)')
let statements = (statementLst |> stmt =>
algStatement(stmt, context, &varDecls, &auxFunction)
;separator="\n")
let initial_statements = if initialCall then
'<%statements%>'
else
'/* nothing to do */'
let if_conditions = if not listEmpty(conditions) then (conditions |> e => '(<%cref(e)%> && !<%crefPre(e)%> /* edge */)';separator=" || ") else '0'
let statements = (statementLst |> stmt => algStatement(stmt, context, &varDecls, &auxFunction);separator="\n")
let else_clause = algStatementWhenElse(elseWhen, &varDecls, &auxFunction)
<<
if(data->simulationInfo->discreteCall == 1)
{
if(initial())
{
<%initial_statements%>
}
else if(0<%if_conditions%>)
if(<%if_conditions%>)
{
<%statements%>
}
Expand All @@ -3227,13 +3213,11 @@ template algStatementWhenElse(Option<DAE.Statement> stmt, Text &varDecls, Text &
::=
match stmt
case SOME(when as STMT_WHEN(__)) then
let statements = (when.statementLst |> stmt =>
algStatement(stmt, contextSimulationDiscrete, &varDecls, &auxFunction)
;separator="\n")
let else_conditions = if not listEmpty(when.conditions) then (when.conditions |> e => '(<%cref(e)%> && !<%crefPre(e)%> /* edge */)';separator=" || ") else '0'
let statements = (when.statementLst |> stmt => algStatement(stmt, contextSimulationDiscrete, &varDecls, &auxFunction);separator="\n")
let else = algStatementWhenElse(when.elseWhen, &varDecls, &auxFunction)
let elseCondStr = (when.conditions |> e => ' || (<%cref(e)%> && !<%crefPre(e)%> /* edge */)')
<<
else if(0<%elseCondStr%>)
else if(<%else_conditions%>)
{
<%statements%>
}
Expand Down

0 comments on commit 639c7bd

Please sign in to comment.