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

Commit e82a713

Browse files
perostOpenModelica-Hudson
authored andcommitted
Propagate component visibility down in NFFlatten.
Belonging to [master]: - #2013 - OpenModelica/OpenModelica-testsuite#778
1 parent 1a074b0 commit e82a713

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import NFComponent.Component;
5959
import NFMod.Modifier;
6060
import Sections = NFSections;
6161
import Prefixes = NFPrefixes;
62+
import NFPrefixes.Visibility;
6263
import RangeIterator = NFRangeIterator;
6364
import Subscript = NFSubscript;
6465
import Type = NFType;
@@ -126,7 +127,7 @@ algorithm
126127
sections := Sections.EMPTY();
127128

128129
(comps, sections) :=
129-
flattenClass(InstNode.getClass(classInst), ComponentRef.EMPTY(), {}, sections);
130+
flattenClass(InstNode.getClass(classInst), ComponentRef.EMPTY(), Visibility.PUBLIC, {}, sections);
130131
comps := listReverseInPlace(comps);
131132

132133
elems := match sections
@@ -151,6 +152,7 @@ protected
151152
function flattenClass
152153
input Class cls;
153154
input ComponentRef prefix;
155+
input Visibility visibility;
154156
input output list<tuple<ComponentRef, Binding>> comps;
155157
input output Sections sections;
156158
protected
@@ -160,7 +162,7 @@ algorithm
160162
case Class.INSTANCED_CLASS(elements = cls_tree as ClassTree.FLAT_TREE())
161163
algorithm
162164
for c in cls_tree.components loop
163-
(comps, sections) := flattenComponent(c, prefix, comps, sections);
165+
(comps, sections) := flattenComponent(c, prefix, visibility, comps, sections);
164166
end for;
165167

166168
sections := flattenSections(cls.sections, prefix, sections);
@@ -181,6 +183,7 @@ end flattenClass;
181183
function flattenComponent
182184
input InstNode component;
183185
input ComponentRef prefix;
186+
input Visibility visibility;
184187
input output list<tuple<ComponentRef, Binding>> comps;
185188
input output Sections sections;
186189
protected
@@ -191,6 +194,7 @@ protected
191194
Binding binding, condition;
192195
list<Dimension> dims;
193196
Class cls;
197+
Visibility vis;
194198
algorithm
195199
// Remove components that are only outer.
196200
if InstNode.isOnlyOuter(component) then
@@ -208,14 +212,18 @@ algorithm
208212
return;
209213
end if;
210214

211-
new_pre := ComponentRef.prefixCref(comp_node, ty, {}, prefix);
212215
cls := InstNode.getClass(c.classInst);
213216

214217
() := match cls
215218
// If the component is of a builtin type, add it to the component list
216219
// along with its binding.
217220
case Class.INSTANCED_BUILTIN()
218221
algorithm
222+
if visibility == Visibility.PROTECTED then
223+
comp_node := InstNode.protectComponent(comp_node);
224+
end if;
225+
226+
new_pre := ComponentRef.prefixCref(comp_node, ty, {}, prefix);
219227
binding := flattenBinding(c.binding, prefix);
220228

221229
if Type.isArray(ty) and Binding.isBound(binding) and Component.isVar(c) then
@@ -233,12 +241,14 @@ algorithm
233241
// directly if it's a scalar or vectorize it if it's an array.
234242
else
235243
algorithm
244+
vis := if InstNode.isProtected(comp_node) then Visibility.PROTECTED else visibility;
236245
dims := Type.arrayDims(ty);
246+
new_pre := ComponentRef.prefixCref(comp_node, ty, {}, prefix);
237247

238248
if listEmpty(dims) then
239-
(comps, sections) := flattenClass(cls, new_pre, comps, sections);
249+
(comps, sections) := flattenClass(cls, new_pre, vis, comps, sections);
240250
else
241-
(comps, sections) := flattenArray(cls, dims, new_pre, comps, sections);
251+
(comps, sections) := flattenArray(cls, dims, new_pre, vis, comps, sections);
242252
end if;
243253
then
244254
();
@@ -259,6 +269,7 @@ function flattenArray
259269
input Class cls;
260270
input list<Dimension> dimensions;
261271
input ComponentRef prefix;
272+
input Visibility visibility;
262273
input output list<tuple<ComponentRef, Binding>> comps;
263274
input output Sections sections;
264275
input list<Subscript> subscripts = {};
@@ -271,14 +282,14 @@ protected
271282
algorithm
272283
if listEmpty(dimensions) then
273284
sub_pre := ComponentRef.setSubscripts(listReverse(subscripts), prefix);
274-
(comps, sections) := flattenClass(cls, sub_pre, comps, sections);
285+
(comps, sections) := flattenClass(cls, sub_pre, visibility, comps, sections);
275286
else
276287
dim :: rest_dims := dimensions;
277288
range_iter := RangeIterator.fromDim(dim);
278289

279290
while RangeIterator.hasNext(range_iter) loop
280291
(range_iter, sub_exp) := RangeIterator.next(range_iter);
281-
(comps, sections) := flattenArray(cls, rest_dims, prefix, comps, sections,
292+
(comps, sections) := flattenArray(cls, rest_dims, prefix, visibility, comps, sections,
282293
Subscript.INDEX(sub_exp) :: subscripts);
283294
end while;
284295
end if;

0 commit comments

Comments
 (0)