| 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 // TODO(ahe): This class is simply wrong. This backend should use | 5 // TODO(ahe): This class is simply wrong. This backend should use |
| 6 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 6 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
| 7 // TreeElements>] is what is needed. | 7 // TreeElements>] is what is needed. |
| 8 class ElementAst { | 8 class ElementAst { |
| 9 final Node ast; | 9 final Node ast; |
| 10 final TreeElements treeElements; | 10 final TreeElements treeElements; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 * 2) The code has typedefs in right hand side of IS checks, | 128 * 2) The code has typedefs in right hand side of IS checks, |
| 129 * 3) The code has classes which extend typedefs, have type arguments typedefs | 129 * 3) The code has classes which extend typedefs, have type arguments typedefs |
| 130 * or type variable bounds typedefs. | 130 * or type variable bounds typedefs. |
| 131 * These restrictions can be less strict. | 131 * These restrictions can be less strict. |
| 132 */ | 132 */ |
| 133 bool isSafeToRemoveTypeDeclarations( | 133 bool isSafeToRemoveTypeDeclarations( |
| 134 Map<ClassElement, Set<Element>> classMembers) { | 134 Map<ClassElement, Set<Element>> classMembers) { |
| 135 Set<DartType> processedTypes = new Set<DartType>(); | 135 Set<DartType> processedTypes = new Set<DartType>(); |
| 136 List<DartType> workQueue = new List<DartType>(); | 136 List<DartType> workQueue = new List<DartType>(); |
| 137 workQueue.addAll( | 137 workQueue.addAll( |
| 138 classMembers.getKeys().map((classElement) => classElement.type)); | 138 classMembers.keys.map((classElement) => classElement.type)); |
| 139 workQueue.addAll(compiler.resolverWorld.isChecks); | 139 workQueue.addAll(compiler.resolverWorld.isChecks); |
| 140 Element typeErrorElement = | 140 Element typeErrorElement = |
| 141 compiler.coreLibrary.find(new SourceString('TypeError')); | 141 compiler.coreLibrary.find(new SourceString('TypeError')); |
| 142 DartType typeErrorType = typeErrorElement.computeType(compiler); | 142 DartType typeErrorType = typeErrorElement.computeType(compiler); |
| 143 if (workQueue.indexOf(typeErrorType) != -1) { | 143 if (workQueue.indexOf(typeErrorType) != -1) { |
| 144 return false; | 144 return false; |
| 145 } | 145 } |
| 146 | 146 |
| 147 void processTypeArguments(Element classElement, NodeList typeArguments) { | 147 void processTypeArguments(Element classElement, NodeList typeArguments) { |
| 148 if (typeArguments == null) return; | 148 if (typeArguments == null) return; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 ]; | 219 ]; |
| 220 return INTERNAL_HELPERS.indexOf(lib) == -1 && !lib.isPlatformLibrary; | 220 return INTERNAL_HELPERS.indexOf(lib) == -1 && !lib.isPlatformLibrary; |
| 221 } | 221 } |
| 222 | 222 |
| 223 void assembleProgram() { | 223 void assembleProgram() { |
| 224 // Conservatively traverse all platform libraries and collect member names. | 224 // Conservatively traverse all platform libraries and collect member names. |
| 225 // TODO(antonm): ideally we should only collect names of used members, | 225 // TODO(antonm): ideally we should only collect names of used members, |
| 226 // however as of today there are problems with names of some core library | 226 // however as of today there are problems with names of some core library |
| 227 // interfaces, most probably for interfaces of literals. | 227 // interfaces, most probably for interfaces of literals. |
| 228 final fixedMemberNames = new Set<String>(); | 228 final fixedMemberNames = new Set<String>(); |
| 229 for (final library in compiler.libraries.getValues()) { | 229 for (final library in compiler.libraries.values) { |
| 230 if (!library.isPlatformLibrary) continue; | 230 if (!library.isPlatformLibrary) continue; |
| 231 library.implementation.forEachLocalMember((Element element) { | 231 library.implementation.forEachLocalMember((Element element) { |
| 232 if (element is ClassElement) { | 232 if (element is ClassElement) { |
| 233 ClassElement classElement = element; | 233 ClassElement classElement = element; |
| 234 // Make sure we parsed the class to initialize its local members. | 234 // Make sure we parsed the class to initialize its local members. |
| 235 // TODO(smok): Figure out if there is a better way to fill local | 235 // TODO(smok): Figure out if there is a better way to fill local |
| 236 // members. | 236 // members. |
| 237 element.parseNode(compiler); | 237 element.parseNode(compiler); |
| 238 for (final member in classElement.localMembers) { | 238 for (final member in classElement.localMembers) { |
| 239 final name = member.name.slowToString(); | 239 final name = member.name.slowToString(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 337 } |
| 338 }); | 338 }); |
| 339 | 339 |
| 340 // Add synthesized constructors to classes with no resolved constructors, | 340 // Add synthesized constructors to classes with no resolved constructors, |
| 341 // but which originally had any constructor. That should prevent | 341 // but which originally had any constructor. That should prevent |
| 342 // those classes from being instantiable with default constructor. | 342 // those classes from being instantiable with default constructor. |
| 343 Identifier synthesizedIdentifier = | 343 Identifier synthesizedIdentifier = |
| 344 new Identifier(new StringToken(IDENTIFIER_INFO, '', -1)); | 344 new Identifier(new StringToken(IDENTIFIER_INFO, '', -1)); |
| 345 | 345 |
| 346 NextClassElement: | 346 NextClassElement: |
| 347 for (ClassElement classElement in classMembers.getKeys()) { | 347 for (ClassElement classElement in classMembers.keys) { |
| 348 for (Element member in classMembers[classElement]) { | 348 for (Element member in classMembers[classElement]) { |
| 349 if (member.isConstructor()) continue NextClassElement; | 349 if (member.isConstructor()) continue NextClassElement; |
| 350 } | 350 } |
| 351 if (classElement.constructors.isEmpty) continue NextClassElement; | 351 if (classElement.constructors.isEmpty) continue NextClassElement; |
| 352 | 352 |
| 353 // TODO(antonm): check with AAR team if there is better approach. | 353 // TODO(antonm): check with AAR team if there is better approach. |
| 354 // As an idea: provide template as a Dart code---class C { C.name(); }--- | 354 // As an idea: provide template as a Dart code---class C { C.name(); }--- |
| 355 // and then overwrite necessary parts. | 355 // and then overwrite necessary parts. |
| 356 SynthesizedConstructorElement constructor = | 356 SynthesizedConstructorElement constructor = |
| 357 new SynthesizedConstructorElement(classElement); | 357 new SynthesizedConstructorElement(classElement); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 emitCode(unparser, imports, topLevelNodes, memberNodes); | 438 emitCode(unparser, imports, topLevelNodes, memberNodes); |
| 439 compiler.assembledCode = unparser.result; | 439 compiler.assembledCode = unparser.result; |
| 440 | 440 |
| 441 // Output verbose info about size ratio of resulting bundle to all | 441 // Output verbose info about size ratio of resulting bundle to all |
| 442 // referenced non-platform sources. | 442 // referenced non-platform sources. |
| 443 logResultBundleSizeInfo(topLevelElements); | 443 logResultBundleSizeInfo(topLevelElements); |
| 444 } | 444 } |
| 445 | 445 |
| 446 void logResultBundleSizeInfo(Set<Element> topLevelElements) { | 446 void logResultBundleSizeInfo(Set<Element> topLevelElements) { |
| 447 Collection<LibraryElement> referencedLibraries = | 447 Collection<LibraryElement> referencedLibraries = |
| 448 compiler.libraries.getValues().filter(isUserLibrary); | 448 compiler.libraries.values.filter(isUserLibrary); |
| 449 // Sum total size of scripts in each referenced library. | 449 // Sum total size of scripts in each referenced library. |
| 450 int nonPlatformSize = 0; | 450 int nonPlatformSize = 0; |
| 451 for (LibraryElement lib in referencedLibraries) { | 451 for (LibraryElement lib in referencedLibraries) { |
| 452 for (CompilationUnitElement compilationUnit in lib.compilationUnits) { | 452 for (CompilationUnitElement compilationUnit in lib.compilationUnits) { |
| 453 nonPlatformSize += compilationUnit.script.text.length; | 453 nonPlatformSize += compilationUnit.script.text.length; |
| 454 } | 454 } |
| 455 } | 455 } |
| 456 int percentage = compiler.assembledCode.length * 100 ~/ nonPlatformSize; | 456 int percentage = compiler.assembledCode.length * 100 ~/ nonPlatformSize; |
| 457 log('Total used non-platform files size: ${nonPlatformSize} bytes, ' | 457 log('Total used non-platform files size: ${nonPlatformSize} bytes, ' |
| 458 'bundle size: ${compiler.assembledCode.length} bytes (${percentage}%)'); | 458 'bundle size: ${compiler.assembledCode.length} bytes (${percentage}%)'); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 } | 541 } |
| 542 | 542 |
| 543 compareElements(e0, e1) { | 543 compareElements(e0, e1) { |
| 544 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); | 544 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); |
| 545 if (result != 0) return result; | 545 if (result != 0) return result; |
| 546 return compareBy((e) => e.position().charOffset)(e0, e1); | 546 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 547 } | 547 } |
| 548 | 548 |
| 549 List<Element> sortElements(Collection<Element> elements) => | 549 List<Element> sortElements(Collection<Element> elements) => |
| 550 sorted(elements, compareElements); | 550 sorted(elements, compareElements); |
| OLD | NEW |