Skip to content

Commit

Permalink
use 'start' attribute if parameter has no binding (ticket:5065)
Browse files Browse the repository at this point in the history
- better Component.getFixedAttribute implementation
- use start attribute if the component has no binding and has fixed=true (or has no fixed and is a parameter or structural parameter)

Belonging to [master]:
  - OpenModelica/OMCompiler#2611
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Aug 20, 2018
1 parent 11eaca3 commit 07b398d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
7 changes: 7 additions & 0 deletions Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -302,6 +302,13 @@ algorithm
comp := InstNode.component(node);
binding := Component.getBinding(comp);

if Binding.isUnbound(binding) then
// use the start value only if the component is a parameter(fixed=true)
if Component.getFixedAttribute(comp) and (Component.isParameter(comp) or Component.isStructuralParameter(comp)) then
binding := Class.lookupAttributeBinding("start", InstNode.getClass(node));
end if;
end if;

if Binding.isUnbound(binding) then
binding := makeComponentBinding(comp, node, Expression.toCref(defaultExp), target);
end if;
Expand Down
40 changes: 14 additions & 26 deletions Compiler/NFFrontEnd/NFComponent.mo
Expand Up @@ -780,34 +780,22 @@ uniontype Component
list<Modifier> typeAttrs = {};
Binding binding;
algorithm
try
typeAttrs := match (component)
case (TYPED_COMPONENT())
then Class.getTypeAttributes(InstNode.getClass(component.classInst));
else {};
end match;
else
typeAttrs := {};
end try;
if listEmpty(typeAttrs) then
// for parameters the default is fixed = true
if isParameter(component) then
fixed := true;
else
fixed := false;
end if;
// for parameters the default is fixed = true
if isParameter(component) or isStructuralParameter(component) then
fixed := true;
else
fixed := false;
end if;

binding := Class.lookupAttributeBinding("fixed", InstNode.getClass(classInstance(component)));

// no fixed attribute present
if Binding.isUnbound(binding) then
return;
end if;
for m in typeAttrs loop
fixed := matchcontinue(m)
case Modifier.MODIFIER(name = "fixed", binding = binding)
algorithm
fixed := fixed and Expression.isTrue(Binding.getTypedExp(binding));
then
fixed;
else fixed;
end matchcontinue;
end for;

fixed := fixed and Expression.isTrue(Binding.getTypedExp(binding));

end getFixedAttribute;

function isDeleted
Expand Down

0 comments on commit 07b398d

Please sign in to comment.