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

Commit

Permalink
NFInst changes
Browse files Browse the repository at this point in the history
- Started implementation of NFExpression and NFType to replace
  DAE.Exp and DAE.Type.
- Added Array.exist.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 20, 2017
1 parent c80769b commit 20fbe26
Show file tree
Hide file tree
Showing 21 changed files with 3,443 additions and 1,793 deletions.
10 changes: 6 additions & 4 deletions Compiler/NFFrontEnd/NFBinding.mo
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ encapsulated package NFBinding

public
import DAE;
import NFExpression.Expression;
import NFInstNode.InstNode;
import SCode;
import Type = NFType;

protected
import Dump;
Expand All @@ -65,8 +67,8 @@ uniontype Binding
end UNTYPED_BINDING;

record TYPED_BINDING
DAE.Exp bindingExp;
DAE.Type bindingType;
Expression bindingExp;
Type bindingType;
DAE.Const variability;
Integer propagatedDims;
SourceInfo info;
Expand Down Expand Up @@ -118,7 +120,7 @@ public

function typedExp
input Binding binding;
output Option<DAE.Exp> exp;
output Option<Expression> exp;
algorithm
exp := match binding
case TYPED_BINDING() then SOME(binding.bindingExp);
Expand Down Expand Up @@ -159,7 +161,7 @@ public
case UNBOUND() then "";
case RAW_BINDING() then prefix + Dump.printExpStr(binding.bindingExp);
case UNTYPED_BINDING() then prefix + Dump.printExpStr(binding.bindingExp);
case TYPED_BINDING() then prefix + ExpressionDump.printExpStr(binding.bindingExp);
case TYPED_BINDING() then prefix + Expression.toString(binding.bindingExp);
end match;
end toString;

Expand Down
43 changes: 37 additions & 6 deletions Compiler/NFFrontEnd/NFComponent.mo
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ encapsulated package NFComponent

import DAE;
import NFBinding.Binding;
import NFDimension.Dimension;
import Dimension = NFDimension;
import NFInstNode.InstNode;
import NFMod.Modifier;
import SCode.Element;
import SCode;
import Type = NFType;

protected
import NFInstUtil;
Expand Down Expand Up @@ -96,7 +97,7 @@ uniontype Component

record TYPED_COMPONENT
InstNode classInst;
DAE.Type ty;
Type ty;
Binding binding;
Component.Attributes attributes;
end TYPED_COMPONENT;
Expand Down Expand Up @@ -159,15 +160,15 @@ uniontype Component

function getType
input Component component;
output DAE.Type ty;
output Type ty;
algorithm
ty := match component
case TYPED_COMPONENT() then component.ty;
end match;
end getType;

function setType
input DAE.Type ty;
input Type ty;
input output Component component;
algorithm
component := match component
Expand All @@ -187,9 +188,9 @@ uniontype Component
algorithm
() := match component
local
DAE.Type ty;
Type ty;

case TYPED_COMPONENT(ty = DAE.Type.T_ARRAY(ty = ty))
case TYPED_COMPONENT(ty = Type.ARRAY(elementType = ty))
algorithm
component.ty := ty;
then
Expand Down Expand Up @@ -235,6 +236,36 @@ uniontype Component
end match;
end attr2DaeAttr;

function direction
input Component component;
output DAE.VarDirection 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();
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;
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;
end isOutput;
end Component;

annotation(__OpenModelica_Interface="frontend");
Expand Down
116 changes: 91 additions & 25 deletions Compiler/NFFrontEnd/NFDimension.mo
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,105 @@
*
*/


encapsulated package NFDimension
" file: NFMod.mo
package: NFMod
description: A type for dimensions in NFInst.
"

public
import Absyn;
import DAE;

encapsulated uniontype NFDimension
protected
import List;
import Dimension = NFDimension;

public
uniontype Dimension
record UNTYPED_DIM
import Absyn.Exp;
import Absyn.Path;
import Dump;
import NFExpression.Expression;

record UNTYPED
Absyn.Exp dimension;
Boolean isProcessing;
end UNTYPED_DIM;
end UNTYPED;

record TYPED_DIM
DAE.Dimension dimension;
end TYPED_DIM;
record INTEGER
Integer size;
end INTEGER;

public
function dimension
input Dimension inDim;
output DAE.Dimension outDim;
record BOOLEAN
end BOOLEAN;

record ENUM
Absyn.Path enumTypeName;
list<String> literals;
end ENUM;

record EXP
Expression exp;
end EXP;

record UNKNOWN
end UNKNOWN;

function toDAE
input Dimension dim;
output DAE.Dimension daeDim;
algorithm
daeDim := match dim
case INTEGER() then DAE.DIM_INTEGER(dim.size);
case BOOLEAN() then DAE.DIM_BOOLEAN();
case ENUM()
then DAE.DIM_ENUM(dim.enumTypeName, dim.literals, listLength(dim.literals));
case EXP() then DAE.DIM_EXP(Expression.toDAE(dim.exp));
case UNKNOWN() then DAE.DIM_UNKNOWN();
end match;
end toDAE;

function size
input Dimension dim;
output Integer size;
algorithm
size := match dim
case INTEGER() then dim.size;
case BOOLEAN() then 2;
case ENUM() then listLength(dim.literals);
end match;
end size;

function isEqual
input Dimension dim1;
input Dimension dim2;
output Boolean isEqual;
algorithm
isEqual := match (dim1, dim2)
case (UNKNOWN(), _) then true;
case (_, UNKNOWN()) then true;
case (EXP(), _) then true;
case (_, EXP()) then true;
else Dimension.size(dim1) == Dimension.size(dim2);
end match;
end isEqual;

function isEqualKnown
input Dimension dim1;
input Dimension dim2;
output Boolean isEqual;
algorithm
isEqual := match (dim1, dim2)
case (UNKNOWN(), _) then false;
case (_, UNKNOWN()) then false;
case (EXP(), EXP()) then Expression.isEqual(dim1.exp, dim2.exp);
else Dimension.size(dim1) == Dimension.size(dim2);
end match;
end isEqualKnown;

function toString
input Dimension dim;
output String str;
algorithm
TYPED_DIM(dimension = outDim) := inDim;
end dimension;
end Dimension;
str := match dim
case INTEGER() then String(dim.size);
case BOOLEAN() then "Boolean";
case ENUM() then Absyn.pathString(dim.enumTypeName);
case EXP() then Expression.toString(dim.exp);
case UNKNOWN() then ":";
case UNTYPED() then Dump.printExpStr(dim.dimension);
end match;
end toString;

annotation(__OpenModelica_Interface="frontend");
end NFDimension;
40 changes: 21 additions & 19 deletions Compiler/NFFrontEnd/NFEquation.mo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

encapsulated package NFEquation

import DAE;
import Absyn;
import NFExpression.Expression;
import Type = NFType;

public uniontype Equation
record UNTYPED_EQUALITY
Expand All @@ -41,9 +43,9 @@ public uniontype Equation
end UNTYPED_EQUALITY;

record EQUALITY
DAE.Exp lhs "The left hand side expression.";
DAE.Exp rhs "The right hand side expression.";
DAE.Type ty;
Expression lhs "The left hand side expression.";
Expression rhs "The right hand side expression.";
Type ty;
SourceInfo info;
end EQUALITY;

Expand All @@ -54,12 +56,12 @@ public uniontype Equation
end UNTYPED_CONNECT;

record CONNECT
DAE.ComponentRef lhs "The left hand side component.";
Expression lhs "The left hand side component.";
//NFConnect2.Face lhsFace "The face of the lhs component, inside or outside.";
DAE.Type lhsType "The type of the lhs component.";
DAE.ComponentRef rhs "The right hand side component.";
Type lhsType "The type of the lhs component.";
Expression rhs "The right hand side component.";
//NFConnect2.Face rhsFace "The face of the rhs component, inside or outside.";
DAE.Type rhsType "The type of the rhs component.";
Type rhsType "The type of the rhs component.";
//Prefix prefix;
SourceInfo info;
end CONNECT;
Expand All @@ -74,8 +76,8 @@ public uniontype Equation
record FOR
String name "The name of the iterator variable.";
Integer index "The index of the iterator variable.";
DAE.Type indexType "The type of the index/iterator variable.";
Option<DAE.Exp> range "The range expression to loop over.";
Type indexType "The type of the index/iterator variable.";
Option<Expression> range "The range expression to loop over.";
list<Equation> body "The body of the for loop.";
SourceInfo info;
end FOR;
Expand All @@ -86,7 +88,7 @@ public uniontype Equation
end UNTYPED_IF;

record IF
list<tuple<DAE.Exp, list<Equation>>> branches
list<tuple<Expression, list<Equation>>> branches
"List of branches, where each branch is a tuple of a condition and a body.";
SourceInfo info;
end IF;
Expand All @@ -97,7 +99,7 @@ public uniontype Equation
end UNTYPED_WHEN;

record WHEN
list<tuple<DAE.Exp, list<Equation>>> branches
list<tuple<Expression, list<Equation>>> branches
"List of branches, where each branch is a tuple of a condition and a body.";
SourceInfo info;
end WHEN;
Expand All @@ -110,9 +112,9 @@ public uniontype Equation
end UNTYPED_ASSERT;

record ASSERT
DAE.Exp condition "The assert condition.";
DAE.Exp message "The message to display if the assert fails.";
DAE.Exp level "Error or warning";
Expression condition "The assert condition.";
Expression message "The message to display if the assert fails.";
Expression level "Error or warning";
SourceInfo info;
end ASSERT;

Expand All @@ -122,7 +124,7 @@ public uniontype Equation
end UNTYPED_TERMINATE;

record TERMINATE
DAE.Exp message "The message to display if the terminate triggers.";
Expression message "The message to display if the terminate triggers.";
SourceInfo info;
end TERMINATE;

Expand All @@ -133,8 +135,8 @@ public uniontype Equation
end UNTYPED_REINIT;

record REINIT
DAE.ComponentRef cref "The variable to reinitialize.";
DAE.Exp reinitExp "The new value of the variable.";
Expression cref "The variable to reinitialize.";
Expression reinitExp "The new value of the variable.";
SourceInfo info;
end REINIT;

Expand All @@ -144,7 +146,7 @@ public uniontype Equation
end UNTYPED_NORETCALL;

record NORETCALL
DAE.Exp exp;
Expression exp;
SourceInfo info;
end NORETCALL;
end Equation;
Expand Down

0 comments on commit 20fbe26

Please sign in to comment.