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

Commit

Permalink
Basic connection handling for NFInst.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 3, 2017
1 parent 2c5818d commit 75a3089
Show file tree
Hide file tree
Showing 29 changed files with 2,657 additions and 83 deletions.
4 changes: 4 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,14 @@ function cat "Concatenate arrays along given dimension"
end cat;

function actualStream
input Real x;
output Real y;
external "builtin";
end actualStream;

function inStream
input Real x;
output Real y;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'inStream()'\">inStream()</a>
Expand Down
28 changes: 21 additions & 7 deletions Compiler/NFFrontEnd/NFBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import Pointer;
import NFPrefixes.Variability;
import ComponentRef = NFComponentRef;
import NFComponentRef.Origin;
import Restriction = NFRestriction;

encapsulated package Elements
import SCode;
Expand Down Expand Up @@ -115,19 +116,22 @@ end Elements;
// modifiers and illegal in other cases).
constant InstNode ANYTYPE_NODE = InstNode.CLASS_NODE("polymorphic",
Elements.ANY,
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.ANY_TYPE("unknown"), NFClassTree.EMPTY, Modifier.NOMOD())),
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.ANY_TYPE("unknown"), NFClassTree.EMPTY,
Modifier.NOMOD(), Restriction.TYPE())),
arrayCreate(NFInstNode.NUMBER_OF_CACHES, NFInstNode.CachedData.NO_CACHE()),
InstNode.EMPTY_NODE(), InstNodeType.NORMAL_CLASS());

constant InstNode REAL_NODE = InstNode.CLASS_NODE("Real",
Elements.REAL,
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.REAL(), NFClassTree.EMPTY, Modifier.NOMOD())),
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.REAL(), NFClassTree.EMPTY,
Modifier.NOMOD(), Restriction.TYPE())),
arrayCreate(NFInstNode.NUMBER_OF_CACHES, NFInstNode.CachedData.NO_CACHE()),
InstNode.EMPTY_NODE(), InstNodeType.NORMAL_CLASS());

constant InstNode INTEGER_NODE = InstNode.CLASS_NODE("Integer",
Elements.INTEGER,
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.INTEGER(), NFClassTree.EMPTY, Modifier.NOMOD())),
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.INTEGER(), NFClassTree.EMPTY,
Modifier.NOMOD(), Restriction.TYPE())),
listArray({NFInstNode.CachedData.FUNCTION({NFBuiltinFuncs.INTEGER}, true, false), NFInstNode.CachedData.NO_CACHE(), NFInstNode.CachedData.NO_CACHE()}),
InstNode.EMPTY_NODE(), InstNodeType.NORMAL_CLASS());

Expand All @@ -136,7 +140,8 @@ constant ComponentRef INTEGER_CREF =

constant InstNode BOOLEAN_NODE = InstNode.CLASS_NODE("Boolean",
Elements.BOOLEAN,
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.BOOLEAN(), NFClassTree.EMPTY, Modifier.NOMOD())),
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.BOOLEAN(), NFClassTree.EMPTY,
Modifier.NOMOD(), Restriction.TYPE())),
arrayCreate(NFInstNode.NUMBER_OF_CACHES, NFInstNode.CachedData.NO_CACHE()),
InstNode.EMPTY_NODE(), InstNodeType.NORMAL_CLASS());

Expand All @@ -145,7 +150,8 @@ constant ComponentRef BOOLEAN_CREF =

constant InstNode STRING_NODE = InstNode.CLASS_NODE("String",
Elements.STRING,
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.STRING(), NFClassTree.EMPTY, Modifier.NOMOD())),
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.STRING(), NFClassTree.EMPTY,
Modifier.NOMOD(), Restriction.TYPE())),
listArray({ NFInstNode.CachedData.FUNCTION({
NFBuiltinFuncs.STRING_ENUM, NFBuiltinFuncs.STRING_INT,
NFBuiltinFuncs.STRING_BOOL, NFBuiltinFuncs.STRING_REAL,
Expand All @@ -162,7 +168,8 @@ constant ComponentRef STRING_CREF =

constant InstNode ENUM_NODE = InstNode.CLASS_NODE("enumeration",
Elements.ENUMERATION,
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.ENUMERATION_ANY(), NFClassTree.EMPTY, Modifier.NOMOD())),
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.ENUMERATION_ANY(), NFClassTree.EMPTY,
Modifier.NOMOD(), Restriction.ENUMERATION())),
arrayCreate(NFInstNode.NUMBER_OF_CACHES, NFInstNode.CachedData.NO_CACHE()),
InstNode.EMPTY_NODE(), InstNodeType.NORMAL_CLASS());

Expand All @@ -171,7 +178,8 @@ constant Type STATESELECT_TYPE = Type.ENUMERATION(

constant InstNode STATESELECT_NODE = InstNode.CLASS_NODE("StateSelect",
Elements.STATESELECT,
Pointer.createImmutable(Class.PARTIAL_BUILTIN(STATESELECT_TYPE, NFClassTree.EMPTY, Modifier.NOMOD())),
Pointer.createImmutable(Class.PARTIAL_BUILTIN(STATESELECT_TYPE, NFClassTree.EMPTY,
Modifier.NOMOD(), Restriction.ENUMERATION())),
arrayCreate(NFInstNode.NUMBER_OF_CACHES, NFInstNode.CachedData.NO_CACHE()),
InstNode.EMPTY_NODE(), InstNodeType.NORMAL_CLASS());

Expand Down Expand Up @@ -286,6 +294,12 @@ constant ComponentRef STATESELECT_ALWAYS_CREF =
constant Type ASSERTIONLEVEL_TYPE = Type.ENUMERATION(
Absyn.IDENT("AssertionLevel"), {"error", "warning"});

constant Expression ASSERTIONLEVEL_ERROR = Expression.ENUM_LITERAL(
ASSERTIONLEVEL_TYPE, "error", 1);

constant Expression ASSERTIONLEVEL_WARNING = Expression.ENUM_LITERAL(
ASSERTIONLEVEL_TYPE, "error", 2);

constant InstNode TIME =
InstNode.COMPONENT_NODE("time",
Pointer.createImmutable(Component.TYPED_COMPONENT(
Expand Down
12 changes: 12 additions & 0 deletions Compiler/NFFrontEnd/NFBuiltinFuncs.mo
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,17 @@ constant Function STRING_ENUM = Function.FUNCTION(Path.IDENT("String"),
Slot.SLOT("leftJustified", SlotType.NAMED, SOME(Expression.BOOLEAN(true)), NONE())
}, Type.STRING(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, Pointer.createImmutable(true));

constant Function ABS_REAL = Function.FUNCTION(Path.IDENT("abs"),
InstNode.EMPTY_NODE(), {REAL_PARAM, REAL_PARAM}, {REAL_PARAM}, {}, {},
Type.REAL(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, Pointer.createImmutable(true));

constant Function MAX_REAL = Function.FUNCTION(Path.IDENT("max"),
InstNode.EMPTY_NODE(), {REAL_PARAM, REAL_PARAM}, {REAL_PARAM}, {}, {},
Type.REAL(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, Pointer.createImmutable(true));

constant Function IN_STREAM = Function.FUNCTION(Path.IDENT("inStream"),
InstNode.EMPTY_NODE(), {REAL_PARAM}, {REAL_PARAM}, {}, {},
Type.REAL(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, Pointer.createImmutable(true));

annotation(__OpenModelica_Interface="frontend");
end NFBuiltinFuncs;
13 changes: 13 additions & 0 deletions Compiler/NFFrontEnd/NFCall.mo
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,19 @@ protected
fail();
end match;
end makeSizeCall;

function makeBuiltinCall
"Creates a call to a builtin function, given a Function and a list of
argument expressions."
input Function func;
input list<Expression> args;
output Call call;
algorithm
call := TYPED_CALL(func, args,
CallAttributes.CALL_ATTR(func.returnType, false, true, false, false,
DAE.NO_INLINE(), DAE.NO_TAIL()));
end makeBuiltinCall;

end Call;

annotation(__OpenModelica_Interface="frontend");
Expand Down
103 changes: 99 additions & 4 deletions Compiler/NFFrontEnd/NFClass.mo
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ import NFComponent.Component;
import Dimension = NFDimension;
import NFClassTree.ClassTree;
import NFSections.Sections;
import Restriction = NFRestriction;
import Expression = NFExpression;

protected
import Binding = NFBinding;

public
uniontype Class
uniontype Prefixes
record PREFIXES
Expand Down Expand Up @@ -72,6 +78,7 @@ uniontype Class
ClassTree elements;
Modifier modifier;
Class.Prefixes prefixes;
Restriction restriction;
end EXPANDED_CLASS;

record DERIVED_CLASS
Expand All @@ -80,23 +87,28 @@ uniontype Class
list<Dimension> dims;
Class.Prefixes prefixes;
Component.Attributes attributes;
Restriction restriction;
end DERIVED_CLASS;

record PARTIAL_BUILTIN
Type ty;
ClassTree elements;
Modifier modifier;
Restriction restriction;
end PARTIAL_BUILTIN;

record INSTANCED_CLASS
ClassTree elements;
Sections sections;
Type ty;
Restriction restriction;
end INSTANCED_CLASS;

record INSTANCED_BUILTIN
Type ty;
ClassTree elements;
list<Modifier> attributes;
Restriction restriction;
end INSTANCED_BUILTIN;

function fromSCode
Expand All @@ -120,15 +132,17 @@ uniontype Class
ClassTree tree;
algorithm
tree := ClassTree.fromEnumeration(literals, enumType, enumClass);
cls := PARTIAL_BUILTIN(enumType, tree, Modifier.NOMOD());
cls := PARTIAL_BUILTIN(enumType, tree, Modifier.NOMOD(),
Restriction.ENUMERATION());
end fromEnumeration;

function initExpandedClass
input output Class cls;
algorithm
cls := match cls
case PARTIAL_CLASS()
then EXPANDED_CLASS(cls.elements, cls.modifier, Prefixes.DEFAULT());
then EXPANDED_CLASS(cls.elements, cls.modifier, Prefixes.DEFAULT(),
Restriction.UNKNOWN());
end match;
end initExpandedClass;

Expand All @@ -137,8 +151,8 @@ uniontype Class
input output Class cls;
algorithm
cls := match cls
case EXPANDED_CLASS() then INSTANCED_CLASS(cls.elements, sections);
case INSTANCED_CLASS() then INSTANCED_CLASS(cls.elements, sections);
case INSTANCED_CLASS()
then INSTANCED_CLASS(cls.elements, sections, cls.ty, cls.restriction);
end match;
end setSections;

Expand All @@ -150,6 +164,38 @@ uniontype Class
node := ClassTree.lookupElement(name, classTree(cls));
end lookupElement;

function lookupAttribute
input String name;
input Class cls;
output Modifier attribute = Modifier.NOMOD();
algorithm
() := match cls
case INSTANCED_BUILTIN()
algorithm
for attr in cls.attributes loop
if Modifier.name(attr) == name then
attribute := attr;
break;
end if;
end for;
then
();

else ();
end match;
end lookupAttribute;

function lookupAttributeValue
input String name;
input Class cls;
output Option<Expression> value;
protected
Modifier attr;
algorithm
attr := lookupAttribute(name, cls);
value := Binding.typedExp(Modifier.binding(attr));
end lookupAttributeValue;

function isBuiltin
input Class cls;
output Boolean isBuiltin;
Expand Down Expand Up @@ -299,6 +345,55 @@ uniontype Class
end match;
end getTypeAttributes;

function getType
input Class cls;
input InstNode clsNode;
output Type ty;
algorithm
ty := match cls
case DERIVED_CLASS() then getType(InstNode.getClass(cls.baseClass), clsNode);
case INSTANCED_CLASS() then cls.ty;
case PARTIAL_BUILTIN() then cls.ty;
case INSTANCED_BUILTIN()
then match cls.ty
case Type.ANY_TYPE("unknown") then Type.ANY_TYPE(InstNode.name(clsNode));
else cls.ty;
end match;
else Type.UNKNOWN();
end match;
end getType;

function restriction
input Class cls;
output Restriction res;
algorithm
res := match cls
case INSTANCED_CLASS() then cls.restriction;
case INSTANCED_BUILTIN() then cls.restriction;
case EXPANDED_CLASS() then cls.restriction;
case PARTIAL_BUILTIN() then cls.restriction;
case DERIVED_CLASS() then cls.restriction;
else Restriction.UNKNOWN();
end match;
end restriction;

function setRestriction
input Restriction res;
input output Class cls;
algorithm
() := match cls
case INSTANCED_CLASS() algorithm cls.restriction := res; then ();
case INSTANCED_BUILTIN() algorithm cls.restriction := res; then ();
case EXPANDED_CLASS() algorithm cls.restriction := res; then ();
case DERIVED_CLASS() algorithm cls.restriction := res; then ();
end match;
end setRestriction;

function isConnectorClass
input Class cls;
output Boolean isConnector = Restriction.isConnector(restriction(cls));
end isConnectorClass;

end Class;

annotation(__OpenModelica_Interface="frontend");
Expand Down
28 changes: 28 additions & 0 deletions Compiler/NFFrontEnd/NFClassTree.mo
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,34 @@ public
arrayUpdate(getExtends(tree), 1, extNode);
end setClassExtends;

function enumerateComponents
input ClassTree tree;
output list<InstNode> components;
protected
LookupTree.Tree ltree;
array<InstNode> comps;
algorithm
FLAT_TREE(tree = ltree, components = comps) := tree;
components := LookupTree.fold(ltree, function enumerateComponents2(comps = comps), {});
end enumerateComponents;

function enumerateComponents2
input String name;
input LookupTree.Entry entry;
input array<InstNode> comps;
input output list<InstNode> components;
algorithm
() := match entry
case LookupTree.Entry.COMPONENT()
algorithm
components := comps[entry.index] :: components;
then
();

else ();
end match;
end enumerateComponents2;

protected

function instExtendsComps
Expand Down

0 comments on commit 75a3089

Please sign in to comment.