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

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: Comments & some fixes 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
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..9d1cc802cb07d0f8805f3ec1d4f03cc1b5a8cd75 100644
--- a/pkg/compiler/lib/src/js_backend/minify_namer.dart
+++ b/pkg/compiler/lib/src/js_backend/minify_namer.dart
@@ -31,9 +31,9 @@ class MinifyNamer extends Namer {
String getFreshName(String proposedName,
Set<String> usedNames,
Map<String, String> suggestedNames,
- {bool ensureSafe: true}) {
- var freshName;
- var suggestion = suggestedNames[proposedName];
+ {bool sanitizeForNatives, bool sanitizeForAnnotations}) {
floitsch 2015/02/06 12:59:55 Add comment that sanitizeForNatives/sanitizeForAnn
asgerf 2015/02/06 13:27:06 Done.
+ String freshName;
+ String suggestion = suggestedNames[proposedName];
if (suggestion != null && !usedNames.contains(suggestion)) {
freshName = suggestion;
} else {
@@ -44,18 +44,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 +82,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 +170,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 +217,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 +295,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 +425,7 @@ class _MixinFieldNamingScope extends _FieldNamingScope {
: super.inherit(container, superScope, registry);
String _nextName() {
- var proposed = super._nextName();
+ String proposed = super._nextName();
return proposed + r'$';
}
}

Powered by Google App Engine
This is Rietveld 408576698