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

Commit

Permalink
[NF] Record constructor fixes.
Browse files Browse the repository at this point in the history
- Only add constructor inputs to the list of field names when
  constructing ComplexType.RECORD types.
- Make non-modifiable fields protected when creating the DAE type, like
  the old frontend does.
- Propagate visibility to Component.Attributes.toDAE so we get the
  actual visibility in the DAE.ATTR.

Belonging to [master]:
  - #2826
  - OpenModelica/OpenModelica-testsuite#1089
  • Loading branch information
perost authored and OpenModelica-Hudson committed Dec 12, 2018
1 parent a16d2aa commit d8ca873
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
24 changes: 13 additions & 11 deletions Compiler/NFFrontEnd/NFComponent.mo
Expand Up @@ -124,17 +124,19 @@ uniontype Component
Replaceable isReplaceable;
end ATTRIBUTES;

function toDAE
input Attributes ina;
output DAE.Attributes outa;
algorithm
outa := DAE.ATTR(connectorTypeToDAE(ina.connectorType)
, parallelismToSCode(ina.parallelism)
, variabilityToSCode(ina.variability)
, directionToAbsyn(ina.direction)
, innerOuterToAbsyn(ina.innerOuter)
, SCode.PUBLIC() // TODO: Use the actual visibility.
);
function toDAE
input Attributes ina;
input Visibility vis;
output DAE.Attributes outa;
algorithm
outa := DAE.ATTR(
connectorTypeToDAE(ina.connectorType),
parallelismToSCode(ina.parallelism),
variabilityToSCode(ina.variability),
directionToAbsyn(ina.direction),
innerOuterToAbsyn(ina.innerOuter),
visibilityToSCode(vis)
);
end toDAE;

function toString
Expand Down
34 changes: 33 additions & 1 deletion Compiler/NFFrontEnd/NFConvertDAE.mo
Expand Up @@ -1088,6 +1088,10 @@ protected
DAE.Var type_var;
algorithm
typeVars := match cls as InstNode.getClass(complexCls)
case Class.INSTANCED_CLASS(restriction = Restriction.RECORD())
then list(makeTypeRecordVar(c) for c guard not InstNode.isEmpty(c)
in ClassTree.getComponents(cls.elements));

case Class.INSTANCED_CLASS(elements = ClassTree.FLAT_TREE())
then list(makeTypeVar(c) for c guard not (InstNode.isOnlyOuter(c) or InstNode.isEmpty(c))
in ClassTree.getComponents(cls.elements));
Expand All @@ -1101,17 +1105,45 @@ function makeTypeVar
output DAE.Var typeVar;
protected
Component comp;
Component.Attributes attr;
algorithm
comp := InstNode.component(InstNode.resolveOuter(component));
attr := Component.getAttributes(comp);

typeVar := DAE.TYPES_VAR(
InstNode.name(component),
Component.Attributes.toDAE(Component.getAttributes(comp)),
Component.Attributes.toDAE(attr, InstNode.visibility(component)),
Type.toDAE(Component.getType(comp)),
Binding.toDAE(Component.getBinding(comp)),
NONE()
);
end makeTypeVar;

function makeTypeRecordVar
input InstNode component;
output DAE.Var typeVar;
protected
Component comp;
Component.Attributes attr;
Visibility vis;
algorithm
comp := InstNode.component(component);
attr := Component.getAttributes(comp);

if Component.isConst(comp) and Component.hasBinding(comp) then
vis := Visibility.PROTECTED;
else
vis := InstNode.visibility(component);
end if;

typeVar := DAE.TYPES_VAR(
InstNode.name(component),
Component.Attributes.toDAE(attr, vis),
Type.toDAE(Component.getType(comp)),
Binding.toDAE(Component.getBinding(comp)),
NONE()
);
end makeTypeRecordVar;

annotation(__OpenModelica_Interface="frontend");
end NFConvertDAE;
4 changes: 2 additions & 2 deletions Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -1892,12 +1892,12 @@ function makeRecordComplexType
output ComplexType ty;
protected
InstNode cls_node;
list<String> inputs;
list<String> fields;
algorithm
cls_node := if SCode.isOperatorRecord(InstNode.definition(node))
then InstNode.classScope(node) else InstNode.classScope(InstNode.getDerivedNode(node));
fields := list(InstNode.name(c) for c guard not InstNode.isEmpty(c) in
ClassTree.getComponents(Class.classTree(cls)));
fields := list(InstNode.name(c) for c in Record.collectRecordParams(cls));
ty := ComplexType.RECORD(cls_node, fields);
end makeRecordComplexType;

Expand Down
6 changes: 6 additions & 0 deletions Compiler/NFFrontEnd/NFPrefixes.mo
Expand Up @@ -453,6 +453,12 @@ function visibilityToDAE
DAE.VarVisibility.PUBLIC() else DAE.VarVisibility.PROTECTED();
end visibilityToDAE;

function visibilityToSCode
input Visibility vis;
output SCode.Visibility scodeVis = if vis == Visibility.PUBLIC then
SCode.Visibility.PUBLIC() else SCode.Visibility.PROTECTED();
end visibilityToSCode;

function visibilityString
input Visibility vis;
output String str = if vis == Visibility.PUBLIC then "public" else "protected";
Expand Down
7 changes: 3 additions & 4 deletions Compiler/NFFrontEnd/NFRecord.mo
Expand Up @@ -101,7 +101,7 @@ algorithm
Inst.instExpressions(ctor_node);

// Collect the record fields.
(inputs, locals) := collectRecordParams(ctor_node);
(inputs, locals) := collectRecordParams(InstNode.getClass(ctor_node));

// Create the output record element, using the instance created above as both parent and type.
out_comp := Component.UNTYPED_COMPONENT(ctor_node, listArray({}),
Expand All @@ -121,7 +121,7 @@ algorithm
end instDefaultConstructor;

function collectRecordParams
input InstNode recNode;
input Class recClass;
output list<InstNode> inputs = {};
output list<InstNode> locals = {};
protected
Expand All @@ -131,8 +131,7 @@ protected
Component comp;
ClassTree tree;
algorithm
Error.assertion(InstNode.isClass(recNode), getInstanceName() + " got non-class node", sourceInfo());
tree := Class.classTree(InstNode.getClass(recNode));
tree := Class.classTree(recClass);

() := match tree
case ClassTree.FLAT_TREE(components = components)
Expand Down

0 comments on commit d8ca873

Please sign in to comment.