Skip to content

Commit

Permalink
Stripping of direction in nfinst.
Browse files Browse the repository at this point in the history
- Implemented stripping of input/output on non top-level components,
  including support for the useLocalDirection flag.

Belonging to [master]:
  - OpenModelica/OMCompiler#1999
  - OpenModelica/OpenModelica-testsuite#774
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 8, 2017
1 parent 7360bc3 commit 89998d3
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions Compiler/NFFrontEnd/NFConvertDAE.mo
Expand Up @@ -59,6 +59,7 @@ import Sections = NFSections;
import Function = NFFunction.Function;
import ClassTree = NFClassTree;
import NFPrefixes.Visibility;
import NFPrefixes.Direction;

public
function convert
Expand Down Expand Up @@ -90,14 +91,17 @@ protected
function convertComponents
input list<tuple<ComponentRef, Binding>> components;
input output list<DAE.Element> elements;
protected
Boolean localDir = Flags.getConfigBool(Flags.USE_LOCAL_DIRECTION);
algorithm
for comp in listReverse(components) loop
elements := convertComponent(comp) :: elements;
elements := convertComponent(comp, localDir) :: elements;
end for;
end convertComponents;

function convertComponent
input tuple<ComponentRef, Binding> component;
input Boolean useLocalDir;
output DAE.Element daeVar;
protected
ComponentRef cref;
Expand All @@ -119,7 +123,7 @@ algorithm

binding_exp := convertBinding(binding);
var_attr := convertVarAttributes(Class.getTypeAttributes(cls), ty);
daeVar := makeDAEVar(cref, ty, binding_exp, attr, InstNode.visibility(comp_node), var_attr, info);
daeVar := makeDAEVar(cref, ty, binding_exp, attr, InstNode.visibility(comp_node), var_attr, useLocalDir, info);
end convertComponent;

function makeDAEVar
Expand All @@ -129,24 +133,34 @@ function makeDAEVar
input Component.Attributes attr;
input Visibility vis;
input Option<DAE.VariableAttributes> vattr;
input Boolean useLocalDir;
input SourceInfo info;
output DAE.Element var;
protected
DAE.ComponentRef dcref;
DAE.Type dty;
DAE.ElementSource source;
Direction dir;
algorithm
dcref := ComponentRef.toDAE(cref);
dty := Type.toDAE(ty);
source := ElementSource.createElementSource(info);

var := match attr
case Component.Attributes.ATTRIBUTES()
algorithm
// Strip input/output from non top-level components unless
// --useLocalDirection=true has been set.
if attr.direction == Direction.NONE or useLocalDir then
dir := attr.direction;
else
dir := getComponentDirection(attr.direction, cref);
end if;
then
DAE.VAR(
dcref,
Prefixes.variabilityToDAE(attr.variability),
Prefixes.directionToDAE(attr.direction),
Prefixes.directionToDAE(dir),
Prefixes.parallelismToDAE(attr.parallelism),
Prefixes.visibilityToDAE(vis),
dty,
Expand All @@ -168,6 +182,22 @@ algorithm
end match;
end makeDAEVar;

function getComponentDirection
"Returns the given direction if the cref refers to a top-level component or to
a component in a top-level connector, otherwise returns Direction.NONE."
input output Direction dir;
input ComponentRef cref;
protected
ComponentRef rest_cref = ComponentRef.rest(cref);
algorithm
dir := match rest_cref
case ComponentRef.EMPTY() then dir;
case ComponentRef.CREF()
then if InstNode.isConnector(rest_cref.node) then
getComponentDirection(dir, rest_cref) else Direction.NONE;
end match;
end getComponentDirection;

function convertBinding
input Binding binding;
output Option<DAE.Exp> bindingExp;
Expand Down Expand Up @@ -970,7 +1000,7 @@ algorithm
var_attr := convertVarAttributes(Class.getTypeAttributes(cls), ty);
attr := comp.attributes;
then
makeDAEVar(cref, ty, binding, attr, InstNode.visibility(node), var_attr, info);
makeDAEVar(cref, ty, binding, attr, InstNode.visibility(node), var_attr, true, info);

else
algorithm
Expand Down

0 comments on commit 89998d3

Please sign in to comment.