Skip to content

Commit

Permalink
[NF] update non flattened records
Browse files Browse the repository at this point in the history
 - only for new backend
 - adds all elements to record as children
 - mainly used for attributes
  • Loading branch information
kabdelhak authored and perost committed Dec 8, 2020
1 parent 1ddf691 commit 11cb38e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFExpandableConnectors.mo
Expand Up @@ -388,7 +388,7 @@ algorithm
elem_name := ComponentRef.prefixCref(node, ty, {}, exp_name);
// TODO: This needs more work, the new connector might be a complex connector.
var := Variable.VARIABLE(elem_name, ty, NFBinding.EMPTY_BINDING,
Visibility.PUBLIC, NFComponent.DEFAULT_ATTR, {},
Visibility.PUBLIC, NFComponent.DEFAULT_ATTR, {}, {},
SOME(SCode.COMMENT(NONE(), SOME("virtual variable in expandable connector"))),
ElementSource.getInfo(c.source));
vars := var :: vars;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFlatModel.mo
Expand Up @@ -613,7 +613,7 @@ public
end if;

recordVar := Variable.VARIABLE(recordName, record_ty, record_binding, InstNode.visibility(record_node),
Component.getAttributes(record_comp), {}, Component.comment(record_comp), InstNode.info(record_node));
Component.getAttributes(record_comp), {}, {}, Component.comment(record_comp), InstNode.info(record_node));
end reconstructRecordInstance;

annotation(__OpenModelica_Interface="frontend");
Expand Down
50 changes: 34 additions & 16 deletions OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -270,6 +270,7 @@ protected
Binding condition;
Class cls;
Visibility vis;
list<Variable> children;
algorithm
// Remove components that are only outer.
if InstNode.isOnlyOuter(component) then
Expand All @@ -291,13 +292,25 @@ algorithm
cls := InstNode.getClass(c.classInst);
vis := if InstNode.isProtected(component) then Visibility.PROTECTED else visibility;

if isComplexComponent(ty, settings) then
(vars, sections) := flattenComplexComponent(comp_node, c, cls, ty,
(vars, sections) := match getComponentType(ty, settings)
case ComponentType.COMPLEX
then flattenComplexComponent(comp_node, c, cls, ty,
vis, outerBinding, prefix, vars, sections, settings);
else
(vars, sections) := flattenSimpleComponent(comp_node, c, vis, outerBinding,
Class.getTypeAttributes(cls), prefix, vars, sections, settings);
end if;

case ComponentType.NORMAL
then flattenSimpleComponent(comp_node, c, vis, outerBinding,
Class.getTypeAttributes(cls), prefix, vars, sections, settings, {});

case ComponentType.RECORD algorithm
(children, sections) := flattenComplexComponent(comp_node, c, cls, ty,
vis, outerBinding, prefix, {}, sections, settings);
then flattenSimpleComponent(comp_node, c, vis, outerBinding,
Class.getTypeAttributes(cls), prefix, vars, sections, settings, children);

else algorithm
Error.assertion(false, getInstanceName() + " got unknown component", sourceInfo());
then fail();
end match;
then
();

Expand Down Expand Up @@ -394,19 +407,23 @@ algorithm
end match;
end deleteClassComponents;

function isComplexComponent
function getComponentType
input Type ty;
input FlattenSettings settings;
output Boolean isComplex;
output ComponentType compTy;
algorithm
isComplex := match ty
case Type.COMPLEX(complexTy = ComplexType.EXTERNAL_OBJECT()) then false;
case Type.COMPLEX(complexTy = ComplexType.RECORD()) then not settings.newBackend;
case Type.COMPLEX() then true;
case Type.ARRAY() then isComplexComponent(ty.elementType, settings);
else false;
compTy := match ty
case Type.COMPLEX(complexTy = ComplexType.EXTERNAL_OBJECT())
then ComponentType.NORMAL;
case Type.COMPLEX(complexTy = ComplexType.RECORD()) guard(settings.newBackend)
then ComponentType.RECORD;
case Type.COMPLEX() then ComponentType.COMPLEX;
case Type.ARRAY() then getComponentType(ty.elementType, settings);
else ComponentType.NORMAL;
end match;
end isComplexComponent;
end getComponentType;

type ComponentType = enumeration(NORMAL, COMPLEX, RECORD);

function flattenSimpleComponent
input InstNode node;
Expand All @@ -418,6 +435,7 @@ function flattenSimpleComponent
input output list<Variable> vars;
input output Sections sections;
input FlattenSettings settings;
input list<Variable> children;
protected
InstNode comp_node = node;
ComponentRef name;
Expand Down Expand Up @@ -477,7 +495,7 @@ algorithm
ty_attrs := ("fixed", Binding.FLAT_BINDING(Expression.BOOLEAN(false), Variability.CONSTANT)) :: ty_attrs;
end if;

vars := Variable.VARIABLE(name, ty, binding, visibility, comp_attr, ty_attrs, cmt, info) :: vars;
vars := Variable.VARIABLE(name, ty, binding, visibility, comp_attr, ty_attrs, children, cmt, info) :: vars;
end flattenSimpleComponent;

function flattenTypeAttribute
Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/NFFrontEnd/NFScalarize.mo
Expand Up @@ -102,7 +102,7 @@ protected
algorithm
if Type.isArray(var.ty) then
try
Variable.VARIABLE(name, ty, binding, vis, attr, ty_attr, cmt, info) := var;
Variable.VARIABLE(name, ty, binding, vis, attr, ty_attr, _, cmt, info) := var;
crefs := ComponentRef.scalarize(name);

if listEmpty(crefs) then
Expand All @@ -120,12 +120,12 @@ algorithm
(binding_iter, exp) := ExpressionIterator.next(binding_iter);
binding := Binding.FLAT_BINDING(exp, bind_var);
ty_attr := nextTypeAttributes(ty_attr_names, ty_attr_iters);
vars := Variable.VARIABLE(cr, ty, binding, vis, attr, ty_attr, cmt, info) :: vars;
vars := Variable.VARIABLE(cr, ty, binding, vis, attr, ty_attr, {}, cmt, info) :: vars;
end for;
else
for cr in crefs loop
ty_attr := nextTypeAttributes(ty_attr_names, ty_attr_iters);
vars := Variable.VARIABLE(cr, ty, binding, vis, attr, ty_attr, cmt, info) :: vars;
vars := Variable.VARIABLE(cr, ty, binding, vis, attr, ty_attr, {}, cmt, info) :: vars;
end for;
end if;
else
Expand Down
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFVariable.mo
Expand Up @@ -53,6 +53,7 @@ public
Visibility visibility;
Component.Attributes attributes;
list<tuple<String, Binding>> typeAttributes;
list<Variable> children;
Option<SCode.Comment> comment;
SourceInfo info;
end VARIABLE;
Expand All @@ -78,7 +79,7 @@ public
attr := Component.getAttributes(comp);
cmt := Component.comment(comp);
info := InstNode.info(node);
variable := VARIABLE(cref, ty, binding, vis, attr, {}, cmt, info);
variable := VARIABLE(cref, ty, binding, vis, attr, {}, {}, cmt, info);
end fromCref;

function isStructural
Expand Down

0 comments on commit 11cb38e

Please sign in to comment.