Skip to content

Commit 71985f0

Browse files
committed
Fix for #2482:
- Handle 'end' when used as subscript of qualified cref. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18167 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent f99b5bb commit 71985f0

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

Compiler/FrontEnd/Absyn.mo

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6197,4 +6197,49 @@ algorithm
61976197
end matchcontinue;
61986198
end getNamedAnnotationStr;
61996199

6200+
public function mapCrefParts
6201+
"This function splits each part of a cref into CREF_IDENTs and applies the
6202+
given function to each part. If the given cref is a qualified cref then the
6203+
map function is expected to also return CREF_IDENT, so that the split cref
6204+
can be reconstructed. Otherwise the map function is free to return whatever
6205+
it wants."
6206+
input ComponentRef inCref;
6207+
input MapFunc inMapFunc;
6208+
output ComponentRef outCref;
6209+
6210+
partial function MapFunc
6211+
input ComponentRef inCref;
6212+
output ComponentRef outCref;
6213+
end MapFunc;
6214+
algorithm
6215+
outCref := match(inCref, inMapFunc)
6216+
local
6217+
Ident name;
6218+
list<Subscript> subs;
6219+
ComponentRef rest_cref;
6220+
ComponentRef cref;
6221+
6222+
case (CREF_QUAL(name, subs, rest_cref), _)
6223+
equation
6224+
cref = CREF_IDENT(name, subs);
6225+
CREF_IDENT(name, subs) = inMapFunc(cref);
6226+
rest_cref = mapCrefParts(rest_cref, inMapFunc);
6227+
then
6228+
CREF_QUAL(name, subs, rest_cref);
6229+
6230+
case (CREF_FULLYQUALIFIED(cref), _)
6231+
equation
6232+
cref = mapCrefParts(cref, inMapFunc);
6233+
then
6234+
CREF_FULLYQUALIFIED(cref);
6235+
6236+
else
6237+
equation
6238+
cref = inMapFunc(inCref);
6239+
then
6240+
cref;
6241+
6242+
end match;
6243+
end mapCrefParts;
6244+
62006245
end Absyn;

Compiler/FrontEnd/Static.mo

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14828,6 +14828,15 @@ protected function replaceEnd
1482814828
It uses a couple of stacks and crap to handle all of this :)."
1482914829
input Absyn.ComponentRef cr;
1483014830
output Absyn.ComponentRef ocr;
14831+
algorithm
14832+
ocr := Absyn.mapCrefParts(cr, replaceEnd2);
14833+
end replaceEnd;
14834+
14835+
protected function replaceEnd2
14836+
"Single pass traversal that replaces end-expressions with the correct size-expression.
14837+
It uses a couple of stacks and crap to handle all of this :)."
14838+
input Absyn.ComponentRef cr;
14839+
output Absyn.ComponentRef ocr;
1483114840
protected
1483214841
Absyn.ComponentRef stripcr;
1483314842
algorithm
@@ -14836,6 +14845,6 @@ algorithm
1483614845
// print("stripCref " +& Dump.printExpStr(Absyn.CREF(stripcr)) +& "\n");
1483714846
(ocr,_) := Absyn.traverseExpBidirCref(cr,(replaceEndEnter,replaceEndExit,({Absyn.CREF(stripcr)},{0},{true})));
1483814847
// print("replaceEnd end " +& Dump.printExpStr(Absyn.CREF(ocr)) +& "\n");
14839-
end replaceEnd;
14848+
end replaceEnd2;
1484014849

1484114850
end Static;

0 commit comments

Comments
 (0)