Skip to content

Commit

Permalink
- Improved the handling of if-expressions to better handle arrays wit…
Browse files Browse the repository at this point in the history
…h different

  sizes in the branches.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24092 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Jan 19, 2015
1 parent a3d3b12 commit 6f45669
Show file tree
Hide file tree
Showing 4 changed files with 686 additions and 486 deletions.
51 changes: 41 additions & 10 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -9115,7 +9115,7 @@ public function dimensionsEqualAllowZero
input DAE.Dimension dim2;
output Boolean res;
algorithm
res := matchcontinue(dim1, dim2)
res := match(dim1, dim2)
local
Boolean b;
Integer d1, d2;
Expand All @@ -9136,7 +9136,7 @@ algorithm
boolAnd(intEq(d2,0), intNe(d1,0))));
then
b;
end matchcontinue;
end match;
end dimensionsEqualAllowZero;

public function dimensionsKnownAndEqual
Expand All @@ -9157,26 +9157,26 @@ public function dimensionKnown
input DAE.Dimension dim;
output Boolean known;
algorithm
known := matchcontinue(dim)
known := match(dim)
case DAE.DIM_UNKNOWN() then false;
case DAE.DIM_EXP(exp = DAE.ICONST()) then true;
case DAE.DIM_EXP(exp = DAE.BCONST()) then true;
case DAE.DIM_EXP(exp = DAE.ENUM_LITERAL()) then true;
case DAE.DIM_EXP() then false;
case _ then true;
end matchcontinue;
else true;
end match;
end dimensionKnown;

public function dimensionKnownAndNonZero
"Checks whether a dimensions is known or not."
input DAE.Dimension dim;
output Boolean known;
algorithm
known := matchcontinue(dim)
known := match(dim)
case DAE.DIM_EXP(exp = DAE.ICONST(0)) then false;
case DAE.DIM_INTEGER(0) then false;
else dimensionKnown(dim);
end matchcontinue;
end match;
end dimensionKnownAndNonZero;

public function dimensionsKnownAndNonZero
Expand All @@ -9193,13 +9193,23 @@ public function dimensionUnknownOrExp
input DAE.Dimension dim;
output Boolean known;
algorithm
known := matchcontinue(dim)
known := match(dim)
case DAE.DIM_UNKNOWN() then true;
case DAE.DIM_EXP() then true;
case _ then false;
end matchcontinue;
else false;
end match;
end dimensionUnknownOrExp;

public function dimensionUnknown
input DAE.Dimension inDimension;
output Boolean outUnknown;
algorithm
outUnknown := match(inDimension)
case DAE.DIM_UNKNOWN() then true;
else false;
end match;
end dimensionUnknown;

public function subscriptEqual
"Returns true if two subscript lists are equal."
input list<DAE.Subscript> inSubscriptLst1;
Expand Down Expand Up @@ -11989,5 +11999,26 @@ algorithm
end match;
end isAsubExp;

public function typeCast
input DAE.Exp inExp;
input DAE.Type inType;
output DAE.Exp outExp;
algorithm
outExp := DAE.CAST(inType, inExp);
outExp := ExpressionSimplify.simplify1(outExp);
end typeCast;

public function typeCastElements
input DAE.Exp inExp;
input DAE.Type inType;
output DAE.Exp outExp;
protected
DAE.Type ty;
algorithm
ty := typeof(inExp);
ty := Types.setArrayElementType(ty, inType);
outExp := typeCast(inExp, ty);
end typeCastElements;

annotation(__OpenModelica_Interface="frontend");
end Expression;
12 changes: 6 additions & 6 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -755,14 +755,14 @@ algorithm
Boolean b;
case (_, _)
equation
if Config.acceptMetaModelicaGrammar()
then // adrpo: DO NOT COMPARE TYPES for equivalence for MetaModelica!
if Config.acceptMetaModelicaGrammar() then
// adrpo: DO NOT COMPARE TYPES for equivalence for MetaModelica!
b = true;
else // compare
ty1 = Expression.typeof(inExp1);
ty2 = Expression.typeof(inExp2);
ty2 = Types.traverseType(ty2, -1, Types.makeExpDimensionsUnknown);
b = Types.equivtypes(ty1,ty2);
ty1 = Expression.typeof(inExp1);
ty2 = Expression.typeof(inExp2);
ty2 = Types.traverseType(ty2, -1, Types.makeExpDimensionsUnknown);
b = Types.equivtypes(ty1,ty2);
end if;
then b;
end match;
Expand Down

0 comments on commit 6f45669

Please sign in to comment.