Skip to content

Commit

Permalink
fix for ticket:4258
Browse files Browse the repository at this point in the history
- create more unique scopes when there are redeclares for derived classes
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Feb 24, 2017
1 parent a5c5270 commit 7172627
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Compiler/FFrontEnd/FGraph.mo
Expand Up @@ -1651,6 +1651,13 @@ algorithm
Graph gclass;
SCode.Element c;

/*
case (_, _, _, _, _, _, _)
equation
print(Absyn.pathString(PrefixUtil.prefixToPath(inPrefix)) + " S:" + getGraphNameStr(inSourceEnv) + "/" + inSourceName + " ||| " + "T:" + getGraphNameStr(inTargetClassEnv) + "/" + SCode.elementName(inTargetClass) + "\n");
then
fail();*/

// case (_, _, _, _, _, _, _) then (inTargetClassEnv, inTargetClass, inIH);

// don't do this if there is no modifications on the class
Expand Down
29 changes: 29 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -12952,5 +12952,34 @@ algorithm
end match;
end compare;

public function isInvariantExpNoTraverse "For use with traverseExp"
input output DAE.Exp e;
input output Boolean b;
algorithm
if not b then
return;
end if;
b := match e
case DAE.ICONST() then true;
case DAE.RCONST() then true;
case DAE.SCONST() then true;
case DAE.BCONST() then true;
case DAE.BINARY() then true;
case DAE.UNARY() then true;
case DAE.LBINARY() then true;
case DAE.LUNARY() then true;
case DAE.RELATION() then true;
case DAE.IFEXP() then true;
case DAE.CALL(path=Absyn.FULLYQUALIFIED()) then true;
case DAE.PARTEVALFUNCTION(path=Absyn.FULLYQUALIFIED()) then true;
case DAE.ARRAY() then true;
case DAE.MATRIX() then true;
case DAE.RANGE() then true;
case DAE.CONS() then true;
case DAE.LIST() then true;
else false;
end match;
end isInvariantExpNoTraverse;

annotation(__OpenModelica_Interface="frontend");
end Expression;
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Inst.mo
Expand Up @@ -2281,7 +2281,7 @@ algorithm

if match r
case SCode.Restriction.R_PACKAGE() then false;
else if SCode.restrictionEqual(r,re) then Mod.isInvariantMod(mod) else false;
else if SCode.restrictionEqual(r,re) then Mod.isInvariantMod(mod) and Mod.isInvariantDAEMod(mods) else false;
end match then
// Is a very simple modification on an operator record; we do not need to handle it by adding SCode.EXTENDS
// print("Short-circuit: " + SCodeDump.restrString(r)+" "+SCodeDump.restrString(re)+" : "+SCodeDump.printModStr(mod)+"\n");
Expand Down
40 changes: 40 additions & 0 deletions Compiler/FrontEnd/Mod.mo
Expand Up @@ -238,6 +238,46 @@ algorithm
end match;
end isInvariantMod;

public function isInvariantDAEMod "Is the modification one that does not depend on the scope it is evaluated in?"
input DAE.Mod mod;
output Boolean b;
protected
DAE.Exp e;
Absyn.Exp exp;
SCode.Mod mods;
algorithm
b := match mod
case DAE.NOMOD() then true;
case DAE.MOD(binding=NONE())
algorithm
b := match mod.binding
case SOME(DAE.TYPED(modifierAsExp = e))
algorithm
(_, b) := Expression.traverseExpBottomUp(e, Expression.isInvariantExpNoTraverse, true);
then b;
case SOME(DAE.UNTYPED(exp))
algorithm
(_, b) := Absyn.traverseExp(exp, Absyn.isInvariantExpNoTraverse, true);
then b;
else true;
end match;
if not b then
return;
end if;
for sm in mod.subModLst loop
if not isInvariantDAEMod(sm.mod) then
b := false;
return;
end if;
end for;
then true;
// operator record ComplexCurrent = Complex(redeclare Modelica.SIunits.Current re, redeclare Modelica.SIunits.Current im)
case DAE.Mod.REDECL(element=SCode.Element.COMPONENT(modifications=mods,typeSpec=Absyn.TypeSpec.TPATH(path=Absyn.Path.FULLYQUALIFIED(),arrayDim=NONE())))
then isInvariantMod(mods);
else false; // Redeclarations, etc
end match;
end isInvariantDAEMod;

public function elabModForBasicType "
Same as elabMod, but if a named Mod is not part of a basic type, fail instead."
input FCore.Cache inCache;
Expand Down

0 comments on commit 7172627

Please sign in to comment.