Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Make linspace evaluate dimensions of parameter input third argument


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15002 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 30, 2013
1 parent e861589 commit 6be1b9f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 25 deletions.
10 changes: 10 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6210,6 +6210,16 @@ algorithm
end matchcontinue;
end isRange;

public function isReduction
input DAE.Exp inExp;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inExp)
case DAE.REDUCTION(expr = _) then true;
case _ then false;
end matchcontinue;
end isReduction;

public function isOne
"function: isOne
Returns true if an expression is constant
Expand Down
8 changes: 3 additions & 5 deletions Compiler/FrontEnd/InstSection.mo
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ algorithm
(cache,e2_1,prop2,_) = Static.elabExp(cache, env, e2, impl, NONE(), true /*do vectorization*/, pre, info);
(cache, e1_1, prop1) = Ceval.cevalIfConstant(cache, env, e1_1, prop1, impl, info);
(cache, e2_1, prop2) = Ceval.cevalIfConstant(cache, env, e2_1, prop2, impl, info);

(cache,e1_1,e2_1,prop1) = condenseArrayEquation(cache,env,e1,e2,e1_1,e2_1,prop1,prop2,impl,pre,info);

(cache,e1_2) = PrefixUtil.prefixExp(cache,env, ih, e1_1, pre);
Expand All @@ -505,7 +504,7 @@ algorithm
source = DAEUtil.addCommentToSource(source,comment);
//Check that the lefthandside and the righthandside get along.
dae = instEqEquation(e1_2, prop1, e2_2, prop2, source, initial_, impl);

ci_state_1 = instEquationCommonCiTrans(ci_state, initial_);
then
(cache,env,ih,dae,csets,ci_state_1,graph);
Expand Down Expand Up @@ -1305,8 +1304,7 @@ algorithm
(e1,_) = ExpressionSimplify.simplify(e1);
(e2_1,_) = ExpressionSimplify.simplify(e2_1);
dae = instEqEquation2(e1, e2_1, t_1, c, source, initial_);
then
dae;
then dae;

case (e1, (p1 as DAE.PROP_TUPLE(type_ = t1)),
e2, (p2 as DAE.PROP_TUPLE(type_ = t2, tupleConst = tp)), _, initial_, impl) /* PR. */
Expand Down Expand Up @@ -1769,7 +1767,7 @@ algorithm
equation
true = Config.splitArrays();
true = Expression.dimensionKnown(dim);
true = Expression.isRange(lhs) or Expression.isRange(rhs);
true = Expression.isRange(lhs) or Expression.isRange(rhs) or Expression.isReduction(lhs) or Expression.isReduction(rhs);
ds = Types.getDimensions(tp);
then
DAE.DAE({DAE.ARRAY_EQUATION(ds, lhs, rhs, source)});
Expand Down
52 changes: 51 additions & 1 deletion Compiler/FrontEnd/Static.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7593,12 +7593,62 @@ algorithm
((call_exp,(_,didInline))) := Inline.inlineCall((call_exp,((SOME(functionTree),{DAE.EARLY_INLINE()}),false)));
(call_exp,_) := ExpressionSimplify.condsimplify(didInline,call_exp);
didInline := didInline and (not Config.acceptMetaModelicaGrammar() /* Some weird errors when inlining. Becomes boxed even if it shouldn't... */);
restype := Debug.bcallret2(didInline, Types.fixUnknownDimensions, Types.getPropType(prop_1), Debug.bcallret1(didInline, Expression.typeof, call_exp, DAE.T_UNKNOWN_DEFAULT), Types.getPropType(prop_1));
(cache,restype) := fixUnknownDimensions(didInline, cache, inEnv, Types.getPropType(prop_1), call_exp);
prop_1 := Debug.bcallret2(didInline, Types.setTypeInProps, restype, prop_1, prop_1);
expProps := Util.if_(Util.isSuccess(status),SOME((call_exp,prop_1)),NONE());
outCache := cache;
end elabCallArgs3;

protected function fixUnknownDimensions
input Boolean didInline;
input Env.Cache inCache;
input Env.Env env;
input DAE.Type ty1;
input DAE.Exp call_exp;
output Env.Cache cache;
output DAE.Type oty;
algorithm
(cache,oty) := match (didInline,inCache,env,ty1,call_exp)
local
DAE.Type ty2;
case (false,_,_,_,_) then (inCache,ty1);
else
equation
ty2 = Expression.typeof(call_exp);
(cache,oty) = fixUnknownDimensions2(inCache,env,ty1,ty2);
then (cache,oty);
end match;
end fixUnknownDimensions;

protected function fixUnknownDimensions2 "Fixes unknown dimensions by getting hints from the final expression"
input Env.Cache inCache;
input Env.Env env;
input DAE.Type ty1;
input DAE.Type ty2 "Simplified type, but might have more dimensions known";
output Env.Cache cache;
output DAE.Type ty;
algorithm
(cache,ty) := matchcontinue (inCache,env,ty1,ty2)
local
DAE.Type inner1,inner2;
DAE.TypeSource ts1,ts2;
DAE.Dimensions dims2;
DAE.Dimension d;
DAE.Exp exp;
Integer i;
case (cache,_,DAE.T_ARRAY(ty=inner1,dims={DAE.DIM_UNKNOWN()},source=ts1),DAE.T_ARRAY(ty=inner2,dims=(d as DAE.DIM_INTEGER(_))::dims2,source=ts2))
equation
(cache,inner1) = fixUnknownDimensions2(cache,env,inner1,DAE.T_ARRAY(inner2,dims2,ts2));
then (cache,DAE.T_ARRAY(inner1,d::{},ts1));
case (cache,_,DAE.T_ARRAY(ty=inner1,dims={DAE.DIM_UNKNOWN()},source=ts1),DAE.T_ARRAY(ty=inner2,dims=(d as DAE.DIM_EXP(exp))::dims2,source=ts2))
equation
(cache,Values.INTEGER(i),_) = Ceval.ceval(cache,env,exp,false,NONE(),Ceval.NO_MSG());
(cache,inner1) = fixUnknownDimensions2(cache,env,inner1,DAE.T_ARRAY(inner2,dims2,ts2));
then (cache,DAE.T_ARRAY(inner1,DAE.DIM_INTEGER(i)::{},ts1));
else (inCache,ty1);
end matchcontinue;
end fixUnknownDimensions2;

protected function isValidWRTParallelScope
input Absyn.Path inFn;
input Boolean isBuiltin;
Expand Down
19 changes: 0 additions & 19 deletions Compiler/FrontEnd/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7640,25 +7640,6 @@ algorithm
end match;
end ifExpMakeDimsUnknown;

public function fixUnknownDimensions "Fixes unknown dimensions by getting hints from the final expression"
input DAE.Type ty1;
input DAE.Type ty2 "Simplified type, but might have more dimensions known";
output DAE.Type ty;
algorithm
ty := match (ty1,ty2)
local
DAE.Type inner1,inner2;
DAE.TypeSource ts1,ts2;
DAE.Dimensions dims2;
DAE.Dimension d;
case (DAE.T_ARRAY(ty=inner1,dims={DAE.DIM_UNKNOWN()},source=ts1),DAE.T_ARRAY(ty=inner2,dims=(d as DAE.DIM_INTEGER(_))::dims2,source=ts2))
equation
inner1 = fixUnknownDimensions(inner1,DAE.T_ARRAY(inner2,dims2,ts2));
then DAE.T_ARRAY(inner1,d::{},ts1);
else ty1;
end match;
end fixUnknownDimensions;

public function isFixedWithNoBinding
"check if the type has bindings for everything
if is parameter or constant without fixed = false
Expand Down

0 comments on commit 6be1b9f

Please sign in to comment.