Skip to content

Commit

Permalink
[NF] Record binding fixes.
Browse files Browse the repository at this point in the history
- Fix type in Expression.recordElement.
- Fix parents in Binding.recordFieldBinding.

Belonging to [master]:
  - OpenModelica/OMCompiler#2880
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 17, 2019
1 parent ef2d3b4 commit bbc0127
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
14 changes: 8 additions & 6 deletions Compiler/NFFrontEnd/NFBinding.mo
Expand Up @@ -260,39 +260,41 @@ public
end isRecordExp;

function recordFieldBinding
input String fieldName;
input InstNode fieldNode;
input Binding recordBinding;
output Binding fieldBinding = recordBinding;
protected
Expression exp;
Type ty;
Variability var;
String field_name = InstNode.name(fieldNode);
algorithm
fieldBinding := match fieldBinding
case UNTYPED_BINDING()
algorithm
fieldBinding.bindingExp := Expression.recordElement(fieldName, fieldBinding.bindingExp);
fieldBinding.bindingExp := Expression.recordElement(field_name, fieldBinding.bindingExp);
then
fieldBinding;

case TYPED_BINDING()
algorithm
exp := Expression.recordElement(fieldName, fieldBinding.bindingExp);
exp := Expression.recordElement(field_name, fieldBinding.bindingExp);
ty := Expression.typeOf(exp);
var := Expression.variability(exp);
then
TYPED_BINDING(exp, ty, var, fieldBinding.parents, fieldBinding.isEach, fieldBinding.evaluated, fieldBinding.isFlattened, fieldBinding.info);
TYPED_BINDING(exp, ty, var, fieldNode :: fieldBinding.parents, fieldBinding.isEach,
fieldBinding.evaluated, fieldBinding.isFlattened, fieldBinding.info);

case FLAT_BINDING()
algorithm
exp := Expression.recordElement(fieldName, fieldBinding.bindingExp);
exp := Expression.recordElement(field_name, fieldBinding.bindingExp);
var := Expression.variability(exp);
then
FLAT_BINDING(exp, var);

case CEVAL_BINDING()
algorithm
fieldBinding.bindingExp := Expression.recordElement(fieldName, fieldBinding.bindingExp);
fieldBinding.bindingExp := Expression.recordElement(field_name, fieldBinding.bindingExp);
then
fieldBinding;

Expand Down
7 changes: 5 additions & 2 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -4588,6 +4588,7 @@ public
Class cls;
Type ty;
Integer index;
list<Expression> expl;

case RECORD(ty = Type.COMPLEX(cls = node))
algorithm
Expand All @@ -4607,9 +4608,11 @@ public
case ARRAY(ty = Type.ARRAY(elementType = Type.COMPLEX(cls = node)))
algorithm
index := Class.lookupComponentIndex(elementName, InstNode.getClass(node));
recordExp.elements := list(nthRecordElement(index, e) for e in recordExp.elements);
expl := list(nthRecordElement(index, e) for e in recordExp.elements);
ty := Type.liftArrayLeft(Expression.typeOf(listHead(expl)),
Dimension.fromInteger(listLength(expl)));
then
recordExp;
Expression.makeArray(ty, expl, recordExp.literal);

else
algorithm
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -698,7 +698,7 @@ algorithm

// If we found a binding, get the binding for the field from it.
if Binding.isBound(binding) then
binding := Binding.recordFieldBinding(InstNode.name(component), binding);
binding := Binding.recordFieldBinding(component, binding);
end if;
else
binding := NFBinding.EMPTY_BINDING;
Expand Down

0 comments on commit bbc0127

Please sign in to comment.