Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Fix the check for final modification.
Browse files Browse the repository at this point in the history
- Moved the final attribute from NFMod.Modifier to NFBinding.Binding,
  so that an element can be declared final without having a binding.
- Update the check for merging two modifiers where the inner is final.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 21, 2016
1 parent dc38639 commit bd46362
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
5 changes: 1 addition & 4 deletions Compiler/NFFrontEnd/NFBinding.mo
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ uniontype Binding

record RAW_BINDING
Absyn.Exp bindingExp;
SCode.Final finalPrefix;
SCode.Each eachPrefix;
Component.Scope scope;
Integer propagatedDims;
SourceInfo info;
Expand All @@ -77,7 +75,6 @@ uniontype Binding
public
function fromAbsyn
input Option<Absyn.Exp> bindingExp;
input SCode.Final finalPrefix;
input SCode.Each eachPrefix;
input Integer dimensions;
input SourceInfo info;
Expand All @@ -94,7 +91,7 @@ public
pd := if SCode.eachBool(eachPrefix) then -1 else dimensions;
scope := Component.Scope.RELATIVE_COMP(0);
then
RAW_BINDING(exp, finalPrefix, eachPrefix, scope, pd, info);
RAW_BINDING(exp, scope, pd, info);

else UNBOUND();
end match;
Expand Down
13 changes: 13 additions & 0 deletions Compiler/NFFrontEnd/NFComponent.mo
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ uniontype Component
end match;
end setModifier;

function mergeModifier
input Modifier modifier;
input output Component component;
algorithm
() := match component
case COMPONENT_DEF()
algorithm
component.modifier := Modifier.merge(modifier, component.modifier);
then
();
end match;
end mergeModifier;

function getType
input Component component;
output DAE.Type ty;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFInst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ algorithm
// Modifier is for a component, add it to the component in the array.
case ClassTree.Entry.COMPONENT()
algorithm
ComponentNode.apply(components[entry.index], Component.setModifier, m);
ComponentNode.apply(components[entry.index], Component.mergeModifier, m);
then
();

Expand Down
22 changes: 12 additions & 10 deletions Compiler/NFFrontEnd/NFMod.mo
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ end ModifierScope;
uniontype Modifier
record MODIFIER
String name;
SCode.Final finalPrefix;
SCode.Each eachPrefix;
Binding binding;
ModTable.Tree subModifiers;
SourceInfo info;
Expand Down Expand Up @@ -152,12 +154,12 @@ public

case SCode.MOD()
algorithm
binding := Binding.fromAbsyn(mod.binding, mod.finalPrefix, mod.eachPrefix, 0, mod.info);
binding := Binding.fromAbsyn(mod.binding, mod.eachPrefix, 0, mod.info);
submod_lst := list((m.ident, createSubMod(m, modScope, scope)) for m in mod.subModLst);
submod_table := ModTable.fromList(submod_lst,
function mergeLocal(scope = modScope, prefix = {}));
then
MODIFIER(name, binding, submod_table, mod.info);
MODIFIER(name, mod.finalPrefix, mod.eachPrefix, binding, submod_table, mod.info);

case SCode.REDECL()
then REDECLARE(mod.finalPrefix, mod.eachPrefix, mod.element, scope);
Expand Down Expand Up @@ -225,13 +227,13 @@ public
// Two modifiers, merge bindings and submodifiers.
case (MODIFIER(), MODIFIER())
algorithm
checkFinalOverride(outerMod.name, outerMod.binding,
outerMod.info, innerMod.binding, innerMod.info);
checkFinalOverride(innerMod.finalPrefix, outerMod.name, outerMod.binding,
outerMod.info, innerMod.info);
binding := if Binding.isBound(outerMod.binding) then
outerMod.binding else innerMod.binding;
submods := ModTable.join(innerMod.subModifiers, outerMod.subModifiers, merge);
then
MODIFIER(outerMod.name, binding, submods, outerMod.info);
MODIFIER(outerMod.name, outerMod.finalPrefix, outerMod.eachPrefix, binding, submods, outerMod.info);

case (REDECLARE(), _) then outerMod;
case (_, REDECLARE()) then innerMod;
Expand Down Expand Up @@ -401,18 +403,18 @@ protected
function checkFinalOverride
"Checks that a modifier is not trying to override a final modifier. In that
case it prints an error and fails, otherwise it does nothing."
input SCode.Final innerFinal;
input String name;
input Binding outerBinding;
input SourceInfo outerInfo;
input Binding innerBinding;
input SourceInfo innerInfo;
algorithm
_ := match (outerBinding, innerBinding)
case (Binding.RAW_BINDING(), Binding.RAW_BINDING(finalPrefix = SCode.FINAL()))
_ := match innerFinal
case SCode.FINAL()
algorithm
Error.addMultiSourceMessage(Error.FINAL_COMPONENT_OVERRIDE,
{name, Dump.printExpStr(outerBinding.bindingExp)},
{outerInfo, innerInfo});
{name, Binding.toString(outerBinding)},
{outerInfo, innerInfo});
then
fail();

Expand Down

0 comments on commit bd46362

Please sign in to comment.