Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package com.google.dart.compiler.backend.isolate; | 5 package com.google.dart.compiler.backend.isolate; |
| 6 | 6 |
| 7 import java.io.FileNotFoundException; | 7 import java.io.FileNotFoundException; |
| 8 import java.io.IOException; | 8 import java.io.IOException; |
| 9 import java.io.PrintStream; | 9 import java.io.PrintStream; |
| 10 import java.util.Collection; | 10 import java.util.Collection; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 return true; | 92 return true; |
| 93 return false; | 93 return false; |
| 94 } | 94 } |
| 95 | 95 |
| 96 private static boolean isPromise(DartTypeNode x) { | 96 private static boolean isPromise(DartTypeNode x) { |
| 97 if (!(x.getIdentifier() instanceof DartIdentifier)) | 97 if (!(x.getIdentifier() instanceof DartIdentifier)) |
| 98 return false; | 98 return false; |
| 99 String name = ((DartIdentifier)x.getIdentifier()).getTargetName(); | 99 String name = ((DartIdentifier)x.getIdentifier()).getTargetName(); |
| 100 return name.equals("Promise"); | 100 return name.equals("Promise"); |
| 101 } | 101 } |
| 102 | |
| 103 private String getPromiseType(DartTypeNode x) { | |
| 104 assert isPromise(x); | |
| 105 List<DartTypeNode> types = x.getTypeArguments(); | |
| 106 assert types.size() == 1; | |
| 107 return ((DartIdentifier)types.get(0).getIdentifier()).getTargetName(); | |
| 108 } | |
| 109 | |
| 110 // [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.
| |
| 111 private static boolean isPromiseForProxy(DartTypeNode x) { | |
| 112 if (!isPromise(x)) | |
| 113 return false; | |
| 114 List<DartTypeNode> types = x.getTypeArguments(); | |
| 115 if (types.size() != 1) | |
| 116 return false; | |
| 117 String name = ((DartIdentifier)types.get(0).getIdentifier()).getTargetName() ; | |
| 118 return name.endsWith("$Proxy"); | |
| 119 } | |
| 102 | 120 |
| 103 private static boolean isVoid(DartTypeNode x) { | 121 private static boolean isVoid(DartTypeNode x) { |
| 104 if (!isSimpleType(x)) | 122 if (!isSimpleType(x)) |
| 105 return false; | 123 return false; |
| 106 return ((DartIdentifier)x.getIdentifier()).getTargetName().equals("void"); | 124 return ((DartIdentifier)x.getIdentifier()).getTargetName().equals("void"); |
| 107 } | 125 } |
| 108 | 126 |
| 109 private static boolean isProxyType(DartTypeNode x) { | 127 private static boolean isProxyType(DartTypeNode x) { |
| 110 if (!(x.getIdentifier() instanceof DartIdentifier)) | 128 if (!(x.getIdentifier() instanceof DartIdentifier)) |
| 111 return false; | 129 return false; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 * return new Purse$ProxyImpl(this.call(["sproutPurse"])); | 282 * return new Purse$ProxyImpl(this.call(["sproutPurse"])); |
| 265 * } | 283 * } |
| 266 * | 284 * |
| 267 * void deposit(int amount, Purse$Proxy source) { | 285 * void deposit(int amount, Purse$Proxy source) { |
| 268 * this.send(["deposit", amount, source]); | 286 * this.send(["deposit", amount, source]); |
| 269 * } | 287 * } |
| 270 * } | 288 * } |
| 271 */ | 289 */ |
| 272 private void generateProxyClass(DartClass clazz) { | 290 private void generateProxyClass(DartClass clazz) { |
| 273 String name = clazz.getClassName(); | 291 String name = clazz.getClassName(); |
| 274 p("interface " + name + "$Proxy {"); | 292 p("interface " + name + "$Proxy extends Proxy {"); |
| 275 printProxyInterfaceFunctions(clazz); | 293 printProxyInterfaceFunctions(clazz); |
| 276 p("}"); | 294 p("}"); |
| 277 nl(); | 295 nl(); |
| 278 nl(); | 296 nl(); |
| 279 | 297 |
| 280 p("class " + name + "$ProxyImpl extends ProxyImpl implements " + name + "$Pr oxy {"); | 298 p("class " + name + "$ProxyImpl extends ProxyImpl implements " + name + "$Pr oxy {"); |
| 281 nl(); | 299 nl(); |
| 282 p(" " + name + "$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }"); | 300 p(" " + name + "$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }"); |
| 283 nl(); | 301 nl(); |
| 284 p(" " + name | 302 p(" " + name |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 311 return false; | 329 return false; |
| 312 p(" {"); | 330 p(" {"); |
| 313 nl(); | 331 nl(); |
| 314 p(" "); | 332 p(" "); |
| 315 final DartFunction func = x.getFunction(); | 333 final DartFunction func = x.getFunction(); |
| 316 final DartTypeNode returnTypeNode = func.getReturnTypeNode(); | 334 final DartTypeNode returnTypeNode = func.getReturnTypeNode(); |
| 317 final boolean isVoid = isVoid(returnTypeNode); | 335 final boolean isVoid = isVoid(returnTypeNode); |
| 318 final boolean isSimple = isSimpleType(returnTypeNode); | 336 final boolean isSimple = isSimpleType(returnTypeNode); |
| 319 final boolean isProxy = isProxyType(returnTypeNode); | 337 final boolean isProxy = isProxyType(returnTypeNode); |
| 320 final boolean isPromise = isPromise(returnTypeNode); | 338 final boolean isPromise = isPromise(returnTypeNode); |
| 321 if (!isVoid) { | 339 final boolean isPromiseForProxy = isPromiseForProxy(returnTypeNode); |
| 322 p("return "); | 340 if (isPromiseForProxy) { |
| 323 if (!isSimple) { | 341 String type = getPromiseType(returnTypeNode); |
| 324 p("new "); | 342 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.
| |
| 325 accept(returnTypeNode); | 343 } else { |
| 326 if (!isProxy) { | 344 if (!isVoid) { |
| 327 p("$Proxy"); | 345 p("return "); |
| 346 if (!isSimple) { | |
| 347 p("new "); | |
| 348 accept(returnTypeNode); | |
| 349 if (!isProxy) { | |
| 350 p("$Proxy"); | |
| 351 } | |
| 352 p("Impl("); | |
| 328 } | 353 } |
| 329 p("Impl("); | |
| 330 } | 354 } |
| 331 } | 355 if (isProxy) { |
| 332 if (isProxy) { | 356 // Note that Promises are Proxies. |
| 333 // Note that Promises are Proxies. | 357 p("new PromiseProxy"); |
| 334 p("new PromiseProxy"); | 358 if (isPromise) { |
| 335 if (isPromise) { | 359 printTypeArguments(returnTypeNode); |
| 336 printTypeArguments(returnTypeNode); | 360 } else { |
| 337 } else { | 361 p("<SendPort>"); |
| 338 p("<SendPort>"); | 362 } |
| 363 p("("); | |
| 339 } | 364 } |
| 340 p("("); | |
| 341 } | 365 } |
| 342 p("this."); | 366 p("this."); |
| 343 if (isVoid) { | 367 if (isVoid) { |
| 344 p("send"); | 368 p("send"); |
| 345 } else { | 369 } else { |
| 346 p("call"); | 370 p("call"); |
| 347 } | 371 } |
| 348 p("([\""); | 372 p("([\""); |
| 349 accept(x.getName()); | 373 accept(x.getName()); |
| 350 p("\""); | 374 p("\""); |
| 351 DartVisitor params = new DartVisitor() { | 375 DartVisitor params = new DartVisitor() { |
| 352 @Override | 376 @Override |
| 353 public boolean visit(DartIdentifier x, DartContext ctx) { | 377 public boolean visit(DartIdentifier x, DartContext ctx) { |
| 354 p(", "); | 378 p(", "); |
| 355 p(x.getTargetName()); | 379 p(x.getTargetName()); |
| 356 return false; | 380 return false; |
| 357 } | 381 } |
| 358 | 382 |
| 359 @Override | 383 @Override |
| 360 public boolean visit(DartParameter x, DartContext ctx) { | 384 public boolean visit(DartParameter x, DartContext ctx) { |
| 361 accept(x.getName()); | 385 accept(x.getName()); |
| 362 return false; | 386 return false; |
| 363 } | 387 } |
| 364 }; | 388 }; |
| 365 params.acceptList(func.getParams()); | 389 params.acceptList(func.getParams()); |
| 366 p("])"); | 390 p("])"); |
| 367 if (isProxy) { | 391 if (isPromiseForProxy) { |
| 368 p(")"); | 392 p("))))"); |
| 369 } | 393 } else { |
| 370 if (!isSimple) { | 394 if (isProxy) { |
| 371 p(")"); | 395 p(")"); |
| 396 } | |
| 397 if (!isSimple) { | |
| 398 p(")"); | |
| 399 } | |
| 372 } | 400 } |
| 373 p(";"); | 401 p(";"); |
| 374 nl(); | 402 nl(); |
| 375 | 403 |
| 376 p(" }"); | 404 p(" }"); |
| 377 nl(); | 405 nl(); |
| 378 | 406 |
| 379 return false; | 407 return false; |
| 380 } | 408 } |
| 381 | 409 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 404 if (first) { | 432 if (first) { |
| 405 p(" "); | 433 p(" "); |
| 406 } else { | 434 } else { |
| 407 p(" else "); | 435 p(" else "); |
| 408 } | 436 } |
| 409 p("if (command == \""); | 437 p("if (command == \""); |
| 410 printFunctionName(member); | 438 printFunctionName(member); |
| 411 p("\") {"); | 439 p("\") {"); |
| 412 nl(); | 440 nl(); |
| 413 int proxies = unpackParams(member); | 441 int proxies = unpackParams(member); |
| 414 String extra = ""; | |
| 415 if (proxies != 0) { | 442 if (proxies != 0) { |
| 416 p(" Promise done = new Promise();"); | 443 // FIXME(benl): we don't need to gather them anymore, could just pass th em directly. Too |
| 417 nl(); | 444 // lazy right now. |
| 418 p(" done.waitFor(promises, " + proxies + ");"); | |
| 419 nl(); | |
| 420 p(" done.addCompleteHandler((_) {"); | |
| 421 nl(); | |
| 422 gatherProxies(member); | 445 gatherProxies(member); |
| 423 extra = " "; | |
| 424 } | 446 } |
| 425 callTarget((DartMethodDefinition)member, extra); | 447 callTarget((DartMethodDefinition)member, ""); |
| 426 if (proxies != 0) { | |
| 427 p(" });"); | |
| 428 nl(); | |
| 429 } | |
| 430 p(" }"); | 448 p(" }"); |
| 431 first = false; | 449 first = false; |
| 432 } | 450 } |
| 433 p(" else {"); | 451 p(" else {"); |
| 434 nl(); | 452 nl(); |
| 435 p(" // TODO(kasperl,benl): Somehow throw an exception instead."); | 453 p(" // TODO(kasperl,benl): Somehow throw an exception instead."); |
| 436 nl(); | 454 nl(); |
| 437 p(" reply(\"Exception: command '\" + command + \"' not understood by " + dispatcherName + ".\");"); | 455 p(" reply(\"Exception: command '\" + command + \"' not understood by " + dispatcherName + ".\");"); |
| 438 nl(); | 456 nl(); |
| 439 p(" }"); | 457 p(" }"); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 accept(param); | 659 accept(param); |
| 642 } | 660 } |
| 643 return false; | 661 return false; |
| 644 } | 662 } |
| 645 | 663 |
| 646 @Override | 664 @Override |
| 647 public boolean visit(DartParameter x, DartContext ctx) { | 665 public boolean visit(DartParameter x, DartContext ctx) { |
| 648 boolean isSimpleType = isSimpleType(x.getTypeNode()); | 666 boolean isSimpleType = isSimpleType(x.getTypeNode()); |
| 649 | 667 |
| 650 if (!isSimpleType) { | 668 if (!isSimpleType) { |
| 651 p(" "); | 669 p(" "); |
| 652 accept(x.getTypeNode()); | 670 accept(x.getTypeNode()); |
| 653 p(" "); | 671 p(" "); |
| 654 accept(x.getName()); | 672 accept(x.getName()); |
| 655 p(" = new "); | 673 p(" = new "); |
| 656 accept(x.getTypeNode()); | 674 accept(x.getTypeNode()); |
| 657 p("Impl(promises[" + proxies + "]);"); | 675 p("Impl(promises[" + proxies + "]);"); |
| 658 ++proxies; | 676 ++proxies; |
| 659 nl(); | 677 nl(); |
| 660 } | 678 } |
| 661 return false; | 679 return false; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 847 } | 865 } |
| 848 p(" "); | 866 p(" "); |
| 849 visitor.accept(x.getName()); | 867 visitor.accept(x.getName()); |
| 850 p("("); | 868 p("("); |
| 851 printParams(func.getParams()); | 869 printParams(func.getParams()); |
| 852 p(")"); | 870 p(")"); |
| 853 | 871 |
| 854 return true; | 872 return true; |
| 855 } | 873 } |
| 856 } | 874 } |
| OLD | NEW |