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

Unified Diff: frog/leg/emitter.dart

Issue 9414010: Allow method-calls to getters (assuming they contain closures). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments and update status file. Created 8 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 | « frog/leg/compiler.dart ('k') | frog/leg/resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/emitter.dart
diff --git a/frog/leg/emitter.dart b/frog/leg/emitter.dart
index 72978c3ba56c52ee7eee034138013b934fe5eb7e..f978e1774152790c8151ae80fc98cbfdb2852886 100644
--- a/frog/leg/emitter.dart
+++ b/frog/leg/emitter.dart
@@ -370,6 +370,56 @@ function(child, parent) {
}
}
+ void emitCallStubForGetter(StringBuffer buffer,
+ ClassElement enclosingClass,
+ Element member,
+ Set<Selector> selectors) {
+ String prototype =
+ "${namer.isolatePropertyAccess(enclosingClass)}.prototype";
+ String getter;
+ if (member.kind == ElementKind.GETTER) {
+ getter = "this.${namer.getterName(member.name)}()";
+ } else {
+ getter = "this.${namer.instanceFieldName(member.name)}";
+ }
+ for (Selector selector in selectors) {
+ String invocationName =
+ namer.instanceMethodInvocationName(member.name, selector);
+ SourceString callName = Namer.CLOSURE_INVOCATION_NAME;
+ String closureCallName =
+ namer.instanceMethodInvocationName(callName, selector);
+ List<String> arguments = <String>[];
+ for (int i = 0; i < selector.argumentCount; i++) {
+ arguments.add("arg$i");
+ }
+ String joined = Strings.join(arguments, ", ");
+ buffer.add("$prototype.$invocationName = function($joined) {\n");
+ buffer.add(" return $getter.$closureCallName($joined);\n");
+ buffer.add("};\n");
+ }
+ }
+
+ void emitCallStubForGetters(StringBuffer buffer) {
+ for (ClassElement classElement in compiler.universe.instantiatedClasses) {
+ for (ClassElement currentClass = classElement;
+ currentClass !== null;
+ currentClass = currentClass.superclass) {
+ // TODO(floitsch): we don't need to deal with members that have been
+ // overwritten by subclasses.
+ for (Element member in currentClass.members) {
+ if (!member.isInstanceMember()) continue;
+ if (member.kind == ElementKind.GETTER ||
+ member.kind == ElementKind.FIELD) {
+ Set<Selector> selectors =
+ compiler.universe.invokedNames[member.name];
+ if (selectors == null || selectors.isEmpty()) continue;
+ emitCallStubForGetter(buffer, currentClass, member, selectors);
+ }
+ }
+ }
+ }
+ }
+
void emitStaticNonFinalFieldInitializations(StringBuffer buffer) {
// Adds initializations inside the Isolate constructor.
// Example:
@@ -463,6 +513,7 @@ function(child, parent) {
emitStaticFunctions(buffer);
emitStaticFunctionGetters(buffer);
emitDynamicFunctionGetters(buffer);
+ emitCallStubForGetters(buffer);
emitStaticFinalFieldInitializations(buffer);
buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
Element main = compiler.mainApp.find(Compiler.MAIN);
« no previous file with comments | « frog/leg/compiler.dart ('k') | frog/leg/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698