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

Unified Diff: pkg/compiler/lib/src/js_backend/minify_namer.dart

Issue 891673003: dart2js: Refactoring, documentation, and a few bugfixes in Namer class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/js_backend/constant_emitter.dart ('k') | pkg/compiler/lib/src/js_backend/namer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_backend/minify_namer.dart
diff --git a/pkg/compiler/lib/src/js_backend/minify_namer.dart b/pkg/compiler/lib/src/js_backend/minify_namer.dart
index 4641afdd5fe6fd5cbfe1bb187b86c03eb3060a83..579429e82259688f042e27cd3e17a3d79707d9be 100644
--- a/pkg/compiler/lib/src/js_backend/minify_namer.dart
+++ b/pkg/compiler/lib/src/js_backend/minify_namer.dart
@@ -26,14 +26,18 @@ class MinifyNamer extends Namer {
_FieldNamingRegistry fieldRegistry;
- // You can pass an invalid identifier to this and unlike its non-minifying
- // counterpart it will never return the proposedName as the new fresh name.
+ /// You can pass an invalid identifier to this and unlike its non-minifying
+ /// counterpart it will never return the proposedName as the new fresh name.
+ ///
+ /// [sanitizeForNatives] and [sanitizeForAnnotations] are ignored because the
+ /// minified names will always avoid clashing with annotated names or natives.
String getFreshName(String proposedName,
Set<String> usedNames,
Map<String, String> suggestedNames,
- {bool ensureSafe: true}) {
- var freshName;
- var suggestion = suggestedNames[proposedName];
+ {bool sanitizeForNatives: false,
+ bool sanitizeForAnnotations: false}) {
+ String freshName;
+ String suggestion = suggestedNames[proposedName];
if (suggestion != null && !usedNames.contains(suggestion)) {
freshName = suggestion;
} else {
@@ -44,18 +48,20 @@ class MinifyNamer extends Namer {
return freshName;
}
- String getClosureVariableName(String name, int id) {
+ String getClosureVariableName(String _, int id) {
if (id < ALPHABET_CHARACTERS) {
return new String.fromCharCodes([_letterNumber(id)]);
}
- return "${getMappedInstanceName('closure')}_$id";
+ // Fall back to a slightly longer name.
+ String basename = _disambiguateMember(null, 'closure');
+ return '${basename}_$id';
}
// From issue 7554. These should not be used on objects (as instance
// variables) because they clash with names from the DOM. However, it is
// OK to use them as fields, as we only access fields directly if we know
// the receiver type.
- static const _reservedNativeProperties = const <String>[
+ static const List<String> _reservedNativeProperties = const <String>[
'Q', 'a', 'b', 'c', 'd', 'e', 'f', 'r', 'x', 'y', 'z',
// 2-letter:
'ch', 'cx', 'cy', 'db', 'dx', 'dy', 'fr', 'fx', 'fy', 'go', 'id', 'k1',
@@ -80,9 +86,11 @@ class MinifyNamer extends Namer {
'Text', 'time', 'type', 'view', 'warn', 'wrap', 'ZERO'];
void reserveBackendNames() {
- for (var name in _reservedNativeProperties) {
+ for (String name in _reservedNativeProperties) {
if (name.length < 2) {
- instanceNameMap[name] = name;
+ // Ensure the 1-letter names are disambiguated to the same name.
+ String disambiguatedName = name;
+ reservePublicMemberName(name, disambiguatedName);
}
usedInstanceNames.add(name);
// Getter and setter names are autogenerated by prepending 'g' and 's' to
@@ -166,12 +174,12 @@ class MinifyNamer extends Namer {
// in a predictable order determined by the proposed name. This is in order
// to make the renamer stable: small changes in the input should nornally
// result in relatively small changes in the output.
- for (var n = 1; n <= 3; n++) {
+ for (int n = 1; n <= 3; n++) {
int h = hash;
while (h > 10) {
- var codes = <int>[_letterNumber(h)];
+ List<int> codes = <int>[_letterNumber(h)];
int h2 = h ~/ ALPHABET_CHARACTERS;
- for (var i = 1; i < n; i++) {
+ for (int i = 1; i < n; i++) {
codes.add(_alphaNumericNumber(h2));
h2 ~/= ALPHANUMERIC_CHARACTERS;
}
@@ -213,9 +221,9 @@ class MinifyNamer extends Namer {
/// If we can't find a hash based name in the three-letter space, then base
/// the name on a letter and a counter.
String _badName(int hash, Set<String> usedNames) {
- var startLetter = new String.fromCharCodes([_letterNumber(hash)]);
- var name;
- var i = 0;
+ String startLetter = new String.fromCharCodes([_letterNumber(hash)]);
+ String name;
+ int i = 0;
do {
name = "$startLetter${i++}";
} while (usedNames.contains(name));
@@ -291,8 +299,7 @@ class _FieldNamingRegistry {
nameStore.add(MinifyNamer._reservedNativeProperties[count]);
} else {
nameStore.add(namer.getFreshName("field$count",
- namer.usedInstanceNames, namer.suggestedInstanceNames,
- ensureSafe: true));
+ namer.usedInstanceNames, namer.suggestedInstanceNames));
}
}
@@ -422,7 +429,7 @@ class _MixinFieldNamingScope extends _FieldNamingScope {
: super.inherit(container, superScope, registry);
String _nextName() {
- var proposed = super._nextName();
+ String proposed = super._nextName();
return proposed + r'$';
}
}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/constant_emitter.dart ('k') | pkg/compiler/lib/src/js_backend/namer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698