Rename various Proxy classes. Provide a Proxy interface.

Review URL: http://codereview.chromium.org//8383034

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@684 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
benl@google.com 2011-10-25 11:09:54 +00:00
parent 60fbf3c3cd
commit a64fbe01a8
6 changed files with 32 additions and 17 deletions

View file

@ -277,7 +277,7 @@ public class DartIsolateStubGenerator extends AbstractBackend {
nl(); nl();
nl(); nl();
p("class " + name + "$ProxyImpl extends Proxy implements " + name + "$Proxy {"); p("class " + name + "$ProxyImpl extends ProxyImpl implements " + name + "$Proxy {");
nl(); nl();
p(" " + name + "$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }"); p(" " + name + "$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }");
nl(); nl();

View file

@ -262,23 +262,23 @@ class PromiseImpl<T> implements Promise<T> {
} }
} }
class ProxyImpl { class ProxyBase {
ProxyImpl.forPort(SendPort port) { ProxyBase.forPort(SendPort port) {
_promise = new Promise<SendPort>(); _promise = new Promise<SendPort>();
_promise.complete(port); _promise.complete(port);
} }
// Construct a proxy for a message reply; see the [Proxy.forReply] // Construct a proxy for a message reply; see the [Proxy.forReply]
// documentation for more details. // documentation for more details.
ProxyImpl.forReply(Promise<SendPort> port) { ProxyBase.forReply(Promise<SendPort> port) {
_promise = port; _promise = port;
} }
// Note that comparing proxies or using them in maps is illegal // Note that comparing proxies or using them in maps is illegal
// until they complete. // until they complete.
bool operator ==(var other) { bool operator ==(var other) {
return (other is ProxyImpl) && _promise.value == other._promise.value; return (other is ProxyBase) && _promise.value == other._promise.value;
} }
int hashCode() => _promise.value.hashCode(); int hashCode() => _promise.value.hashCode();

View file

@ -90,15 +90,29 @@ interface Promise<T> factory PromiseImpl<T> {
} }
class Proxy extends ProxyImpl { interface Proxy factory ProxyImpl {
Proxy.forPort(SendPort port) Proxy.forPort(SendPort port);
Proxy.forIsolate(Isolate isolate);
Proxy._forIsolateWithPromise(Isolate isolate, Promise<SendPort> promise);
/*
* The [Proxy.forReply] constructor is used to create a proxy for
* the object that will be the reply to a message send.
*/
Proxy.forReply(Promise<SendPort> port);
}
class ProxyImpl extends ProxyBase implements Proxy {
ProxyImpl.forPort(SendPort port)
: super.forPort(port) { } : super.forPort(port) { }
Proxy.forIsolate(Isolate isolate) ProxyImpl.forIsolate(Isolate isolate)
: this._forIsolateWithPromise(isolate, new Promise<SendPort>()); : this._forIsolateWithPromise(isolate, new Promise<SendPort>());
Proxy._forIsolateWithPromise(Isolate isolate, Promise<SendPort> promise) ProxyImpl._forIsolateWithPromise(Isolate isolate, Promise<SendPort> promise)
// TODO(floitsch): it seems wrong to call super.forReply here. // TODO(floitsch): it seems wrong to call super.forReply here.
: super.forReply(promise) { : super.forReply(promise) {
isolate.spawn().then((SendPort port) { isolate.spawn().then((SendPort port) {
@ -110,7 +124,7 @@ class Proxy extends ProxyImpl {
* The [Proxy.forReply] constructor is used to create a proxy for * The [Proxy.forReply] constructor is used to create a proxy for
* the object that will be the reply to a message send. * the object that will be the reply to a message send.
*/ */
Proxy.forReply(Promise<SendPort> port) ProxyImpl.forReply(Promise<SendPort> port)
: super.forReply(port) { } : super.forReply(port) { }
} }
@ -130,7 +144,7 @@ class Dispatcher<T> {
} }
static SendPort serve(Dispatcher dispatcher) { static SendPort serve(Dispatcher dispatcher) {
ReceivePort port = ProxyImpl.register(dispatcher); ReceivePort port = ProxyBase.register(dispatcher);
dispatcher._serve(port); dispatcher._serve(port);
return port.toSendPort(); return port.toSendPort();
} }

View file

@ -16,7 +16,7 @@ interface Purse$Proxy {
Promise<int> deposit(int amount, Purse$Proxy source); Promise<int> deposit(int amount, Purse$Proxy source);
} }
class Purse$ProxyImpl extends Proxy implements Purse$Proxy { class Purse$ProxyImpl extends ProxyImpl implements Purse$Proxy {
Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }
Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { } Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { }
factory Purse$ProxyImpl.createIsolate() { factory Purse$ProxyImpl.createIsolate() {
@ -93,7 +93,7 @@ interface PowerfulPurse$Proxy {
Purse$Proxy weak(); Purse$Proxy weak();
} }
class PowerfulPurse$ProxyImpl extends Proxy implements PowerfulPurse$Proxy { class PowerfulPurse$ProxyImpl extends ProxyImpl implements PowerfulPurse$Proxy {
PowerfulPurse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } PowerfulPurse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }
PowerfulPurse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { } PowerfulPurse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { }
factory PowerfulPurse$ProxyImpl.createIsolate() { factory PowerfulPurse$ProxyImpl.createIsolate() {
@ -169,7 +169,7 @@ interface Mint$Proxy {
PowerfulPurse$Proxy promote(Purse$Proxy purse); PowerfulPurse$Proxy promote(Purse$Proxy purse);
} }
class Mint$ProxyImpl extends Proxy implements Mint$Proxy { class Mint$ProxyImpl extends ProxyImpl implements Mint$Proxy {
Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }
Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { } Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { }
factory Mint$ProxyImpl.createIsolate() { factory Mint$ProxyImpl.createIsolate() {

View file

@ -12,7 +12,7 @@ interface Mint$Proxy {
Purse$Proxy createPurse(int balance); Purse$Proxy createPurse(int balance);
} }
class Mint$ProxyImpl extends Proxy implements Mint$Proxy { class Mint$ProxyImpl extends ProxyImpl implements Mint$Proxy {
Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }
Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { } Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { }
factory Mint$ProxyImpl.createIsolate() { factory Mint$ProxyImpl.createIsolate() {
@ -69,7 +69,7 @@ interface Purse$Proxy {
Promise<int> deposit(int amount, Purse$Proxy source); Promise<int> deposit(int amount, Purse$Proxy source);
} }
class Purse$ProxyImpl extends Proxy implements Purse$Proxy { class Purse$ProxyImpl extends ProxyImpl implements Purse$Proxy {
Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { }
Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { } Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])) { }
factory Purse$ProxyImpl.createIsolate() { factory Purse$ProxyImpl.createIsolate() {

View file

@ -67,7 +67,8 @@ class DartStubTestCase(test_case.StandardTestCase):
t = open(tmp, 'r') t = open(tmp, 'r')
while True: while True:
line = s.readline() line = s.readline()
if not (re.match('^\s+$', line) or line.startswith('//') or line.startswith('#')): if not (re.match('^\s+$', line) or line.startswith('//')
or line.startswith('#')):
break break
d.write(line) d.write(line)
d.write(t.read()) d.write(t.read())