Skip to content

Commit

Permalink
NFInst improvements.
Browse files Browse the repository at this point in the history
- Merge the class and instance tree by merging ComponentNode into
  InstNode.
- Renamed NFInstance to NFClass.
- Removed Component.EXTENDS_NODE, use class InstNode instead.
- Improved lookupCref to be able to start with a class scope, to get rid
  of fake components.
- Got rid of Lookup.LookupResult, not needed with new InstNode.
- Got rid of Component.Scope, use InstNode as binding scope instead.
- Cleaned up lots of obsolete code.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Dec 9, 2016
1 parent 926c35e commit 8c0a156
Show file tree
Hide file tree
Showing 16 changed files with 809 additions and 1,476 deletions.
8 changes: 3 additions & 5 deletions Compiler/NFFrontEnd/NFBinding.mo
Expand Up @@ -38,7 +38,6 @@ encapsulated package NFBinding

public
import DAE;
import NFComponent.Component;
import NFInstNode.InstNode;
import SCode;

Expand All @@ -52,15 +51,15 @@ uniontype Binding

record RAW_BINDING
Absyn.Exp bindingExp;
Component.Scope scope;
InstNode scope;
Integer propagatedDims;
SourceInfo info;
end RAW_BINDING;

record UNTYPED_BINDING
Absyn.Exp bindingExp;
Boolean isProcessing;
Component.Scope scope;
InstNode scope;
Integer propagatedDims;
SourceInfo info;
end UNTYPED_BINDING;
Expand All @@ -78,19 +77,18 @@ public
input Option<Absyn.Exp> bindingExp;
input SCode.Each eachPrefix;
input Integer dimensions;
input InstNode scope;
input SourceInfo info;
output Binding binding;
algorithm
binding := match bindingExp
local
Absyn.Exp exp;
Integer pd;
Component.Scope scope;

case SOME(exp)
algorithm
pd := if SCode.eachBool(eachPrefix) then -1 else dimensions;
scope := Component.Scope.RELATIVE_COMP(0);
then
RAW_BINDING(exp, scope, pd, info);

Expand Down
153 changes: 60 additions & 93 deletions Compiler/NFFrontEnd/NFInstance.mo → Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -29,10 +29,9 @@
*
*/

encapsulated package NFInstance
encapsulated package NFClass

import BaseAvlTree;
import NFComponentNode.ComponentNode;
import NFEquation.Equation;
import NFInstNode.InstNode;
import NFMod.Modifier;
Expand All @@ -54,7 +53,6 @@ encapsulated package ClassTree

import BaseAvlTree;
import NFInstNode.InstNode;
import NFComponentNode.ComponentNode;

extends BaseAvlTree(redeclare type Key = String,
redeclare type Value = Entry);
Expand All @@ -80,7 +78,7 @@ encapsulated package ClassTree
annotation(__OpenModelica_Interface="util");
end ClassTree;

uniontype Instance
uniontype Class
record NOT_INSTANTIATED end NOT_INSTANTIATED;

record PARTIAL_CLASS
Expand All @@ -91,8 +89,8 @@ uniontype Instance

record EXPANDED_CLASS
ClassTree.Tree elements;
list<ComponentNode> extendsNodes;
array<ComponentNode> components;
list<InstNode> extendsNodes;
array<InstNode> components;
Modifier modifier;
list<Equation> equations;
list<Equation> initialEquations;
Expand All @@ -102,7 +100,7 @@ uniontype Instance

record INSTANCED_CLASS
ClassTree.Tree elements;
array<ComponentNode> components;
array<InstNode> components;
list<Equation> equations;
list<Equation> initialEquations;
list<list<Statement>> algorithms;
Expand All @@ -122,22 +120,22 @@ uniontype Instance
type Element = ClassTree.Entry;

function emptyInstancedClass
output Instance instance;
output Class cls;
algorithm
instance := INSTANCED_CLASS(ClassTree.new(), listArray({}), {}, {}, {}, {});
cls := INSTANCED_CLASS(ClassTree.new(), listArray({}), {}, {}, {}, {});
end emptyInstancedClass;

function initExpandedClass
input ClassTree.Tree classes;
output Instance instance;
output Class cls;
algorithm
instance := EXPANDED_CLASS(classes, {}, listArray({}), Modifier.NOMOD(), {}, {}, {}, {});
cls := EXPANDED_CLASS(classes, {}, listArray({}), Modifier.NOMOD(), {}, {}, {}, {});
end initExpandedClass;

function instExpandedClass
input array<ComponentNode> components;
input Instance expandedClass;
output Instance instancedClass;
input array<InstNode> components;
input Class expandedClass;
output Class instancedClass;
algorithm
instancedClass := match expandedClass
case EXPANDED_CLASS()
Expand All @@ -148,48 +146,48 @@ uniontype Instance
end instExpandedClass;

function components
input Instance instance;
output array<ComponentNode> components;
input Class cls;
output array<InstNode> components;
algorithm
components := match instance
case EXPANDED_CLASS() then instance.components;
case INSTANCED_CLASS() then instance.components;
components := match cls
case EXPANDED_CLASS() then cls.components;
case INSTANCED_CLASS() then cls.components;
end match;
end components;

function setComponents
input array<ComponentNode> components;
input output Instance instance;
input array<InstNode> components;
input output Class cls;
algorithm
_ := match instance
_ := match cls
case EXPANDED_CLASS()
algorithm
instance.components := components;
cls.components := components;
then
();

case INSTANCED_CLASS()
algorithm
instance.components := components;
cls.components := components;
then
();
end match;
end setComponents;

function setElements
input ClassTree.Tree elements;
input output Instance instance;
input output Class cls;
algorithm
_ := match instance
_ := match cls
case EXPANDED_CLASS()
algorithm
instance.elements := elements;
cls.elements := elements;
then
();

case INSTANCED_CLASS()
algorithm
instance.elements := elements;
cls.elements := elements;
then
();
end match;
Expand All @@ -200,76 +198,45 @@ uniontype Instance
input list<Equation> initialEquations;
input list<list<Statement>> algorithms;
input list<list<Statement>> initialAlgorithms;
input output Instance instance;
input output Class cls;
algorithm
instance := match instance
cls := match cls
case EXPANDED_CLASS()
then EXPANDED_CLASS(instance.elements, instance.extendsNodes, instance.components,
instance.modifier, equations, initialEquations, algorithms, initialAlgorithms);
then EXPANDED_CLASS(cls.elements, cls.extendsNodes, cls.components,
cls.modifier, equations, initialEquations, algorithms, initialAlgorithms);

case INSTANCED_CLASS()
then INSTANCED_CLASS(instance.elements, instance.components, equations,
then INSTANCED_CLASS(cls.elements, cls.components, equations,
initialEquations, algorithms, initialAlgorithms);
end match;
end setSections;

function lookupElement
input String name;
input Instance instance;
output Element element;
input Class cls;
output InstNode node;
protected
ClassTree.Tree scope;
Class.Element element;
algorithm
scope := match instance
case EXPANDED_CLASS() then instance.elements;
case INSTANCED_CLASS() then instance.elements;
scope := match cls
case EXPANDED_CLASS() then cls.elements;
case INSTANCED_CLASS() then cls.elements;
end match;

element := ClassTree.get(scope, name);
end lookupElement;

function lookupClass
input String name;
input Instance instance;
output InstNode cls;
algorithm
Element.CLASS(node = cls) := lookupElement(name, instance);
end lookupClass;

function lookupComponent
input String name;
input Instance instance;
output ComponentNode component;
protected
Integer index;
algorithm
component := lookupComponentByElement(lookupElement(name, instance), instance);
end lookupComponent;

function lookupComponentByIndex
input Integer index;
input Instance instance;
output ComponentNode component;
algorithm
component := arrayGet(components(instance), index);
end lookupComponentByIndex;

function lookupComponentByElement
input Element element;
input Instance instance;
output ComponentNode component;
protected
Integer index;
algorithm
Element.COMPONENT(index = index) := element;
component := arrayGet(components(instance), index);
end lookupComponentByElement;
node := match element
case Element.CLASS() then element.node;
case Element.COMPONENT() then arrayGet(components(cls), element.index);
end match;
end lookupElement;

function isBuiltin
input Instance instance;
input Class cls;
output Boolean isBuiltin;
algorithm
isBuiltin := match instance
isBuiltin := match cls
case PARTIAL_BUILTIN() then true;
case INSTANCED_BUILTIN() then true;
else false;
Expand All @@ -278,24 +245,24 @@ uniontype Instance

function setModifier
input Modifier modifier;
input output Instance instance;
input output Class cls;
algorithm
_ := match instance
_ := match cls
case PARTIAL_CLASS()
algorithm
instance.modifier := modifier;
cls.modifier := modifier;
then
();

case EXPANDED_CLASS()
algorithm
instance.modifier := modifier;
cls.modifier := modifier;
then
();

case PARTIAL_BUILTIN()
algorithm
instance.modifier := modifier;
cls.modifier := modifier;
then
();

Expand All @@ -309,21 +276,21 @@ uniontype Instance
end setModifier;

function getModifier
input Instance instance;
input Class cls;
output Modifier modifier;
algorithm
modifier := match instance
case PARTIAL_CLASS() then instance.modifier;
case EXPANDED_CLASS() then instance.modifier;
case PARTIAL_BUILTIN() then instance.modifier;
modifier := match cls
case PARTIAL_CLASS() then cls.modifier;
case EXPANDED_CLASS() then cls.modifier;
case PARTIAL_BUILTIN() then cls.modifier;
else Modifier.NOMOD();
end match;
end getModifier;

function clone
input output Instance instance;
input output Class cls;
algorithm
() := match instance
() := match cls
local
ClassTree.Tree tree;

Expand All @@ -336,14 +303,14 @@ uniontype Instance
case EXPANDED_CLASS()
algorithm
//instance.elements := ClassTree.map(instance.elements, cloneEntry);
instance.components := Array.map(instance.components, ComponentNode.clone);
cls.components := Array.map(cls.components, InstNode.clone);
then
();

case INSTANCED_CLASS()
algorithm
//instance.elements := ClassTree.map(instance.elements, cloneEntry);
instance.components := Array.map(instance.components, ComponentNode.clone);
cls.components := Array.map(cls.components, InstNode.clone);
then
();

Expand All @@ -361,7 +328,7 @@ uniontype Instance
else entry;
end match;
end cloneEntry;
end Instance;
end Class;

annotation(__OpenModelica_Interface="frontend");
end NFInstance;
end NFClass;

0 comments on commit 8c0a156

Please sign in to comment.