Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(931)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 * 2) The code has typedefs in right hand side of IS checks, 130 * 2) The code has typedefs in right hand side of IS checks,
131 * 3) The code has classes which extend typedefs, have type arguments typedefs 131 * 3) The code has classes which extend typedefs, have type arguments typedefs
132 * or type variable bounds typedefs. 132 * or type variable bounds typedefs.
133 * These restrictions can be less strict. 133 * These restrictions can be less strict.
134 */ 134 */
135 bool isSafeToRemoveTypeDeclarations( 135 bool isSafeToRemoveTypeDeclarations(
136 Map<ClassElement, Set<Element>> classMembers) { 136 Map<ClassElement, Set<Element>> classMembers) {
137 Set<DartType> processedTypes = new Set<DartType>(); 137 Set<DartType> processedTypes = new Set<DartType>();
138 List<DartType> workQueue = new List<DartType>(); 138 List<DartType> workQueue = new List<DartType>();
139 workQueue.addAll( 139 workQueue.addAll(
140 classMembers.keys.map((classElement) => classElement.thisType)); 140 classMembers.keys.mappedBy((classElement) => classElement.thisType));
141 workQueue.addAll(compiler.resolverWorld.isChecks); 141 workQueue.addAll(compiler.resolverWorld.isChecks);
142 Element typeErrorElement = 142 Element typeErrorElement =
143 compiler.coreLibrary.find(new SourceString('TypeError')); 143 compiler.coreLibrary.find(new SourceString('TypeError'));
144 DartType typeErrorType = typeErrorElement.computeType(compiler); 144 DartType typeErrorType = typeErrorElement.computeType(compiler);
145 if (workQueue.indexOf(typeErrorType) != -1) { 145 if (workQueue.indexOf(typeErrorType) != -1) {
146 return false; 146 return false;
147 } 147 }
148 148
149 void processTypeArguments(Element classElement, NodeList typeArguments) { 149 void processTypeArguments(Element classElement, NodeList typeArguments) {
150 if (typeArguments == null) return; 150 if (typeArguments == null) return;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 'Map', 'List', 'num', 'int', 'double', 'bool' 203 'Map', 'List', 'num', 'int', 'double', 'bool'
204 ]; 204 ];
205 final coreLibrary = compiler.coreLibrary; 205 final coreLibrary = compiler.coreLibrary;
206 for (final name in LITERAL_TYPE_NAMES) { 206 for (final name in LITERAL_TYPE_NAMES) {
207 ClassElement classElement = coreLibrary.findLocal(new SourceString(name)); 207 ClassElement classElement = coreLibrary.findLocal(new SourceString(name));
208 classElement.ensureResolved(compiler); 208 classElement.ensureResolved(compiler);
209 } 209 }
210 } 210 }
211 void codegen(WorkItem work) { } 211 void codegen(WorkItem work) { }
212 void processNativeClasses(Enqueuer world, 212 void processNativeClasses(Enqueuer world,
213 Collection<LibraryElement> libraries) { } 213 Iterable<LibraryElement> libraries) { }
214 214
215 bool isUserLibrary(LibraryElement lib) { 215 bool isUserLibrary(LibraryElement lib) {
216 final INTERNAL_HELPERS = [ 216 final INTERNAL_HELPERS = [
217 compiler.jsHelperLibrary, 217 compiler.jsHelperLibrary,
218 compiler.interceptorsLibrary, 218 compiler.interceptorsLibrary,
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() {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 final unparser = new EmitterUnparser(renames); 444 final unparser = new EmitterUnparser(renames);
445 emitCode(unparser, imports, topLevelNodes, memberNodes); 445 emitCode(unparser, imports, topLevelNodes, memberNodes);
446 compiler.assembledCode = unparser.result; 446 compiler.assembledCode = unparser.result;
447 447
448 // Output verbose info about size ratio of resulting bundle to all 448 // Output verbose info about size ratio of resulting bundle to all
449 // referenced non-platform sources. 449 // referenced non-platform sources.
450 logResultBundleSizeInfo(topLevelElements); 450 logResultBundleSizeInfo(topLevelElements);
451 } 451 }
452 452
453 void logResultBundleSizeInfo(Set<Element> topLevelElements) { 453 void logResultBundleSizeInfo(Set<Element> topLevelElements) {
454 Collection<LibraryElement> referencedLibraries = 454 Iterable<LibraryElement> referencedLibraries =
455 compiler.libraries.values.filter(isUserLibrary); 455 compiler.libraries.values.where(isUserLibrary);
456 // Sum total size of scripts in each referenced library. 456 // Sum total size of scripts in each referenced library.
457 int nonPlatformSize = 0; 457 int nonPlatformSize = 0;
458 for (LibraryElement lib in referencedLibraries) { 458 for (LibraryElement lib in referencedLibraries) {
459 for (CompilationUnitElement compilationUnit in lib.compilationUnits) { 459 for (CompilationUnitElement compilationUnit in lib.compilationUnits) {
460 nonPlatformSize += compilationUnit.script.text.length; 460 nonPlatformSize += compilationUnit.script.text.length;
461 } 461 }
462 } 462 }
463 int percentage = compiler.assembledCode.length * 100 ~/ nonPlatformSize; 463 int percentage = compiler.assembledCode.length * 100 ~/ nonPlatformSize;
464 log('Total used non-platform files size: ${nonPlatformSize} bytes, ' 464 log('Total used non-platform files size: ${nonPlatformSize} bytes, '
465 'bundle size: ${compiler.assembledCode.length} bytes (${percentage}%)'); 465 'bundle size: ${compiler.assembledCode.length} bytes (${percentage}%)');
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 result.sort(comparison); 554 result.sort(comparison);
555 return result; 555 return result;
556 } 556 }
557 557
558 compareElements(e0, e1) { 558 compareElements(e0, e1) {
559 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); 559 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1);
560 if (result != 0) return result; 560 if (result != 0) return result;
561 return compareBy((e) => e.position().charOffset)(e0, e1); 561 return compareBy((e) => e.position().charOffset)(e0, e1);
562 } 562 }
563 563
564 List<Element> sortElements(Collection<Element> elements) => 564 List<Element> sortElements(Iterable<Element> elements) =>
565 sorted(elements, compareElements); 565 sorted(elements, compareElements);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698