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

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

Issue 10875040: Support customizing API (and hence mock) compiler to minify the output. (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
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 /** 5 /**
6 * Renames only top-level elements that would let to ambiguity if not renamed. 6 * Renames only top-level elements that would let to ambiguity if not renamed.
7 * TODO(smok): Make sure that top-level fields are correctly renamed. 7 * TODO(smok): Make sure that top-level fields are correctly renamed.
8 */ 8 */
9 void renamePlaceholders( 9 void renamePlaceholders(
10 Compiler compiler, 10 Compiler compiler,
11 PlaceholderCollector placeholderCollector, 11 PlaceholderCollector placeholderCollector,
12 Map<Node, String> renames, 12 Map<Node, String> renames,
13 Map<LibraryElement, String> imports) { 13 Map<LibraryElement, String> imports,
14 bool minify) {
14 final Map<LibraryElement, Map<String, String>> renamed 15 final Map<LibraryElement, Map<String, String>> renamed
15 = new Map<LibraryElement, Map<String, String>>(); 16 = new Map<LibraryElement, Map<String, String>>();
16 final Set<String> usedTopLevelIdentifiers = new Set<String>(); 17 final Set<String> usedTopLevelIdentifiers = new Set<String>();
17 // TODO(antonm): we should also populate this set with top-level 18 // TODO(antonm): we should also populate this set with top-level
18 // names from core library. 19 // names from core library.
19 usedTopLevelIdentifiers.add('main'); // Never rename anything to 'main'. 20 usedTopLevelIdentifiers.add('main'); // Never rename anything to 'main'.
20 21
21 Generator topLevelGenerator = 22 Generator topLevelGenerator =
22 true ? conservativeGenerator : new MinifyingGenerator('ABCD').generate; 23 minify ? new MinifyingGenerator('ABCD').generate : conservativeGenerator;
23 String generateUniqueName(name) { 24 String generateUniqueName(name) {
24 String newName = topLevelGenerator( 25 String newName = topLevelGenerator(
25 name, usedTopLevelIdentifiers.contains); 26 name, usedTopLevelIdentifiers.contains);
26 usedTopLevelIdentifiers.add(newName); 27 usedTopLevelIdentifiers.add(newName);
27 return newName; 28 return newName;
28 } 29 }
29 30
30 rename(library, originalName) => 31 rename(library, originalName) =>
31 renamed.putIfAbsent(library, () => <String>{}) 32 renamed.putIfAbsent(library, () => <String>{})
32 .putIfAbsent(originalName, () => generateUniqueName(originalName)); 33 .putIfAbsent(originalName, () => generateUniqueName(originalName));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 int length = alphabet.length; 122 int length = alphabet.length;
122 StringBuffer resultBuilder = new StringBuffer(); 123 StringBuffer resultBuilder = new StringBuffer();
123 while (index >= length) { 124 while (index >= length) {
124 resultBuilder.add(alphabet[index % length]); 125 resultBuilder.add(alphabet[index % length]);
125 index ~/= length; 126 index ~/= length;
126 } 127 }
127 resultBuilder.add(alphabet[index]); 128 resultBuilder.add(alphabet[index]);
128 return resultBuilder.toString(); 129 return resultBuilder.toString();
129 } 130 }
130 } 131 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/dart_backend/backend.dart ('k') | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698