Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
partial support for handling functions
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Dec 5, 2016
1 parent da294f8 commit 4a4bd52
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/InstUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7269,7 +7269,7 @@ algorithm
end match;
end makeNonExpSubscript;

protected function getFunctionAttributes
public function getFunctionAttributes
"Looks at the annotations of an SCode.Element to create the function attributes,
i.e. Inline and Purity"
input SCode.Element cl;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Static.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6952,7 +6952,7 @@ algorithm
end match;
end elabBuiltinHandlerInternal;

protected function isBuiltinFunc "Returns true if the function name given as argument
public function isBuiltinFunc "Returns true if the function name given as argument
is a builtin function, which either has a elabBuiltinHandler function
or can be found in the builtin environment."
input Absyn.Path inPath "the path of the found function";
Expand Down Expand Up @@ -7925,7 +7925,7 @@ algorithm
outCache := cache;
end elabCallArgs3;

protected function inlineBuiltin
public function inlineBuiltin
input DAE.FunctionBuiltin isBuiltin;
input DAE.InlineType inlineType;
output DAE.InlineType outInlineType;
Expand Down
64 changes: 61 additions & 3 deletions Compiler/NFFrontEnd/NFComponent.mo
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,51 @@ import NFDimension.Dimension;
import NFInstNode.InstNode;
import NFMod.Modifier;
import SCode.Element;
import SCode;

protected
import NFInstUtil;

public
constant Component.Attributes DEFAULT_ATTR =
Component.Attributes.ATTRIBUTES(DAE.VARIABLE(), DAE.BIDIR(), DAE.PUBLIC(), DAE.NON_CONNECTOR());
Component.Attributes.ATTRIBUTES(
DAE.NON_CONNECTOR(),
DAE.NON_PARALLEL(),
DAE.VARIABLE(),
DAE.BIDIR(),
DAE.NOT_INNER_OUTER(),
DAE.PUBLIC());

constant Component.Attributes INPUT_ATTR =
Component.Attributes.ATTRIBUTES(DAE.VARIABLE(), DAE.INPUT(), DAE.PUBLIC(), DAE.NON_CONNECTOR());
Component.Attributes.ATTRIBUTES(
DAE.NON_CONNECTOR(),
DAE.NON_PARALLEL(),
DAE.VARIABLE(),
DAE.INPUT(),
DAE.NOT_INNER_OUTER(),
DAE.PUBLIC());

constant Component.Attributes OUTPUT_ATTR =
Component.Attributes.ATTRIBUTES(
DAE.NON_CONNECTOR(),
DAE.NON_PARALLEL(),
DAE.VARIABLE(),
DAE.OUTPUT(),
DAE.NOT_INNER_OUTER(),
DAE.PUBLIC());

constant Component.Scope DEFAULT_SCOPE = Component.Scope.RELATIVE_COMP(0);

uniontype Component
uniontype Attributes
record ATTRIBUTES
// adrpo: keep the order in DAE.ATTR
DAE.ConnectorType connectorType;
DAE.VarParallelism parallelism;
DAE.VarKind variability;
DAE.VarDirection direction;
DAE.VarInnerOuter innerOuter;
DAE.VarVisibility visibility;
DAE.ConnectorType connectorType;
end ATTRIBUTES;
end Attributes;

Expand Down Expand Up @@ -198,6 +229,33 @@ uniontype Component
else ();
end match;
end unliftType;

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

function attr2DaeAttr
input Attributes attr;
output DAE.Attributes daeAttr;
algorithm
daeAttr := match(attr)
case ATTRIBUTES()
then DAE.ATTR(
NFInstUtil.daeToSCodeConnectorType(attr.connectorType),
NFInstUtil.daeToSCodeParallelism(attr.parallelism),
NFInstUtil.daeToSCodeVariability(attr.variability),
NFInstUtil.daeToAbsynDirection(attr.direction),
NFInstUtil.daeToAbsynInnerOuter(attr.innerOuter),
NFInstUtil.daeToSCodeVisibility(attr.visibility));
end match;
end attr2DaeAttr;

end Component;

annotation(__OpenModelica_Interface="frontend");
Expand Down
10 changes: 7 additions & 3 deletions Compiler/NFFrontEnd/NFInst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -811,16 +811,20 @@ function instComponentAttributes
input SCode.Prefixes compPrefs;
output Component.Attributes attributes;
protected
DAE.ConnectorType connectorType;
DAE.VarParallelism parallelism;
DAE.VarKind variability;
DAE.VarDirection direction;
DAE.VarInnerOuter innerOuter;
DAE.VarVisibility visiblity;
DAE.ConnectorType connectorType;
algorithm
connectorType := InstUtil.translateConnectorType(compAttr.connectorType);
parallelism := InstUtil.translateParallelism(compAttr.parallelism);
variability := InstUtil.translateVariability(compAttr.variability);
direction := InstUtil.translateDirection(compAttr.direction);
innerOuter := InstUtil.translateInnerOuter(compPrefs.innerOuter);
visiblity := InstUtil.translateVisibility(compPrefs.visibility);
connectorType := InstUtil.translateConnectorType(compAttr.connectorType);
attributes := Component.Attributes.ATTRIBUTES(variability, direction, visiblity, connectorType);
attributes := Component.Attributes.ATTRIBUTES(connectorType, parallelism, variability, direction, innerOuter, visiblity);
end instComponentAttributes;

function instTypeSpec
Expand Down
22 changes: 21 additions & 1 deletion Compiler/NFFrontEnd/NFInstNode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import NFComponent.Component;
import NFInst.Instance;
import NFPrefix.Prefix;
import SCode;
import Absyn;

uniontype InstParent
record CLASS
Expand Down Expand Up @@ -258,7 +259,8 @@ uniontype InstNode

function scopePrefix
input InstNode node;
input output Prefix prefix = Prefix.NO_PREFIX();
input output Prefix
prefix = Prefix.NO_PREFIX();
algorithm
prefix := match node
local
Expand All @@ -284,6 +286,24 @@ uniontype InstNode
else prefix;
end match;
end scopePrefix;


function path
input InstNode node;
output Absyn.Path p;
protected
String n;
InstNode parent;
algorithm
n := InstNode.name(node);
parent := InstNode.parentScope(node);
p := Absyn.IDENT(n);
p := match(InstNode.nodeType(parent))
case InstNodeType.ROOT_CLASS() then p;
case InstNodeType.TOP_SCOPE() then p;
else Absyn.joinPaths(path(parent), p);
end match;
end path;
end InstNode;

annotation(__OpenModelica_Interface="frontend");
Expand Down
167 changes: 107 additions & 60 deletions Compiler/NFFrontEnd/NFInstUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -237,51 +237,75 @@ public import SCode;
// end match;
//end daePrefixesToDaeAttr;
//
//public function daeToSCodeVisibility
// input DAE.VarVisibility inVisibility;
// output SCode.Visibility outVisibility;
//algorithm
// outVisibility := match(inVisibility)
// case DAE.PUBLIC() then SCode.PUBLIC();
// case DAE.PROTECTED() then SCode.PROTECTED();
// end match;
//end daeToSCodeVisibility;
//
//public function daeToSCodeVariability
// input DAE.VarKind inVariability;
// output SCode.Variability outVariability;
//algorithm
// outVariability := match(inVariability)
// case DAE.VARIABLE() then SCode.VAR();
// case DAE.DISCRETE() then SCode.DISCRETE();
// case DAE.PARAM() then SCode.PARAM();
// case DAE.CONST() then SCode.CONST();
// end match;
//end daeToSCodeVariability;
//
//public function daeToAbsynDirection
// input DAE.VarDirection inDirection;
// output Absyn.Direction outDirection;
//algorithm
// outDirection := match(inDirection)
// case DAE.BIDIR() then Absyn.BIDIR();
// case DAE.INPUT() then Absyn.INPUT();
// case DAE.OUTPUT() then Absyn.OUTPUT();
// end match;
//end daeToAbsynDirection;
//
//protected function daeToSCodeConnectorType
// input DAE.ConnectorType inConnectorType;
// output SCode.ConnectorType outConnectorType;
//algorithm
// outConnectorType := match(inConnectorType)
// case DAE.NON_CONNECTOR() then SCode.POTENTIAL();
// case DAE.POTENTIAL() then SCode.POTENTIAL();
// case DAE.FLOW() then SCode.FLOW();
// case DAE.STREAM() then SCode.STREAM();
// end match;
//end daeToSCodeConnectorType;
//

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

public function daeToSCodeParallelism
input DAE.VarParallelism inParallelism;
output SCode.Parallelism outParallelism;
algorithm
outParallelism := match(inParallelism)
case DAE.PARGLOBAL() then SCode.PARGLOBAL();
case DAE.PARLOCAL() then SCode.PARLOCAL();
case DAE.NON_PARALLEL() then SCode.NON_PARALLEL();
end match;
end daeToSCodeParallelism;

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

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

public function daeToAbsynInnerOuter
input DAE.VarInnerOuter inInnerOuter;
output Absyn.InnerOuter outInnerOuter;
algorithm
outInnerOuter := match(inInnerOuter)
case DAE.INNER() then Absyn.INNER();
case DAE.INNER_OUTER() then Absyn.INNER_OUTER();
case DAE.OUTER() then Absyn.OUTER();
case DAE.NOT_INNER_OUTER() then Absyn.NOT_INNER_OUTER();
end match;
end daeToAbsynInnerOuter;

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

//public function makeDerivedClassType
// input DAE.Type inType;
// input ClassInf.State inState;
Expand Down Expand Up @@ -1596,15 +1620,27 @@ public import SCode;
// end match;
//end translatePrefixes;

public function translateVisibility
input SCode.Visibility inVisibility;
output DAE.VarVisibility outVisibility;
public function translateConnectorType
input SCode.ConnectorType inConnectorType;
output DAE.ConnectorType outConnectorType;
algorithm
outVisibility := match(inVisibility)
case SCode.PUBLIC() then DAE.PUBLIC();
else DAE.PROTECTED();
outConnectorType := match(inConnectorType)
case SCode.FLOW() then DAE.FLOW();
case SCode.STREAM() then DAE.STREAM();
else DAE.NON_CONNECTOR();
end match;
end translateVisibility;
end translateConnectorType;

public function translateParallelism
input SCode.Parallelism inParallelism;
output DAE.VarParallelism outParallelism;
algorithm
outParallelism := match(inParallelism)
case SCode.PARGLOBAL() then DAE.PARGLOBAL();
case SCode.PARLOCAL() then DAE.PARLOCAL();
case SCode.NON_PARALLEL() then DAE.NON_PARALLEL();
end match;
end translateParallelism;

public function translateVariability
input SCode.Variability inVariability;
Expand All @@ -1629,16 +1665,27 @@ algorithm
end match;
end translateDirection;

public function translateConnectorType
input SCode.ConnectorType inConnectorType;
output DAE.ConnectorType outConnectorType;
public function translateInnerOuter
input Absyn.InnerOuter inInnerOuter;
output DAE.VarInnerOuter outInnerOuter;
algorithm
outConnectorType := match(inConnectorType)
case SCode.FLOW() then DAE.FLOW();
case SCode.STREAM() then DAE.STREAM();
else DAE.NON_CONNECTOR();
outInnerOuter := match(inInnerOuter)
case Absyn.INNER() then DAE.INNER();
case Absyn.INNER_OUTER() then DAE.INNER_OUTER();
case Absyn.OUTER() then DAE.OUTER();
case Absyn.NOT_INNER_OUTER() then DAE.NOT_INNER_OUTER();
end match;
end translateConnectorType;
end translateInnerOuter;

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 conditionTrue
// input Condition inCondition;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFLookup.mo
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ end lookupComponent;
function lookupFunctionName
input Absyn.ComponentRef cref;
input Component.Scope scope;
input ComponentNode component "THe component to look in.";
input ComponentNode component "The component to look in.";
input SourceInfo info;
output InstNode func;
output Prefix prefix;
Expand Down

0 comments on commit 4a4bd52

Please sign in to comment.