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

Commit

Permalink
Handle package constants in nfinst.
Browse files Browse the repository at this point in the history
- Implemented new phase that collects used package constants and adds
  them to the flat model to make it complete.
- Implemented ComponentRef.compare.

Belonging to [master]:
  - #1996
  - OpenModelica/OpenModelica-testsuite#772
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 8, 2017
1 parent 2a409cd commit 9b63a0e
Show file tree
Hide file tree
Showing 10 changed files with 453 additions and 28 deletions.
14 changes: 7 additions & 7 deletions Compiler/NFFrontEnd/NFBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ constant InstNode ANYTYPE_NODE = InstNode.CLASS_NODE("polymorphic",
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());
InstNode.EMPTY_NODE(), InstNodeType.BUILTIN_CLASS());

constant InstNode REAL_NODE = InstNode.CLASS_NODE("Real",
Elements.REAL, Visibility.PUBLIC,
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());
InstNode.EMPTY_NODE(), InstNodeType.BUILTIN_CLASS());

constant InstNode INTEGER_NODE = InstNode.CLASS_NODE("Integer",
Elements.INTEGER, Visibility.PUBLIC,
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());
InstNode.EMPTY_NODE(), InstNodeType.BUILTIN_CLASS());

constant ComponentRef INTEGER_CREF =
ComponentRef.CREF(INTEGER_NODE, {}, Type.INTEGER(), Origin.CREF, ComponentRef.EMPTY());
Expand All @@ -144,7 +144,7 @@ constant InstNode BOOLEAN_NODE = InstNode.CLASS_NODE("Boolean",
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());
InstNode.EMPTY_NODE(), InstNodeType.BUILTIN_CLASS());

constant ComponentRef BOOLEAN_CREF =
ComponentRef.CREF(BOOLEAN_NODE, {}, Type.INTEGER(), Origin.CREF, ComponentRef.EMPTY());
Expand All @@ -162,7 +162,7 @@ constant InstNode STRING_NODE = InstNode.CLASS_NODE("String",
NFInstNode.CachedData.NO_CACHE(),
NFInstNode.CachedData.NO_CACHE()}
),
InstNode.EMPTY_NODE(), InstNodeType.NORMAL_CLASS());
InstNode.EMPTY_NODE(), InstNodeType.BUILTIN_CLASS());

constant ComponentRef STRING_CREF =
ComponentRef.CREF(STRING_NODE, {}, Type.INTEGER(), Origin.CREF, ComponentRef.EMPTY());
Expand All @@ -172,7 +172,7 @@ constant InstNode ENUM_NODE = InstNode.CLASS_NODE("enumeration",
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());
InstNode.EMPTY_NODE(), InstNodeType.BUILTIN_CLASS());

constant Type STATESELECT_TYPE = Type.ENUMERATION(
Absyn.IDENT("StateSelect"), {"never", "avoid", "default", "prefer", "always"});
Expand All @@ -182,7 +182,7 @@ constant InstNode STATESELECT_NODE = InstNode.CLASS_NODE("StateSelect",
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());
InstNode.EMPTY_NODE(), InstNodeType.BUILTIN_CLASS());

constant ComponentRef STATESELECT_CREF =
ComponentRef.CREF(STATESELECT_NODE, {}, STATESELECT_TYPE, Origin.CREF, ComponentRef.EMPTY());
Expand Down
47 changes: 45 additions & 2 deletions Compiler/NFFrontEnd/NFComponentRef.mo
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected
import Subscript = NFSubscript;
import Type = NFType;
import NFInstNode.InstNode;
import NFInstNode.InstNodeType;
import RangeIterator = NFRangeIterator;
import Dimension = NFDimension;
import Expression = NFExpression;
Expand Down Expand Up @@ -343,9 +344,29 @@ public
function compare
input ComponentRef cref1;
input ComponentRef cref2;
output Integer comp = 0;
output Integer comp;
algorithm
assert(false, getInstanceName() + ": IMPLEMENT ME");
comp := match (cref1, cref2)
case (CREF(), CREF())
algorithm
comp := stringCompare(InstNode.name(cref1.node), InstNode.name(cref2.node));

if comp <> 0 then
return;
end if;

comp := Subscript.compareList(cref1.subscripts, cref2.subscripts);

if comp <> 0 then
return;
end if;
then
compare(cref1.restCref, cref2.restCref);

case (EMPTY(), EMPTY()) then 0;
case (_, EMPTY()) then 1;
case (EMPTY(), _) then -1;
end match;
end compare;

function isEqual
Expand Down Expand Up @@ -499,5 +520,27 @@ public
end match;
end scalarize;

function isPackageConstant
input ComponentRef cref;
output Boolean isPkgConst;
algorithm
isPkgConst := match cref
case CREF(node = InstNode.CLASS_NODE(nodeType = InstNodeType.NORMAL_CLASS())) then true;
case CREF(origin = Origin.CREF) then isPackageConstant(cref.restCref);
else false;
end match;
end isPackageConstant;

function stripSubscriptsAll
input ComponentRef cref;
output ComponentRef strippedCref;
algorithm
strippedCref := match cref
case CREF()
then CREF(cref.node, {}, cref.ty, cref.origin, stripSubscriptsAll(cref.restCref));
else cref;
end match;
end stripSubscriptsAll;

annotation(__OpenModelica_Interface="frontend");
end NFComponentRef;
7 changes: 0 additions & 7 deletions Compiler/NFFrontEnd/NFConnectionSets.mo
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,13 @@
*/

encapsulated package NFConnectionSets
import BaseHashTable;
import Connect;
import DAE;
import DisjointSets;

import Connector = NFConnector;
import Connection = NFConnection;

protected
import Array;
import Flags;
import List;
import System;
import Util;

public
uniontype Connections
Expand Down
12 changes: 4 additions & 8 deletions Compiler/NFFrontEnd/NFExpression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -433,25 +433,21 @@ public
input list<Expression> expl2;
output Integer comp;
protected
Integer len1, len2;
Expression e2;
list<Expression> rest_expl2 = expl2;
Integer len1, len2;
algorithm
// Check that the lists have the same length, otherwise they can't be equal.
len1 := listLength(expl1);
len2 := listLength(expl2);
comp := Util.intCompare(len1, len2);
comp := Util.intCompare(listLength(expl1), listLength(expl2));
if comp <> 0 then
return;
end if;

for e1 in expl1 loop
e2 :: rest_expl2 := rest_expl2;

// Return false if the expressions are not equal.
comp := compare(e1, e2);
if 0 <> comp then

// Return if the expressions are not equal.
if comp <> 0 then
return;
end if;
end for;
Expand Down
4 changes: 0 additions & 4 deletions Compiler/NFFrontEnd/NFFlatten.mo
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ algorithm
flattenClass(InstNode.getClass(classInst), ComponentRef.EMPTY(), {}, sections);
comps := listReverseInPlace(comps);

//conns := Connections.new();
//(elems, funcs, conns) := flattenNode(classInst, ComponentRef.EMPTY(), {}, funcs, conns);
//elems := resolveConnections(conns, elems);

elems := match sections
case Sections.SECTIONS()
algorithm
Expand Down
3 changes: 3 additions & 0 deletions Compiler/NFFrontEnd/NFInst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import ConvertDAE = NFConvertDAE;
import Scalarize = NFScalarize;
import Restriction = NFRestriction;
import ComplexType = NFComplexType;
import Package = NFPackage;

type EquationScope = enumeration(NORMAL, INITIAL, WHEN);

Expand Down Expand Up @@ -135,6 +136,8 @@ algorithm

// Flatten and convert the class into a DAE.
(elems, funcs) := Flatten.flatten(inst_cls, name);
elems := Package.collectConstants(elems);

elems := Scalarize.scalarize(elems, name);
(dae, daeFuncs) := ConvertDAE.convert(elems, funcs, name, InstNode.info(inst_cls));

Expand Down
8 changes: 8 additions & 0 deletions Compiler/NFFrontEnd/NFInstNode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ uniontype InstNodeType
SCode.Element definition;
end BASE_CLASS;

record BUILTIN_CLASS
"A builtin class."
end BUILTIN_CLASS;

record TOP_SCOPE
"The unnamed class containing all the top-level classes."
end TOP_SCOPE;
Expand Down Expand Up @@ -706,6 +710,8 @@ uniontype InstNode
then scopeList(node.parentScope, node :: accumScopes);
case InstNodeType.BASE_CLASS()
then scopeList(it.parent, accumScopes);
case InstNodeType.BUILTIN_CLASS()
then node :: accumScopes;
else accumScopes;
end match;

Expand Down Expand Up @@ -754,6 +760,8 @@ uniontype InstNode
then scopePath2(node.parentScope, Absyn.QUALIFIED(node.name, accumPath));
case InstNodeType.BASE_CLASS()
then scopePath2(it.parent, accumPath);
case InstNodeType.BUILTIN_CLASS()
then Absyn.QUALIFIED(node.name, accumPath);
else accumPath;
end match;

Expand Down

0 comments on commit 9b63a0e

Please sign in to comment.