Skip to content

Commit

Permalink
- check subtyping of T_ARRAY(dims = list_of_more_than_one) as we can
Browse files Browse the repository at this point in the history
  really get these types now after the removal of DAE.ExpType.
- don't be lazy and do better checking in Inline.
- testsuite should be ok now? Hudson will tell us :)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11246 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Mar 1, 2012
1 parent 480165c commit 807dd76
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 45 deletions.
23 changes: 23 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -6541,6 +6541,29 @@ algorithm
end matchcontinue;
end dimensionsEqual;

public function dimsEqual
"Returns whether two dimensions are equal or not."
input DAE.Dimensions dims1;
input DAE.Dimensions dims2;
output Boolean res;
algorithm
res := matchcontinue(dims1, dims2)
local
Boolean b;
DAE.Dimension d1, d2;
DAE.Dimensions dl1, dl2;

case ({}, {}) then true;
case (d1::dl1, d2::dl2)
equation
true = dimensionsEqual(d1, d2);
true = dimsEqual(dl1, dl2);
then
true;
case (_, _) then false;
end matchcontinue;
end dimsEqual;

public function dimensionsKnownAndEqual
"Checks that two dimensions are specified and equal."
input DAE.Dimension dim1;
Expand Down
82 changes: 39 additions & 43 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -1003,6 +1003,43 @@ algorithm
end match;
end inlineExps;

public function checkExpsTypeEquiv
"@author: adrpo
check two types for equivalence"
input DAE.Exp inExp1;
input DAE.Exp inExp2;
output Boolean bEquiv;
algorithm
bEquiv := matchcontinue(inExp1, inExp2)
local
DAE.Type ty1,ty2;
Boolean b;
case (inExp1, inExp2)
equation
// adrpo: DO NOT COMPARE TYPES for equivalence for MetaModelica!
true = Config.acceptMetaModelicaGrammar();
then true;
case (inExp1, inExp2)
equation
false = Config.acceptMetaModelicaGrammar();
ty1 = Expression.typeof(inExp1);
ty2 = Expression.typeof(inExp2);
true = Types.equivtypes(ty1,ty2);
then
true;
case (inExp1, inExp2)
equation
false = Config.acceptMetaModelicaGrammar();
ty1 = Expression.typeof(inExp1);
ty2 = Expression.typeof(inExp2);
false = Types.equivtypes(ty1,ty2);
print("Error: ty1:[" +& Types.printTypeStr(ty1) +&
"] != ty2:[t" +& Types.printTypeStr(ty2) +& "]\n");
then
false;
end matchcontinue;
end checkExpsTypeEquiv;

public function inlineCall
"function: inlineCall
replaces an inline call with the expression from the function"
Expand All @@ -1024,24 +1061,6 @@ algorithm
DAE.Type ty1,ty2;
case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(inlineType=inlineType)),(fns,_)))
equation
// adrpo: DO NOT COMPARE TYPES for equivalence for MetaModelica!
true = Config.acceptMetaModelicaGrammar();
true = DAEUtil.convertInlineTypeToBool(inlineType);
true = checkInlineType(inlineType,fns);
fn = getFunctionBody(p,fns);
crefs = List.map(fn,getInputCrefs);
crefs = List.select(crefs,removeWilds);
argmap = List.threadTuple(crefs,args);
argmap = extendCrefRecords(argmap);
newExp = getRhsExp(fn);
((newExp,argmap)) = Expression.traverseExp(newExp,replaceArgs,argmap);
// for inlinecalls in functions
((newExp1,(fns1,_))) = Expression.traverseExp(newExp,inlineCall,(fns,true));
then
((newExp1,(fns,true)));
case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(inlineType=inlineType)),(fns,_)))
equation
false = Config.acceptMetaModelicaGrammar();
true = DAEUtil.convertInlineTypeToBool(inlineType);
true = checkInlineType(inlineType,fns);
fn = getFunctionBody(p,fns);
Expand All @@ -1051,11 +1070,7 @@ algorithm
argmap = extendCrefRecords(argmap);
newExp = getRhsExp(fn);
// compare types
ty1 = Expression.typeof(e1);
ty2 = Expression.typeof(newExp);
ty1 = Types.simplifyType(ty1);
ty2 = Types.simplifyType(ty2);
true = Types.equivtypes(ty1,ty2);
true = checkExpsTypeEquiv(e1, newExp);
((newExp,argmap)) = Expression.traverseExp(newExp,replaceArgs,argmap);
// for inlinecalls in functions
((newExp1,(fns1,_))) = Expression.traverseExp(newExp,inlineCall,(fns,true));
Expand Down Expand Up @@ -1084,21 +1099,6 @@ algorithm
DAE.Exp newExp,newExp1, e1;
DAE.InlineType inlineType;
DAE.Type ty1,ty2;
case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(inlineType=inlineType)),(fns,_)))
equation
// adrpo: DO NOT COMPARE TYPES for equivalence for MetaModelica!
true = Config.acceptMetaModelicaGrammar();
fn = getFunctionBody(p,fns);
crefs = List.map(fn,getInputCrefs);
crefs = List.select(crefs,removeWilds);
argmap = List.threadTuple(crefs,args);
argmap = extendCrefRecords(argmap);
newExp = getRhsExp(fn);
((newExp,argmap)) = Expression.traverseExp(newExp,replaceArgs,argmap);
// for inlinecalls in functions
((newExp1,(fns1,_))) = Expression.traverseExp(newExp,forceInlineCall,(fns,true));
then
((newExp1,(fns,true)));
case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(inlineType=inlineType)),(fns,_)))
equation
false = Config.acceptMetaModelicaGrammar();
Expand All @@ -1110,11 +1110,7 @@ algorithm
newExp = getRhsExp(fn);
((newExp,argmap)) = Expression.traverseExp(newExp,replaceArgs,argmap);
// compare types
ty1 = Expression.typeof(e1);
ty2 = Expression.typeof(newExp);
ty1 = Types.simplifyType(ty1);
ty2 = Types.simplifyType(ty2);
true = Types.equivtypes(ty1,ty2);
true = checkExpsTypeEquiv(e1, newExp);
// for inlinecalls in functions
((newExp1,(fns1,_))) = Expression.traverseExp(newExp,forceInlineCall,(fns,true));
then
Expand Down
13 changes: 11 additions & 2 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -1213,6 +1213,7 @@ algorithm
list<Type> type_list1,type_list2,tList1,tList2;
list<String> names1, names2;
DAE.Dimension dim1,dim2;
DAE.Dimensions dlst1, dlst2;
list<FuncArg> farg1,farg2;
DAE.CodeType c1,c2;
DAE.Exp e1,e2;
Expand All @@ -1233,7 +1234,15 @@ algorithm
res = List.isEqualOnTrue(names1, names2, stringEq);
then
res;


case (DAE.T_ARRAY(dims = dlst1 as _::_::_, ty = t1),
DAE.T_ARRAY(dims = dlst2 as _::_::_, ty = t2))
equation
true = Expression.dimsEqual(dlst1, dlst2);
true = subtype(t1, t2);
then
true;

case (DAE.T_ARRAY(ty = t1),DAE.T_ARRAY(dims = {DAE.DIM_UNKNOWN()}, ty = t2))
equation
true = subtype(t1, t2);
Expand All @@ -1245,7 +1254,7 @@ algorithm
true = subtype(t1, t2);
then
true;

case (DAE.T_ARRAY(dims = {DAE.DIM_EXP(exp = e1)}, ty = t1),
DAE.T_ARRAY(dims = {DAE.DIM_EXP(exp = e2)}, ty = t2))
equation
Expand Down

0 comments on commit 807dd76

Please sign in to comment.