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

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

Issue 1062913003: Extract CallStructure from Selector. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix expentancy in unittest Created 5 years, 8 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/namer.dart
diff --git a/pkg/compiler/lib/src/js_backend/namer.dart b/pkg/compiler/lib/src/js_backend/namer.dart
index 1dd4fc100e53f96896b741fd9a12990c4609271c..af5ac3bb0ee4c8327d964c170338b6219f800525 100644
--- a/pkg/compiler/lib/src/js_backend/namer.dart
+++ b/pkg/compiler/lib/src/js_backend/namer.dart
@@ -496,23 +496,27 @@ class Namer {
*
* The resulting name is a *proposed name* and is never minified.
*/
- String privateName(LibraryElement library, String originalName) {
+ String privateName(Name originalName) {
+ String text = originalName.text;
+
// Public names are easy.
- if (!isPrivateName(originalName)) return originalName;
+ if (!originalName.isPrivate) return text;
+
+ LibraryElement library = originalName.library;
// The first library asking for a short private name wins.
LibraryElement owner =
- shortPrivateNameOwners.putIfAbsent(originalName, () => library);
+ shortPrivateNameOwners.putIfAbsent(text, () => library);
if (owner == library) {
- return originalName;
+ return text;
} else {
// Make sure to return a private name that starts with _ so it
// cannot clash with any public names.
// The name is still not guaranteed to be unique, since both the library
// name and originalName could contain $ symbols.
String libraryName = _disambiguateGlobal(library);
- return '_$libraryName\$${originalName}';
+ return '_$libraryName\$${text}';
}
}
@@ -558,9 +562,9 @@ class Namer {
///
/// This is used for the annotated names of `call`, and for the proposed name
/// for other instance methods.
- List<String> callSuffixForSelector(Selector selector) {
- List<String> suffixes = ['${selector.argumentCount}'];
- suffixes.addAll(selector.getOrderedNamedArguments());
+ List<String> callSuffixForStructure(CallStructure callStructure) {
+ List<String> suffixes = ['${callStructure.argumentCount}'];
+ suffixes.addAll(callStructure.getOrderedNamedArguments());
return suffixes;
}
@@ -582,14 +586,13 @@ class Namer {
/// Annotated name for the member being invoked by [selector].
String invocationName(Selector selector) {
- LibraryElement library = selector.library;
switch (selector.kind) {
case SelectorKind.GETTER:
- String disambiguatedName = _disambiguateMember(library, selector.name);
+ String disambiguatedName = _disambiguateMember(selector.memberName);
return deriveGetterName(disambiguatedName);
case SelectorKind.SETTER:
- String disambiguatedName = _disambiguateMember(library, selector.name);
+ String disambiguatedName = _disambiguateMember(selector.memberName);
return deriveSetterName(disambiguatedName);
case SelectorKind.OPERATOR:
@@ -599,13 +602,13 @@ class Namer {
return disambiguatedName; // Operators are not annotated.
case SelectorKind.CALL:
- List<String> suffix = callSuffixForSelector(selector);
+ List<String> suffix = callSuffixForStructure(selector.callStructure);
if (selector.name == Compiler.CALL_OPERATOR_NAME) {
// Derive the annotated name for this variant of 'call'.
return deriveCallMethodName(suffix);
}
String disambiguatedName =
- _disambiguateMember(library, selector.name, suffix);
+ _disambiguateMember(selector.memberName, suffix);
return disambiguatedName; // Methods other than call are not annotated.
default:
@@ -625,9 +628,9 @@ class Namer {
* Returns the disambiguated name for the given field, used for constructing
* the getter and setter names.
*/
- String fieldAccessorName(Element element) {
+ String fieldAccessorName(FieldElement element) {
return element.isInstanceMember
- ? _disambiguateMember(element.library, element.name)
+ ? _disambiguateMember(element.memberName)
: _disambiguateGlobal(element);
}
@@ -635,7 +638,7 @@ class Namer {
* Returns name of the JavaScript property used to store a static or instance
* field.
*/
- String fieldPropertyName(Element element) {
+ String fieldPropertyName(FieldElement element) {
return element.isInstanceMember
? instanceFieldPropertyName(element)
: _disambiguateGlobal(element);
@@ -663,7 +666,7 @@ class Namer {
/**
* Returns the JavaScript property name used to store an instance field.
*/
- String instanceFieldPropertyName(Element element) {
+ String instanceFieldPropertyName(FieldElement element) {
ClassElement enclosingClass = element.enclosingClass;
if (element.hasFixedBackendName) {
@@ -703,7 +706,7 @@ class Namer {
// No superclass uses the disambiguated name as a property name, so we can
// use it for this field. This generates nicer field names since otherwise
// the field name would have to be mangled.
- return _disambiguateMember(element.library, element.name);
+ return _disambiguateMember(element.memberName);
}
bool _isShadowingSuperField(Element element) {
@@ -717,10 +720,10 @@ class Namer {
}
/// Annotated name for the setter of [element].
- String setterForElement(Element element) {
+ String setterForElement(MemberElement element) {
// We dynamically create setters from the field-name. The setter name must
// therefore be derived from the instance field-name.
- String name = _disambiguateMember(element.library, element.name);
+ String name = _disambiguateMember(element.memberName);
return deriveSetterName(name);
}
@@ -739,28 +742,19 @@ class Namer {
}
/// Annotated name for the getter of [element].
- String getterForElement(Element element) {
+ String getterForElement(MemberElement element) {
// We dynamically create getters from the field-name. The getter name must
// therefore be derived from the instance field-name.
- String name = _disambiguateMember(element.library, element.name);
+ String name = _disambiguateMember(element.memberName);
return deriveGetterName(name);
}
- /// Property name for the getter of an instance member with [originalName]
- /// in [library].
- ///
- /// [library] may be `null` if [originalName] is known to be public.
- String getterForMember(LibraryElement library, String originalName) {
- String disambiguatedName = _disambiguateMember(library, originalName);
+ /// Property name for the getter of an instance member with [originalName].
+ String getterForMember(Name originalName) {
+ String disambiguatedName = _disambiguateMember(originalName);
return deriveGetterName(disambiguatedName);
}
- /// Property name for the getter or a public instance member with
- /// [originalName].
- String getterForPublicMember(String originalName) {
- return getterForMember(null, originalName);
- }
-
/// Disambiguated name for a compiler-owned global variable.
///
/// The resulting name is unique within the global-member namespace.
@@ -822,23 +816,19 @@ class Namer {
/// The resulting name, and its associated annotated names, are unique
/// to the ([originalName], [suffixes]) pair within the instance-member
/// namespace.
- String _disambiguateMember(LibraryElement library,
- String originalName,
+ String _disambiguateMember(Name originalName,
[List<String> suffixes = const []]) {
- // For private names, a library must be given.
- assert(isPublicName(originalName) || library != null);
-
// Build a string encoding the library name, if the name is private.
- String libraryKey = isPrivateName(originalName)
- ? _disambiguateGlobal(library)
+ String libraryKey = originalName.isPrivate
+ ? _disambiguateGlobal(originalName.library)
: '';
// In the unique key, separate the name parts by '@'.
// This avoids clashes since the original names cannot contain that symbol.
- String key = '$libraryKey@$originalName@${suffixes.join('@')}';
+ String key = '$libraryKey@${originalName.text}@${suffixes.join('@')}';
String newName = userInstanceMembers[key];
if (newName == null) {
- String proposedName = privateName(library, originalName);
+ String proposedName = privateName(originalName);
if (!suffixes.isEmpty) {
// In the proposed name, separate the name parts by '$', because the
// proposed name must be a valid identifier, but not necessarily unique.
« no previous file with comments | « pkg/compiler/lib/src/inferrer/concrete_types_inferrer.dart ('k') | pkg/compiler/lib/src/js_backend/type_variable_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698