Skip to content

Commit

Permalink
Fixes for bug #1274:
Browse files Browse the repository at this point in the history
- Changed Static.elabBuiltinSize so that the resulting expression is not a
  constant if we don't know the dimensions yet.
- Added check for checkModel in Static.elabBuiltinCat2, in case the dimension is
  not known.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6105 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 13, 2010
1 parent e9d7b36 commit 1e6d000
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 89 deletions.
91 changes: 40 additions & 51 deletions Compiler/Static.mo
Expand Up @@ -2131,7 +2131,7 @@ algorithm
case(0,tty) then tty;
case(n,(DAE.T_FUNCTION(args,resType,isInline),po))
equation
args_1 = Util.listRemoveNth(args,listLength(args) - 1);
args_1 = Util.listRemoveNth(args,listLength(args));
tty = (DAE.T_FUNCTION(args_1,resType,isInline),po);
tty_1 = stripExtraArgsFromType(n-1,tty);
then
Expand Down Expand Up @@ -3260,13 +3260,10 @@ algorithm
// The previous case failed, return a call to the size function instead.
case (cache,env,{arraycr,dim},_,impl,pre)
equation
(cache,dimp,DAE.PROP(_,c1),_,dae1) = elabExp(cache, env, dim, impl, NONE, true,pre);
(cache,arraycrefe,DAE.PROP(arrtp,_),_,dae2) = elabExp(cache, env, arraycr, impl, NONE, true,pre);
c2 = Types.dimensionsKnown(arrtp);
c2_1 = Types.boolConstSize(c2);
c = Types.constAnd(c1, c2_1);
(cache,dimp,_,_,dae1) = elabExp(cache, env, dim, impl, NONE, true,pre);
(cache,arraycrefe,_,_,dae2) = elabExp(cache, env, arraycr, impl, NONE, true,pre);
exp = DAE.SIZE(arraycrefe,SOME(dimp));
prop = DAE.PROP(DAE.T_INTEGER_DEFAULT, c);
prop = DAE.PROP(DAE.T_INTEGER_DEFAULT, DAE.C_PARAM);
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,exp,prop,dae);
Expand Down Expand Up @@ -4711,82 +4708,69 @@ algorithm
end matchcontinue;
end elabBuiltinZeros;

protected function sameDimensions "function: sameDimensions

This function returns true of all the properties, containing types,
have the same dimensions, otherwise false.
"
input list<DAE.Properties> tpl;
protected function sameDimensions
"This function returns true if all properties, containing types, have the same
dimensions, otherwise false."
input list<DAE.Properties> inProps;
output Boolean res;
list<tuple<DAE.TType, Option<Absyn.Path>>> tpl_1;
list<list<Integer>> dimsizes;

list<DAE.Type> types;
list<list<Integer>> dims;
algorithm
tpl_1 := Util.listMap(tpl, Types.getPropType);
dimsizes := Util.listMap(tpl_1, Types.getDimensionSizes);
res := sameDimensions2(dimsizes,1,-1);
types := Util.listMap(inProps, Types.getPropType);
dims := Util.listMap(types, Types.getDimensionSizes);
res := sameDimensions2(dims);
end sameDimensions;

protected function sameDimensionsExceptionDimX "function: sameDimensionsExceptionDimX

This function returns true of all the properties, containing types,
have the same dimensions, otherwise false.
"
input list<DAE.Properties> tpl;
protected function sameDimensionsExceptionDimX
"This function returns true if all properties, containing types, have the same
dimensions (except for dimension X), otherwise false."
input list<DAE.Properties> inProps;
input Integer dimException;
output Boolean res;
list<tuple<DAE.TType, Option<Absyn.Path>>> tpl_1;
list<list<Integer>> dimsizes;

list<DAE.Type> types;
list<list<Integer>> dims;
algorithm
tpl_1 := Util.listMap(tpl, Types.getPropType);
dimsizes := Util.listMap(tpl_1, Types.getDimensionSizes);
res := sameDimensions2(dimsizes,1,dimException);
types := Util.listMap(inProps, Types.getPropType);
dims := Util.listMap(types, Types.getDimensionSizes);
dims := Util.listRemoveNth(dims, dimException);
res := sameDimensions2(dims);
end sameDimensionsExceptionDimX;

protected function sameDimensions2
input list<list<Integer>> inIntegerLstLst;
input Integer dim;
input Integer dimException;
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inIntegerLstLst,dim,dimException)
matchcontinue (inIntegerLstLst)
local
list<list<Integer>> l,restelts;
list<Integer> elts;
Integer dim1,dim2;
case (l,_,_)
case (l)
equation
{} = Util.listFlatten(l);
then
true;
case (l,dim,dimException)
equation
true = dim == dimException;
restelts = Util.listMap(l, Util.listRest);
true = sameDimensions2(restelts,dim+1,dimException);
then true;
case (l,dim,dimException)
case (l)
equation
false = dim == dimException;
elts = Util.listMap(l, Util.listFirst);
restelts = Util.listMap(l, Util.listRest);
true = sameDimensions3(elts);
true = sameDimensions2(restelts,dim+1,dimException);
true = sameDimensions2(restelts);
then
true;
case (_,_,_) then false;
case (_) then false;
end matchcontinue;
end sameDimensions2;

protected function sameDimensions3 "function: sameDimensions3

Helper function to same_dimensions2
"
input list<Integer> inIntegerLst;
output Boolean outBoolean;
protected function sameDimensions3
"Helper function to sameDimensions2. Check that all dimensions in a list are equal."
input list<Integer> inDims;
output Boolean outRes;
algorithm
outBoolean:=
matchcontinue (inIntegerLst)
outRes := matchcontinue (inDims)
local
Integer i1,i2;
Boolean res,res2,res_1;
Expand Down Expand Up @@ -6121,6 +6105,11 @@ algorithm
new_d = old_d*n_args;
then
((DAE.T_ARRAY(DAE.DIM_INTEGER(new_d),tp),p));
case ((DAE.T_ARRAY(arrayDim = DAE.DIM_NONE), _), 1, _)
equation
true = OptManager.getOption("checkModel");
then
inType1;
case ((DAE.T_ARRAY(arrayDim = dim,arrayType = tp),p),n,n_args)
equation
n_1 = n - 1;
Expand Down
27 changes: 14 additions & 13 deletions Compiler/Types.mo
Expand Up @@ -725,24 +725,25 @@ algorithm
end ndims;

public function dimensionsKnown
"function: dimensionsKnown
Returns true of the dimensions of the type is known."
"Returns true if the dimensions of the type is known."
input Type inType;
output Boolean outBoolean;
output Boolean outRes;
algorithm
outBoolean:=
matchcontinue (inType)
local Type tp;
case (tp)
equation
{} = getDimensionSizes(tp);
then
false;
case (tp)
outRes := matchcontinue(inType)
local
DAE.Dimension d;
Type tp;
case ((DAE.T_ARRAY(arrayDim = d, arrayType = tp), _))
equation
_ = getDimensionSizes(tp);
true = Exp.dimensionKnown(d);
true = dimensionsKnown(tp);
then
true;
case ((DAE.T_ARRAY(arrayDim = _), _))
then false;
case ((DAE.T_COMPLEX(complexTypeOption = SOME(tp)), _))
then dimensionsKnown(tp);
case _ then true;
end matchcontinue;
end dimensionsKnown;

Expand Down
40 changes: 15 additions & 25 deletions Compiler/Util.mo
Expand Up @@ -1352,7 +1352,7 @@ end listMap1r_tail;
public function listMapAndFold
"Takes a list, an extra argument and a function. The function will be applied
to each element in the list, and the extra argument will be passed to the
function an updated."
function and updated."
input list<Type_a> inList;
input FuncType inFunc;
input Type_b inArg;
Expand Down Expand Up @@ -3449,35 +3449,25 @@ algorithm
end matchcontinue;
end listUnionOnTrue;

// stefan
public function listRemoveNth
"function: listRemoveNth
removes the Nth element of a list, starting with index 0
listRemove({1,2,3,4,5},2) ==> {1,2,4,5}"
input list<TypeA> inList;
input Integer inPos;
output list<TypeA> outList;
replaceable type TypeA subtypeof Any;
"Removes the nth element of a list, starting with index 1.
Example: listRemove({1,2,3,4,5},2) => {1,3,4,5}"
input list<TypeA> inList;
input Integer inPos;
output list<TypeA> outList;
replaceable type TypeA subtypeof Any;
algorithm
outList := matchcontinue(inList,inPos)
outList := matchcontinue(inList, inPos)
local
list<TypeA> lst,res,tmp1,tmp2;
Integer pos;
case(lst,pos)
TypeA e;
list<TypeA> el;
case (e :: el, 1) then el;
case (e :: el, _)
equation
true = pos == listLength(lst) - 1;
res = listStripLast(lst);
true = inPos > 0;
el = listRemoveNth(el, inPos - 1);
then
res;
case(lst,pos)
equation
true = pos < listLength(lst) - 1;
(tmp1,_) = listSplit(lst,pos);
(_,tmp2) = listSplit(lst,pos + 1);
res = listAppend(tmp1,tmp2);
then
res;
case(_,_) then fail();
e :: el;
end matchcontinue;
end listRemoveNth;

Expand Down

0 comments on commit 1e6d000

Please sign in to comment.