Skip to content

Commit

Permalink
Fix for bug #1796:
Browse files Browse the repository at this point in the history
- Fixed correct order of dimensions in Inst.makeCrefBaseType and
  Inst.arrayBasictypeBaseclass.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12825 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 7, 2012
1 parent 4275eeb commit e7fce4c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 173 deletions.
2 changes: 0 additions & 2 deletions Compiler/BackEnd/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7153,8 +7153,6 @@ algorithm
// insert vars in array
dims = Expression.arrayDimension(tp);
dimsint = Expression.dimensionsSizes(dims);
// workaround for Ticket #1796
dimsint = listReverse(dimsint);
vararray = List.fold1(varlst,insertArrayVars,dimsint,vararray);
// get vars from array sorted
sortedVars = getVarsFromArray(size,vararray,iVars);
Expand Down
99 changes: 43 additions & 56 deletions Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,30 @@ algorithm
end matchcontinue;
end liftArrayLeft;

public function liftArrayLeftList
input Type inType;
input list<DAE.Dimension> inDimensions;
output Type outType;
algorithm
outType := match(inType, inDimensions)
local
Type ty;
DAE.Dimensions dims;
DAE.TypeSource ts;

case (_, {}) then inType;

case (DAE.T_ARRAY(ty, dims, ts), _)
equation
dims = listAppend(inDimensions, dims);
then
DAE.T_ARRAY(ty, dims, ts);

else DAE.T_ARRAY(inType, inDimensions, DAE.emptyTypeSource);

end match;
end liftArrayLeftList;

public function setOpType
"Sets the type of an operator."
input Operator inOp;
Expand Down Expand Up @@ -1499,68 +1523,32 @@ algorithm
end match;
end arrayTypeDimensions;

public function subscriptDimensions "Function: subscriptDimensions
Returns the dimensionality of the subscript expression"
input list<Subscript> insubs;
output DAE.Dimensions oint;
public function subscriptDimensions
"Converts a list of subscript to a list of dimensions."
input list<Subscript> inSubscripts;
output DAE.Dimensions outDimensions;
algorithm
oint := matchcontinue(insubs)
local
Subscript ss;
list<Subscript> subs;
Integer x;
DAE.Dimensions recursive;
DAE.Exp e;
String sub_str;

case ({}) then {};

case ((ss as DAE.INDEX(DAE.ICONST(x)))::subs)
equation
recursive = subscriptDimensions(subs);
then
DAE.DIM_INTEGER(x):: recursive;

case ((ss as DAE.WHOLEDIM()) :: subs)
equation
recursive = subscriptDimensions(subs);
then
DAE.DIM_UNKNOWN() :: recursive;

case ((ss as DAE.INDEX(exp = e)) :: subs)
equation
recursive = subscriptDimensions(subs);
then
DAE.DIM_EXP(e) :: recursive;

case (ss :: subs)
equation
true = Flags.isSet(Flags.FAILTRACE);
sub_str = ExpressionDump.subscriptString(ss);
Debug.fprintln(Flags.FAILTRACE, "- Expression.subscriptDimensions failed on " +& sub_str);
then
fail();
end matchcontinue;
outDimensions := List.map(inSubscripts, subscriptDimension);
end subscriptDimensions;

public function subscriptDimension "Function: subscriptDimension
Returns the dimensionality of the subscript expression"
input Subscript insub;
output DAE.Dimension oint;
public function subscriptDimension
"Converts a subscript to a dimension by interpreting the subscript as a
dimension."
input Subscript inSubscript;
output DAE.Dimension outDimension;
algorithm
oint := matchcontinue(insub)
outDimension := matchcontinue(inSubscript)
local
Subscript ss;
Integer x;
DAE.Exp e;
String sub_str;

case DAE.INDEX(DAE.ICONST(x)) then DAE.DIM_INTEGER(x);

case DAE.WHOLEDIM() then DAE.DIM_UNKNOWN();
case DAE.INDEX(exp = DAE.ICONST(x)) then DAE.DIM_INTEGER(x);
case DAE.INDEX(exp = e) then DAE.DIM_EXP(e);
case DAE.WHOLEDIM() then DAE.DIM_UNKNOWN();

// Special cases for non-expanded arrays
case DAE.WHOLE_NONEXP(exp = DAE.ICONST(x))
case DAE.WHOLE_NONEXP(exp = DAE.ICONST(x))
equation
false = Config.splitArrays();
then
Expand All @@ -1572,15 +1560,14 @@ algorithm
then
DAE.DIM_EXP(e);

case ss as DAE.INDEX(exp = e) then DAE.DIM_EXP(e);

case ss
else
equation
true = Flags.isSet(Flags.FAILTRACE);
sub_str = ExpressionDump.subscriptString(ss);
Debug.fprintln(Flags.FAILTRACE, "- Expression.subscriptDimension failed on " +& sub_str);
sub_str = ExpressionDump.subscriptString(inSubscript);
Debug.traceln("- Expression.subscriptDimension failed on " +& sub_str);
then
fail();

end matchcontinue;
end subscriptDimension;

Expand Down
156 changes: 41 additions & 115 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2470,92 +2470,25 @@ protected function arrayBasictypeBaseclass
author: PA"
input InstDims inInstDims;
input DAE.Type inType;
output Option<DAE.Type> outTypesTypeOption;
algorithm
outTypesTypeOption := matchcontinue (inInstDims,inType)
local
DAE.Type tp,tp_1;
DAE.Dimensions lst;
InstDims inst_dims;
case ({},tp) then NONE();
case (inst_dims,tp)
equation
lst = instdimsIntOptList(List.last(inst_dims));
tp_1 = arrayBasictypeBaseclass2(lst, tp);
then
SOME(tp_1);
/*
case (inst_dims,tp)
equation
str = stringDelimitList(List.map(List.flatten(inst_dims),ExpressionDump.printSubscriptStr),",");
str = "Inst.arrayBasictypeBaseclass failed: " +& str;
Error.addMessage(Error.INTERNAL_ERROR,{str});
then fail();
*/
end matchcontinue;
end arrayBasictypeBaseclass;

protected function instdimsIntOptList
"function: instdimsIntOptList
author: PA"
input list<DAE.Subscript> inInstDims;
output DAE.Dimensions outIntegerOptionLst;
output Option<DAE.Type> outOptType;
algorithm
outIntegerOptionLst := matchcontinue (inInstDims)
outOptType := match(inInstDims, inType)
local
DAE.Dimensions res;
Integer i;
list<DAE.Subscript> ss;
DAE.Exp e;
case ({}) then {};
case (DAE.INDEX(exp = DAE.ICONST(integer = i)) :: ss)
equation
res = instdimsIntOptList(ss);
then
(DAE.DIM_INTEGER(i) :: res);
case (DAE.WHOLEDIM() :: ss)
equation
res = instdimsIntOptList(ss);
then
DAE.DIM_UNKNOWN() :: res;
// The case of non-expanded arrays.
case (DAE.WHOLE_NONEXP(exp=e) :: ss)
equation
false = Config.splitArrays();
res = instdimsIntOptList(ss);
then
DAE.DIM_EXP(e) :: res;
case (DAE.INDEX(exp = _) :: ss)
equation
true = Flags.getConfigBool(Flags.CHECK_MODEL);
res = instdimsIntOptList(ss);
then
DAE.DIM_UNKNOWN() :: res;
end matchcontinue;
end instdimsIntOptList;
DAE.Type ty;
DAE.Dimensions dims;

protected function arrayBasictypeBaseclass2
"function: arrayBasictypeBaseclass2
author: PA"
input DAE.Dimensions inDimensionLst;
input DAE.Type inType;
output DAE.Type outType;
algorithm
outType := match (inDimensionLst,inType)
local
DAE.Type tp,tp_1,res;
DAE.Dimension d;
DAE.Dimensions ds;
case ({},tp) then tp;
case ((d :: ds),tp)
case ({}, _) then NONE();

else
equation
tp_1 = Types.liftArray(tp, d);
res = arrayBasictypeBaseclass2(ds, tp_1);
dims = Expression.subscriptDimensions(List.last(inInstDims));
ty = Expression.liftArrayLeftList(inType, dims);
then
res;
end match;
end arrayBasictypeBaseclass2;
SOME(ty);

end match;
end arrayBasictypeBaseclass;

public function partialInstClassIn
"function: partialInstClassIn
This function is used when instantiating classes in lookup of other classes.
Expand Down Expand Up @@ -16444,44 +16377,37 @@ algorithm
end matchcontinue;
end propagateAbSCDirection2;

protected function makeCrefBaseType "Function: makeCrefBaseType"
input DAE.Type baseType;
input InstDims dims;
output DAE.Type ety;
algorithm ety := matchcontinue(baseType,dims)
local
DAE.Type ty;
DAE.Type tp_1,btp;
DAE.Dimensions lst;
protected function makeCrefBaseType
input DAE.Type inBaseType;
input InstDims inDimensions;
output DAE.Type outType;
algorithm
outType := Types.simplifyType(makeCrefBaseType2(inBaseType, inDimensions));
end makeCrefBaseType;

protected function makeCrefBaseType2
input DAE.Type inBaseType;
input InstDims inDimensions;
output DAE.Type outType;
algorithm
outType := matchcontinue(inBaseType, inDimensions)
local
DAE.Type ty;
DAE.Dimensions dims;

// Types extending basic type has dimensions already added
case (baseType as DAE.T_SUBTYPE_BASIC(complexType = btp),dims) equation
ty = Types.simplifyType(btp);
then ty;

case(baseType, dims)
equation
lst = instdimsIntOptList(List.last(dims));
tp_1 = arrayBasictypeBaseclass2(lst, baseType);
ty = Types.simplifyType(tp_1);
then
ty;

case(baseType, dims)
equation
failure(_ = instdimsIntOptList(List.last(dims)));
ty = Types.simplifyType(baseType);
then
ty;
case (DAE.T_SUBTYPE_BASIC(complexType = ty), _) then ty;
case (_, {}) then inBaseType;

case(_,_)
equation
Debug.fprint(Flags.FAILTRACE, "- make_makeCrefBaseType failed\n");
print("makCrefBaseType failed\n");
then
fail();
end matchcontinue;
end makeCrefBaseType;
else
equation
dims = Expression.subscriptDimensions(List.last(inDimensions));
ty = Expression.liftArrayLeftList(inBaseType, dims);
then
ty;

end matchcontinue;
end makeCrefBaseType2;

protected function liftNonBasicTypesNDimensions "Function: liftNonBasicTypesNDimensions
This is to handle a Option<integer> list of dimensions."
Expand Down

0 comments on commit e7fce4c

Please sign in to comment.