Skip to content

Commit

Permalink
- fix bug #2363
Browse files Browse the repository at this point in the history
- keep smooth(0, ...) in Static.mo
- handle smooth(0, ...) in Ceval.mo (smooth(0, constant) -> constant)
- handle smooth in Codegen.tpl
- update expected output for tests
- NOTE: Modelica.Electrical.Analog.Examples.SimpleTriacCircuit gives small numeric differences, use the OpenModelica result file


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17388 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Sep 26, 2013
1 parent 2307c98 commit 2aabb85
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/Ceval.mo
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ algorithm
(cache,v,stOpt) = cevalBuiltin(cache,env, expExp, impl, stOpt,msg,numIter+1);
then
(cache,v,stOpt);

// ceval smooth(0, expr) -> expr
case (cache, env, (e as DAE.CALL(path=funcpath, expLst={DAE.ICONST(0), expExp}, attr=DAE.CALL_ATTR(isImpure=false))), impl, stOpt, msg,_)
equation
Absyn.IDENT("smooth") = Absyn.makeNotFullyQualified(funcpath);
(cache,value,stOpt) = ceval(cache,env,expExp,impl,stOpt,msg,numIter+1);
then
(cache,value,stOpt);

// adrpo: TODO! this needs more work as if we don't have a symtab we run into unloading of dlls problem
// lochel: do not evaluate impure function calls
Expand Down
7 changes: 5 additions & 2 deletions Compiler/FrontEnd/Static.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3072,17 +3072,20 @@ algorithm
Integer pInt;
Prefix.Prefix pre;

// adrpo: according to #2363: https://trac.openmodelica.org/OpenModelica/ticket/2363
// smooth(0, e) should not be removed!
/*
case (cache,env,{Absyn.INTEGER(pInt),expr},_,impl,pre,_) // if p is 0 just return the expression!
equation
true = pInt == 0;
(cache,expr_1,DAE.PROP(tp,c),_) = elabExp(cache,env, expr, impl,NONE(), true,pre,info);
(cache,expr_1,DAE.PROP(tp,c),_) = elabExp(cache,env, expr, impl,NONE(),true,pre,info);
b1 = Types.isReal(tp);
b2 = Types.isRecordWithOnlyReals(tp);
true = Util.boolOrList({b1,b2});
etp = Types.simplifyType(tp);
exp = expr_1;
then
(cache,exp,DAE.PROP(tp,c));
(cache,exp,DAE.PROP(tp,c));*/

case (cache,env,{p,expr},_,impl,pre,_)
equation
Expand Down
6 changes: 6 additions & 0 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7660,6 +7660,12 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/, Text &varD
::=
match call
// special builtins
case CALL(path=IDENT(name="smooth"),
expLst={e1, e2}) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
let var2 = daeExp(e2, context, &preExp, &varDecls)
'/* smooth(<%var1%>, <%var2%>) */ <%var2%>'

case CALL(path=IDENT(name="DIVISION"),
expLst={e1, e2, DAE.SCONST(string=string)}) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
Expand Down

0 comments on commit 2aabb85

Please sign in to comment.