Skip to content

Commit

Permalink
Added component attributes to new instantiation.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed May 25, 2016
1 parent 5184da3 commit cbc9561
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 52 deletions.
10 changes: 10 additions & 0 deletions Compiler/FrontEnd/NFComponent.mo
Expand Up @@ -38,6 +38,15 @@ import NFBinding.Binding;
import NFMod.Modifier;

uniontype Component
uniontype Attributes
record ATTRIBUTES
DAE.VarKind variability;
DAE.VarDirection direction;
DAE.VarVisibility visibility;
DAE.ConnectorType connectorType;
end ATTRIBUTES;
end Attributes;

record COMPONENT_DEF
Element definition;
Modifier modifier;
Expand All @@ -49,6 +58,7 @@ uniontype Component
InstNode classInst;
Type ty;
Binding binding;
Component.Attributes attributes;
end COMPONENT;

function name
Expand Down
12 changes: 7 additions & 5 deletions Compiler/FrontEnd/NFFlatten.mo
Expand Up @@ -112,8 +112,10 @@ algorithm
Instance i;
DAE.Element var;
DAE.ComponentRef cref;
Component.Attributes attr;

case Component.COMPONENT(classInst = InstNode.INST_NODE(instance = Instance.INSTANCED_BUILTIN()))
case Component.COMPONENT(classInst = InstNode.INST_NODE(instance = Instance.INSTANCED_BUILTIN()),
attributes = attr as Component.Attributes.ATTRIBUTES())
algorithm
cref := DAE.CREF_IDENT(component.name, DAE.T_UNKNOWN_DEFAULT, {});
for id in prefix loop
Expand All @@ -122,14 +124,14 @@ algorithm

var := DAE.VAR(
cref,
DAE.VARIABLE(),
DAE.BIDIR(),
attr.variability,
attr.direction,
DAE.NON_PARALLEL(),
DAE.PUBLIC(),
attr.visibility,
component.ty,
Binding.untypedExp(component.binding),
{},
DAE.NON_CONNECTOR(),
attr.connectorType,
DAE.emptyElementSource,
NONE(),
NONE(),
Expand Down
27 changes: 25 additions & 2 deletions Compiler/FrontEnd/NFInst.mo
Expand Up @@ -54,6 +54,7 @@ import NFMod.ModifierScope;
protected
import Error;
import Flatten = NFFlatten;
import InstUtil = NFInstUtil;
import List;
import Lookup = NFLookup;
import MetaModelica.Dangerous;
Expand Down Expand Up @@ -355,7 +356,9 @@ algorithm
// Add component ids to the scope.
idx := 1;
for c in components loop
scope := ClassTree.add(scope, Component.name(c), ElementId.COMPONENT_ID(idx));
// TODO: Handle components with the same name.
scope := ClassTree.add(scope, Component.name(c),
ElementId.COMPONENT_ID(idx), ClassTree.addConflictReplace);
idx := idx + 1;
end for;

Expand Down Expand Up @@ -607,6 +610,7 @@ protected
Binding binding;
DAE.Type ty;
Component redecl_comp;
Component.Attributes attr;
algorithm
(component, tree) := match component
case Component.COMPONENT_DEF(modifier = comp_mod as Modifier.REDECLARE())
Expand All @@ -624,11 +628,30 @@ algorithm
binding := Modifier.binding(comp_mod);
(cls, tree) := instTypeSpec(comp.typeSpec, comp_mod, comp.info, tree);
ty := makeType(cls);
attr := instComponentAttributes(comp.attributes, comp.prefixes);
then
(Component.COMPONENT(comp.name, cls, ty, binding), tree);
(Component.COMPONENT(comp.name, cls, ty, binding, attr), tree);

end match;
end instComponent;

function instComponentAttributes
input SCode.Attributes compAttr;
input SCode.Prefixes compPrefs;
output Component.Attributes attributes;
protected
DAE.VarKind variability;
DAE.VarDirection direction;
DAE.VarVisibility visiblity;
DAE.ConnectorType connectorType;
algorithm
variability := InstUtil.translateVariability(compAttr.variability);
direction := InstUtil.translateDirection(compAttr.direction);
visiblity := InstUtil.translateVisibility(compPrefs.visibility);
connectorType := InstUtil.translateConnectorType(compAttr.connectorType);
attributes := Component.Attributes.ATTRIBUTES(variability, direction, visiblity, connectorType);
end instComponentAttributes;

function instTypeSpec
input Absyn.TypeSpec typeSpec;
input Modifier modifier;
Expand Down
90 changes: 45 additions & 45 deletions Compiler/FrontEnd/NFInstUtil.mo
Expand Up @@ -1595,51 +1595,51 @@ public import SCode;
//
// end match;
//end translatePrefixes;
//
//public function translateVisibility
// input SCode.Visibility inVisibility;
// output DAE.VarVisibility outVisibility;
//algorithm
// outVisibility := match(inVisibility)
// case SCode.PUBLIC() then DAE.PUBLIC();
// else DAE.PROTECTED();
// end match;
//end translateVisibility;
//
//public function translateVariability
// input SCode.Variability inVariability;
// output DAE.VarKind outVariability;
//algorithm
// outVariability := match(inVariability)
// case SCode.VAR() then DAE.VARIABLE();
// case SCode.PARAM() then DAE.PARAM();
// case SCode.CONST() then DAE.CONST();
// case SCode.DISCRETE() then DAE.DISCRETE();
// end match;
//end translateVariability;
//
//public function translateDirection
// input Absyn.Direction inDirection;
// output DAE.VarDirection outDirection;
//algorithm
// outDirection := match(inDirection)
// case Absyn.BIDIR() then DAE.BIDIR();
// case Absyn.OUTPUT() then DAE.OUTPUT();
// case Absyn.INPUT() then DAE.INPUT();
// end match;
//end translateDirection;
//
//public function translateConnectorType
// input SCode.ConnectorType inConnectorType;
// output DAE.ConnectorType outConnectorType;
//algorithm
// outConnectorType := match(inConnectorType)
// case SCode.FLOW() then DAE.FLOW();
// case SCode.STREAM() then DAE.STREAM();
// else DAE.NON_CONNECTOR();
// end match;
//end translateConnectorType;
//

public function translateVisibility
input SCode.Visibility inVisibility;
output DAE.VarVisibility outVisibility;
algorithm
outVisibility := match(inVisibility)
case SCode.PUBLIC() then DAE.PUBLIC();
else DAE.PROTECTED();
end match;
end translateVisibility;

public function translateVariability
input SCode.Variability inVariability;
output DAE.VarKind outVariability;
algorithm
outVariability := match(inVariability)
case SCode.VAR() then DAE.VARIABLE();
case SCode.PARAM() then DAE.PARAM();
case SCode.CONST() then DAE.CONST();
case SCode.DISCRETE() then DAE.DISCRETE();
end match;
end translateVariability;

public function translateDirection
input Absyn.Direction inDirection;
output DAE.VarDirection outDirection;
algorithm
outDirection := match(inDirection)
case Absyn.BIDIR() then DAE.BIDIR();
case Absyn.OUTPUT() then DAE.OUTPUT();
case Absyn.INPUT() then DAE.INPUT();
end match;
end translateDirection;

public function translateConnectorType
input SCode.ConnectorType inConnectorType;
output DAE.ConnectorType outConnectorType;
algorithm
outConnectorType := match(inConnectorType)
case SCode.FLOW() then DAE.FLOW();
case SCode.STREAM() then DAE.STREAM();
else DAE.NON_CONNECTOR();
end match;
end translateConnectorType;

//public function conditionTrue
// input Condition inCondition;
// output Boolean outCondition;
Expand Down

0 comments on commit cbc9561

Please sign in to comment.