OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart_backend; | 5 part of dart_backend; |
6 | 6 |
7 // TODO(ahe): This class is simply wrong. This backend should use | 7 // TODO(ahe): This class is simply wrong. This backend should use |
8 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
9 // TreeElements>] is what is needed. | 9 // TreeElements>] is what is needed. |
10 class ElementAst { | 10 class ElementAst { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 // TODO(antonm): TypeError.srcType and TypeError.dstType are defined in | 257 // TODO(antonm): TypeError.srcType and TypeError.dstType are defined in |
258 // runtime/lib/error.dart. Overall, all DartVM specific libs should be | 258 // runtime/lib/error.dart. Overall, all DartVM specific libs should be |
259 // accounted for. | 259 // accounted for. |
260 fixedMemberNames.add('srcType'); | 260 fixedMemberNames.add('srcType'); |
261 fixedMemberNames.add('dstType'); | 261 fixedMemberNames.add('dstType'); |
262 | 262 |
263 /** | 263 /** |
264 * Tells whether we should output given element. Corelib classes like | 264 * Tells whether we should output given element. Corelib classes like |
265 * Object should not be in the resulting code. | 265 * Object should not be in the resulting code. |
266 */ | 266 */ |
267 bool shouldOutput(Element element) => | 267 bool shouldOutput(Element element) { |
268 !identical(element.kind, ElementKind.VOID) && | 268 return !identical(element.kind, ElementKind.VOID) |
269 isUserLibrary(element.getLibrary()) && | 269 && isUserLibrary(element.getLibrary()) |
270 element is !SynthesizedConstructorElement && | 270 && element is !SynthesizedConstructorElement |
271 element is !AbstractFieldElement; | 271 && element is !AbstractFieldElement; |
272 } | |
272 | 273 |
273 final elementAsts = new Map<Element, ElementAst>(); | 274 final elementAsts = new Map<Element, ElementAst>(); |
274 | 275 |
275 parse(element) => element.parseNode(compiler); | 276 parse(element) => element.parseNode(compiler); |
276 | 277 |
277 Set<Element> topLevelElements = new Set<Element>(); | 278 Set<Element> topLevelElements = new Set<Element>(); |
278 Map<ClassElement, Set<Element>> classMembers = | 279 Map<ClassElement, Set<Element>> classMembers = |
279 new Map<ClassElement, Set<Element>>(); | 280 new Map<ClassElement, Set<Element>>(); |
280 | 281 |
281 // Build all top level elements to emit and necessary class members. | 282 // Build all top level elements to emit and necessary class members. |
(...skipping 26 matching lines...) Expand all Loading... | |
308 newClassElementCallback = (ClassElement classElement) { | 309 newClassElementCallback = (ClassElement classElement) { |
309 if (!shouldOutput(classElement)) return; | 310 if (!shouldOutput(classElement)) return; |
310 addClass(classElement); | 311 addClass(classElement); |
311 }; | 312 }; |
312 | 313 |
313 compiler.resolverWorld.instantiatedClasses.forEach( | 314 compiler.resolverWorld.instantiatedClasses.forEach( |
314 (ClassElement classElement) { | 315 (ClassElement classElement) { |
315 if (shouldOutput(classElement)) addClass(classElement); | 316 if (shouldOutput(classElement)) addClass(classElement); |
316 }); | 317 }); |
317 resolvedElements.forEach((element, treeElements) { | 318 resolvedElements.forEach((element, treeElements) { |
318 if (!shouldOutput(element)) return; | 319 if (!shouldOutput(element) || treeElements == null) return; |
ahe
2012/11/05 09:47:05
Why would treeElements be null?
| |
319 | |
320 var elementAst = new ElementAst.rewrite( | 320 var elementAst = new ElementAst.rewrite( |
321 compiler, parse(element), treeElements, stripAsserts); | 321 compiler, parse(element), treeElements, stripAsserts); |
322 if (element.isField()) { | 322 if (element.isField()) { |
323 final list = (element as VariableElement).variables; | 323 final list = (element as VariableElement).variables; |
324 elementAst = elementAsts.putIfAbsent( | 324 elementAst = elementAsts.putIfAbsent( |
325 list, () => new VariableListAst(parse(list))); | 325 list, () => new VariableListAst(parse(list))); |
326 (elementAst as VariableListAst).add(element, treeElements); | 326 (elementAst as VariableListAst).add(element, treeElements); |
327 element = list; | 327 element = list; |
328 } | 328 } |
329 | 329 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 } | 555 } |
556 | 556 |
557 compareElements(e0, e1) { | 557 compareElements(e0, e1) { |
558 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); | 558 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); |
559 if (result != 0) return result; | 559 if (result != 0) return result; |
560 return compareBy((e) => e.position().charOffset)(e0, e1); | 560 return compareBy((e) => e.position().charOffset)(e0, e1); |
561 } | 561 } |
562 | 562 |
563 List<Element> sortElements(Collection<Element> elements) => | 563 List<Element> sortElements(Collection<Element> elements) => |
564 sorted(elements, compareElements); | 564 sorted(elements, compareElements); |
OLD | NEW |