Changeset 13986
- Timestamp:
- 2012-11-20T14:00:36+01:00 (11 years ago)
- Location:
- trunk/Compiler/FrontEnd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/FrontEnd/InstSymbolTable.mo
r13963 r13986 157 157 symboltable." 158 158 input Class inClass; 159 output Class outClass; 160 output SymbolTable outSymbolTable; 161 algorithm 162 (outClass, outSymbolTable) := match(inClass) 159 output SymbolTable outSymbolTable; 160 algorithm 161 outSymbolTable := match(inClass) 163 162 local 164 163 SymbolTable st; … … 173 172 bucket_size = Util.nextPrime(intDiv((comp_size * 4), 3)) + 1; 174 173 st = createSized(bucket_size); 175 (cls, st)= addClass(inClass, st);174 st = addClass(inClass, st); 176 175 st = addAliases(inClass, st); 177 176 // Add the special variable time to the symboltable. 178 177 st = addUniqueComponent(Absyn.IDENT("time"), BUILTIN_TIME_COMP, st); 179 178 then 180 (cls, st);179 st; 181 180 182 181 end match; … … 251 250 252 251 public function addClass 253 "Adds the elements of a given class to the symboltable."252 "Adds the components of a given class to the symboltable." 254 253 input Class inClass; 255 254 input SymbolTable inSymbolTable; 256 output Class outClass; 257 output SymbolTable outSymbolTable; 258 algorithm 259 (outClass, outSymbolTable) := match(inClass, inSymbolTable) 255 output SymbolTable outSymbolTable; 256 algorithm 257 outSymbolTable := match(inClass, inSymbolTable) 260 258 local 261 259 list<Element> comps; … … 265 263 Absyn.Path name; 266 264 267 // A basic type doesn't have any elements, nothing to add.265 // A basic type doesn't have any components, nothing to add. 268 266 case (InstTypes.BASIC_TYPE(name), st) then (inClass, st); 269 267 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); 276 271 277 272 end match; … … 284 279 input list<Element> inElements; 285 280 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; 282 algorithm 283 outSymbolTable := List.fold(inElements, addElement, inSymbolTable); 291 284 end addElements; 292 293 protected function addElements2294 "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 algorithm301 (outElements, outSymbolTable) := match(inElements, inSymbolTable, inAccumEl)302 local303 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 equation312 // 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 then319 (rest_el, st);320 321 end match;322 end addElements2;323 285 324 286 public function addElement … … 328 290 input Element inElement; 329 291 input SymbolTable inSymbolTable; 330 output Element outElement; 331 output SymbolTable outSymbolTable; 332 algorithm 333 (outElement, outSymbolTable) := match(inElement, inSymbolTable) 292 output SymbolTable outSymbolTable; 293 algorithm 294 outSymbolTable := match(inElement, inSymbolTable) 334 295 local 335 296 Component comp; 336 297 Class cls; 337 298 SymbolTable st; 338 Absyn.Path bc;339 DAE.Type ty;340 299 341 300 case (InstTypes.ELEMENT(comp, cls), st) … … 344 303 st = addComponent(comp, st); 345 304 // 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; 349 308 350 309 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); 355 311 356 312 end match; … … 616 572 input Element inElement; 617 573 input SymbolTable inSymbolTable; 618 output Element outElement;619 574 output SymbolTable outSymbolTable; 620 575 output Boolean outAdded; 621 576 algorithm 622 (out Element, outSymbolTable, outAdded) := match(inElement, inSymbolTable)577 (outSymbolTable, outAdded) := match(inElement, inSymbolTable) 623 578 local 624 579 Component comp; … … 639 594 (cls, st) = addClassOnTrue(cls, st, added); 640 595 then 641 ( InstTypes.ELEMENT(comp, cls),st, added);596 (st, added); 642 597 643 598 end match; … … 674 629 // element from an extends. In that case we should make sure that the new 675 630 // component is equivalent to the old one, and return the symboltable 676 // uncha gned.631 // unchanged. 677 632 case (_, _, SOME(comp), st) 678 633 equation 634 /*********************************************************************/ 635 // TODO: Check if this is still needed, since we check duplicate 636 // elements in SCodeInst.instClassItem now. 637 /*********************************************************************/ 679 638 //checkEqualComponents 680 639 then -
trunk/Compiler/FrontEnd/SCodeInst.mo
r13985 r13986 134 134 name = Absyn.pathLastIdent(inClassPath); 135 135 136 // ---------------- Instantiation --------------- 136 /*********************************************************************/ 137 /* ------------------------- INSTANTIATION ------------------------- */ 138 /*********************************************************************/ 139 137 140 // Look up the class to instantiate in the environment. 138 141 (item, path, env) = 139 142 SCodeLookup.lookupClassName(inClassPath, inEnv, Absyn.dummyInfo); 143 140 144 // Instantiate that class. 141 145 functions = HashTablePathToFunction.emptyHashTableSized(BaseHashTable.lowBucketSize); … … 149 153 //print(InstDump.modelStr(name, cls)); print("\n"); 150 154 151 // ------------------- Typing ------------------- 155 /*********************************************************************/ 156 /* ----------------------------- TYPING ---------------------------- */ 157 /*********************************************************************/ 158 152 159 // 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. 154 162 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); 156 165 157 166 // Mark structural parameters. … … 180 189 (cls, conn) = Typing.typeSections(cls, symtab); 181 190 191 // Generate connect equations. 182 192 flows = ConnectUtil2.collectFlowConnectors(cls); 183 193 dae_conn = ConnectEquations.generateEquations(conn, flows); … … 192 202 193 203 //print("SCodeInst took " +& realString(System.getTimerIntervalTime()) +& " seconds.\n"); 204 205 /*********************************************************************/ 206 /* --------------------------- EXPANSION --------------------------- */ 207 /*********************************************************************/ 194 208 195 209 // Expand the instantiated and typed class into scalar components, … … 3843 3857 // Instantiate the element and update the symbol table. 3844 3858 (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); 3846 3860 // Recursively instantiate any conditional components in this element. 3847 3861 (oel, st, globals) = instConditionalElementOnTrue(added, el, st, globals);
Note: See TracChangeset
for help on using the changeset viewer.