Chromium Code Reviews| 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 class BailoutException { | 5 class BailoutException { |
| 6 final String reason; | 6 final String reason; |
| 7 | 7 |
| 8 const BailoutException(this.reason); | 8 const BailoutException(this.reason); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 final LIBS_TO_IGNORE = [ | 63 final LIBS_TO_IGNORE = [ |
| 64 compiler.jsHelperLibrary, | 64 compiler.jsHelperLibrary, |
| 65 compiler.interceptorsLibrary, | 65 compiler.interceptorsLibrary, |
| 66 ]; | 66 ]; |
| 67 bool shouldOutput(Element element) => | 67 bool shouldOutput(Element element) => |
| 68 element.kind !== ElementKind.VOID && | 68 element.kind !== ElementKind.VOID && |
| 69 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 && | 69 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 && |
| 70 !isDartCoreLib(compiler, element.getLibrary()); | 70 !isDartCoreLib(compiler, element.getLibrary()); |
| 71 | 71 |
| 72 try { | 72 try { |
| 73 Set<TypedefElement> typedefs = new Set<TypedefElement>(); | |
| 73 PlaceholderCollector collector = new PlaceholderCollector(compiler); | 74 PlaceholderCollector collector = new PlaceholderCollector(compiler); |
| 74 resolvedElements.forEach((element, treeElements) { | 75 resolvedElements.forEach((element, treeElements) { |
| 75 if (!shouldOutput(element)) return; | 76 if (!shouldOutput(element)) return; |
| 77 if (element is AbstractFieldElement) return; | |
| 76 collector.collect(element, treeElements); | 78 collector.collect(element, treeElements); |
| 79 new AdditionalElementCollector( | |
| 80 compiler, | |
|
Roman
2012/08/09 16:48:03
style nazi: Can you please make it more compact? I
Anton Muhin
2012/08/09 17:01:08
Done.
| |
| 81 element, treeElements, | |
| 82 typedefs) | |
| 83 .collect(); | |
| 77 }); | 84 }); |
| 78 | 85 |
| 79 ConflictingRenamer renamer = | 86 ConflictingRenamer renamer = |
| 80 new ConflictingRenamer(compiler, collector.placeholders); | 87 new ConflictingRenamer(compiler, collector.placeholders); |
| 81 Emitter emitter = new Emitter(compiler, renamer); | 88 Emitter emitter = new Emitter(compiler, renamer); |
| 82 resolvedElements.forEach((element, treeElements) { | 89 resolvedElements.forEach((element, treeElements) { |
| 83 if (!shouldOutput(element)) return; | 90 if (!shouldOutput(element)) return; |
| 84 if (element.isMember()) { | 91 if (element.isMember()) { |
| 85 ClassElement enclosingClass = element.getEnclosingClass(); | 92 ClassElement enclosingClass = element.getEnclosingClass(); |
| 86 assert(enclosingClass.isClass()); | 93 assert(enclosingClass.isClass()); |
| 87 assert(enclosingClass.isTopLevel()); | 94 assert(enclosingClass.isTopLevel()); |
| 88 addMemberToClass(element, enclosingClass); | 95 addMemberToClass(element, enclosingClass); |
| 89 return; | 96 return; |
| 90 } | 97 } |
| 91 if (!element.isTopLevel()) { | 98 if (!element.isTopLevel()) { |
| 92 bailout('Cannot process non top-level $element'); | 99 bailout('Cannot process non top-level $element'); |
| 93 } | 100 } |
| 94 | 101 |
| 95 emitter.outputElement(element); | 102 emitter.outputElement(element); |
| 96 }); | 103 }); |
| 97 | 104 |
| 105 typedefs.forEach(emitter.outputElement); | |
|
Roman
2012/08/09 16:48:03
I think we also want to traverse typedef nodes, be
Anton Muhin
2012/08/09 17:01:09
I believe we traverse those typedefs as a part of
| |
| 106 | |
| 98 // Now output resolved classes with inner elements we met before. | 107 // Now output resolved classes with inner elements we met before. |
| 99 resolvedClassMembers.forEach(emitter.outputClass); | 108 resolvedClassMembers.forEach(emitter.outputClass); |
| 100 compiler.assembledCode = emitter.toString(); | 109 compiler.assembledCode = emitter.toString(); |
| 101 } catch (BailoutException e) { | 110 } catch (BailoutException e) { |
| 102 compiler.assembledCode = ''' | 111 compiler.assembledCode = ''' |
| 103 main() { | 112 main() { |
| 104 final bailout_reason = "${e.reason}"; | 113 final bailout_reason = "${e.reason}"; |
| 105 } | 114 } |
| 106 '''; | 115 '''; |
| 107 } | 116 } |
| 108 } | 117 } |
| 109 | 118 |
| 110 log(String message) => compiler.log('[DartBackend] $message'); | 119 log(String message) => compiler.log('[DartBackend] $message'); |
| 111 } | 120 } |
| 112 | 121 |
| 113 /** | 122 /** |
| 114 * Checks if [:libraryElement:] is a core lib, that is a library | 123 * Checks if [:libraryElement:] is a core lib, that is a library |
| 115 * provided by the implementation like dart:core, dart:coreimpl, etc. | 124 * provided by the implementation like dart:core, dart:coreimpl, etc. |
| 116 */ | 125 */ |
| 117 bool isDartCoreLib(Compiler compiler, LibraryElement libraryElement) { | 126 bool isDartCoreLib(Compiler compiler, LibraryElement libraryElement) { |
| 118 final libraries = compiler.libraries; | 127 final libraries = compiler.libraries; |
| 119 for (final uri in libraries.getKeys()) { | 128 for (final uri in libraries.getKeys()) { |
| 120 if (libraryElement === libraries[uri]) { | 129 if (libraryElement === libraries[uri]) { |
| 121 if (uri.startsWith('dart:')) return true; | 130 if (uri.startsWith('dart:')) return true; |
| 122 } | 131 } |
| 123 } | 132 } |
| 124 return false; | 133 return false; |
| 125 } | 134 } |
| 135 | |
| 136 class AdditionalElementCollector extends AbstractVisitor { | |
|
Roman
2012/08/09 16:48:03
Please think about better name. What is "additiona
Anton Muhin
2012/08/09 17:01:09
Ok, is it any better?
On 2012/08/09 16:48:03, Rom
| |
| 137 final Compiler compiler; | |
| 138 final Element element; | |
| 139 final TreeElements treeElements; | |
| 140 final Set<TypedefElement> typedefs; | |
| 141 | |
| 142 AdditionalElementCollector( | |
| 143 this.compiler, | |
| 144 this.element, this.treeElements, | |
| 145 this.typedefs); | |
| 146 | |
| 147 visitNode(Node node) { node.visitChildren(this); } | |
| 148 | |
| 149 visitTypeAnnotation(TypeAnnotation typeAnnotation) { | |
| 150 Element element = treeElements[typeAnnotation]; | |
|
Roman
2012/08/09 16:48:03
I think canonically types should be resolved throu
Anton Muhin
2012/08/09 17:01:09
Right now I don't want to resolve types, meaning I
| |
| 151 if (element !== null) { | |
| 152 if (element.isTypedef()) typedefs.add(element as TypedefElement); | |
|
ahe
2012/08/09 16:51:55
The cast is unnecessary. Dart is a dynamically typ
Anton Muhin
2012/08/09 17:01:09
Sure, I was just concerned if some tool will give
| |
| 153 } | |
| 154 typeAnnotation.visitChildren(this); | |
| 155 } | |
| 156 | |
| 157 void collect() { | |
| 158 element.parseNode(compiler).accept(this); | |
| 159 } | |
| 160 } | |
| OLD | NEW |