Skip to content

Commit

Permalink
fix ticket:3783
Browse files Browse the repository at this point in the history
- add flag keepRedeclares to removeComponentModifiers and removeExtendsModifiers set to false by default
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Apr 20, 2016
1 parent 45c0cb2 commit c76b40b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 30 deletions.
3 changes: 3 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -6470,7 +6470,10 @@ public function elementArgName
output Path outName;
algorithm
outName := match(inArg)
local
ElementSpec e;
case MODIFICATION(path = outName) then outName;
case REDECLARATION(elementSpec = e) then makeIdentPathFromString(elementSpecName(e));
end match;
end elementArgName;

Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -2868,6 +2868,7 @@ end getComponentModifierNames;
function removeComponentModifiers
input TypeName class_;
input String componentName;
input Boolean keepRedeclares = false;
output Boolean success;
external "builtin";
annotation(
Expand All @@ -2880,6 +2881,7 @@ end removeComponentModifiers;
function removeExtendsModifiers
input TypeName className;
input TypeName baseClassName;
input Boolean keepRedeclares = false;
output Boolean success;
external "builtin";
annotation(
Expand Down
16 changes: 10 additions & 6 deletions Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -715,7 +715,7 @@ algorithm
Real timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2,r,r1,r2,linearizeTime,curveWidth,offset,offset1,offset2,scaleFactor,scaleFactor1,scaleFactor2;
GlobalScript.Statements istmts;
list<GlobalScript.Statements> istmtss;
Boolean have_corba, bval, anyCode, b, b1, b2, externalWindow, logX, logY, autoScale, forceOMPlot, gcc_res, omcfound, rm_res, touch_res, uname_res, ifcpp, ifmsvc,sort, builtin, showProtected, inputConnectors, outputConnectors, sanityCheckFailed;
Boolean have_corba, bval, anyCode, b, b1, b2, externalWindow, logX, logY, autoScale, forceOMPlot, gcc_res, omcfound, rm_res, touch_res, uname_res, ifcpp, ifmsvc,sort, builtin, showProtected, inputConnectors, outputConnectors, sanityCheckFailed, keepRedeclares;
FCore.Cache cache;
list<GlobalScript.LoadedFile> lf;
Absyn.ComponentRef crefCName;
Expand Down Expand Up @@ -2067,18 +2067,22 @@ algorithm
then
(cache,v,st);

case (cache,_,"removeComponentModifiers",{Values.CODE(Absyn.C_TYPENAME(path)),Values.STRING(str1)},(st as GlobalScript.SYMBOLTABLE(ast = p)),_)
case (cache,_,"removeComponentModifiers",
Values.CODE(Absyn.C_TYPENAME(path))::
Values.STRING(str1)::
Values.BOOL(keepRedeclares)::_,(st as GlobalScript.SYMBOLTABLE(ast = p)),_)
equation
(p,b) = Interactive.removeComponentModifiers(path, str1, p);
(p,b) = Interactive.removeComponentModifiers(path, str1, p, keepRedeclares);
st = GlobalScriptUtil.setSymbolTableAST(st, p);
then
(cache,Values.BOOL(b),st);

case (cache,_,"removeExtendsModifiers",
{Values.CODE(Absyn.C_TYPENAME(classpath)),
Values.CODE(Absyn.C_TYPENAME(baseClassPath))},st as GlobalScript.SYMBOLTABLE(ast=p),_)
Values.CODE(Absyn.C_TYPENAME(classpath))::
Values.CODE(Absyn.C_TYPENAME(baseClassPath))::
Values.BOOL(keepRedeclares)::_,st as GlobalScript.SYMBOLTABLE(ast=p),_)
equation
(p,b) = Interactive.removeExtendsModifiers(classpath, baseClassPath, p);
(p,b) = Interactive.removeExtendsModifiers(classpath, baseClassPath, p, keepRedeclares);
st = GlobalScriptUtil.setSymbolTableAST(st, p);
then
(cache,Values.BOOL(b),st);
Expand Down
79 changes: 55 additions & 24 deletions Compiler/Script/Interactive.mo
Expand Up @@ -4940,6 +4940,7 @@ public function removeExtendsModifiers
input Absyn.Path inClassPath;
input Absyn.Path inBaseClassPath;
input Absyn.Program inProgram;
input Boolean keepRedeclares;
output Absyn.Program outProgram;
output Boolean outResult;
algorithm
Expand All @@ -4956,7 +4957,7 @@ algorithm
within_ = buildWithin(p_class);
cdef = getPathedClassInProgram(p_class, p);
env = getClassEnv(p, p_class);
cdef_1 = removeExtendsModifiersInClass(cdef, inherit_class, env);
cdef_1 = removeExtendsModifiersInClass(cdef, inherit_class, env, keepRedeclares);
newp = updateProgram(Absyn.PROGRAM({cdef_1},within_), p);
then
(newp, true);
Expand All @@ -4968,6 +4969,7 @@ protected function removeExtendsModifiersInClass
input Absyn.Class inClass;
input Absyn.Path inPath;
input FCore.Graph inEnv;
input Boolean keepRedeclares = false;
output Absyn.Class outClass;
algorithm
outClass:=
Expand All @@ -4990,15 +4992,15 @@ algorithm
body = Absyn.PARTS(typeVars = typeVars,classAttrs = classAttrs,classParts = parts,ann = ann,comment = cmt),info = file_info),
inherit_name,env)
equation
parts_1 = removeExtendsModifiersInClassparts(parts, inherit_name, env);
parts_1 = removeExtendsModifiersInClassparts(parts, inherit_name, env, keepRedeclares);
then
Absyn.CLASS(id,p,f,e,r,Absyn.PARTS(typeVars,classAttrs,parts_1,ann,cmt),file_info);
/* adrpo: handle also model extends M end M; */
case (Absyn.CLASS(name = id,partialPrefix = p,finalPrefix = f,encapsulatedPrefix = e,restriction = r,
body = Absyn.CLASS_EXTENDS(baseClassName=bcname,parts = parts,modifications=modif,ann=ann,comment = cmt),info = file_info),
inherit_name,env)
equation
parts_1 = removeExtendsModifiersInClassparts(parts, inherit_name, env);
parts_1 = removeExtendsModifiersInClassparts(parts, inherit_name, env, keepRedeclares);
then
Absyn.CLASS(id,p,f,e,r,Absyn.CLASS_EXTENDS(bcname,modif,cmt,parts_1,ann),file_info);
end match;
Expand All @@ -5008,36 +5010,37 @@ protected function removeExtendsModifiersInClassparts
input list<Absyn.ClassPart> inAbsynClassPartLst;
input Absyn.Path inPath;
input FCore.Graph inEnv;
input Boolean keepRedeclares;
output list<Absyn.ClassPart> outAbsynClassPartLst;
algorithm
outAbsynClassPartLst:=
matchcontinue (inAbsynClassPartLst,inPath,inEnv)
matchcontinue (inAbsynClassPartLst,inPath,inEnv, keepRedeclares)
local
list<Absyn.ClassPart> res,rest;
list<Absyn.ElementItem> elts_1,elts;
Absyn.Path inherit;
FCore.Graph env;
Absyn.ClassPart elt;

case ({},_,_) then {};
case ({},_,_,_) then {};

case ((Absyn.PUBLIC(contents = elts) :: rest),inherit,env)
case ((Absyn.PUBLIC(contents = elts) :: rest),inherit,env,_)
equation
res = removeExtendsModifiersInClassparts(rest, inherit, env);
elts_1 = removeExtendsModifiersInElementitems(elts, inherit, env);
res = removeExtendsModifiersInClassparts(rest, inherit, env, keepRedeclares);
elts_1 = removeExtendsModifiersInElementitems(elts, inherit, env, keepRedeclares);
then
(Absyn.PUBLIC(elts_1) :: res);

case ((Absyn.PROTECTED(contents = elts) :: rest),inherit,env)
case ((Absyn.PROTECTED(contents = elts) :: rest),inherit,env,_)
equation
res = removeExtendsModifiersInClassparts(rest, inherit, env);
elts_1 = removeExtendsModifiersInElementitems(elts, inherit, env);
res = removeExtendsModifiersInClassparts(rest, inherit, env, keepRedeclares);
elts_1 = removeExtendsModifiersInElementitems(elts, inherit, env, keepRedeclares);
then
(Absyn.PROTECTED(elts_1) :: res);

case ((elt :: rest),inherit,env)
case ((elt :: rest),inherit,env,_)
equation
res = removeExtendsModifiersInClassparts(rest, inherit, env);
res = removeExtendsModifiersInClassparts(rest, inherit, env, keepRedeclares);
then
(elt :: res);

Expand All @@ -5048,26 +5051,30 @@ protected function removeExtendsModifiersInElementitems
input list<Absyn.ElementItem> inAbsynElementItemLst;
input Absyn.Path inPath;
input FCore.Graph inEnv;
input Boolean keepRedeclares;
output list<Absyn.ElementItem> outAbsynElementItemLst;
algorithm
outAbsynElementItemLst:=
matchcontinue (inAbsynElementItemLst,inPath,inEnv)
matchcontinue (inAbsynElementItemLst,inPath,inEnv,keepRedeclares)
local
list<Absyn.ElementItem> res,rest;
Absyn.Element elt_1,elt;
Absyn.Path inherit;
FCore.Graph env;
Absyn.ElementItem elitem;
case ({},_,_) then {};
case ((Absyn.ELEMENTITEM(element = elt) :: rest),inherit,env)

case ({},_,_,_) then {};

case ((Absyn.ELEMENTITEM(element = elt) :: rest),inherit,env,_)
equation
res = removeExtendsModifiersInElementitems(rest, inherit, env);
elt_1 = removeExtendsModifiersInElement(elt, inherit, env);
res = removeExtendsModifiersInElementitems(rest, inherit, env, keepRedeclares);
elt_1 = removeExtendsModifiersInElement(elt, inherit, env, keepRedeclares);
then
(Absyn.ELEMENTITEM(elt_1) :: res);
case ((elitem :: rest),inherit,env)

case ((elitem :: rest),inherit,env,_)
equation
res = removeExtendsModifiersInElementitems(rest, inherit, env);
res = removeExtendsModifiersInElementitems(rest, inherit, env, keepRedeclares);
then
(elitem :: res);
end matchcontinue;
Expand All @@ -5077,6 +5084,7 @@ protected function removeExtendsModifiersInElement
input Absyn.Element inElement;
input Absyn.Path inPath;
input FCore.Graph inEnv;
input Boolean keepRedeclares;
output Absyn.Element outElement;
algorithm
outElement:=
Expand All @@ -5099,8 +5107,9 @@ algorithm
equation
(_,path_1) = Inst.makeFullyQualified(FCore.emptyCache(),env, path);
true = Absyn.pathEqual(inherit, path_1);
eargs = if not keepRedeclares then {} else list(e for e guard(match e case Absyn.REDECLARATION() then true; else false; end match) in eargs);
then
Absyn.ELEMENT(f,r,i,Absyn.EXTENDS(path,{},annOpt),info,constr);
Absyn.ELEMENT(f,r,i,Absyn.EXTENDS(path,eargs,annOpt),info,constr);
else inElement;
end matchcontinue;
end removeExtendsModifiersInElement;
Expand Down Expand Up @@ -5680,6 +5689,7 @@ public function removeComponentModifiers
input Absyn.Path path;
input String inComponentName;
input Absyn.Program inProgram;
input Boolean keepRedeclares;
output Absyn.Program outProgram;
output Boolean outResult;
protected
Expand All @@ -5689,7 +5699,7 @@ algorithm
try
within_ := buildWithin(path);
cls := getPathedClassInProgram(path, inProgram);
cls := clearComponentModifiersInClass(cls, inComponentName);
cls := clearComponentModifiersInClass(cls, inComponentName, keepRedeclares);
outProgram := updateProgram(Absyn.PROGRAM({cls}, within_), inProgram);
outResult := true;
else
Expand All @@ -5701,18 +5711,20 @@ end removeComponentModifiers;
protected function clearComponentModifiersInClass
input Absyn.Class inClass;
input String inComponentName;
input Boolean keepRedeclares;
output Absyn.Class outClass = inClass;
algorithm
(outClass, true) := Absyn.traverseClassComponents(inClass,
function clearComponentModifiersInCompitems(inComponentName =
inComponentName), false);
inComponentName, keepRedeclares = keepRedeclares), false);
end clearComponentModifiersInClass;

protected function clearComponentModifiersInCompitems
"Helper function to clearComponentModifiersInClass. Clears the modifiers in a ComponentItem."
input list<Absyn.ComponentItem> inComponents;
input Boolean inFound;
input String inComponentName;
input Boolean keepRedeclares = false;
output list<Absyn.ComponentItem> outComponents = {};
output Boolean outFound;
output Boolean outContinue;
Expand All @@ -5732,7 +5744,7 @@ algorithm
_ := match item
case Absyn.COMPONENTITEM(component = comp as Absyn.COMPONENT())
algorithm
comp.modification := NONE();
comp.modification := if not keepRedeclares then NONE() else stripModifiersKeepRedeclares(comp.modification);
item.component := comp;
then
();
Expand All @@ -5753,6 +5765,25 @@ algorithm
outContinue := true;
end clearComponentModifiersInCompitems;

protected function stripModifiersKeepRedeclares
input Option<Absyn.Modification> inMod;
output Option<Absyn.Modification> outMod;
algorithm
outMod := match(inMod)
local
Absyn.Modification m;
list<Absyn.ElementArg> ea;
Absyn.EqMod em;
case NONE() then NONE();
case SOME(Absyn.CLASSMOD(ea, em))
algorithm
ea := list(e for e guard(match e case Absyn.REDECLARATION() then true; else false; end match) in ea);
m := Absyn.CLASSMOD(ea, Absyn.NOMOD());
then
SOME(m);
end match;
end stripModifiersKeepRedeclares;

protected function setComponentModifier
"Sets a submodifier of a component."
input Absyn.ComponentRef inClass;
Expand Down

0 comments on commit c76b40b

Please sign in to comment.