From 1e6d000ffc6e101157e16132673cc59c124f0ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Mon, 13 Sep 2010 13:02:37 +0000 Subject: [PATCH] Fixes for bug #1274: - 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 --- Compiler/Static.mo | 91 ++++++++++++++++++++-------------------------- Compiler/Types.mo | 27 +++++++------- Compiler/Util.mo | 40 ++++++++------------ 3 files changed, 69 insertions(+), 89 deletions(-) diff --git a/Compiler/Static.mo b/Compiler/Static.mo index c0fe7d0c351..cbc7a4d4271 100644 --- a/Compiler/Static.mo +++ b/Compiler/Static.mo @@ -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 @@ -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); @@ -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 tpl; +protected function sameDimensions + "This function returns true if all properties, containing types, have the same + dimensions, otherwise false." + input list inProps; output Boolean res; - list>> tpl_1; - list> dimsizes; + + list types; + list> 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 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 inProps; input Integer dimException; output Boolean res; - list>> tpl_1; - list> dimsizes; + + list types; + list> 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> inIntegerLstLst; - input Integer dim; - input Integer dimException; output Boolean outBoolean; algorithm outBoolean:= - matchcontinue (inIntegerLstLst,dim,dimException) + matchcontinue (inIntegerLstLst) local list> l,restelts; list 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 inIntegerLst; - output Boolean outBoolean; +protected function sameDimensions3 + "Helper function to sameDimensions2. Check that all dimensions in a list are equal." + input list inDims; + output Boolean outRes; algorithm - outBoolean:= - matchcontinue (inIntegerLst) + outRes := matchcontinue (inDims) local Integer i1,i2; Boolean res,res2,res_1; @@ -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; diff --git a/Compiler/Types.mo b/Compiler/Types.mo index 02e50927f16..3da93e310b6 100644 --- a/Compiler/Types.mo +++ b/Compiler/Types.mo @@ -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; diff --git a/Compiler/Util.mo b/Compiler/Util.mo index faf1495c887..1d7bc21c91f 100644 --- a/Compiler/Util.mo +++ b/Compiler/Util.mo @@ -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 inList; input FuncType inFunc; input Type_b inArg; @@ -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 inList; - input Integer inPos; - output list 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 inList; + input Integer inPos; + output list outList; + replaceable type TypeA subtypeof Any; algorithm - outList := matchcontinue(inList,inPos) + outList := matchcontinue(inList, inPos) local - list lst,res,tmp1,tmp2; - Integer pos; - case(lst,pos) + TypeA e; + list 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;