Skip to content

Commit

Permalink
- More cleanup of Static.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23633 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Dec 2, 2014
1 parent 0b23e35 commit 18e8fd8
Show file tree
Hide file tree
Showing 6 changed files with 1,637 additions and 2,388 deletions.
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -1211,7 +1211,7 @@ public function crefIsIdent
output Boolean res;
algorithm
res := match(cr)
case(DAE.CREF_IDENT(_,_,_)) then true;
case DAE.CREF_IDENT() then true;
else false;
end match;
end crefIsIdent;
Expand All @@ -1223,7 +1223,7 @@ public function crefIsNotIdent
output Boolean res;
algorithm
res := match(cr)
case(DAE.CREF_IDENT(_,_,_)) then false;
case DAE.CREF_IDENT() then false;
else true;
end match;
end crefIsNotIdent;
Expand Down
36 changes: 34 additions & 2 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -1023,7 +1023,7 @@ algorithm
case (e as DAE.CALL(path = Absyn.IDENT("cross"), expLst = expl))
equation
{DAE.ARRAY(array = v1),DAE.ARRAY(array = v2)} = expl;
expl = Static.elabBuiltinCross2(v1, v2);
expl = simplifyCross(v1, v2);
tp = Expression.typeof(e);
// Since there is a bug somewhere in simplify that gives wrong types for arrays we take the type from cross.
scalar = not Expression.isArrayType(Expression.unliftArray(tp));
Expand All @@ -1032,7 +1032,7 @@ algorithm

case (e as DAE.CALL(path = Absyn.IDENT("skew"), expLst = {DAE.ARRAY(array = v1)}))
equation
mexpl = Static.elabBuiltinSkew2(v1);
mexpl = simplifySkew(v1);
tp = Expression.typeof(e);
then DAE.MATRIX(tp, 3, mexpl);

Expand Down Expand Up @@ -5554,5 +5554,37 @@ algorithm
end match;
end removeMinMaxFoldableValues;

public function simplifySkew
"Simplifies the skew operator."
input list<DAE.Exp> v1;
output list<list<DAE.Exp>> res;
protected
DAE.Exp x1, x2, x3, zero;
algorithm
{x1, x2, x3} := v1;
zero := Expression.makeConstZero(Expression.typeof(x1));

res := {{zero, Expression.negate(x3), x2},
{x3, zero, Expression.negate(x1)},
{Expression.negate(x2), x1, zero}};
end simplifySkew;

public function simplifyCross
"Simplifies the cross operator."
input list<DAE.Exp> v1;
input list<DAE.Exp> v2;
output list<DAE.Exp> res;
protected
DAE.Exp x1, x2, x3, y1, y2, y3;
algorithm
{x1, x2, x3} := v1;
{y1, y2, y3} := v2;

// res = {x[2]*y[3] - x[3]*y[2], x[3]*y[1] - x[1]*y[3], x[1]*y[2] - x[2]*y[1]}
res := {Expression.makeDiff(Expression.makeProduct(x2, y3), Expression.makeProduct(x3, y2)),
Expression.makeDiff(Expression.makeProduct(x3, y1), Expression.makeProduct(x1, y3)),
Expression.makeDiff(Expression.makeProduct(x1, y2), Expression.makeProduct(x2, y1))};
end simplifyCross;

annotation(__OpenModelica_Interface="frontend");
end ExpressionSimplify;
5 changes: 2 additions & 3 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -1604,10 +1604,9 @@ algorithm
then
(cache,res);

// Check for special builtin operators that can not be represented in environment like for instance cardinality
case (cache,env,Absyn.IDENT(name = str),_)
// Check for cardinality that can not be represented in the environment.
case (cache,env,Absyn.IDENT(name = str as "cardinality"),_)
equation
_ = Static.elabBuiltinHandlerGeneric(str);
env = FGraph.topScope(env);
res = createGenericBuiltinFunctions(env, str);
then
Expand Down

0 comments on commit 18e8fd8

Please sign in to comment.