Skip to content

Commit

Permalink
Added --ignoreReplaceable flag.
Browse files Browse the repository at this point in the history
- Added the --ignoreReplaceable flag that disables the check that
  an element is replaceable before redeclaring.

Belonging to [master]:
  - OpenModelica/OMCompiler#2057
  - OpenModelica/OpenModelica-testsuite#795
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 29, 2017
1 parent c73638c commit a0c7ddf
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 105 deletions.
46 changes: 27 additions & 19 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -3820,6 +3820,7 @@ protected
DAE.Mod redecl_mod, m, old_m;
String redecl_name, name;
Boolean found;
SCode.Replaceable repl;
Option<SCode.ConstrainClass> cc;
list<SCode.Element> cc_comps;
list<Absyn.ComponentRef> crefs;
Expand All @@ -3834,8 +3835,7 @@ algorithm

(outElement, outMod) := matchcontinue (redecl_el, inElement)
// Redeclaration of component.
case (SCode.COMPONENT(),
SCode.COMPONENT(prefixes = SCode.PREFIXES(replaceablePrefix = SCode.REPLACEABLE(cc = cc))))
case (SCode.COMPONENT(), SCode.COMPONENT(prefixes = SCode.PREFIXES(replaceablePrefix = repl)))
algorithm
true := redecl_name == inElement.name;

Expand All @@ -3848,23 +3848,31 @@ algorithm
(outCache, old_m) := Mod.elabMod(outCache, outEnv, outIH, inPrefix,
inElement.modifications, inImpl, Mod.COMPONENT(inElement.name), inElement.info);

if isSome(cc) then
// Constraining type on the component:
// Extract components belonging to constraining class.
cc_comps := InstUtil.extractConstrainingComps(cc, inEnv, inPrefix);
// Keep previous constraining class mods.
redecl_mod := InstUtil.keepConstrainingTypeModifersOnly(redecl_mod, cc_comps);
old_m := InstUtil.keepConstrainingTypeModifersOnly(old_m, cc_comps);

m := Mod.merge(m, redecl_mod, redecl_name);
m := Mod.merge(m, old_m, redecl_name);
m := Mod.merge(m, inCmod, redecl_name);
else
// No constraining type on comp, throw away modifiers prior to redeclaration:
m := Mod.merge(redecl_mod, m, redecl_name);
m := Mod.merge(m, old_m, redecl_name);
m := Mod.merge(inCmod, m, redecl_name);
end if;
m := match repl
case SCode.REPLACEABLE(cc = cc as SOME(_))
algorithm
// Constraining type on the component:
// Extract components belonging to constraining class.
cc_comps := InstUtil.extractConstrainingComps(cc, inEnv, inPrefix);
// Keep previous constraining class mods.
redecl_mod := InstUtil.keepConstrainingTypeModifersOnly(redecl_mod, cc_comps);
old_m := InstUtil.keepConstrainingTypeModifersOnly(old_m, cc_comps);

m := Mod.merge(m, redecl_mod, redecl_name);
m := Mod.merge(m, old_m, redecl_name);
m := Mod.merge(m, inCmod, redecl_name);
then
m;

else
algorithm
// No constraining type on comp, throw away modifiers prior to redeclaration:
m := Mod.merge(redecl_mod, m, redecl_name);
m := Mod.merge(m, old_m, redecl_name);
m := Mod.merge(inCmod, m, redecl_name);
then
m;
end match;

(outCache, outElement) :=
propagateRedeclCompAttr(outCache, outEnv, inElement, redecl_el);
Expand Down
163 changes: 78 additions & 85 deletions Compiler/FrontEnd/NFSCodeCheck.mo
Expand Up @@ -204,7 +204,7 @@ public function checkRedeclaredElementPrefix
input SCode.Element inReplacement;
input SourceInfo inInfo;
algorithm
_ := match(inItem, inReplacement, inInfo)
_ := match(inItem, inReplacement)
local
SCode.Replaceable repl;
SCode.Final fin;
Expand All @@ -214,58 +214,54 @@ algorithm
SCode.Restriction res;
SCode.Visibility vis1, vis2;
String ty;
Integer err_count;
Absyn.TypeSpec ty1, ty2;
Boolean ok;

case (NFSCodeEnv.VAR(var =
SCode.COMPONENT(name = name, prefixes = SCode.PREFIXES(
finalPrefix = fin, replaceablePrefix = repl),
attributes = SCode.ATTR(variability = var), typeSpec = ty1, info = info)),
SCode.COMPONENT(prefixes = SCode.PREFIXES(), typeSpec = ty2), _)
equation
err_count = Error.getNumErrorMessages();
ty = "component";
checkCompRedeclarationReplaceable(name, repl, ty1, ty2, inInfo, info);
checkRedeclarationFinal(name, ty, fin, inInfo, info);
checkRedeclarationVariability(name, ty, var, inInfo, info);
SCode.COMPONENT(prefixes = SCode.PREFIXES(), typeSpec = ty2))
algorithm
ty := "component";
ok := checkCompRedeclarationReplaceable(name, repl, ty1, ty2, inInfo, info);
ok := checkRedeclarationFinal(name, ty, fin, inInfo, info) and ok;
ok := checkRedeclarationVariability(name, ty, var, inInfo, info) and ok;
//checkRedeclarationVisibility(name, ty, vis1, vis2, inInfo, info);
true = intEq(err_count, Error.getNumErrorMessages());
true := ok;
then
();

case (NFSCodeEnv.CLASS(cls =
SCode.CLASS(name = name, prefixes = SCode.PREFIXES(
finalPrefix = fin, replaceablePrefix = repl),
restriction = res, info = info)),
SCode.CLASS(prefixes = SCode.PREFIXES()), _)
equation
err_count = Error.getNumErrorMessages();
ty = SCodeDump.restrictionStringPP(res);
checkClassRedeclarationReplaceable(name, ty, repl, inInfo, info);
checkRedeclarationFinal(name, ty, fin, inInfo, info);
SCode.CLASS(prefixes = SCode.PREFIXES()))
algorithm
ty := SCodeDump.restrictionStringPP(res);
ok := checkClassRedeclarationReplaceable(name, ty, repl, inInfo, info);
ok := checkRedeclarationFinal(name, ty, fin, inInfo, info) and ok;
//checkRedeclarationVisibility(name, ty, vis1, vis2, inInfo, info);
true = intEq(err_count, Error.getNumErrorMessages());
true := ok;
then
();

case (NFSCodeEnv.VAR(var = SCode.COMPONENT(name = name, info = info)),
SCode.CLASS(restriction = res), _)
equation
ty = SCodeDump.restrictionStringPP(res);
ty = "a " + ty;
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inInfo);
Error.addSourceMessage(Error.INVALID_REDECLARE_AS,
{"component", name, ty}, info);
SCode.CLASS(restriction = res))
algorithm
ty := SCodeDump.restrictionStringPP(res);
ty := "a " + ty;
Error.addMultiSourceMessage(Error.INVALID_REDECLARE_AS,
{"component", name, ty}, {inInfo, info});
then
fail();

case (NFSCodeEnv.CLASS(cls = SCode.CLASS(restriction = res, info = info)),
SCode.COMPONENT(name = name), _)
equation
ty = SCodeDump.restrictionStringPP(res);
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inInfo);
Error.addSourceMessage(Error.INVALID_REDECLARE_AS,
{ty, name, "a component"}, info);
SCode.COMPONENT(name = name))
algorithm
ty := SCodeDump.restrictionStringPP(res);
Error.addMultiSourceMessage(Error.INVALID_REDECLARE_AS,
{ty, name, "a component"}, {inInfo, info});
then
fail();

Expand All @@ -279,17 +275,18 @@ protected function checkClassRedeclarationReplaceable
input SCode.Replaceable inReplaceable;
input SourceInfo inOriginInfo;
input SourceInfo inInfo;
output Boolean isValid;
algorithm
_ := match(inName, inType, inReplaceable, inOriginInfo, inInfo)
case (_, _, SCode.REPLACEABLE(), _, _) then ();

case (_, _, SCode.NOT_REPLACEABLE(), _, _)
equation
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
Error.addSourceMessage(Error.REDECLARE_NON_REPLACEABLE,
{inType, inName}, inInfo);
isValid := match inReplaceable
case SCode.NOT_REPLACEABLE() guard not Flags.getConfigBool(Flags.IGNORE_REPLACEABLE)
algorithm
Error.addMultiSourceMessage(Error.REDECLARE_NON_REPLACEABLE,
{inType, inName}, {inOriginInfo, inInfo});
then
();
false;

else true;

end match;
end checkClassRedeclarationReplaceable;

Expand All @@ -300,27 +297,24 @@ protected function checkCompRedeclarationReplaceable
input Absyn.TypeSpec inType2;
input SourceInfo inOriginInfo;
input SourceInfo inInfo;
output Boolean isValid;
algorithm
_ := match(inName, inReplaceable, inType1, inType2, inOriginInfo, inInfo)
local
SCode.Element var;
Absyn.TypeSpec ty1, ty2;

case (_, SCode.REPLACEABLE(), _, _, _, _) then ();

case (_, SCode.NOT_REPLACEABLE(), _, _, _, _)
isValid := match inReplaceable
case SCode.NOT_REPLACEABLE()
guard Absyn.pathEqual(Absyn.typeSpecPath(inType1),
Absyn.typeSpecPath(inType2))
then
();
true;

case (_, SCode.NOT_REPLACEABLE(), _, _, _, _)
equation
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
Error.addSourceMessage(Error.REDECLARE_NON_REPLACEABLE,
{"component", inName}, inInfo);
case SCode.NOT_REPLACEABLE() guard not Flags.getConfigBool(Flags.IGNORE_REPLACEABLE)
algorithm
Error.addMultiSourceMessage(Error.REDECLARE_NON_REPLACEABLE,
{"component", inName}, {inOriginInfo, inInfo});
then
();
fail();

else true;

end match;
end checkCompRedeclarationReplaceable;

Expand All @@ -330,17 +324,18 @@ protected function checkRedeclarationFinal
input SCode.Final inFinal;
input SourceInfo inOriginInfo;
input SourceInfo inInfo;
output Boolean isValid;
algorithm
_ := match(inName, inType, inFinal, inOriginInfo, inInfo)
case (_, _, SCode.NOT_FINAL(), _, _) then ();
isValid := match inFinal
case SCode.NOT_FINAL() then true;

case (_, _, SCode.FINAL(), _, _)
equation
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
Error.addSourceMessage(Error.INVALID_REDECLARE,
{"final", inType, inName}, inInfo);
case SCode.FINAL()
algorithm
Error.addMultiSourceMessage(Error.INVALID_REDECLARE,
{"final", inType, inName}, {inOriginInfo, inInfo});
then
();
false;

end match;
end checkRedeclarationFinal;

Expand All @@ -350,17 +345,17 @@ protected function checkRedeclarationVariability
input SCode.Variability inVariability;
input SourceInfo inOriginInfo;
input SourceInfo inInfo;
output Boolean isValid;
algorithm
_ := match(inName, inType, inVariability, inOriginInfo, inInfo)
case (_, _, SCode.CONST(), _, _)
equation
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
Error.addSourceMessage(Error.INVALID_REDECLARE,
{"constant", inType, inName}, inInfo);
isValid := match inVariability
case SCode.CONST()
algorithm
Error.addMultiSourceMessage(Error.INVALID_REDECLARE,
{"constant", inType, inName}, {inOriginInfo, inInfo});
then
();
false;

else ();
else true;
end match;
end checkRedeclarationVariability;

Expand All @@ -371,26 +366,24 @@ protected function checkRedeclarationVisibility
input SCode.Visibility inNewVisibility;
input SourceInfo inOriginInfo;
input SourceInfo inNewInfo;
output Boolean isValid;
algorithm
_ := match(inName, inType, inOriginalVisibility, inNewVisibility,
inOriginInfo, inNewInfo)
case (_, _, SCode.PUBLIC(), SCode.PROTECTED(), _, _)
equation
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inNewInfo);
Error.addSourceMessage(Error.INVALID_REDECLARE_AS,
{"public element", inName, "protected"}, inOriginInfo);
isValid := match (inOriginalVisibility, inNewVisibility)
case (SCode.PUBLIC(), SCode.PROTECTED())
algorithm
Error.addMultiSourceMessage(Error.INVALID_REDECLARE_AS,
{"public element", inName, "protected"}, {inNewInfo, inOriginInfo});
then
fail();
false;

case (_, _, SCode.PROTECTED(), SCode.PUBLIC(), _, _)
equation
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inNewInfo);
Error.addSourceMessage(Error.INVALID_REDECLARE_AS,
{"protected element", inName, "public"}, inOriginInfo);
case (SCode.PROTECTED(), SCode.PUBLIC())
algorithm
Error.addMultiSourceMessage(Error.INVALID_REDECLARE_AS,
{"protected element", inName, "public"}, {inNewInfo, inOriginInfo});
then
fail();
false;

else ();
else true;
end match;
end checkRedeclarationVisibility;

Expand Down
6 changes: 5 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -1401,6 +1401,9 @@ constant ConfigFlag HOMOTOPY_APPROACH = CONFIG_FLAG(116, "homotopyApproach",
("adaptiveGlobal", Util.gettext("Global homotopy approach with adaptive lambda steps. The homotopy parameter effects the entire initialization system."))
})),
Util.gettext("Sets the homotopy approach."));
constant ConfigFlag IGNORE_REPLACEABLE = CONFIG_FLAG(117, "ignoreReplaceable",
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Sets whether to ignore replaceability or not when redeclaring."));

protected
// This is a list of all configuration flags. A flag can not be used unless it's
Expand Down Expand Up @@ -1522,7 +1525,8 @@ constant list<ConfigFlag> allConfigFlags = {
TEARING_STRICTNESS,
INTERACTIVE,
ZEROMQ_FILE_SUFFIX,
HOMOTOPY_APPROACH
HOMOTOPY_APPROACH,
IGNORE_REPLACEABLE
};

public function new
Expand Down

0 comments on commit a0c7ddf

Please sign in to comment.