Changeset bf001f11 in OpenModelica


Ignore:
Timestamp:
2012-11-20T14:00:36+01:00 (11 years ago)
Author:
Per Östlund <per.ostlund@…>
Branches:
Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
3dda9d88
Parents:
14915b6
Message:
  • Don't return the class from InstSymbolTable.addClass, it's no longer needed since classes are flattened in SCodeInst.instClassItem.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13986 f25d12d1-65f4-0310-ae8a-bbce733d8d8e

Location:
Compiler/FrontEnd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Compiler/FrontEnd/InstSymbolTable.mo

    rd8d7974 rbf001f11  
    157157   symboltable."
    158158  input Class inClass;
    159   output Class outClass;
    160   output SymbolTable outSymbolTable;
    161 algorithm
    162   (outClass, outSymbolTable) := match(inClass)
     159  output SymbolTable outSymbolTable;
     160algorithm
     161  outSymbolTable := match(inClass)
    163162    local
    164163      SymbolTable st;
     
    173172        bucket_size = Util.nextPrime(intDiv((comp_size * 4), 3)) + 1;
    174173        st = createSized(bucket_size);
    175         (cls, st) = addClass(inClass, st);
     174        st = addClass(inClass, st);
    176175        st = addAliases(inClass, st);
    177176        // Add the special variable time to the symboltable.
    178177        st = addUniqueComponent(Absyn.IDENT("time"), BUILTIN_TIME_COMP, st);
    179178      then
    180         (cls, st);
     179        st;
    181180
    182181  end match;
     
    251250
    252251public function addClass
    253   "Adds the elements of a given class to the symboltable."
     252  "Adds the components of a given class to the symboltable."
    254253  input Class inClass;
    255254  input SymbolTable inSymbolTable;
    256   output Class outClass;
    257   output SymbolTable outSymbolTable;
    258 algorithm
    259   (outClass, outSymbolTable) := match(inClass, inSymbolTable)
     255  output SymbolTable outSymbolTable;
     256algorithm
     257  outSymbolTable := match(inClass, inSymbolTable)
    260258    local
    261259      list<Element> comps;
     
    265263      Absyn.Path name;
    266264
    267     // A basic type doesn't have any elements, nothing to add.
     265    // A basic type doesn't have any components, nothing to add.
    268266    case (InstTypes.BASIC_TYPE(name), st) then (inClass, st);
    269267
    270     // A complex class, add it's elements to the symboltable.
    271     case (InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), st)
    272       equation
    273         (comps, st) = addElements(comps, st);
    274       then
    275         (InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), st);
     268    // A complex class, add its components to the symboltable.
     269    case (InstTypes.COMPLEX_CLASS(components = comps), st)
     270      then addElements(comps, st);
    276271
    277272  end match;
     
    284279  input list<Element> inElements;
    285280  input SymbolTable inSymbolTable;
    286   output list<Element> outElements;
    287   output SymbolTable outSymbolTable;
    288 algorithm
    289   (outElements, outSymbolTable) :=
    290     addElements2(inElements, inSymbolTable, {});
     281  output SymbolTable outSymbolTable;
     282algorithm
     283  outSymbolTable := List.fold(inElements, addElement, inSymbolTable);
    291284end addElements;
    292 
    293 protected function addElements2
    294   "Tail-recursive implementation of addElements."
    295   input list<Element> inElements;
    296   input SymbolTable inSymbolTable;
    297   input list<Element> inAccumEl;
    298   output list<Element> outElements;
    299   output SymbolTable outSymbolTable;
    300 algorithm
    301   (outElements, outSymbolTable) := match(inElements, inSymbolTable, inAccumEl)
    302     local
    303       Element el;
    304       list<Element> rest_el, accum_el;
    305       Boolean added;
    306       SymbolTable st;
    307 
    308     case ({}, st, _) then (inAccumEl, st);
    309 
    310     case (el :: rest_el, st, _)
    311       equation
    312         // Try to add the element to the symboltable.
    313         (el, st) = addElement(el, st);
    314         // Add the element to the accumulation list if it was added.
    315         accum_el = el :: inAccumEl;
    316         // Add the rest of the elements.
    317         (rest_el, st) = addElements2(rest_el, st, accum_el);
    318       then
    319         (rest_el, st);
    320 
    321   end match;
    322 end addElements2;
    323285
    324286public function addElement
     
    328290  input Element inElement;
    329291  input SymbolTable inSymbolTable;
    330   output Element outElement;
    331   output SymbolTable outSymbolTable;
    332 algorithm
    333   (outElement, outSymbolTable) := match(inElement, inSymbolTable)
     292  output SymbolTable outSymbolTable;
     293algorithm
     294  outSymbolTable := match(inElement, inSymbolTable)
    334295    local
    335296      Component comp;
    336297      Class cls;
    337298      SymbolTable st;
    338       Absyn.Path bc;
    339       DAE.Type ty;
    340299
    341300    case (InstTypes.ELEMENT(comp, cls), st)
     
    344303        st = addComponent(comp, st);
    345304        // Add the component's class.
    346         (cls, st) = addClass(cls, st);
    347       then
    348         (InstTypes.ELEMENT(comp, cls), st);
     305        st = addClass(cls, st);
     306      then
     307        st;
    349308
    350309    case (InstTypes.CONDITIONAL_ELEMENT(comp), st)
    351       equation
    352         st = addComponent(comp, st);
    353       then
    354         (InstTypes.CONDITIONAL_ELEMENT(comp), st);
     310      then addComponent(comp, st);
    355311
    356312  end match;
     
    616572  input Element inElement;
    617573  input SymbolTable inSymbolTable;
    618   output Element outElement;
    619574  output SymbolTable outSymbolTable;
    620575  output Boolean outAdded;
    621576algorithm
    622   (outElement, outSymbolTable, outAdded) := match(inElement, inSymbolTable)
     577  (outSymbolTable, outAdded) := match(inElement, inSymbolTable)
    623578    local
    624579      Component comp;
     
    639594        (cls, st) = addClassOnTrue(cls, st, added);
    640595      then
    641         (InstTypes.ELEMENT(comp, cls), st, added);
     596        (st, added);
    642597
    643598  end match;
     
    674629    // element from an extends. In that case we should make sure that the new
    675630    // component is equivalent to the old one, and return the symboltable
    676     // unchagned.
     631    // unchanged.
    677632    case (_, _, SOME(comp), st)
    678633      equation
     634        /*********************************************************************/
     635        // TODO: Check if this is still needed, since we check duplicate
     636        // elements in SCodeInst.instClassItem now.
     637        /*********************************************************************/
    679638        //checkEqualComponents
    680639      then
  • Compiler/FrontEnd/SCodeInst.mo

    r14915b6 rbf001f11  
    134134        name = Absyn.pathLastIdent(inClassPath);
    135135
    136         // ---------------- Instantiation ---------------
     136        /*********************************************************************/
     137        /* ------------------------- INSTANTIATION ------------------------- */
     138        /*********************************************************************/
     139
    137140        // Look up the class to instantiate in the environment.
    138141        (item, path, env) =
    139142          SCodeLookup.lookupClassName(inClassPath, inEnv, Absyn.dummyInfo);
     143
    140144        // Instantiate that class.
    141145        functions = HashTablePathToFunction.emptyHashTableSized(BaseHashTable.lowBucketSize);
     
    149153        //print(InstDump.modelStr(name, cls)); print("\n");
    150154
    151         // ------------------- Typing -------------------
     155        /*********************************************************************/
     156        /* ----------------------------- TYPING ---------------------------- */
     157        /*********************************************************************/
     158
    152159        // Build the symboltable to use for typing.
    153         (cls, symtab) = InstSymbolTable.build(cls);
     160        symtab = InstSymbolTable.build(cls);
     161        // Add the package constants found during instantiation.
    154162        symtab = InstSymbolTable.merge(symtab, constants);
    155         (_, symtab) = InstSymbolTable.addClass(builtin_el, symtab);
     163        // Add any builtin elements we might need, like StateSelect.
     164        symtab = InstSymbolTable.addClass(builtin_el, symtab);
    156165
    157166        // Mark structural parameters.
     
    180189        (cls, conn) = Typing.typeSections(cls, symtab);
    181190       
     191        // Generate connect equations.
    182192        flows = ConnectUtil2.collectFlowConnectors(cls);
    183193        dae_conn = ConnectEquations.generateEquations(conn, flows);
     
    192202
    193203        //print("SCodeInst took " +& realString(System.getTimerIntervalTime()) +& " seconds.\n");
     204
     205        /*********************************************************************/
     206        /* --------------------------- EXPANSION --------------------------- */
     207        /*********************************************************************/
    194208
    195209        // Expand the instantiated and typed class into scalar components,
     
    38433857        // Instantiate the element and update the symbol table.
    38443858        (el, globals) = instElement(sel, inMod, inPrefixes, inEnv, inPrefix, INST_ALL(), globals);
    3845         (el, st, added) = InstSymbolTable.addInstCondElement(el, st);
     3859        (st, added) = InstSymbolTable.addInstCondElement(el, st);
    38463860        // Recursively instantiate any conditional components in this element.
    38473861        (oel, st, globals) = instConditionalElementOnTrue(added, el, st, globals);
Note: See TracChangeset for help on using the changeset viewer.