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

Unified Diff: frog/leg/namer.dart

Issue 9193016: Add the arity to calls, and support noSuchMethodException. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' 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
===================================================================
--- frog/leg/namer.dart (revision 3496)
+++ frog/leg/namer.dart (working copy)
@@ -29,17 +29,20 @@
final String ISOLATE = "Isolate";
- String closureInvocationName() {
+ String closureInvocationName(int arity) {
// TODO(floitsch): mangle, while not conflicting with instance names.
- return '\$call';
+ return '\$call\$$arity';
floitsch 2012/01/24 11:46:03 return instanceMethodeName(const SourceString(@'$c
ngeoffray 2012/01/24 12:09:39 Done.
}
- String instanceName(SourceString name) {
- String candidate = '$name';
+ String instanceMethodName(SourceString name, int arity) {
// TODO(floitsch): mangle, while preserving uniqueness.
- return candidate;
+ return '$name\$$arity';
}
+ String instanceFieldName(SourceString name) {
+ return '$name';
+ }
+
String setterName(SourceString name) {
return 'set\$$name';
}
@@ -49,42 +52,28 @@
}
/**
- * The constructor-body name is computed from the corresponding
- * constructor element because, in the case of a super-initialization, the
- * body element is not accessible.
+ * Returns a preferred JS-id for the given top-level or static element.
+ * The returned id is guaranteed to be a valid JS-id.
*/
- String constructorBodyName(Element element) {
- assert(element.kind == ElementKind.GENERATIVE_CONSTRUCTOR);
- // TODO(floitsch): the constructor-body name must not conflict with other
- // instance fields.
- // TOD(floitsch): deal with named constructors.
- return instanceName(element.name);
- }
-
- /**
- * Returns a preferred JS-id for the given element. The returned id is
- * guaranteed to be a valid JS-id.
- *
- * For instance-members the returned strings are guaranteed not to clash. For
- * static variables there might be clashes. In the latter case the caller
- * needs to ensure uniqueness.
- */
String _computeGuess(Element element) {
- if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) {
- ConstructorBodyElement bodyElement = element;
- return constructorBodyName(bodyElement.constructor);
+ assert(!element.isInstanceMember());
+ if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR) {
+ SourceString name = getConstructorName(element);
+ return instanceMethodName(name, element.parameterCount(compiler));
+ } else {
+ // TODO(floitsch): deal with named constructors.
+ String name = '${element.name}';
+ if (element.kind == ElementKind.FUNCTION) {
+ FunctionElement functionElement = element;
+ name = '$name\$${functionElement.parameterCount(compiler)}';
+ }
+ // Prefix the name with '$' if it is reserved.
+ if (jsReserved.contains(name)) {
+ name = "\$$name";
+ assert(!jsReserved.contains(name));
+ }
+ return name;
}
-
- if (element.isInstanceMember()) return instanceName(element.name);
-
- // TODO(floitsch): deal with named constructors.
- String name = '${element.name}';
- // Prefix the name with '$' if it is reserved.
- if (jsReserved.contains(name)) {
- name = "\$$name";
- assert(!jsReserved.contains(name));
- }
- return name;
}
String getBailoutName(Element element) {
@@ -109,54 +98,55 @@
SourceString name;
if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) {
ConstructorBodyElement bodyElement = element;
- name = getConstructorName(bodyElement.constructor);
+ SourceString name = getConstructorName(bodyElement.constructor);
+ return instanceMethodName(name, bodyElement.parameterCount(compiler));
+ } else if (element.kind == ElementKind.FUNCTION) {
+ FunctionElement functionElement = element;
+ int parameterCount = functionElement.parameterCount(compiler);
+ return instanceMethodName(element.name, parameterCount);
} else {
- name = element.name;
+ return instanceFieldName(element.name);
}
- return instanceName(name);
- }
- String cached = globals[element];
- if (cached !== null) return cached;
-
- 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;
+ // Dealing with a top-level or static element.
+ String cached = globals[element];
+ if (cached !== null) return cached;
- case ElementKind.GENERATIVE_CONSTRUCTOR:
- case ElementKind.FUNCTION:
- case ElementKind.CLASS:
- case ElementKind.FIELD:
- // We need to make sure the name is unique.
- int usedCount = usedGlobals[guess];
- if (usedCount === null) {
- // No element with this name has been used before.
- usedGlobals[guess] = 1;
- globals[element] = guess;
+ String guess = _computeGuess(element);
+ switch (element.kind) {
+ case ElementKind.VARIABLE:
+ case ElementKind.PARAMETER:
+ // The name is not guaranteed to be unique.
return guess;
- } else {
- // Not the first time we see an element with this name. Append a
- // number to make it unique.
- String name;
- do {
- usedCount++;
- name = '$guess$usedCount';
- } while (usedGlobals[name] !== null);
- usedGlobals[guess] = usedCount;
- globals[element] = name;
- return name;
- }
- default:
- compiler.internalError('getName for unknown kind: ${element.kind}',
- node: element.parseNode(compiler, compiler));
+ case ElementKind.GENERATIVE_CONSTRUCTOR:
+ case ElementKind.FUNCTION:
+ case ElementKind.CLASS:
+ case ElementKind.FIELD:
+ // We need to make sure the name is unique.
+ int usedCount = usedGlobals[guess];
+ if (usedCount === null) {
+ // No element with this name has been used before.
+ usedGlobals[guess] = 1;
+ globals[element] = guess;
+ return guess;
+ } else {
+ // Not the first time we see an element with this name. Append a
+ // number to make it unique.
+ String name;
+ do {
+ usedCount++;
+ name = '$guess$usedCount';
+ } while (usedGlobals[name] !== null);
+ usedGlobals[guess] = usedCount;
+ globals[element] = name;
+ return name;
+ }
+
+ default:
+ compiler.internalError('getName for unknown kind: ${element.kind}',
+ node: element.parseNode(compiler, compiler));
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698