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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 * Object should not be in the resulting code. | 186 * Object should not be in the resulting code. |
187 */ | 187 */ |
188 @override | 188 @override |
189 bool shouldOutput(Element element) { | 189 bool shouldOutput(Element element) { |
190 return (!element.library.isPlatformLibrary && | 190 return (!element.library.isPlatformLibrary && |
191 !element.isSynthesized && | 191 !element.isSynthesized && |
192 element is! AbstractFieldElement) | 192 element is! AbstractFieldElement) |
193 || mirrorRenamer.isMirrorHelperLibrary(element.library); | 193 || mirrorRenamer.isMirrorHelperLibrary(element.library); |
194 } | 194 } |
195 | 195 |
196 void assembleProgram() { | 196 int assembleProgram() { |
197 ElementAstCreationContext context = | 197 ElementAstCreationContext context = |
198 new _ElementAstCreationContext(compiler, constantSystem); | 198 new _ElementAstCreationContext(compiler, constantSystem); |
199 | 199 |
200 ElementAst computeElementAst(AstElement element) { | 200 ElementAst computeElementAst(AstElement element) { |
201 if (!compiler.irBuilder.hasIr(element)) { | 201 if (!compiler.irBuilder.hasIr(element)) { |
202 return new ElementAst(element.resolvedAst.node, | 202 return new ElementAst(element.resolvedAst.node, |
203 element.resolvedAst.elements); | 203 element.resolvedAst.elements); |
204 } else { | 204 } else { |
205 cps_ir.ExecutableDefinition definition = | 205 cps_ir.ExecutableDefinition definition = |
206 compiler.irBuilder.getIr(element); | 206 compiler.irBuilder.getIr(element); |
207 return createElementAst(context, element, definition); | 207 return createElementAst(context, element, definition); |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 // TODO(johnniwinther): Remove the need for this method. | 211 // TODO(johnniwinther): Remove the need for this method. |
212 void postProcessElementAst( | 212 void postProcessElementAst( |
213 AstElement element, ElementAst elementAst, | 213 AstElement element, ElementAst elementAst, |
214 newTypedefElementCallback, | 214 newTypedefElementCallback, |
215 newClassElementCallback) { | 215 newClassElementCallback) { |
216 ReferencedElementCollector collector = | 216 ReferencedElementCollector collector = |
217 new ReferencedElementCollector(compiler, | 217 new ReferencedElementCollector(compiler, |
218 element, | 218 element, |
219 elementAst, | 219 elementAst, |
220 newTypedefElementCallback, | 220 newTypedefElementCallback, |
221 newClassElementCallback); | 221 newClassElementCallback); |
222 collector.collect(); | 222 collector.collect(); |
223 } | 223 } |
224 | 224 |
225 String assembledCode = outputter.assembleProgram( | 225 int totalSize = outputter.assembleProgram( |
226 libraries: compiler.libraryLoader.libraries, | 226 libraries: compiler.libraryLoader.libraries, |
227 instantiatedClasses: compiler.resolverWorld.directlyInstantiatedClasses, | 227 instantiatedClasses: compiler.resolverWorld.directlyInstantiatedClasses, |
228 resolvedElements: compiler.enqueuer.resolution.resolvedElements, | 228 resolvedElements: compiler.enqueuer.resolution.resolvedElements, |
229 usedTypeLiterals: usedTypeLiterals, | 229 usedTypeLiterals: usedTypeLiterals, |
230 postProcessElementAst: postProcessElementAst, | 230 postProcessElementAst: postProcessElementAst, |
231 computeElementAst: computeElementAst, | 231 computeElementAst: computeElementAst, |
232 shouldOutput: shouldOutput, | 232 shouldOutput: shouldOutput, |
233 isSafeToRemoveTypeDeclarations: isSafeToRemoveTypeDeclarations, | 233 isSafeToRemoveTypeDeclarations: isSafeToRemoveTypeDeclarations, |
234 sortElements: sortElements, | 234 sortElements: sortElements, |
235 mirrorRenamer: mirrorRenamer, | 235 mirrorRenamer: mirrorRenamer, |
236 mainFunction: compiler.mainFunction, | 236 mainFunction: compiler.mainFunction, |
237 outputUri: compiler.outputUri); | 237 outputUri: compiler.outputUri); |
238 compiler.assembledCode = assembledCode; | |
239 | |
240 int totalSize = assembledCode.length; | |
241 | 238 |
242 // Output verbose info about size ratio of resulting bundle to all | 239 // Output verbose info about size ratio of resulting bundle to all |
243 // referenced non-platform sources. | 240 // referenced non-platform sources. |
244 logResultBundleSizeInfo( | 241 logResultBundleSizeInfo( |
245 outputter.libraryInfo.userLibraries, | 242 outputter.libraryInfo.userLibraries, |
246 outputter.elementInfo.topLevelElements, | 243 outputter.elementInfo.topLevelElements, |
247 assembledCode.length); | 244 totalSize); |
| 245 |
| 246 return totalSize; |
248 } | 247 } |
249 | 248 |
250 void logResultBundleSizeInfo(Iterable<LibraryElement> userLibraries, | 249 void logResultBundleSizeInfo(Iterable<LibraryElement> userLibraries, |
251 Iterable<Element> topLevelElements, | 250 Iterable<Element> topLevelElements, |
252 int totalOutputSize) { | 251 int totalOutputSize) { |
253 // Sum total size of scripts in each referenced library. | 252 // Sum total size of scripts in each referenced library. |
254 int nonPlatformSize = 0; | 253 int nonPlatformSize = 0; |
255 for (LibraryElement lib in userLibraries) { | 254 for (LibraryElement lib in userLibraries) { |
256 for (CompilationUnitElement compilationUnit in lib.compilationUnits) { | 255 for (CompilationUnitElement compilationUnit in lib.compilationUnits) { |
257 nonPlatformSize += compilationUnit.script.file.length; | 256 nonPlatformSize += compilationUnit.script.file.length; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 } | 542 } |
544 | 543 |
545 void traceGraph(String title, var irObject) { | 544 void traceGraph(String title, var irObject) { |
546 compiler.tracer.traceGraph(title, irObject); | 545 compiler.tracer.traceGraph(title, irObject); |
547 } | 546 } |
548 | 547 |
549 DartTypes get dartTypes => compiler.types; | 548 DartTypes get dartTypes => compiler.types; |
550 | 549 |
551 InternalErrorFunction get internalError => compiler.internalError; | 550 InternalErrorFunction get internalError => compiler.internalError; |
552 } | 551 } |
OLD | NEW |