Skip to content

Commit

Permalink
Fix for #2482:
Browse files Browse the repository at this point in the history
- Handle 'end' when used as subscript of qualified cref.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18167 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Nov 18, 2013
1 parent f99b5bb commit 71985f0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
45 changes: 45 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6197,4 +6197,49 @@ algorithm
end matchcontinue;
end getNamedAnnotationStr;

public function mapCrefParts
"This function splits each part of a cref into CREF_IDENTs and applies the
given function to each part. If the given cref is a qualified cref then the
map function is expected to also return CREF_IDENT, so that the split cref
can be reconstructed. Otherwise the map function is free to return whatever
it wants."
input ComponentRef inCref;
input MapFunc inMapFunc;
output ComponentRef outCref;

partial function MapFunc
input ComponentRef inCref;
output ComponentRef outCref;
end MapFunc;
algorithm
outCref := match(inCref, inMapFunc)
local
Ident name;
list<Subscript> subs;
ComponentRef rest_cref;
ComponentRef cref;

case (CREF_QUAL(name, subs, rest_cref), _)
equation
cref = CREF_IDENT(name, subs);
CREF_IDENT(name, subs) = inMapFunc(cref);
rest_cref = mapCrefParts(rest_cref, inMapFunc);
then
CREF_QUAL(name, subs, rest_cref);

case (CREF_FULLYQUALIFIED(cref), _)
equation
cref = mapCrefParts(cref, inMapFunc);
then
CREF_FULLYQUALIFIED(cref);

else
equation
cref = inMapFunc(inCref);
then
cref;

end match;
end mapCrefParts;

end Absyn;
11 changes: 10 additions & 1 deletion Compiler/FrontEnd/Static.mo
Original file line number Diff line number Diff line change
Expand Up @@ -14828,6 +14828,15 @@ protected function replaceEnd
It uses a couple of stacks and crap to handle all of this :)."
input Absyn.ComponentRef cr;
output Absyn.ComponentRef ocr;
algorithm
ocr := Absyn.mapCrefParts(cr, replaceEnd2);
end replaceEnd;

protected function replaceEnd2
"Single pass traversal that replaces end-expressions with the correct size-expression.
It uses a couple of stacks and crap to handle all of this :)."
input Absyn.ComponentRef cr;
output Absyn.ComponentRef ocr;
protected
Absyn.ComponentRef stripcr;
algorithm
Expand All @@ -14836,6 +14845,6 @@ algorithm
// print("stripCref " +& Dump.printExpStr(Absyn.CREF(stripcr)) +& "\n");
(ocr,_) := Absyn.traverseExpBidirCref(cr,(replaceEndEnter,replaceEndExit,({Absyn.CREF(stripcr)},{0},{true})));
// print("replaceEnd end " +& Dump.printExpStr(Absyn.CREF(ocr)) +& "\n");
end replaceEnd;
end replaceEnd2;

end Static;

0 comments on commit 71985f0

Please sign in to comment.