Skip to content

Commit

Permalink
- Use ModelicaBuiltin.mo to describe skew
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10077 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 10, 2011
1 parent 9fc8fde commit 7c3c183
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 63 deletions.
6 changes: 6 additions & 0 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -683,6 +683,12 @@ algorithm
then
DAE.ARRAY(tp, scalar,expl);

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

// Simplify built-in function fill. MathCore depends on this being done here, do not remove!
case (DAE.CALL(path = Absyn.IDENT("fill"), expLst = e::expl))
equation
Expand Down
18 changes: 14 additions & 4 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -237,6 +237,8 @@ function outerProduct = overload(OpenModelica.Internal.outerProductInt,OpenModel

function cross = overload(OpenModelica.Internal.crossInt,OpenModelica.Internal.crossReal);

function skew = overload(OpenModelica.Internal.skewInt,OpenModelica.Internal.skewReal);

// Dummy functions that can't be properly defined in Modelica, but used by
// SCodeFlatten to define which builtin functions exist (SCodeFlatten doesn't
// care how the functions are defined, only if they exist or not).
Expand Down Expand Up @@ -269,10 +271,6 @@ function symmetric
external "builtin";
end symmetric;

function skew
external "builtin";
end skew;

function smooth
external "builtin";
end smooth;
Expand Down Expand Up @@ -517,6 +515,18 @@ package Internal "Contains internal implementations, e.g. overloaded builtin fun
*/
end crossReal;

function skewInt
input Integer[3] x;
output Integer[3,3] y;
external "builtin" skew(x,y);
end skewInt;

function skewReal
input Real[3] x;
output Real[3,3] y;
external "builtin" skew(x,y);
end skewReal;

end Internal;

package Scripting
Expand Down
60 changes: 1 addition & 59 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -5348,64 +5348,7 @@ algorithm
end matchcontinue;
end elabBuiltinScalar;

protected function elabBuiltinSkew "
author: PA

This function handles the built in skew operator.

"
input Env.Cache inCache;
input Env.Env inEnv;
input list<Absyn.Exp> inAbsynExpLst;
input list<Absyn.NamedArg> inNamedArg;
input Boolean inBoolean;
input Prefix.Prefix inPrefix;
input Absyn.Info info;
output Env.Cache outCache;
output DAE.Exp outExp;
output DAE.Properties outProperties;
algorithm
(outCache,outExp,outProperties):=
matchcontinue (inCache,inEnv,inAbsynExpLst,inNamedArg,inBoolean,inPrefix,info)
local
DAE.Exp e1, call;
DAE.Type tp1;
DAE.Const c1;
list<Env.Frame> env;
Boolean impl;
Env.Cache cache;
Absyn.Exp v1;
list<DAE.Exp> expl1;
list<list<DAE.Exp>> mexpl;
DAE.ExpType etp1,etp,etp3;
DAE.Type eltTp;
Prefix.Prefix pre;

//First, try symbolic simplification
case (cache,env,{v1},_,impl,pre,info)
equation
(cache,DAE.ARRAY(etp1,true,expl1),DAE.PROP(tp1,c1),_) = elabExp(cache,env, v1, impl,NONE(),true,pre,info);
{3} = Types.getDimensionSizes(tp1);
mexpl = elabBuiltinSkew2(expl1);
tp1 = Types.liftArray(tp1,DAE.DIM_INTEGER(3));
etp3 = Types.elabType(tp1);
then
(cache,DAE.MATRIX(etp3,3,mexpl),DAE.PROP(tp1,c1));

//Fallback, use builtin function skew
case (cache,env,{v1},_,impl,pre,info) equation
(cache,e1,DAE.PROP(tp1,c1),_) = elabExp(cache,env, v1, impl,NONE(),true,pre,info);
{3} = Types.getDimensionSizes(tp1);
etp = Expression.typeof(e1);
eltTp = Types.arrayElementType(tp1);
tp1 = Types.liftArrayListDims(eltTp, {DAE.DIM_INTEGER(3), DAE.DIM_INTEGER(3)});
etp = DAE.ET_ARRAY(etp, {DAE.DIM_INTEGER(3), DAE.DIM_INTEGER(3)});
call = Expression.makeBuiltinCall("skew", {e1}, etp);
then (cache, call, DAE.PROP(tp1,DAE.C_VAR()));
end matchcontinue;
end elabBuiltinSkew;

protected function elabBuiltinSkew2 "help function to elabBuiltinSkew"
public function elabBuiltinSkew2 "help function to ExpressionSimplify"
input list<DAE.Exp> v1;
output list<list<DAE.Exp>> res;
algorithm
Expand Down Expand Up @@ -5998,7 +5941,6 @@ algorithm
case "vector" then elabBuiltinVector;
case "matrix" then elabBuiltinMatrix;
case "scalar" then elabBuiltinScalar;
case "skew" then elabBuiltinSkew;
case "String" then elabBuiltinString;
case "rooted" then elabBuiltinRooted;
case "Integer" then elabBuiltinIntegerEnum;
Expand Down

0 comments on commit 7c3c183

Please sign in to comment.