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

Side by Side Diff: lib/compiler/implementation/tree/nodes.dart

Issue 10441044: Refactor common logic of SsaBuilder.visitSend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Next iteration Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 interface Visitor<R> { 5 interface Visitor<R> {
6 R visitBlock(Block node); 6 R visitBlock(Block node);
7 R visitBreakStatement(BreakStatement node); 7 R visitBreakStatement(BreakStatement node);
8 R visitCascade(Cascade node); 8 R visitCascade(Cascade node);
9 R visitCascadeReceiver(CascadeReceiver node); 9 R visitCascadeReceiver(CascadeReceiver node);
10 R visitCaseMatch(CaseMatch node); 10 R visitCaseMatch(CaseMatch node);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 return argumentsNode.getEndToken(); 286 return argumentsNode.getEndToken();
287 } 287 }
288 if (selector !== null) return selector.getEndToken(); 288 if (selector !== null) return selector.getEndToken();
289 return receiver.getBeginToken(); 289 return receiver.getBeginToken();
290 } 290 }
291 291
292 Send copyWithReceiver(Node newReceiver) { 292 Send copyWithReceiver(Node newReceiver) {
293 assert(receiver === null); 293 assert(receiver === null);
294 return new Send(newReceiver, selector, argumentsNode); 294 return new Send(newReceiver, selector, argumentsNode);
295 } 295 }
296
297 analyse([
ahe 2012/06/01 13:50:34 To be perfectly clear: I don't like this method.
Anton Muhin 2012/06/01 14:07:06 What will you like more? analyseSubtype? subtype
298 bool methodInterceptionEnabled,
299 TreeElements elements,
300 SendVisitor sendVisitor]) {
301 if (isSuperCall) {
302 return sendVisitor.visitSuperSend(this);
303 } else if (isOperator && methodInterceptionEnabled) {
304 return sendVisitor.visitOperatorSend(this);
305 } else if (isPropertyAccess) {
306 return sendVisitor.visitGetterSend(this);
307 } else if (Elements.isClosureSend(this, elements)) {
308 return sendVisitor.visitClosureSend(this);
309 } else {
310 Element element = elements[this];
311 if (element === null) {
312 // Example: f() with 'f' unbound.
313 // This can only happen inside an instance method.
314 return sendVisitor.visitDynamicSend(this);
315 } else if (element.kind == ElementKind.CLASS) {
316 sendVisitor.internalError("Cannot generate code for send", node: node);
317 } else if (element.isInstanceMember()) {
318 // Example: f() with 'f' bound to instance method.
319 return sendVisitor.visitDynamicSend(this);
320 } else if (element.kind === ElementKind.FOREIGN) {
321 return sendVisitor.visitForeignSend(this);
322 } else if (!element.isInstanceMember()) {
323 // Example: A.f() or f() with 'f' bound to a static function.
324 // Also includes new A() or new A.named() which is treated like a
325 // static call to a factory.
326 return sendVisitor.visitStaticSend(this);
327 } else {
328 sendVisitor.internalError("Cannot generate code for send", node: node);
329 }
330 }
331 }
332 }
333
334 interface SendVisitor {
335 visitSuperSend(Send node);
336 visitOperatorSend(Send node);
337 visitGetterSend(Send node);
338 visitClosureSend(Send node);
339 visitDynamicSend(Send node);
340 visitForeignSend(Send node);
341 visitStaticSend(Send node);
342
343 internalError(String reason, [Node node]);
296 } 344 }
297 345
298 class Postfix extends NodeList { 346 class Postfix extends NodeList {
299 Postfix() : super(nodes: const EmptyLink<Node>()); 347 Postfix() : super(nodes: const EmptyLink<Node>());
300 Postfix.singleton(Node argument) : super.singleton(argument); 348 Postfix.singleton(Node argument) : super.singleton(argument);
301 } 349 }
302 350
303 class Prefix extends NodeList { 351 class Prefix extends NodeList {
304 Prefix() : super(nodes: const EmptyLink<Node>()); 352 Prefix() : super(nodes: const EmptyLink<Node>());
305 Prefix.singleton(Node argument) : super.singleton(argument); 353 Prefix.singleton(Node argument) : super.singleton(argument);
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 * argument). 1748 * argument).
1701 * 1749 *
1702 * TODO(ahe): This method is controversial, the team needs to discuss 1750 * TODO(ahe): This method is controversial, the team needs to discuss
1703 * if top-level methods are acceptable and what naming conventions to 1751 * if top-level methods are acceptable and what naming conventions to
1704 * use. 1752 * use.
1705 */ 1753 */
1706 initializerDo(Node node, f(Node node)) { 1754 initializerDo(Node node, f(Node node)) {
1707 SendSet send = node.asSendSet(); 1755 SendSet send = node.asSendSet();
1708 if (send !== null) return f(send.arguments.head); 1756 if (send !== null) return f(send.arguments.head);
1709 } 1757 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698