From f103a0d61bbc406ea02bbc5cc7dba60158b452fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Thu, 22 Mar 2018 15:17:20 +0100 Subject: [PATCH] [NF] Create equations for complex bindings. Belonging to [master]: - OpenModelica/OMCompiler#2305 --- Compiler/NFFrontEnd/NFExpression.mo | 10 ++++++++++ Compiler/NFFrontEnd/NFFlatten.mo | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Compiler/NFFrontEnd/NFExpression.mo b/Compiler/NFFrontEnd/NFExpression.mo index 7829a69b128..b0a8b363742 100644 --- a/Compiler/NFFrontEnd/NFExpression.mo +++ b/Compiler/NFFrontEnd/NFExpression.mo @@ -2580,6 +2580,16 @@ public end match; end isInteger; + function isRecord + input Expression exp; + output Boolean isRecord; + algorithm + isRecord := match exp + case RECORD() then true; + else false; + end match; + end isRecord; + function fillType input Type ty; input Expression fillExp; diff --git a/Compiler/NFFrontEnd/NFFlatten.mo b/Compiler/NFFrontEnd/NFFlatten.mo index ca0c08745be..57047c5e1ff 100644 --- a/Compiler/NFFrontEnd/NFFlatten.mo +++ b/Compiler/NFFrontEnd/NFFlatten.mo @@ -215,7 +215,7 @@ algorithm (vars, sections) := match cls case Class.INSTANCED_BUILTIN() then flattenSimpleComponent(comp_node, c, vis, cls.attributes, prefix, vars, sections); - else flattenComplexComponent(comp_node, cls, ty, vis, prefix, vars, sections); + else flattenComplexComponent(comp_node, c, cls, ty, vis, prefix, vars, sections); end match; then (); @@ -283,6 +283,7 @@ end flattenTypeAttribute; function flattenComplexComponent input InstNode node; + input Component comp; input Class cls; input Type ty; input Visibility visibility; @@ -292,12 +293,30 @@ function flattenComplexComponent protected list dims; ComponentRef name; + Binding binding; + Expression binding_exp; + Equation eq; algorithm dims := Type.arrayDims(ty); name := ComponentRef.prefixCref(node, ty, {}, prefix); // Flatten the class directly if the component is a scalar, otherwise scalarize it. if listEmpty(dims) then + binding := Component.getBinding(comp); + + if Binding.isBound(binding) then + binding_exp := Binding.getTypedExp(binding); + + if not Expression.isRecord(binding_exp) then + eq := Equation.EQUALITY(Expression.CREF(ty, name), binding_exp, ty, + ElementSource.createElementSource(InstNode.info(node))); + sections := Sections.prependEquation(eq, sections); + binding := Binding.UNBOUND(); + else + // TODO: Split record expressions and pass them to flattenClass. + end if; + end if; + (vars, sections) := flattenClass(cls, name, visibility, vars, sections); else (vars, sections) := flattenArray(cls, dims, name, visibility, vars, sections);