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

Commit

Permalink
NFInst clean up.
Browse files Browse the repository at this point in the history
- Remove some parts of Component which are already in InstNode.
- Use an InstNode in NFMod.REDECLARE instead of keeping the element
  and scope separate.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Dec 13, 2016
1 parent c978947 commit a617ea7
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 26 deletions.
2 changes: 0 additions & 2 deletions Compiler/NFFrontEnd/NFComponent.mo
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ uniontype Component
end Attributes;

record COMPONENT_DEF
Element definition;
Modifier modifier;
end COMPONENT_DEF;

Expand All @@ -93,7 +92,6 @@ uniontype Component
array<Dimension> dimensions;
Binding binding;
Component.Attributes attributes;
SourceInfo info;
end UNTYPED_COMPONENT;

record TYPED_COMPONENT
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFFunc.mo
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ algorithm
fn_name := InstNode.name(classNode);
cls := InstNode.definition(classNode);
// create a component that has the name of the function and the scope of the function as its type
fakeComponent := InstNode.newComponent(fn_name,
fakeComponent := InstNode.newComponent(
SCode.COMPONENT(
fn_name,
SCode.defaultPrefixes,
Expand Down
24 changes: 11 additions & 13 deletions Compiler/NFFrontEnd/NFInst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ algorithm
SCode.COMMENT(NONE(), NONE()), Absyn.dummyInfo);

// Make an InstNode for the top scope.
topNode := InstNode.newClass("<top>", cls, InstNode.EMPTY_NODE(), InstNodeType.TOP_SCOPE());
topNode := InstNode.newClass(cls, InstNode.EMPTY_NODE(), InstNodeType.TOP_SCOPE());

// Create a scope from the top classes, and insert them into the top scope class.
scope := makeScope(topClasses, topNode);
Expand All @@ -163,7 +163,7 @@ algorithm
// A class, create a new instance node for it and add it to the tree.
case SCode.CLASS()
algorithm
node := InstNode.newClass(e.name, e, parentScope);
node := InstNode.newClass(e, parentScope);
scope := addClassToScope(e.name, ClassTree.Entry.CLASS(node), e.info, scope);
then
();
Expand Down Expand Up @@ -453,7 +453,7 @@ algorithm
case SCode.COMPONENT()
algorithm
// A component, add it to the list of components.
components := InstNode.newComponent(e.name, e) :: components;
components := InstNode.newComponent(e) :: components;
then
();

Expand Down Expand Up @@ -565,9 +565,8 @@ algorithm

case Modifier.REDECLARE()
algorithm
node := InstNode.newClass(SCode.elementName(m.element), m.element, m.scope);
elements := ClassTree.add(elements, InstNode.name(node),
ClassTree.Entry.CLASS(node), ClassTree.addConflictReplace);
elements := ClassTree.add(elements, InstNode.name(m.element),
ClassTree.Entry.CLASS(m.element), ClassTree.addConflictReplace);
then
();

Expand Down Expand Up @@ -752,17 +751,16 @@ protected
list<Dimension> dims;
algorithm
component := InstNode.component(node);
comp := InstNode.definition(node);

() := match component
case Component.COMPONENT_DEF(modifier = comp_mod as Modifier.REDECLARE())
() := match (component, comp)
case (Component.COMPONENT_DEF(modifier = comp_mod as Modifier.REDECLARE()), _)
algorithm
component := Component.COMPONENT_DEF(comp_mod.element, Modifier.NOMOD());
node := InstNode.updateComponent(component, node);
node := instComponent(node, parent, comp_mod.scope);
node := instComponent(comp_mod.element, parent, InstNode.parent(comp_mod.element));
then
();

case Component.COMPONENT_DEF(definition = comp as SCode.COMPONENT())
case (Component.COMPONENT_DEF(), SCode.COMPONENT())
algorithm
name := InstNode.name(node);
node := InstNode.setOrphanParent(parent, node);
Expand All @@ -784,7 +782,7 @@ algorithm

// Instantiate attributes and create the untyped component.
attr := instComponentAttributes(comp.attributes, comp.prefixes);
inst_comp := Component.UNTYPED_COMPONENT(cls, listArray(dims), binding, attr, comp.info);
inst_comp := Component.UNTYPED_COMPONENT(cls, listArray(dims), binding, attr);
node := InstNode.updateComponent(inst_comp, node);
then
();
Expand Down
43 changes: 40 additions & 3 deletions Compiler/NFFrontEnd/NFInstNode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,68 @@ uniontype InstNode

record EMPTY_NODE end EMPTY_NODE;

function new
input SCode.Element definition;
input InstNode parent;
output InstNode node;
algorithm
node := match definition
case SCode.CLASS()
then CLASS_NODE(definition.name, definition,
arrayCreate(1, Class.NOT_INSTANTIATED()), parent, NORMAL_CLASS());
case SCode.COMPONENT()
then COMPONENT_NODE(definition.name, definition,
arrayCreate(1, Component.COMPONENT_DEF(Modifier.NOMOD())), parent);
end match;
end new;

function newClass
input String name;
input SCode.Element definition;
input InstNode parent;
input InstNodeType nodeType = NORMAL_CLASS();
output InstNode node;
protected
array<Class> i;
String name;
algorithm
SCode.CLASS(name = name) := definition;
i := arrayCreate(1, Class.NOT_INSTANTIATED());
node := CLASS_NODE(name, definition, i, parent, nodeType);
end newClass;

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

function isClass
input InstNode node;
output Boolean isClass;
algorithm
isClass := match node
case CLASS_NODE() then true;
else false;
end match;
end isClass;

function isComponent
input InstNode node;
output Boolean isComponent;
algorithm
isComponent := match node
case COMPONENT_NODE() then true;
else false;
end match;
end isComponent;

function name
input InstNode node;
output String name;
Expand Down
10 changes: 4 additions & 6 deletions Compiler/NFFrontEnd/NFMod.mo
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ uniontype Modifier
record REDECLARE
SCode.Final finalPrefix;
SCode.Each eachPrefix;
SCode.Element element;
InstNode scope;
InstNode element;
end REDECLARE;

record NOMOD end NOMOD;
Expand Down Expand Up @@ -162,7 +161,7 @@ public
MODIFIER(name, mod.finalPrefix, mod.eachPrefix, binding, submod_table, mod.info);

case SCode.REDECL()
then REDECLARE(mod.finalPrefix, mod.eachPrefix, mod.element, scope);
then REDECLARE(mod.finalPrefix, mod.eachPrefix, InstNode.new(mod.element, scope));

end match;
end create;
Expand All @@ -184,8 +183,7 @@ public
algorithm
name := match modifier
case MODIFIER() then modifier.name;
case REDECLARE(element = SCode.COMPONENT(name = name)) then name;
case REDECLARE(element = SCode.CLASS(name = name)) then name;
case REDECLARE() then InstNode.name(modifier.element);
end match;
end name;

Expand All @@ -195,7 +193,7 @@ public
algorithm
info := match modifier
case MODIFIER() then modifier.info;
case REDECLARE() then SCode.elementInfo(modifier.element);
case REDECLARE() then InstNode.info(modifier.element);
else Absyn.dummyInfo;
end match;
end info;
Expand Down
3 changes: 2 additions & 1 deletion Compiler/NFFrontEnd/NFTyping.mo
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ protected
algorithm
() := match c
// An untyped component, type it.
case Component.UNTYPED_COMPONENT(dimensions = dims, info = info)
case Component.UNTYPED_COMPONENT(dimensions = dims)
algorithm
ty_dims := {};
info := InstNode.info(component);

for i in 1:arrayLength(dims) loop
dims[i] := typeDimension(dims[i], parent, info);
Expand Down

0 comments on commit a617ea7

Please sign in to comment.