Chromium Code Reviews| Index: compiler/java/com/google/dart/compiler/backend/isolate/DartIsolateStubGenerator.java |
| =================================================================== |
| --- compiler/java/com/google/dart/compiler/backend/isolate/DartIsolateStubGenerator.java (revision 999) |
| +++ compiler/java/com/google/dart/compiler/backend/isolate/DartIsolateStubGenerator.java (working copy) |
| @@ -99,6 +99,24 @@ |
| String name = ((DartIdentifier)x.getIdentifier()).getTargetName(); |
| return name.equals("Promise"); |
| } |
| + |
| + private String getPromiseType(DartTypeNode x) { |
| + assert isPromise(x); |
| + List<DartTypeNode> types = x.getTypeArguments(); |
| + assert types.size() == 1; |
| + return ((DartIdentifier)types.get(0).getIdentifier()).getTargetName(); |
| + } |
| + |
| + // [x] is a promise for a proxy. |
|
floitsch
2011/11/02 14:34:27
Hehe. This is Java. No [x] here :)
Ben Laurie (Google)
2011/11/02 14:45:44
Comment was pointless anyway, deleted.
|
| + private static boolean isPromiseForProxy(DartTypeNode x) { |
| + if (!isPromise(x)) |
| + return false; |
| + List<DartTypeNode> types = x.getTypeArguments(); |
| + if (types.size() != 1) |
| + return false; |
| + String name = ((DartIdentifier)types.get(0).getIdentifier()).getTargetName(); |
| + return name.endsWith("$Proxy"); |
| + } |
| private static boolean isVoid(DartTypeNode x) { |
| if (!isSimpleType(x)) |
| @@ -271,7 +289,7 @@ |
| */ |
| private void generateProxyClass(DartClass clazz) { |
| String name = clazz.getClassName(); |
| - p("interface " + name + "$Proxy {"); |
| + p("interface " + name + "$Proxy extends Proxy {"); |
| printProxyInterfaceFunctions(clazz); |
| p("}"); |
| nl(); |
| @@ -318,26 +336,32 @@ |
| final boolean isSimple = isSimpleType(returnTypeNode); |
| final boolean isProxy = isProxyType(returnTypeNode); |
| final boolean isPromise = isPromise(returnTypeNode); |
| - if (!isVoid) { |
| - p("return "); |
| - if (!isSimple) { |
| - p("new "); |
| - accept(returnTypeNode); |
| - if (!isProxy) { |
| - p("$Proxy"); |
| + final boolean isPromiseForProxy = isPromiseForProxy(returnTypeNode); |
| + if (isPromiseForProxy) { |
| + String type = getPromiseType(returnTypeNode); |
| + p("return new Promise<" + type + ">.fromValue(new " + type + "Impl(new PromiseProxy<SendPort>(new PromiseProxy<SendPort>("); |
|
floitsch
2011/11/02 14:34:27
This is just way too much without comments...: a p
Ben Laurie (Google)
2011/11/02 14:45:44
Done.
floitsch
2011/11/02 16:04:17
Can't see them.
Ben Laurie (Google)
2011/11/02 21:09:34
I have no idea why, but uploaded now.
|
| + } else { |
| + if (!isVoid) { |
| + p("return "); |
| + if (!isSimple) { |
| + p("new "); |
| + accept(returnTypeNode); |
| + if (!isProxy) { |
| + p("$Proxy"); |
| + } |
| + p("Impl("); |
| } |
| - p("Impl("); |
| } |
| - } |
| - if (isProxy) { |
| - // Note that Promises are Proxies. |
| - p("new PromiseProxy"); |
| - if (isPromise) { |
| - printTypeArguments(returnTypeNode); |
| - } else { |
| - p("<SendPort>"); |
| + if (isProxy) { |
| + // Note that Promises are Proxies. |
| + p("new PromiseProxy"); |
| + if (isPromise) { |
| + printTypeArguments(returnTypeNode); |
| + } else { |
| + p("<SendPort>"); |
| + } |
| + p("("); |
| } |
| - p("("); |
| } |
| p("this."); |
| if (isVoid) { |
| @@ -364,12 +388,16 @@ |
| }; |
| params.acceptList(func.getParams()); |
| p("])"); |
| - if (isProxy) { |
| - p(")"); |
| + if (isPromiseForProxy) { |
| + p("))))"); |
| + } else { |
| + if (isProxy) { |
| + p(")"); |
| + } |
| + if (!isSimple) { |
| + p(")"); |
| + } |
| } |
| - if (!isSimple) { |
| - p(")"); |
| - } |
| p(";"); |
| nl(); |
| @@ -411,22 +439,12 @@ |
| p("\") {"); |
| nl(); |
| int proxies = unpackParams(member); |
| - String extra = ""; |
| if (proxies != 0) { |
| - p(" Promise done = new Promise();"); |
| - nl(); |
| - p(" done.waitFor(promises, " + proxies + ");"); |
| - nl(); |
| - p(" done.addCompleteHandler((_) {"); |
| - nl(); |
| + // FIXME(benl): we don't need to gather them anymore, could just pass them directly. Too |
| + // lazy right now. |
| gatherProxies(member); |
| - extra = " "; |
| } |
| - callTarget((DartMethodDefinition)member, extra); |
| - if (proxies != 0) { |
| - p(" });"); |
| - nl(); |
| - } |
| + callTarget((DartMethodDefinition)member, ""); |
| p(" }"); |
| first = false; |
| } |
| @@ -648,7 +666,7 @@ |
| boolean isSimpleType = isSimpleType(x.getTypeNode()); |
| if (!isSimpleType) { |
| - p(" "); |
| + p(" "); |
| accept(x.getTypeNode()); |
| p(" "); |
| accept(x.getName()); |