Skip to content

Commit 6f45669

Browse files
committed
- Improved the handling of if-expressions to better handle arrays with different
sizes in the branches. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24092 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent a3d3b12 commit 6f45669

File tree

4 files changed

+686
-486
lines changed

4 files changed

+686
-486
lines changed

Compiler/FrontEnd/Expression.mo

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9115,7 +9115,7 @@ public function dimensionsEqualAllowZero
91159115
input DAE.Dimension dim2;
91169116
output Boolean res;
91179117
algorithm
9118-
res := matchcontinue(dim1, dim2)
9118+
res := match(dim1, dim2)
91199119
local
91209120
Boolean b;
91219121
Integer d1, d2;
@@ -9136,7 +9136,7 @@ algorithm
91369136
boolAnd(intEq(d2,0), intNe(d1,0))));
91379137
then
91389138
b;
9139-
end matchcontinue;
9139+
end match;
91409140
end dimensionsEqualAllowZero;
91419141

91429142
public function dimensionsKnownAndEqual
@@ -9157,26 +9157,26 @@ public function dimensionKnown
91579157
input DAE.Dimension dim;
91589158
output Boolean known;
91599159
algorithm
9160-
known := matchcontinue(dim)
9160+
known := match(dim)
91619161
case DAE.DIM_UNKNOWN() then false;
91629162
case DAE.DIM_EXP(exp = DAE.ICONST()) then true;
91639163
case DAE.DIM_EXP(exp = DAE.BCONST()) then true;
91649164
case DAE.DIM_EXP(exp = DAE.ENUM_LITERAL()) then true;
91659165
case DAE.DIM_EXP() then false;
9166-
case _ then true;
9167-
end matchcontinue;
9166+
else true;
9167+
end match;
91689168
end dimensionKnown;
91699169

91709170
public function dimensionKnownAndNonZero
91719171
"Checks whether a dimensions is known or not."
91729172
input DAE.Dimension dim;
91739173
output Boolean known;
91749174
algorithm
9175-
known := matchcontinue(dim)
9175+
known := match(dim)
91769176
case DAE.DIM_EXP(exp = DAE.ICONST(0)) then false;
91779177
case DAE.DIM_INTEGER(0) then false;
91789178
else dimensionKnown(dim);
9179-
end matchcontinue;
9179+
end match;
91809180
end dimensionKnownAndNonZero;
91819181

91829182
public function dimensionsKnownAndNonZero
@@ -9193,13 +9193,23 @@ public function dimensionUnknownOrExp
91939193
input DAE.Dimension dim;
91949194
output Boolean known;
91959195
algorithm
9196-
known := matchcontinue(dim)
9196+
known := match(dim)
91979197
case DAE.DIM_UNKNOWN() then true;
91989198
case DAE.DIM_EXP() then true;
9199-
case _ then false;
9200-
end matchcontinue;
9199+
else false;
9200+
end match;
92019201
end dimensionUnknownOrExp;
92029202

9203+
public function dimensionUnknown
9204+
input DAE.Dimension inDimension;
9205+
output Boolean outUnknown;
9206+
algorithm
9207+
outUnknown := match(inDimension)
9208+
case DAE.DIM_UNKNOWN() then true;
9209+
else false;
9210+
end match;
9211+
end dimensionUnknown;
9212+
92039213
public function subscriptEqual
92049214
"Returns true if two subscript lists are equal."
92059215
input list<DAE.Subscript> inSubscriptLst1;
@@ -11989,5 +11999,26 @@ algorithm
1198911999
end match;
1199012000
end isAsubExp;
1199112001

12002+
public function typeCast
12003+
input DAE.Exp inExp;
12004+
input DAE.Type inType;
12005+
output DAE.Exp outExp;
12006+
algorithm
12007+
outExp := DAE.CAST(inType, inExp);
12008+
outExp := ExpressionSimplify.simplify1(outExp);
12009+
end typeCast;
12010+
12011+
public function typeCastElements
12012+
input DAE.Exp inExp;
12013+
input DAE.Type inType;
12014+
output DAE.Exp outExp;
12015+
protected
12016+
DAE.Type ty;
12017+
algorithm
12018+
ty := typeof(inExp);
12019+
ty := Types.setArrayElementType(ty, inType);
12020+
outExp := typeCast(inExp, ty);
12021+
end typeCastElements;
12022+
1199212023
annotation(__OpenModelica_Interface="frontend");
1199312024
end Expression;

Compiler/FrontEnd/Inline.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -755,14 +755,14 @@ algorithm
755755
Boolean b;
756756
case (_, _)
757757
equation
758-
if Config.acceptMetaModelicaGrammar()
759-
then // adrpo: DO NOT COMPARE TYPES for equivalence for MetaModelica!
758+
if Config.acceptMetaModelicaGrammar() then
759+
// adrpo: DO NOT COMPARE TYPES for equivalence for MetaModelica!
760760
b = true;
761761
else // compare
762-
ty1 = Expression.typeof(inExp1);
763-
ty2 = Expression.typeof(inExp2);
764-
ty2 = Types.traverseType(ty2, -1, Types.makeExpDimensionsUnknown);
765-
b = Types.equivtypes(ty1,ty2);
762+
ty1 = Expression.typeof(inExp1);
763+
ty2 = Expression.typeof(inExp2);
764+
ty2 = Types.traverseType(ty2, -1, Types.makeExpDimensionsUnknown);
765+
b = Types.equivtypes(ty1,ty2);
766766
end if;
767767
then b;
768768
end match;

0 commit comments

Comments
 (0)