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

Commit 350333d

Browse files
perostOpenModelica-Hudson
authored andcommitted
NFInst fixes.
- Fix modifier scope propagation. - Fix binding expansion during flattening.
1 parent adf0f0d commit 350333d

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ algorithm
242242
case Instance.INSTANCED_BUILTIN()
243243
algorithm
244244
cref := Prefix.toCref(prefix);
245-
binding_exp := flattenBinding(component.binding);
245+
binding_exp := flattenBinding(component.binding, prefix);
246246
attr := component.attributes;
247247

248248
var := DAE.VAR(
@@ -278,6 +278,7 @@ end flattenScalar;
278278

279279
function flattenBinding
280280
input Binding binding;
281+
input Prefix prefix;
281282
output Option<DAE.Exp> bindingExp;
282283
algorithm
283284
bindingExp := match binding
@@ -292,11 +293,10 @@ algorithm
292293
case Binding.TYPED_BINDING()
293294
algorithm
294295
// TODO: Implement this in a saner way.
295-
//subs := List.lastN(List.flatten(Prefix.allSubscripts(prefix)),
296-
// binding.propagatedDims);
297-
//then
298-
// SOME(Expression.subscriptExp(binding.bindingExp, subs));
299-
then SOME(binding.bindingExp);
296+
subs := List.lastN(List.flatten(Prefix.allSubscripts(prefix)),
297+
binding.propagatedDims);
298+
then
299+
SOME(Expression.subscriptExp(binding.bindingExp, subs));
300300

301301
else
302302
algorithm

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ protected
649649
list<Dimension> dims;
650650
algorithm
651651
component := ComponentNode.component(node);
652-
name := ComponentNode.name(node);
653652

654653
() := match component
655654
case Component.COMPONENT_DEF(modifier = comp_mod as Modifier.REDECLARE())
@@ -662,6 +661,7 @@ algorithm
662661

663662
case Component.COMPONENT_DEF(definition = comp as SCode.COMPONENT())
664663
algorithm
664+
name := ComponentNode.name(node);
665665
node := ComponentNode.setParent(parent, node);
666666

667667
// Merge the modifier from the component.
@@ -670,16 +670,18 @@ algorithm
670670
comp_mod := Modifier.merge(component.modifier, comp_mod);
671671
comp_mod := Modifier.propagate(comp_mod, listLength(comp.attributes.arrayDims));
672672

673+
binding := instBinding(Modifier.binding(comp_mod), scope);
674+
comp_mod := Modifier.propagateScope(comp_mod);
675+
673676
// Instantiate the type of the component.
674677
cls := instTypeSpec(comp.typeSpec, comp_mod, scope, node, comp.info);
675678

676679
// Instantiate the component's dimensions.
677680
dims := instDimensions(comp.attributes.arrayDims, scope);
678681
Modifier.checkEach(comp_mod, listEmpty(dims), name);
679682

680-
// Instantiate attributes and binding.
683+
// Instantiate attributes and create the untyped component.
681684
attr := instComponentAttributes(comp.attributes, comp.prefixes);
682-
binding := instBinding(Modifier.binding(comp_mod), scope);
683685
inst_comp := Component.UNTYPED_COMPONENT(cls, listArray(dims), binding, attr, comp.info);
684686
node := ComponentNode.setComponent(inst_comp, node);
685687
then

Compiler/NFFrontEnd/NFMod.mo

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public
4343
import Absyn;
4444
import BaseAvlTree;
4545
import NFBinding.Binding;
46+
import NFComponent.Component;
4647
import NFInstNode.InstNode;
4748
import SCode;
4849

@@ -314,6 +315,21 @@ public
314315
end match;
315316
end propagate;
316317

318+
function propagateScope
319+
input output Modifier modifier;
320+
algorithm
321+
_ := match modifier
322+
case MODIFIER()
323+
algorithm
324+
modifier.subModifiers := ModTable.map(modifier.subModifiers,
325+
propagateSubModScope);
326+
then
327+
();
328+
329+
else ();
330+
end match;
331+
end propagateScope;
332+
317333
function checkEach
318334
input Modifier mod;
319335
input Boolean isScalar;
@@ -471,6 +487,39 @@ protected
471487
end match;
472488
end propagateBinding;
473489

490+
function propagateSubModScope
491+
input String name;
492+
input output Modifier modifier;
493+
algorithm
494+
_ := match modifier
495+
case MODIFIER()
496+
algorithm
497+
modifier.binding := propagateBindingScope(modifier.binding);
498+
modifier.subModifiers := ModTable.map(modifier.subModifiers,
499+
propagateSubModScope);
500+
then
501+
();
502+
503+
else ();
504+
end match;
505+
end propagateSubModScope;
506+
507+
function propagateBindingScope
508+
input output Binding binding;
509+
algorithm
510+
_ := match binding
511+
local
512+
Integer l;
513+
514+
case Binding.RAW_BINDING(scope = Component.Scope.RELATIVE_COMP(level = l))
515+
algorithm
516+
binding.scope := Component.Scope.RELATIVE_COMP(l + 1);
517+
then
518+
();
519+
520+
else ();
521+
end match;
522+
end propagateBindingScope;
474523
end Modifier;
475524

476525
annotation(__OpenModelica_Interface="frontend");

0 commit comments

Comments
 (0)