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

Side by Side Diff: lib/compiler/implementation/ssa/builder.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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 List<LabelElement> labels() { 779 List<LabelElement> labels() {
780 List<LabelElement> result = null; 780 List<LabelElement> result = null;
781 for (LabelElement element in target.labels) { 781 for (LabelElement element in target.labels) {
782 if (result === null) result = <LabelElement>[]; 782 if (result === null) result = <LabelElement>[];
783 result.add(element); 783 result.add(element);
784 } 784 }
785 return (result === null) ? const <LabelElement>[] : result; 785 return (result === null) ? const <LabelElement>[] : result;
786 } 786 }
787 } 787 }
788 788
789 class SsaBuilder implements Visitor { 789 class SsaBuilder implements Visitor, SendVisitor {
790 final SsaBuilderTask builder; 790 final SsaBuilderTask builder;
791 TreeElements elements; 791 TreeElements elements;
792 final Interceptors interceptors; 792 final Interceptors interceptors;
793 final WorkItem work; 793 final WorkItem work;
794 bool methodInterceptionEnabled; 794 bool methodInterceptionEnabled;
795 HGraph graph; 795 HGraph graph;
796 LocalsHandler localsHandler; 796 LocalsHandler localsHandler;
797 HInstruction rethrowableException; 797 HInstruction rethrowableException;
798 798
799 Map<TargetElement, JumpHandler> jumpTargets; 799 Map<TargetElement, JumpHandler> jumpTargets;
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after
2240 visit(closure); 2240 visit(closure);
2241 List<HInstruction> inputs = <HInstruction>[pop()]; 2241 List<HInstruction> inputs = <HInstruction>[pop()];
2242 String invocationName = compiler.namer.closureInvocationName( 2242 String invocationName = compiler.namer.closureInvocationName(
2243 new Selector(SelectorKind.INVOCATION, 2243 new Selector(SelectorKind.INVOCATION,
2244 parameters.requiredParameterCount)); 2244 parameters.requiredParameterCount));
2245 push(new HForeign(new DartString.literal('#.$invocationName'), 2245 push(new HForeign(new DartString.literal('#.$invocationName'),
2246 const LiteralDartString('var'), 2246 const LiteralDartString('var'),
2247 inputs)); 2247 inputs));
2248 } 2248 }
2249 2249
2250 handleForeignSend(Send node) { 2250 visitForeignSend(Send node) {
2251 Element element = elements[node]; 2251 Element element = elements[node];
2252 if (element.name == const SourceString('JS')) { 2252 if (element.name == const SourceString('JS')) {
2253 handleForeignJs(node); 2253 handleForeignJs(node);
2254 } else if (element.name == const SourceString('UNINTERCEPTED')) { 2254 } else if (element.name == const SourceString('UNINTERCEPTED')) {
2255 handleForeignUnintercepted(node); 2255 handleForeignUnintercepted(node);
2256 } else if (element.name == const SourceString('JS_HAS_EQUALS')) { 2256 } else if (element.name == const SourceString('JS_HAS_EQUALS')) {
2257 handleForeignJsHasEquals(node); 2257 handleForeignJsHasEquals(node);
2258 } else if (element.name == const SourceString('JS_CURRENT_ISOLATE')) { 2258 } else if (element.name == const SourceString('JS_CURRENT_ISOLATE')) {
2259 handleForeignJsCurrentIsolate(node); 2259 handleForeignJsCurrentIsolate(node);
2260 } else if (element.name == const SourceString('JS_CALL_IN_ISOLATE')) { 2260 } else if (element.name == const SourceString('JS_CALL_IN_ISOLATE')) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 if (element.kind == ElementKind.GETTER) { 2394 if (element.kind == ElementKind.GETTER) {
2395 target = new HInvokeStatic(Selector.GETTER, inputs); 2395 target = new HInvokeStatic(Selector.GETTER, inputs);
2396 add(target); 2396 add(target);
2397 inputs = <HInstruction>[target]; 2397 inputs = <HInstruction>[target];
2398 } 2398 }
2399 addDynamicSendArgumentsToList(node, inputs); 2399 addDynamicSendArgumentsToList(node, inputs);
2400 push(new HInvokeClosure(selector, inputs)); 2400 push(new HInvokeClosure(selector, inputs));
2401 } 2401 }
2402 } 2402 }
2403 2403
2404 visitGetterSend(Send node) {
2405 generateGetter(node, elements[node]);
2406 }
2407
2404 visitSend(Send node) { 2408 visitSend(Send node) {
2405 if (node.isSuperCall) { 2409 node.analyse(
2406 visitSuperSend(node); 2410 methodInterceptionEnabled: this.methodInterceptionEnabled,
2407 } else if (node.isOperator && methodInterceptionEnabled) { 2411 elements: this.elements,
2408 visitOperatorSend(node); 2412 sendVisitor: this
2409 } else if (node.isPropertyAccess) { 2413 );
2410 generateGetter(node, elements[node]); 2414 }
2411 } else if (Elements.isClosureSend(node, elements)) { 2415
2412 visitClosureSend(node); 2416 // TODO(antonm): migrate rest of SsaBuilder to internalError.
2413 } else { 2417 internalError(String reason, [Node node]) {
2414 Element element = elements[node]; 2418 compiler.internalError(reason, node: node);
2415 if (element === null) {
2416 // Example: f() with 'f' unbound.
2417 // This can only happen inside an instance method.
2418 visitDynamicSend(node);
2419 } else if (element.kind == ElementKind.CLASS) {
2420 compiler.internalError("Cannot generate code for send", node: node);
2421 } else if (element.isInstanceMember()) {
2422 // Example: f() with 'f' bound to instance method.
2423 visitDynamicSend(node);
2424 } else if (element.kind === ElementKind.FOREIGN) {
2425 handleForeignSend(node);
2426 } else if (!element.isInstanceMember()) {
2427 // Example: A.f() or f() with 'f' bound to a static function.
2428 // Also includes new A() or new A.named() which is treated like a
2429 // static call to a factory.
2430 visitStaticSend(node);
2431 } else {
2432 compiler.internalError("Cannot generate code for send", node: node);
2433 }
2434 }
2435 } 2419 }
2436 2420
2437 // TODO(karlklose): share with resolver. 2421 // TODO(karlklose): share with resolver.
2438 TypeAnnotation getTypeAnnotationFromSend(Send send) { 2422 TypeAnnotation getTypeAnnotationFromSend(Send send) {
2439 if (send.selector is TypeAnnotation) { 2423 if (send.selector is TypeAnnotation) {
2440 return send.selector; 2424 return send.selector;
2441 } else if (send.selector is Send) { 2425 } else if (send.selector is Send) {
2442 Send selector = send.selector; 2426 Send selector = send.selector;
2443 if (selector.receiver is TypeAnnotation) { 2427 if (selector.receiver is TypeAnnotation) {
2444 return selector.receiver; 2428 return selector.receiver;
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
3405 <HInstruction>[target, input], 3389 <HInstruction>[target, input],
3406 HType.STRING)); 3390 HType.STRING));
3407 return builder.pop(); 3391 return builder.pop();
3408 } 3392 }
3409 3393
3410 HInstruction result(Node node) { 3394 HInstruction result(Node node) {
3411 flushLiterals(node); 3395 flushLiterals(node);
3412 return prefix; 3396 return prefix;
3413 } 3397 }
3414 } 3398 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/tree/nodes.dart » ('j') | lib/compiler/implementation/tree/nodes.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698