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

Commit

Permalink
Redesigned NFInst to eliminate InstanceTree.
Browse files Browse the repository at this point in the history
- Changed NFInstNode to contain a mutable instance, instead of using
  indices to an array of all classes.
- Added NFComponentNode which is similar to NFInstNode but for
  components, to allow for a bidirectional instance tree.
- This is work in progress, expect things to be broken.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 3, 2016
1 parent bc49d1d commit 1081354
Show file tree
Hide file tree
Showing 12 changed files with 1,077 additions and 915 deletions.
9 changes: 5 additions & 4 deletions Compiler/NFFrontEnd/NFBinding.mo
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ encapsulated package NFBinding
"

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

protected
import Dump;
Expand All @@ -52,15 +53,15 @@ uniontype Binding
Absyn.Exp bindingExp;
SCode.Final finalPrefix;
SCode.Each eachPrefix;
Integer scope;
InstNode scope;
Integer propagatedDims;
SourceInfo info;
end RAW_BINDING;

record UNTYPED_BINDING
Absyn.Exp bindingExp;
Boolean isProcessing;
Integer scope;
InstNode scope;
Integer propagatedDims;
SourceInfo info;
end UNTYPED_BINDING;
Expand All @@ -77,7 +78,7 @@ public
input Option<Absyn.Exp> bindingExp;
input SCode.Final finalPrefix;
input SCode.Each eachPrefix;
input Integer scope;
input InstNode scope;
input Integer dimensions;
input SourceInfo info;
output Binding binding;
Expand Down
33 changes: 3 additions & 30 deletions Compiler/NFFrontEnd/NFComponent.mo
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ uniontype Component
record COMPONENT_DEF
Element definition;
Modifier modifier;
Integer scope;
end COMPONENT_DEF;

record UNTYPED_COMPONENT
String name;
InstNode classInst;
array<Dimension> dimensions;
Binding binding;
Expand All @@ -64,7 +62,6 @@ uniontype Component
end UNTYPED_COMPONENT;

record TYPED_COMPONENT
String name;
InstNode classInst;
Type ty;
Binding binding;
Expand All @@ -76,23 +73,10 @@ uniontype Component
end EXTENDS_NODE;

record COMPONENT_REF
String name;
Integer node;
Integer index;
end COMPONENT_REF;

function name
input Component component;
output String name;
algorithm
name := match component
case COMPONENT_DEF(definition = SCode.COMPONENT(name = name)) then name;
case UNTYPED_COMPONENT() then component.name;
case TYPED_COMPONENT() then component.name;
case COMPONENT_REF() then component.name;
end match;
end name;

function isNamedComponent
input Component component;
output Boolean isNamed;
Expand All @@ -117,7 +101,7 @@ uniontype Component
input Modifier modifier;
input output Component component;
algorithm
_ := match component
() := match component
case COMPONENT_DEF()
algorithm
component.modifier := modifier;
Expand All @@ -141,8 +125,7 @@ uniontype Component
algorithm
component := match component
case UNTYPED_COMPONENT()
then TYPED_COMPONENT(component.name, component.classInst, ty,
component.binding, component.attributes);
then TYPED_COMPONENT(component.classInst, ty, component.binding, component.attributes);

case TYPED_COMPONENT()
algorithm
Expand All @@ -155,7 +138,7 @@ uniontype Component
function unliftType
input output Component component;
algorithm
_ := match component
() := match component
local
DAE.Type ty;

Expand All @@ -168,16 +151,6 @@ uniontype Component
else ();
end match;
end unliftType;

function makeTopComponent
input InstNode inst;
output Component comp;
algorithm
comp := TYPED_COMPONENT(InstNode.name(inst), inst, DAE.T_UNKNOWN_DEFAULT,
Binding.UNBOUND(), Attributes.ATTRIBUTES(
DAE.VarKind.VARIABLE(), DAE.VarDirection.BIDIR(),
DAE.VarVisibility.PUBLIC(), DAE.ConnectorType.NON_CONNECTOR()));
end makeTopComponent;
end Component;

annotation(__OpenModelica_Interface="frontend");
Expand Down
196 changes: 196 additions & 0 deletions Compiler/NFFrontEnd/NFComponentNode.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@

/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/

encapsulated package NFComponentNode

import NFComponent.Component;
import NFMod.Modifier;
import SCode.Element;
import NFInstNode.InstNode;

uniontype ComponentNode
record COMPONENT_NODE
String name;
Element definition;
array<Component> component;
ComponentNode parent;
end COMPONENT_NODE;

record EMPTY_NODE end EMPTY_NODE;

function new
input String name;
input Element definition;
input ComponentNode parent = EMPTY_NODE();
output ComponentNode node;
protected
array<Component> c;
algorithm
c := arrayCreate(1, Component.COMPONENT_DEF(definition, Modifier.NOMOD()));
node := COMPONENT_NODE(name, definition, c, parent);
end new;

function newExtends
input InstNode extendsNode;
input Element definition;
output ComponentNode node;
protected
array<Component> c;
algorithm
c := arrayCreate(1, Component.EXTENDS_NODE(extendsNode));
node := COMPONENT_NODE("", definition, c, EMPTY_NODE());
end newExtends;

function newReference
input output ComponentNode component;
input Integer nodeIndex;
input Integer componentIndex;
algorithm
component := clone(component);
component := setComponent(Component.COMPONENT_REF(nodeIndex, componentIndex), component);
end newReference;

function name
input ComponentNode node;
output String name;
algorithm
COMPONENT_NODE(name = name) := node;
end name;

function rename
input output ComponentNode node;
input String name;
algorithm
() := match node
case COMPONENT_NODE()
algorithm
node.name := name;
then
();
end match;
end rename;

function parent
input ComponentNode node;
output ComponentNode parentNode;
algorithm
COMPONENT_NODE(parent = parentNode) := node;
end parent;

function setParent
input ComponentNode parent;
input output ComponentNode node;
algorithm
() := match node
case COMPONENT_NODE()
algorithm
node.parent := parent;
then
();
end match;
end setParent;

function component
input ComponentNode node;
output Component component;
algorithm
component := match node
case COMPONENT_NODE() then node.component[1];
end match;
end component;

function setComponent
input Component component;
input output ComponentNode node;
algorithm
node := match node
case COMPONENT_NODE()
algorithm
arrayUpdate(node.component, 1, component);
then
node;
end match;
end setComponent;

function definition
input ComponentNode node;
output SCode.Element definition;
algorithm
COMPONENT_NODE(definition = definition) := node;
end definition;

function setDefinition
input SCode.Element definition;
input output ComponentNode node;
algorithm
() := match node
case COMPONENT_NODE()
algorithm
node.definition := definition;
then
();
end match;
end setDefinition;

function clone
input ComponentNode node;
output ComponentNode clone;
algorithm
clone := match node
case COMPONENT_NODE()
then COMPONENT_NODE(node.name, node.definition, arrayCopy(node.component), node.parent);
else node;
end match;
end clone;

function apply<ArgT>
input output ComponentNode node;
input FuncType func;
input ArgT arg;

partial function FuncType
input ArgT arg;
input output Component node;
end FuncType;
algorithm
() := match node
case COMPONENT_NODE()
algorithm
node.component[1] := func(arg, node.component[1]);
then
();
end match;
end apply;
end ComponentNode;

annotation(__OpenModelica_Interface="frontend");
end NFComponentNode;

0 comments on commit 1081354

Please sign in to comment.