Skip to content

Commit

Permalink
- Don't return the class from InstSymbolTable.addClass, it's no longe…
Browse files Browse the repository at this point in the history
…r needed

  since classes are flattened in SCodeInst.instClassItem.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13986 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Nov 20, 2012
1 parent 14915b6 commit bf001f1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 67 deletions.
83 changes: 21 additions & 62 deletions Compiler/FrontEnd/InstSymbolTable.mo
Expand Up @@ -156,10 +156,9 @@ public function build
class with the duplicate elements removed is returned along with the new
symboltable."
input Class inClass;
output Class outClass;
output SymbolTable outSymbolTable;
algorithm
(outClass, outSymbolTable) := match(inClass)
outSymbolTable := match(inClass)
local
SymbolTable st;
Integer comp_size, bucket_size;
Expand All @@ -172,12 +171,12 @@ algorithm
comp_size = InstUtil.countElementsInClass(inClass);
bucket_size = Util.nextPrime(intDiv((comp_size * 4), 3)) + 1;
st = createSized(bucket_size);
(cls, st) = addClass(inClass, st);
st = addClass(inClass, st);
st = addAliases(inClass, st);
// Add the special variable time to the symboltable.
st = addUniqueComponent(Absyn.IDENT("time"), BUILTIN_TIME_COMP, st);
then
(cls, st);
st;

end match;
end build;
Expand Down Expand Up @@ -250,29 +249,25 @@ algorithm
end get;

public function addClass
"Adds the elements of a given class to the symboltable."
"Adds the components of a given class to the symboltable."
input Class inClass;
input SymbolTable inSymbolTable;
output Class outClass;
output SymbolTable outSymbolTable;
algorithm
(outClass, outSymbolTable) := match(inClass, inSymbolTable)
outSymbolTable := match(inClass, inSymbolTable)
local
list<Element> comps;
list<Equation> eq, ieq;
list<list<Statement>> al, ial;
SymbolTable st;
Absyn.Path name;

// A basic type doesn't have any elements, nothing to add.
// A basic type doesn't have any components, nothing to add.
case (InstTypes.BASIC_TYPE(name), st) then (inClass, st);

// A complex class, add it's elements to the symboltable.
case (InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), st)
equation
(comps, st) = addElements(comps, st);
then
(InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), st);
// A complex class, add its components to the symboltable.
case (InstTypes.COMPLEX_CLASS(components = comps), st)
then addElements(comps, st);

end match;
end addClass;
Expand All @@ -283,75 +278,36 @@ public function addElements
removed, as well as the updated symboltable."
input list<Element> inElements;
input SymbolTable inSymbolTable;
output list<Element> outElements;
output SymbolTable outSymbolTable;
algorithm
(outElements, outSymbolTable) :=
addElements2(inElements, inSymbolTable, {});
outSymbolTable := List.fold(inElements, addElement, inSymbolTable);
end addElements;

protected function addElements2
"Tail-recursive implementation of addElements."
input list<Element> inElements;
input SymbolTable inSymbolTable;
input list<Element> inAccumEl;
output list<Element> outElements;
output SymbolTable outSymbolTable;
algorithm
(outElements, outSymbolTable) := match(inElements, inSymbolTable, inAccumEl)
local
Element el;
list<Element> rest_el, accum_el;
Boolean added;
SymbolTable st;

case ({}, st, _) then (inAccumEl, st);

case (el :: rest_el, st, _)
equation
// Try to add the element to the symboltable.
(el, st) = addElement(el, st);
// Add the element to the accumulation list if it was added.
accum_el = el :: inAccumEl;
// Add the rest of the elements.
(rest_el, st) = addElements2(rest_el, st, accum_el);
then
(rest_el, st);

end match;
end addElements2;

public function addElement
"Adds an element to the symboltable. Returns the element with duplicate
elements from extends removed, the updated symboltable and a boolean which
tells if the element was added to the symboltable or not."
input Element inElement;
input SymbolTable inSymbolTable;
output Element outElement;
output SymbolTable outSymbolTable;
algorithm
(outElement, outSymbolTable) := match(inElement, inSymbolTable)
outSymbolTable := match(inElement, inSymbolTable)
local
Component comp;
Class cls;
SymbolTable st;
Absyn.Path bc;
DAE.Type ty;

case (InstTypes.ELEMENT(comp, cls), st)
equation
// Add the component.
st = addComponent(comp, st);
// Add the component's class.
(cls, st) = addClass(cls, st);
st = addClass(cls, st);
then
(InstTypes.ELEMENT(comp, cls), st);
st;

case (InstTypes.CONDITIONAL_ELEMENT(comp), st)
equation
st = addComponent(comp, st);
then
(InstTypes.CONDITIONAL_ELEMENT(comp), st);
then addComponent(comp, st);

end match;
end addElement;
Expand Down Expand Up @@ -615,11 +571,10 @@ public function addInstCondElement
symboltable and a boolean which tells if the element was added or not."
input Element inElement;
input SymbolTable inSymbolTable;
output Element outElement;
output SymbolTable outSymbolTable;
output Boolean outAdded;
algorithm
(outElement, outSymbolTable, outAdded) := match(inElement, inSymbolTable)
(outSymbolTable, outAdded) := match(inElement, inSymbolTable)
local
Component comp;
Class cls;
Expand All @@ -638,7 +593,7 @@ algorithm
// Add the element's class if the component was added.
(cls, st) = addClassOnTrue(cls, st, added);
then
(InstTypes.ELEMENT(comp, cls), st, added);
(st, added);

end match;
end addInstCondElement;
Expand Down Expand Up @@ -673,9 +628,13 @@ algorithm
// component. This means that it's already been updated due to a duplicate
// element from an extends. In that case we should make sure that the new
// component is equivalent to the old one, and return the symboltable
// unchagned.
// unchanged.
case (_, _, SOME(comp), st)
equation
/*********************************************************************/
// TODO: Check if this is still needed, since we check duplicate
// elements in SCodeInst.instClassItem now.
/*********************************************************************/
//checkEqualComponents
then
(st, false);
Expand Down
24 changes: 19 additions & 5 deletions Compiler/FrontEnd/SCodeInst.mo
Expand Up @@ -133,10 +133,14 @@ algorithm
System.startTimer();
name = Absyn.pathLastIdent(inClassPath);

// ---------------- Instantiation ---------------
/*********************************************************************/
/* ------------------------- INSTANTIATION ------------------------- */
/*********************************************************************/

// Look up the class to instantiate in the environment.
(item, path, env) =
SCodeLookup.lookupClassName(inClassPath, inEnv, Absyn.dummyInfo);

// Instantiate that class.
functions = HashTablePathToFunction.emptyHashTableSized(BaseHashTable.lowBucketSize);
constants = InstSymbolTable.create();
Expand All @@ -148,11 +152,16 @@ algorithm

//print(InstDump.modelStr(name, cls)); print("\n");

// ------------------- Typing -------------------
/*********************************************************************/
/* ----------------------------- TYPING ---------------------------- */
/*********************************************************************/

// Build the symboltable to use for typing.
(cls, symtab) = InstSymbolTable.build(cls);
symtab = InstSymbolTable.build(cls);
// Add the package constants found during instantiation.
symtab = InstSymbolTable.merge(symtab, constants);
(_, symtab) = InstSymbolTable.addClass(builtin_el, symtab);
// Add any builtin elements we might need, like StateSelect.
symtab = InstSymbolTable.addClass(builtin_el, symtab);

// Mark structural parameters.
(cls, symtab) = assignParamTypes(cls, symtab);
Expand All @@ -179,6 +188,7 @@ algorithm
// Type all equation and algorithm sections in the class.
(cls, conn) = Typing.typeSections(cls, symtab);

// Generate connect equations.
flows = ConnectUtil2.collectFlowConnectors(cls);
dae_conn = ConnectEquations.generateEquations(conn, flows);

Expand All @@ -192,6 +202,10 @@ algorithm

//print("SCodeInst took " +& realString(System.getTimerIntervalTime()) +& " seconds.\n");

/*********************************************************************/
/* --------------------------- EXPANSION --------------------------- */
/*********************************************************************/

// Expand the instantiated and typed class into scalar components,
// equations and algorithms.
(dae, func_tree) = SCodeExpand.expand(name, cls, functions);
Expand Down Expand Up @@ -3842,7 +3856,7 @@ algorithm
sel = SCode.removeComponentCondition(inElement);
// Instantiate the element and update the symbol table.
(el, globals) = instElement(sel, inMod, inPrefixes, inEnv, inPrefix, INST_ALL(), globals);
(el, st, added) = InstSymbolTable.addInstCondElement(el, st);
(st, added) = InstSymbolTable.addInstCondElement(el, st);
// Recursively instantiate any conditional components in this element.
(oel, st, globals) = instConditionalElementOnTrue(added, el, st, globals);
then
Expand Down

0 comments on commit bf001f1

Please sign in to comment.