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

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

Issue 10969008: [dart2dart] Rename --cut-declaration-types flag to --force-cut-declaration-types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
« no previous file with comments | « lib/compiler/implementation/dart2js.dart ('k') | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const bool REMOVE_ASSERTS = false; 5 const bool REMOVE_ASSERTS = false;
6 6
7 class ElementAst { 7 class ElementAst {
8 final Node ast; 8 final Node ast;
9 final TreeElements treeElements; 9 final TreeElements treeElements;
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 return new Block(rewriteNodeList(statements, builder.toLink())); 93 return new Block(rewriteNodeList(statements, builder.toLink()));
94 } 94 }
95 95
96 return rewriteFunctionExpression(node, rewriteBody(node.body)); 96 return rewriteFunctionExpression(node, rewriteBody(node.body));
97 } 97 }
98 } 98 }
99 99
100 class DartBackend extends Backend { 100 class DartBackend extends Backend {
101 final List<CompilerTask> tasks; 101 final List<CompilerTask> tasks;
102 final bool cutDeclarationTypes; 102 final bool forceCutDeclarationTypes;
103 // TODO(antonm): make available from command-line options. 103 // TODO(antonm): make available from command-line options.
104 final bool outputAst = false; 104 final bool outputAst = false;
105 105
106 Map<Element, TreeElements> get resolvedElements => 106 Map<Element, TreeElements> get resolvedElements =>
107 compiler.enqueuer.resolution.resolvedElements; 107 compiler.enqueuer.resolution.resolvedElements;
108 108
109 /** 109 /**
110 * Tells whether it is safe to remove type declarations from variables, 110 * Tells whether it is safe to remove type declarations from variables,
111 * functions parameters. It becomes not safe if: 111 * functions parameters. It becomes not safe if:
112 * 1) TypeError is used somewhere in the code, 112 * 1) TypeError is used somewhere in the code,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 // Check all supertypes. 166 // Check all supertypes.
167 if (element.allSupertypes !== null) { 167 if (element.allSupertypes !== null) {
168 workQueue.addAll(element.allSupertypes.toList()); 168 workQueue.addAll(element.allSupertypes.toList());
169 } 169 }
170 } 170 }
171 } 171 }
172 return true; 172 return true;
173 } 173 }
174 174
175 DartBackend(Compiler compiler, this.cutDeclarationTypes) 175 DartBackend(Compiler compiler, this.forceCutDeclarationTypes)
176 : tasks = <CompilerTask>[], 176 : tasks = <CompilerTask>[],
177 super(compiler); 177 super(compiler);
178 178
179 void enqueueHelpers(Enqueuer world) { 179 void enqueueHelpers(Enqueuer world) {
180 // Right now resolver doesn't always resolve interfaces needed 180 // Right now resolver doesn't always resolve interfaces needed
181 // for literals, so force them. TODO(antonm): fix in the resolver. 181 // for literals, so force them. TODO(antonm): fix in the resolver.
182 final LITERAL_TYPE_NAMES = const [ 182 final LITERAL_TYPE_NAMES = const [
183 'Map', 'List', 'num', 'int', 'double', 'bool' 183 'Map', 'List', 'num', 'int', 'double', 'bool'
184 ]; 184 ];
185 final coreLibrary = compiler.coreLibrary; 185 final coreLibrary = compiler.coreLibrary;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 makePlaceholders(element) { 313 makePlaceholders(element) {
314 collector.collect(element); 314 collector.collect(element);
315 if (element is ClassElement) { 315 if (element is ClassElement) {
316 classMembers[element].forEach(makePlaceholders); 316 classMembers[element].forEach(makePlaceholders);
317 } 317 }
318 } 318 }
319 topLevelElements.forEach(makePlaceholders); 319 topLevelElements.forEach(makePlaceholders);
320 // Create renames. 320 // Create renames.
321 Map<Node, String> renames = new Map<Node, String>(); 321 Map<Node, String> renames = new Map<Node, String>();
322 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); 322 Map<LibraryElement, String> imports = new Map<LibraryElement, String>();
323 bool shouldCutDeclarationTypes = cutDeclarationTypes 323 bool shouldCutDeclarationTypes = forceCutDeclarationTypes
324 || (compiler.enableMinification 324 || (compiler.enableMinification
325 && isSafeToRemoveTypeDeclarations(classMembers)); 325 && isSafeToRemoveTypeDeclarations(classMembers));
326 renamePlaceholders( 326 renamePlaceholders(
327 compiler, collector, renames, imports, 327 compiler, collector, renames, imports,
328 fixedMemberNames, shouldCutDeclarationTypes); 328 fixedMemberNames, shouldCutDeclarationTypes);
329 329
330 // Sort elements. 330 // Sort elements.
331 final sortedTopLevels = sortElements(topLevelElements); 331 final sortedTopLevels = sortElements(topLevelElements);
332 final sortedClassMembers = new Map<ClassElement, List<Element>>(); 332 final sortedClassMembers = new Map<ClassElement, List<Element>>();
333 classMembers.forEach((classElement, members) { 333 classMembers.forEach((classElement, members) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 433 }
434 434
435 compareElements(e0, e1) { 435 compareElements(e0, e1) {
436 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); 436 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1);
437 if (result != 0) return result; 437 if (result != 0) return result;
438 return compareBy((e) => e.position().charOffset)(e0, e1); 438 return compareBy((e) => e.position().charOffset)(e0, e1);
439 } 439 }
440 440
441 List<Element> sortElements(Collection<Element> elements) => 441 List<Element> sortElements(Collection<Element> elements) =>
442 sorted(elements, compareElements); 442 sorted(elements, compareElements);
OLDNEW
« no previous file with comments | « lib/compiler/implementation/dart2js.dart ('k') | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698