Skip to content

Commit

Permalink
Handle : in ComponentReference.compareSubs.
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2533
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jun 27, 2018
1 parent cce54d9 commit fb766b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
8 changes: 2 additions & 6 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -753,13 +753,9 @@ package CompareWithGenericSubscript "Package that can be modified to do differen
end if;
s2::ss := ss;
if compareSubscript == CompareWithSubsType.WithGenericSubscript then
e1 := Expression.getSubscriptExp(s1);
e2 := Expression.getSubscriptExp(s2);
res := stringCompare(ExpressionDump.printExpStr(e1),ExpressionDump.printExpStr(e2));
res := stringCompare(ExpressionDump.printSubscriptStr(s1), ExpressionDump.printSubscriptStr(s2));
elseif compareSubscript == CompareWithSubsType.WithGenericSubscriptNotAlphabetic then
e1 := Expression.getSubscriptExp(s1);
e2 := Expression.getSubscriptExp(s2);
res := Expression.compare(e1, e2);
res := Expression.compareSubscripts(s1, s2);
else
i1 := Expression.subscriptInt(s1);
i2 := Expression.subscriptInt(s2);
Expand Down
18 changes: 18 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -13131,6 +13131,24 @@ algorithm
end match;
end compare;

function compareSubscripts
input DAE.Subscript sub1;
input DAE.Subscript sub2;
output Integer res;
algorithm
if referenceEq(sub1, sub2) then
res := 0;
else
res := match (sub1, sub2)
case (DAE.Subscript.WHOLEDIM(), DAE.Subscript.WHOLEDIM()) then 0;
case (DAE.Subscript.SLICE(), DAE.Subscript.SLICE()) then compare(sub1.exp, sub2.exp);
case (DAE.Subscript.INDEX(), DAE.Subscript.INDEX()) then compare(sub1.exp, sub2.exp);
case (DAE.Subscript.WHOLE_NONEXP(), DAE.Subscript.WHOLE_NONEXP()) then compare(sub1.exp, sub2.exp);
else Util.intCompare(valueConstructor(sub1), valueConstructor(sub2));
end match;
end if;
end compareSubscripts;

public function isInvariantExpNoTraverse "For use with traverseExp"
input output DAE.Exp e;
input output Boolean b;
Expand Down
28 changes: 6 additions & 22 deletions Compiler/FrontEnd/ExpressionDump.mo
Expand Up @@ -370,30 +370,14 @@ end debugPrintSubscriptStr;

public function printSubscriptStr "
Print a Subscript into a String."
input DAE.Subscript inSubscript;
input DAE.Subscript sub;
output String outString;
algorithm
outString:=
match (inSubscript)
local
String s;
DAE.Exp e1;
case (DAE.WHOLEDIM()) then ":";
case (DAE.INDEX(exp = e1))
equation
s = printExpStr(e1);
then
s;
case (DAE.SLICE(exp = e1))
equation
s = printExpStr(e1);
then
s;
case (DAE.WHOLE_NONEXP(exp = e1))
equation
s = printExpStr(e1);
then
"1:"+s;
outString := match sub
case DAE.WHOLEDIM() then ":";
case DAE.INDEX() then printExpStr(sub.exp);
case DAE.SLICE() then printExpStr(sub.exp);
case DAE.WHOLE_NONEXP() then "1:" + printExpStr(sub.exp);
end match;
end printSubscriptStr;

Expand Down

0 comments on commit fb766b3

Please sign in to comment.