Skip to content

Commit

Permalink
[NB] update arrays of records lowering (#11956)
Browse files Browse the repository at this point in the history
- when lowering the children of record arrays inherit the array type dimensions to the children
  • Loading branch information
kabdelhak committed Feb 6, 2024
1 parent 3c9dda4 commit 6abca0b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions OMCompiler/Compiler/NFFrontEnd/NFVariable.mo
Expand Up @@ -35,6 +35,7 @@ encapsulated uniontype NFVariable
import Class = NFClass;
import Component = NFComponent;
import ComponentRef = NFComponentRef;
import Dimension = NFDimension;
import Expression = NFExpression;
import NFInstNode.InstNode;
import NFPrefixes.Visibility;
Expand Down Expand Up @@ -204,10 +205,23 @@ public
"Expands a variable into itself and its children if its complex."
input Variable var;
output list<Variable> children;
protected
function expandChildType
"helper function to inherit the array type dimensions"
input output Variable child;
input list<Dimension> dimensions;
algorithm
child.ty := Type.liftArrayLeftList(child.ty, dimensions);
end expandChildType;
algorithm
children := if (isComplex(var) or isComplexArray(var))
then var :: List.flatten(list(expandChildren(v) for v in var.children))
else {var};
// for non-complex variables the children are empty therefore it will be returned itself
var.children := List.flatten(list(expandChildren(v) for v in var.children));
if isComplexArray(var) then
// if the variable is an array, inherit the array dimensions
var.children := list(expandChildType(v, Type.arrayDims(var.ty)) for v in var.children);
end if;
// return all children and the variable itself
children := var :: var.children;
end expandChildren;

function typeOf
Expand Down

0 comments on commit 6abca0b

Please sign in to comment.