Changeset 13800 for trunk/Compiler/FrontEnd/InstFlatten.mo
- Timestamp:
- 2012-11-05T16:24:03+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/FrontEnd/InstFlatten.mo
r13755 r13800 118 118 end newSymbolTable; 119 119 120 public type Elements = list<Element>; 121 public type Equations = list<Equation>; 122 public type Algorithms = list<list<Statement>>; 123 124 public function flattenClass 125 input Class inClass; 126 input Boolean inContainsExtends; 127 output Class outFlatClass; 128 algorithm 129 outFlatClass := matchcontinue(inClass, inContainsExtends) 130 local 131 Absyn.Path name; 132 Elements el; 133 Equations eq, ieq; 134 Algorithms alg, ialg; 135 list<Class> sections; 136 Integer el_count; 137 Class cls; 138 139 // If we have no extends then we don't need to do anything. 140 case (_, false) then inClass; 141 142 case (InstTypes.COMPLEX_CLASS(name, el, eq, ieq, alg, ialg), _) 143 equation 144 (sections, el_count) = 145 List.accumulateMapFold(el, collectInheritedSections, 0); 146 el = flattenElements(el, el_count, name); 147 cls = InstTypes.COMPLEX_CLASS(name, el, eq, ieq, alg, ialg); 148 cls = List.fold(sections, flattenSections, cls); 149 then 150 cls; 151 152 else 153 equation 154 true = Flags.isSet(Flags.FAILTRACE); 155 Debug.traceln("- InstFlatten.flattenClass failed for " +& 156 Absyn.pathString(InstUtil.getClassName(inClass)) +& "\n"); 157 then 158 fail(); 159 160 end matchcontinue; 161 end flattenClass; 162 163 protected function collectInheritedSections 164 input Element inElements; 165 input Integer inElementCount; 166 input list<Class> inAccumSections; 167 output list<Class> outSections; 168 output Integer outElementCount; 169 algorithm 170 (outSections, outElementCount) := 171 match(inElements, inElementCount, inAccumSections) 172 local 173 list<Class> accum; 174 Integer el_count; 175 Elements el; 176 Class cls; 177 178 case (InstTypes.EXTENDED_ELEMENTS(cls = cls as InstTypes.COMPLEX_CLASS( 179 components = el)), _, _) 180 equation 181 el_count = listLength(el) + inElementCount; 182 then 183 (cls :: inAccumSections, el_count); 184 185 else (inAccumSections, inElementCount + 1); 186 187 end match; 188 end collectInheritedSections; 189 190 protected function flattenSections 191 input Class inSections; 192 input Class inAccumSections; 193 output Class outSections; 194 algorithm 195 outSections := match(inSections, inAccumSections) 196 local 197 Elements el; 198 Equations eq1, eq2, ieq1, ieq2; 199 Algorithms alg1, alg2, ialg1, ialg2; 200 Absyn.Path name; 201 202 case (InstTypes.COMPLEX_CLASS(_, _, eq1, ieq1, alg1, ialg1), 203 InstTypes.COMPLEX_CLASS(name, el, eq2, ieq2, alg2, ialg2)) 204 equation 205 eq1 = listAppend(eq1, eq2); 206 ieq1 = listAppend(ieq1, ieq2); 207 alg1 = listAppend(alg1, alg2); 208 ialg1 = listAppend(ialg1, ialg2); 209 then 210 InstTypes.COMPLEX_CLASS(name, el, eq1, ieq1, alg1, ialg1); 211 212 end match; 213 end flattenSections; 214 120 215 public function flattenElements 121 216 input list<Element> inElements; 217 input Integer inElementCount; 122 218 input Absyn.Path inClassPath; 123 input Boolean inContainsExtends;124 219 output list<Element> outElements; 125 220 algorithm 126 outElements := matchcontinue(inElements, in ClassPath, inContainsExtends)221 outElements := matchcontinue(inElements, inElementCount, inClassPath) 127 222 local 128 223 SymbolTable st; 129 Integer el_count;130 224 list<Element> flat_el; 131 132 // The elements are already flattened if we have no extends. 133 case (_, _, false) then inElements; 225 Class sections; 134 226 135 227 case (_, _, _) 136 228 equation 137 el_count = listLength(inElements); 138 st = newSymbolTable(intDiv(el_count * 4, 3) + 1); 229 st = newSymbolTable(intDiv(inElementCount * 4, 3) + 1); 139 230 (flat_el, _) = flattenElements2(inElements, st, {}, inClassPath, {}); 140 231 then … … 217 308 // For extended elements we can use the names from the type, which are 218 309 // already the last identifiers. 219 var_names = List.map (vars, Types.getVarName);310 var_names = List.mapReverse(vars, Types.getVarName); 220 311 (accum_el, st) = flattenExtendedElements(ext_el, var_names, 221 312 bc :: inExtendPath, inClassPath, st, accum_el); … … 256 347 list<Element> accum_el; 257 348 SymbolTable st; 258 259 // Try to add the component to the 349 Absyn.Path name; 350 Component comp; 351 352 // Try to add the component to the symbol table. 260 353 case (_, _, _, _, st, accum_el) 261 354 equation … … 264 357 (true, st); 265 358 359 // If we couldn't add the component to the symbol table it means it already 360 // exists, so we need to check that it's identical to the already existing 361 // component. 266 362 case (_, _, _, _, st, accum_el) 267 363 equation 268 print("Removing equal " +& inName +& "\n"); 269 // Look up the already existing component here and check that they are 270 // equal. 364 /**********************************************************************/ 365 // TODO: Look up the already existing component here and check that they 366 // are equal. 367 /**********************************************************************/ 271 368 then 272 369 (false, st);
Note: See TracChangeset
for help on using the changeset viewer.