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

Commit 89998d3

Browse files
perostOpenModelica-Hudson
authored andcommitted
Stripping of direction in nfinst.
- Implemented stripping of input/output on non top-level components, including support for the useLocalDirection flag. Belonging to [master]: - #1999 - OpenModelica/OpenModelica-testsuite#774
1 parent 7360bc3 commit 89998d3

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import Sections = NFSections;
5959
import Function = NFFunction.Function;
6060
import ClassTree = NFClassTree;
6161
import NFPrefixes.Visibility;
62+
import NFPrefixes.Direction;
6263

6364
public
6465
function convert
@@ -90,14 +91,17 @@ protected
9091
function convertComponents
9192
input list<tuple<ComponentRef, Binding>> components;
9293
input output list<DAE.Element> elements;
94+
protected
95+
Boolean localDir = Flags.getConfigBool(Flags.USE_LOCAL_DIRECTION);
9396
algorithm
9497
for comp in listReverse(components) loop
95-
elements := convertComponent(comp) :: elements;
98+
elements := convertComponent(comp, localDir) :: elements;
9699
end for;
97100
end convertComponents;
98101

99102
function convertComponent
100103
input tuple<ComponentRef, Binding> component;
104+
input Boolean useLocalDir;
101105
output DAE.Element daeVar;
102106
protected
103107
ComponentRef cref;
@@ -119,7 +123,7 @@ algorithm
119123

120124
binding_exp := convertBinding(binding);
121125
var_attr := convertVarAttributes(Class.getTypeAttributes(cls), ty);
122-
daeVar := makeDAEVar(cref, ty, binding_exp, attr, InstNode.visibility(comp_node), var_attr, info);
126+
daeVar := makeDAEVar(cref, ty, binding_exp, attr, InstNode.visibility(comp_node), var_attr, useLocalDir, info);
123127
end convertComponent;
124128

125129
function makeDAEVar
@@ -129,24 +133,34 @@ function makeDAEVar
129133
input Component.Attributes attr;
130134
input Visibility vis;
131135
input Option<DAE.VariableAttributes> vattr;
136+
input Boolean useLocalDir;
132137
input SourceInfo info;
133138
output DAE.Element var;
134139
protected
135140
DAE.ComponentRef dcref;
136141
DAE.Type dty;
137142
DAE.ElementSource source;
143+
Direction dir;
138144
algorithm
139145
dcref := ComponentRef.toDAE(cref);
140146
dty := Type.toDAE(ty);
141147
source := ElementSource.createElementSource(info);
142148

143149
var := match attr
144150
case Component.Attributes.ATTRIBUTES()
151+
algorithm
152+
// Strip input/output from non top-level components unless
153+
// --useLocalDirection=true has been set.
154+
if attr.direction == Direction.NONE or useLocalDir then
155+
dir := attr.direction;
156+
else
157+
dir := getComponentDirection(attr.direction, cref);
158+
end if;
145159
then
146160
DAE.VAR(
147161
dcref,
148162
Prefixes.variabilityToDAE(attr.variability),
149-
Prefixes.directionToDAE(attr.direction),
163+
Prefixes.directionToDAE(dir),
150164
Prefixes.parallelismToDAE(attr.parallelism),
151165
Prefixes.visibilityToDAE(vis),
152166
dty,
@@ -168,6 +182,22 @@ algorithm
168182
end match;
169183
end makeDAEVar;
170184

185+
function getComponentDirection
186+
"Returns the given direction if the cref refers to a top-level component or to
187+
a component in a top-level connector, otherwise returns Direction.NONE."
188+
input output Direction dir;
189+
input ComponentRef cref;
190+
protected
191+
ComponentRef rest_cref = ComponentRef.rest(cref);
192+
algorithm
193+
dir := match rest_cref
194+
case ComponentRef.EMPTY() then dir;
195+
case ComponentRef.CREF()
196+
then if InstNode.isConnector(rest_cref.node) then
197+
getComponentDirection(dir, rest_cref) else Direction.NONE;
198+
end match;
199+
end getComponentDirection;
200+
171201
function convertBinding
172202
input Binding binding;
173203
output Option<DAE.Exp> bindingExp;
@@ -970,7 +1000,7 @@ algorithm
9701000
var_attr := convertVarAttributes(Class.getTypeAttributes(cls), ty);
9711001
attr := comp.attributes;
9721002
then
973-
makeDAEVar(cref, ty, binding, attr, InstNode.visibility(node), var_attr, info);
1003+
makeDAEVar(cref, ty, binding, attr, InstNode.visibility(node), var_attr, true, info);
9741004

9751005
else
9761006
algorithm

0 commit comments

Comments
 (0)