Skip to content

Commit

Permalink
- evaluated value for error handling and function call (sqrt, log, lo…
Browse files Browse the repository at this point in the history
…g10) only once

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18044 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Nov 7, 2013
1 parent 6797940 commit bc15c52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -4519,7 +4519,7 @@ algorithm
then DAE.BINARY(DAE.UNARY(DAE.UMINUS(ty),e1),DAE.ADD(ty1),DAE.UNARY(DAE.UMINUS(ty),e2));
case (_,DAE.UMINUS_ARR(ty = ty),DAE.BINARY(exp1 = e1,operator = DAE.ADD_ARR(ty = ty1),exp2 = e2))
then DAE.BINARY(DAE.UNARY(DAE.UMINUS_ARR(ty),e1),DAE.ADD_ARR(ty1),DAE.UNARY(DAE.UMINUS_ARR(ty),e2));
// -( a / b) => -a / b
// -( a / b) => (-a) / b
case (_,DAE.UMINUS(ty = ty),DAE.BINARY(exp1 = e1,operator = DAE.DIV(ty = ty1),exp2 = e2))
then DAE.BINARY(DAE.UNARY(DAE.UMINUS(ty),e1),DAE.DIV(ty1),e2);
case (_,DAE.UMINUS_ARR(ty = ty),DAE.BINARY(exp1 = e1,operator = DAE.DIV_ARR(ty = ty1),exp2 = e2))
Expand Down
27 changes: 15 additions & 12 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -8104,27 +8104,30 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/, Text &varD
then
'sqrt(<%argStr%>)'
else
let ass = '(<%argStr%> >= 0.0)'
let tmp = tempDecl(expTypeFromExpModelica(e1),&varDecls)
let ass = '(<%tmp%> >= 0.0)'
let &preExpMsg = buffer ""
let retPre = assertCommonVar(ass,'"Model error: Argument of sqrt(<%Util.escapeModelicaStringToCString(printExpStr(e1))%>) was %g should be >= 0", <%argStr%>', context, &preExpMsg, &varDecls, dummyInfo)
let &preExp += '<%retPre%>'
'sqrt(<%argStr%>)')
let retPre = assertCommonVar(ass,'"Model error: Argument of sqrt(<%Util.escapeModelicaStringToCString(printExpStr(e1))%>) was %g should be >= 0", <%tmp%>', context, &preExpMsg, &varDecls, dummyInfo)
let &preExp += '<%tmp%> = <%argStr%>; <%\n%><%retPre%>'
'sqrt(<%tmp%>)')

case CALL(path=IDENT(name="log"), expLst={e1}, attr=attr as CALL_ATTR(__)) then
let argStr = daeExp(e1, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
let ass = '(<%argStr%> > 0.0)'
let tmp = tempDecl(expTypeFromExpModelica(e1),&varDecls)
let ass = '(<%tmp%> > 0.0)'
let &preExpMsg = buffer ""
let retPre = assertCommonVar(ass,'"Model error: Argument of log(<%Util.escapeModelicaStringToCString(printExpStr(e1))%>) was %g should be > 0", <%argStr%>', context, &preExpMsg, &varDecls, dummyInfo)
let &preExp += '<%retPre%>'
'log(<%argStr%>)'
let retPre = assertCommonVar(ass,'"Model error: Argument of log(<%Util.escapeModelicaStringToCString(printExpStr(e1))%>) was %g should be > 0", <%tmp%>', context, &preExpMsg, &varDecls, dummyInfo)
let &preExp += '<%tmp%> = <%argStr%>;<%retPre%>'
'log(<%tmp%>)'

case CALL(path=IDENT(name="log10"), expLst={e1}, attr=attr as CALL_ATTR(__)) then
let argStr = daeExp(e1, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
let ass = '(<%argStr%> > 0.0)'
let tmp = tempDecl(expTypeFromExpModelica(e1),&varDecls)
let ass = '(<%tmp%> > 0.0)'
let &preExpMsg = buffer ""
let retPre = assertCommonVar(ass,'"Model error: Argument of log10(<%Util.escapeModelicaStringToCString(printExpStr(e1))%>) was %g should be > 0", <%argStr%>', context, &preExpMsg, &varDecls, dummyInfo)
let &preExp += '<%retPre%>'
'log10(<%argStr%>)'
let retPre = assertCommonVar(ass,'"Model error: Argument of log10(<%Util.escapeModelicaStringToCString(printExpStr(e1))%>) was %g should be > 0", <%tmp%>', context, &preExpMsg, &varDecls, dummyInfo)
let &preExp += '<%tmp%> = <%argStr%>;<%retPre%>'
'log10(<%tmp%>)'

/* Begin code generation of event triggering math functions */

Expand Down

0 comments on commit bc15c52

Please sign in to comment.