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

Unified Diff: frog/leg/namer.dart

Issue 9243011: Implement named constructors and resolving of redirecting constructors and super-initializers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move constructor name creation to lookup function. Created 8 years, 11 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: frog/leg/namer.dart
diff --git a/frog/leg/namer.dart b/frog/leg/namer.dart
index 0568f5844092f5800e962443c70e6cc699b2d544..5fd6f94fc8ede0dee5a367c1fb3dc21425b41a69 100644
--- a/frog/leg/namer.dart
+++ b/frog/leg/namer.dart
@@ -91,6 +91,11 @@ class Namer {
return '${getName(element)}\$bailout';
}
+ SourceString getConstructorName(FunctionElement constructor) {
+ String dartName = constructor.name.stringValue;
+ return new SourceString(dartName.replaceFirst('\.', '\$'));
+ }
+
/**
* Returns a preferred JS-id for the given element. The returned id is
* guaranteed to be a valid JS-id. Globals and static fields are furthermore
@@ -101,22 +106,33 @@ class Namer {
*/
String getName(Element element) {
if (element.isInstanceMember()) {
- return instanceName(element.name);
+ SourceString name;
+ if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) {
+ ConstructorBodyElement bodyElement = element;
+ name = getConstructorName(bodyElement.constructor);
+ } else {
+ name = element.name;
+ }
+ return instanceName(name);
}
-
String cached = globals[element];
if (cached !== null) return cached;
- String guess = _computeGuess(element);
+ String guess;
+ if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR) {
+ guess = getConstructorName(element).stringValue;
+ } else {
+ guess = _computeGuess(element);
+ }
switch (element.kind) {
case ElementKind.VARIABLE:
case ElementKind.PARAMETER:
// The name is not guaranteed to be unique.
return guess;
+ case ElementKind.GENERATIVE_CONSTRUCTOR:
case ElementKind.FUNCTION:
case ElementKind.CLASS:
- case ElementKind.GENERATIVE_CONSTRUCTOR:
case ElementKind.FIELD:
// We need to make sure the name is unique.
int usedCount = usedGlobals[guess];

Powered by Google App Engine
This is Rietveld 408576698