Skip to content

Commit

Permalink
Component attribute propagation for NFInst.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Oct 10, 2017
1 parent 7648bd5 commit 3c3ca87
Show file tree
Hide file tree
Showing 8 changed files with 523 additions and 133 deletions.
10 changes: 5 additions & 5 deletions Compiler/NFFrontEnd/NFBuiltin.mo
Expand Up @@ -208,7 +208,7 @@ constant InstNode STATESELECT_NEVER =
InstNode.EMPTY_NODE(),
STATESELECT_TYPE,
STATESELECT_NEVER_BINDING,
NFComponent.CONST_ATTR,
Component.Attributes.DEFAULT(),
Absyn.dummyInfo)),
STATESELECT_NODE);

Expand All @@ -221,7 +221,7 @@ constant InstNode STATESELECT_AVOID =
InstNode.EMPTY_NODE(),
STATESELECT_TYPE,
STATESELECT_AVOID_BINDING,
NFComponent.CONST_ATTR,
Component.Attributes.DEFAULT(),
Absyn.dummyInfo)),
STATESELECT_NODE);

Expand All @@ -234,7 +234,7 @@ constant InstNode STATESELECT_DEFAULT =
InstNode.EMPTY_NODE(),
STATESELECT_TYPE,
STATESELECT_DEFAULT_BINDING,
NFComponent.CONST_ATTR,
Component.Attributes.DEFAULT(),
Absyn.dummyInfo)),
STATESELECT_NODE);

Expand All @@ -247,7 +247,7 @@ constant InstNode STATESELECT_PREFER =
InstNode.EMPTY_NODE(),
STATESELECT_TYPE,
STATESELECT_PREFER_BINDING,
NFComponent.CONST_ATTR,
Component.Attributes.DEFAULT(),
Absyn.dummyInfo)),
STATESELECT_NODE);

Expand All @@ -260,7 +260,7 @@ constant InstNode STATESELECT_ALWAYS =
InstNode.EMPTY_NODE(),
STATESELECT_TYPE,
STATESELECT_ALWAYS_BINDING,
NFComponent.CONST_ATTR,
Component.Attributes.DEFAULT(),
Absyn.dummyInfo)),
STATESELECT_NODE);

Expand Down
23 changes: 22 additions & 1 deletion Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -80,7 +80,7 @@ uniontype Class
Modifier modifier;
list<Dimension> dims;
Class.Prefixes prefixes;
Absyn.Direction direction;
Component.Attributes attributes;
end DERIVED_CLASS;

record PARTIAL_BUILTIN
Expand Down Expand Up @@ -269,6 +269,27 @@ uniontype Class
end match;
end getDimensions;

function isProtected
input Class cls;
output Boolean isProtected;
algorithm
isProtected := match cls
case EXPANDED_CLASS(prefixes = Prefixes.PREFIXES(visibility = SCode.Visibility.PROTECTED())) then true;
case DERIVED_CLASS(prefixes = Prefixes.PREFIXES(visibility = SCode.Visibility.PROTECTED())) then true;
else false;
end match;
end isProtected;

function getAttributes
input Class cls;
output Component.Attributes attr;
algorithm
attr := match cls
case DERIVED_CLASS() then cls.attributes;
else Component.Attributes.DEFAULT();
end match;
end getAttributes;

end Class;

annotation(__OpenModelica_Interface="frontend");
Expand Down
122 changes: 68 additions & 54 deletions Compiler/NFFrontEnd/NFComponent.mo
Expand Up @@ -41,54 +41,67 @@ import SCode.Element;
import SCode;
import Type = NFType;
import Expression = NFExpression;
import NFPrefixes.{Variability, InnerOuter};
import NFPrefixes.*;

protected
import NFInstUtil;
import List;
import Prefixes = NFPrefixes;

public
constant Component.Attributes CONST_ATTR =
Component.Attributes.ATTRIBUTES(
DAE.NON_CONNECTOR(),
DAE.NON_PARALLEL(),
Variability.CONTINUOUS,
DAE.BIDIR(),
InnerOuter.NOT_INNER_OUTER,
DAE.PUBLIC());

constant Component.Attributes INPUT_ATTR =
Component.Attributes.ATTRIBUTES(
DAE.NON_CONNECTOR(),
DAE.NON_PARALLEL(),
Variability.CONTINUOUS,
DAE.INPUT(),
InnerOuter.NOT_INNER_OUTER,
DAE.PUBLIC());
ConnectorType.POTENTIAL,
Parallelism.NON_PARALLEL,
Variability.CONTINUOUS,
Direction.INPUT,
InnerOuter.NOT_INNER_OUTER,
Visibility.PUBLIC
);

constant Component.Attributes OUTPUT_ATTR =
Component.Attributes.ATTRIBUTES(
DAE.NON_CONNECTOR(),
DAE.NON_PARALLEL(),
Variability.CONTINUOUS,
DAE.OUTPUT(),
InnerOuter.NOT_INNER_OUTER,
DAE.PUBLIC());
ConnectorType.POTENTIAL,
Parallelism.NON_PARALLEL,
Variability.CONTINUOUS,
Direction.OUTPUT,
InnerOuter.NOT_INNER_OUTER,
Visibility.PUBLIC
);

constant Component.Attributes PROTECTED_ATTR =
Component.Attributes.ATTRIBUTES(
ConnectorType.POTENTIAL,
Parallelism.NON_PARALLEL,
Variability.CONTINUOUS,
Direction.NONE,
InnerOuter.NOT_INNER_OUTER,
Visibility.PROTECTED
);

uniontype Component
uniontype Attributes
record ATTRIBUTES
// adrpo: keep the order in DAE.ATTR
DAE.ConnectorType connectorType;
DAE.VarParallelism parallelism;
ConnectorType connectorType;
Parallelism parallelism;
Variability variability;
DAE.VarDirection direction;
Direction direction;
InnerOuter innerOuter;
DAE.VarVisibility visibility;
Visibility visibility;
end ATTRIBUTES;

record DEFAULT end DEFAULT;

function isDefault
input Attributes attr;
output Boolean isDefault;
algorithm
isDefault := match attr
case DEFAULT() then true;
else false;
end match;
end isDefault;
end Attributes;

record COMPONENT_DEF
Expand All @@ -101,7 +114,6 @@ uniontype Component
array<Dimension> dimensions;
Binding binding;
Component.Attributes attributes;
Boolean isRedeclare;
SourceInfo info;
end UNTYPED_COMPONENT;

Expand Down Expand Up @@ -304,6 +316,26 @@ uniontype Component
end match;
end getAttributes;

function setAttributes
input Component.Attributes attr;
input output Component component;
algorithm
() := match component
case UNTYPED_COMPONENT()
algorithm
component.attributes := attr;
then
();

case TYPED_COMPONENT()
algorithm
component.attributes := attr;
then
();

end match;
end setAttributes;

function getBinding
input Component component;
output Binding b;
Expand All @@ -327,33 +359,23 @@ uniontype Component

function direction
input Component component;
output DAE.VarDirection direction;
output Direction direction;
algorithm
direction := match component
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(direction = direction)) then direction;
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(direction = direction)) then direction;
else DAE.VarDirection.BIDIR();
else Direction.NONE;
end match;
end direction;

function isInput
input Component component;
output Boolean isInput;
algorithm
isInput := match direction(component)
case DAE.VarDirection.INPUT() then true;
else false;
end match;
output Boolean isInput = direction(component) == Direction.INPUT;
end isInput;

function isOutput
input Component component;
output Boolean isOutput;
algorithm
isOutput := match direction(component)
case DAE.VarDirection.OUTPUT() then true;
else false;
end match;
output Boolean isOutput = direction(component) == Direction.OUTPUT;
end isOutput;

function variability
Expand All @@ -362,11 +384,9 @@ uniontype Component
algorithm
variability := match component
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
case TYPED_COMPONENT(attributes = Attributes.DEFAULT()) then Variability.CONTINUOUS;
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
case UNTYPED_COMPONENT(attributes = Attributes.DEFAULT()) then Variability.CONTINUOUS;
case ITERATOR() then Variability.CONSTANT;
else fail();
else Variability.CONTINUOUS;
end match;
end variability;

Expand All @@ -382,27 +402,22 @@ uniontype Component

function visibility
input Component component;
output DAE.VarVisibility visibility;
output Visibility visibility;
algorithm
visibility := match component
case COMPONENT_DEF() then
if SCode.isElementProtected(component.definition) then
DAE.VarVisibility.PROTECTED() else DAE.VarVisibility.PUBLIC();
Visibility.PROTECTED else Visibility.PUBLIC;
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(visibility = visibility)) then visibility;
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(visibility = visibility)) then visibility;
// Iterators and enumeration literals can't be accessed in a way where visibility matters.
else DAE.VarVisibility.PUBLIC();
else Visibility.PUBLIC;
end match;
end visibility;

function isPublic
input Component component;
output Boolean isInput;
algorithm
isInput := match visibility(component)
case DAE.VarVisibility.PUBLIC() then true;
else false;
end match;
output Boolean isInput = visibility(component) == Visibility.PUBLIC;
end isPublic;

function isRedeclare
Expand All @@ -411,7 +426,6 @@ uniontype Component
algorithm
isRedeclare := match component
case COMPONENT_DEF() then SCode.isElementRedeclare(component.definition);
case UNTYPED_COMPONENT() then component.isRedeclare;
else false;
end match;
end isRedeclare;
Expand Down
18 changes: 15 additions & 3 deletions Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -431,9 +431,21 @@ algorithm
var := match attr
case Component.Attributes.ATTRIBUTES()
then
DAE.VAR(cref, Prefixes.variabilityToDAE(attr.variability), attr.direction,
attr.parallelism, attr.visibility, ty, binding, {}, attr.connectorType,
source, vattr, NONE(), Absyn.NOT_INNER_OUTER());
DAE.VAR(
cref,
Prefixes.variabilityToDAE(attr.variability),
Prefixes.directionToDAE(attr.direction),
Prefixes.parallelismToDAE(attr.parallelism),
Prefixes.visibilityToDAE(attr.visibility),
ty,
binding,
{},
Prefixes.connectorTypeToDAE(attr.connectorType),
source,
vattr,
NONE(),
Absyn.NOT_INNER_OUTER()
);

else
DAE.VAR(cref, DAE.VarKind.VARIABLE(), DAE.VarDirection.BIDIR(),
Expand Down

0 comments on commit 3c3ca87

Please sign in to comment.