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

Commit fe78a6d

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Implement ElementSource.getElementSourceTypes.
Belonging to [master]: - #2974
1 parent fe6fd31 commit fe78a6d

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,37 @@ algorithm
9292
end convert;
9393

9494
protected
95+
uniontype VariableConversionSettings
96+
record VARIABLE_CONVERSION_SETTINGS
97+
Boolean useLocalDirection;
98+
Boolean isFunctionParameter;
99+
Boolean addTypeToSource;
100+
end VARIABLE_CONVERSION_SETTINGS;
101+
end VariableConversionSettings;
102+
103+
constant VariableConversionSettings FUNCTION_VARIABLE_CONVERSION_SETTINGS =
104+
VARIABLE_CONVERSION_SETTINGS(false, true, false);
105+
95106
function convertVariables
96107
input list<Variable> variables;
97108
input output list<DAE.Element> elements;
98109
protected
99-
Boolean localDir = Flags.getConfigBool(Flags.USE_LOCAL_DIRECTION);
110+
VariableConversionSettings settings;
100111
algorithm
112+
settings := VariableConversionSettings.VARIABLE_CONVERSION_SETTINGS(
113+
useLocalDirection = Flags.getConfigBool(Flags.USE_LOCAL_DIRECTION),
114+
isFunctionParameter = false,
115+
addTypeToSource = Flags.isSet(Flags.INFO_XML_OPERATIONS) or Flags.isSet(Flags.VISUAL_XML)
116+
);
117+
101118
for var in listReverse(variables) loop
102-
elements := convertVariable(var, localDir) :: elements;
119+
elements := convertVariable(var, settings) :: elements;
103120
end for;
104121
end convertVariables;
105122

106123
function convertVariable
107124
input Variable var;
108-
input Boolean useLocalDir;
125+
input VariableConversionSettings settings;
109126
output DAE.Element daeVar;
110127
protected
111128
Option<DAE.VariableAttributes> var_attr;
@@ -114,7 +131,7 @@ algorithm
114131
binding_exp := Binding.toDAEExp(var.binding);
115132
var_attr := convertVarAttributes(var.typeAttributes, var.ty, var.attributes);
116133
daeVar := makeDAEVar(var.name, var.ty, binding_exp, var.attributes,
117-
var.visibility, var_attr, var.comment, useLocalDir, false, var.info);
134+
var.visibility, var_attr, var.comment, settings, var.info);
118135
end convertVariable;
119136

120137
function makeDAEVar
@@ -125,8 +142,7 @@ function makeDAEVar
125142
input Visibility vis;
126143
input Option<DAE.VariableAttributes> vattr;
127144
input Option<SCode.Comment> comment;
128-
input Boolean useLocalDir;
129-
input Boolean isFunctionParam;
145+
input VariableConversionSettings settings;
130146
input SourceInfo info;
131147
output DAE.Element var;
132148
protected
@@ -136,15 +152,19 @@ protected
136152
Direction dir;
137153
algorithm
138154
dcref := ComponentRef.toDAE(cref);
139-
dty := Type.toDAE(if isFunctionParam then Type.arrayElementType(ty) else ty);
155+
dty := Type.toDAE(if settings.isFunctionParameter then Type.arrayElementType(ty) else ty);
140156
source := ElementSource.createElementSource(info);
141157

158+
if settings.addTypeToSource then
159+
source := addComponentTypeToSource(cref, source);
160+
end if;
161+
142162
var := match attr
143163
case Component.Attributes.ATTRIBUTES()
144164
algorithm
145165
// Strip input/output from non top-level components unless
146166
// --useLocalDirection=true has been set.
147-
if attr.direction == Direction.NONE or useLocalDir then
167+
if attr.direction == Direction.NONE or settings.useLocalDirection then
148168
dir := attr.direction;
149169
else
150170
dir := getComponentDirection(attr.direction, cref);
@@ -175,6 +195,22 @@ algorithm
175195
end match;
176196
end makeDAEVar;
177197

198+
function addComponentTypeToSource
199+
input ComponentRef cref;
200+
input output DAE.ElementSource source;
201+
algorithm
202+
source := match cref
203+
case ComponentRef.CREF()
204+
algorithm
205+
source := ElementSource.addElementSourceType(source,
206+
InstNode.scopePath(InstNode.classScope(InstNode.parent(cref.node))));
207+
then
208+
addComponentTypeToSource(cref.restCref, source);
209+
210+
else source;
211+
end match;
212+
end addComponentTypeToSource;
213+
178214
function getComponentDirection
179215
"Returns the given direction if the cref refers to a top-level component or to
180216
a component in a top-level connector, otherwise returns Direction.NONE."
@@ -1007,7 +1043,8 @@ algorithm
10071043
attr := comp.attributes;
10081044
var_attr := convertVarAttributes(ty_attr, ty, attr);
10091045
then
1010-
makeDAEVar(cref, ty, binding, attr, InstNode.visibility(node), var_attr, comp.comment, true, true, info);
1046+
makeDAEVar(cref, ty, binding, attr, InstNode.visibility(node), var_attr,
1047+
comp.comment, FUNCTION_VARIABLE_CONVERSION_SETTINGS, info);
10111048

10121049
else
10131050
algorithm

0 commit comments

Comments
 (0)