Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- min({time,...,time}) = time


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9617 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 9, 2011
1 parent 703d525 commit aa65adb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
23 changes: 19 additions & 4 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -2606,17 +2606,32 @@ algorithm outCrefExp := match(inVar,inCrefPrefix)
end match;
end generateCrefsExpFromExpVar;

public function makeRealArray
public function makeScalarArray
"function: makeRealArray
Construct an array node of an DAE.Exp list of type REAL."
input list<DAE.Exp> inExpLst;
input DAE.ExpType et;
output DAE.Exp outExp;
algorithm
outExp:=
match (inExpLst)
local list<DAE.Exp> expl;
case (expl) then DAE.ARRAY(DAE.ET_REAL(),false,expl);
match (inExpLst,et)
local
list<DAE.Exp> expl;
Integer i;
case (expl,et)
equation
i = listLength(expl);
then DAE.ARRAY(DAE.ET_ARRAY(et,{DAE.DIM_INTEGER(i)}),true,expl);
end match;
end makeScalarArray;

public function makeRealArray
"function: makeRealArray
Construct an array node of an DAE.Exp list of type REAL."
input list<DAE.Exp> expl;
output DAE.Exp outExp;
algorithm
outExp := makeScalarArray(expl,DAE.ET_REAL());
end makeRealArray;

public function makeRealAdd
Expand Down
20 changes: 19 additions & 1 deletion Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -620,13 +620,31 @@ algorithm
list<DAE.Exp> v1, v2;
Boolean scalar;
list<Values.Value> valueLst;
Integer i;
Integer i,i1,i2;
String str;
Real r;

// min/max function on arrays of only 1 element
case (DAE.CALL(path=Absyn.IDENT("min"),expLst={DAE.ARRAY(array={e})})) then e;
case (DAE.CALL(path=Absyn.IDENT("max"),expLst={DAE.ARRAY(array={e})})) then e;
// Try to unify the expressions :)
case (DAE.CALL(path=Absyn.IDENT("min"),expLst={DAE.ARRAY(array=es)},attr=DAE.CALL_ATTR(ty=tp)))
equation
i1 = listLength(es);
es = Util.listUnion(es,es);
i2 = listLength(es);
false = i1 == i2;
e = Expression.makeScalarArray(es,tp);
then Expression.makeBuiltinCall("min",{e},tp);
case (DAE.CALL(path=Absyn.IDENT("max"),expLst={DAE.ARRAY(array=es)},attr=DAE.CALL_ATTR(ty=tp)))
equation
i1 = listLength(es);
es = Util.listUnion(es,es);
i2 = listLength(es);
false = i1 == i2;
e = Expression.makeScalarArray(es,tp);
then Expression.makeBuiltinCall("max",{e},tp);

case (DAE.CALL(path=Absyn.IDENT("min"),attr=DAE.CALL_ATTR(ty=DAE.ET_ARRAY(tp,{_})),expLst={DAE.ARRAY(array={e1,e2})}))
equation
e = Expression.makeBuiltinCall("min",{e1,e2},tp);
Expand Down

0 comments on commit aa65adb

Please sign in to comment.