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

Side by Side Diff: lib/compiler/implementation/ssa/builder.dart

Issue 10868069: Throw a runtime error when trying to call a constructor of a class that could not be resolved. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | tests/co19/co19-dart2js.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 95
96 Element getIndexAssignmentInterceptor() { 96 Element getIndexAssignmentInterceptor() {
97 return compiler.findHelper(const SourceString('indexSet')); 97 return compiler.findHelper(const SourceString('indexSet'));
98 } 98 }
99 99
100 Element getExceptionUnwrapper() { 100 Element getExceptionUnwrapper() {
101 return compiler.findHelper(const SourceString('unwrapException')); 101 return compiler.findHelper(const SourceString('unwrapException'));
102 } 102 }
103 103
104 Element getThrowRuntimeError() {
105 return compiler.findHelper(const SourceString('throwRuntimeError'));
106 }
107
104 Element getClosureConverter() { 108 Element getClosureConverter() {
105 return compiler.findHelper(const SourceString('convertDartClosureToJS')); 109 return compiler.findHelper(const SourceString('convertDartClosureToJS'));
106 } 110 }
107 111
108 Element getTraceFromException() { 112 Element getTraceFromException() {
109 return compiler.findHelper(const SourceString('getTraceFromException')); 113 return compiler.findHelper(const SourceString('getTraceFromException'));
110 } 114 }
111 115
112 Element getEqualsInterceptor() { 116 Element getEqualsInterceptor() {
113 return compiler.findHelper(const SourceString('eq')); 117 return compiler.findHelper(const SourceString('eq'));
(...skipping 2389 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 return HType.MUTABLE_ARRAY; 2507 return HType.MUTABLE_ARRAY;
2504 } 2508 }
2505 } else if (element.isGenerativeConstructor()) { 2509 } else if (element.isGenerativeConstructor()) {
2506 ClassElement cls = element.getEnclosingClass(); 2510 ClassElement cls = element.getEnclosingClass();
2507 return new HBoundedType.exact(cls.type); 2511 return new HBoundedType.exact(cls.type);
2508 } else { 2512 } else {
2509 return HType.UNKNOWN; 2513 return HType.UNKNOWN;
2510 } 2514 }
2511 } 2515 }
2512 2516
2517 Element constructor = elements[node];
2513 Selector selector = elements.getSelector(node); 2518 Selector selector = elements.getSelector(node);
2514 Element element = elements[node]; 2519 if (compiler.enqueuer.resolution.getCachedElements(constructor) === null) {
2515 if (compiler.enqueuer.resolution.getCachedElements(element) === null) { 2520 compiler.internalError("Unresolved element: $constructor", node: node);
2516 compiler.internalError("Unresolved element: $element", node: node);
2517 } 2521 }
2518 FunctionElement functionElement = element; 2522 FunctionElement functionElement = constructor;
2519 element = functionElement.defaultImplementation; 2523 constructor = functionElement.defaultImplementation;
2520 HInstruction target = new HStatic(element); 2524 HInstruction target = new HStatic(constructor);
2521 add(target); 2525 add(target);
2522 var inputs = <HInstruction>[]; 2526 var inputs = <HInstruction>[];
2523 inputs.add(target); 2527 inputs.add(target);
2524 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments, 2528 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments,
2525 element, inputs); 2529 constructor, inputs);
2526 if (!succeeded) { 2530 if (!succeeded) {
2527 // TODO(ngeoffray): Match the VM behavior and throw an 2531 // TODO(ngeoffray): Match the VM behavior and throw an
2528 // exception at runtime. 2532 // exception at runtime.
2529 compiler.cancel('Unimplemented non-matching static call', node: node); 2533 compiler.cancel('Unimplemented non-matching static call', node: node);
2530 } 2534 }
2531 2535
2532 TypeAnnotation annotation = getTypeAnnotationFromSend(node); 2536 TypeAnnotation annotation = getTypeAnnotationFromSend(node);
2533 elements.getType(annotation).arguments.forEach((Type argument) { 2537 elements.getType(annotation).arguments.forEach((Type argument) {
2534 inputs.add(analyzeTypeArgument(argument, node)); 2538 inputs.add(analyzeTypeArgument(argument, node));
2535 }); 2539 });
2536 2540
2537 HType elementType = computeType(element); 2541 HType elementType = computeType(constructor);
2538 HInstruction newInstance = new HInvokeStatic(inputs, elementType); 2542 HInstruction newInstance = new HInvokeStatic(inputs, elementType);
2539 pushWithPosition(newInstance, node); 2543 pushWithPosition(newInstance, node);
2540 } 2544 }
2541 2545
2542 visitStaticSend(Send node) { 2546 visitStaticSend(Send node) {
2543 Selector selector = elements.getSelector(node); 2547 Selector selector = elements.getSelector(node);
2544 Element element = elements[node]; 2548 Element element = elements[node];
2545 if (element === compiler.assertMethod && !compiler.enableUserAssertions) { 2549 if (element === compiler.assertMethod && !compiler.enableUserAssertions) {
2546 stack.add(graph.addConstantNull()); 2550 stack.add(graph.addConstantNull());
2547 return; 2551 return;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2597 } else if (send.selector is Send) { 2601 } else if (send.selector is Send) {
2598 Send selector = send.selector; 2602 Send selector = send.selector;
2599 if (selector.receiver is TypeAnnotation) { 2603 if (selector.receiver is TypeAnnotation) {
2600 return selector.receiver; 2604 return selector.receiver;
2601 } 2605 }
2602 } else { 2606 } else {
2603 compiler.internalError("malformed send in new expression"); 2607 compiler.internalError("malformed send in new expression");
2604 } 2608 }
2605 } 2609 }
2606 2610
2611 void generateRuntimeError(Node node, String message) {
2612 DartString messageObject = new DartString.literal(message);
2613 HInstruction errorMessage = graph.addConstantString(messageObject, node);
2614 Element helper = interceptors.getThrowRuntimeError();
2615 pushInvokeHelper1(helper, errorMessage);
2616 }
2617
2607 visitNewExpression(NewExpression node) { 2618 visitNewExpression(NewExpression node) {
2608 Element element = elements[node.send]; 2619 Element element = elements[node.send];
2609 if (Element.isInvalid(element)) { 2620 if (element != null && element.isErroneous()) {
2610 ErroneousElement error = element; 2621 ErroneousElement error = element;
2611 Message message = error.errorMessage; 2622 Message message = error.errorMessage;
2612 if (message.kind === MessageKind.CANNOT_FIND_CONSTRUCTOR) { 2623 if (message.kind === MessageKind.CANNOT_FIND_CONSTRUCTOR) {
2613 Element helper = 2624 Element helper =
2614 compiler.findHelper(const SourceString('throwNoSuchMethod')); 2625 compiler.findHelper(const SourceString('throwNoSuchMethod'));
2615 DartString receiverLiteral = new DartString.literal(''); 2626 DartString receiverLiteral = new DartString.literal('');
2616 HInstruction receiver = graph.addConstantString(receiverLiteral, node); 2627 HInstruction receiver = graph.addConstantString(receiverLiteral, node);
2617 String constructorName = 'constructor ${message.arguments[0]}'; 2628 String constructorName = 'constructor ${message.arguments[0]}';
2618 DartString nameLiteral = new DartString.literal(constructorName); 2629 DartString nameLiteral = new DartString.literal(constructorName);
2619 HInstruction name = graph.addConstantString(nameLiteral, node.send); 2630 HInstruction name = graph.addConstantString(nameLiteral, node.send);
2620 List<HInstruction> inputs = <HInstruction>[]; 2631 List<HInstruction> inputs = <HInstruction>[];
2621 node.send.arguments.forEach((argumentNode) { 2632 node.send.arguments.forEach((argumentNode) {
2622 visit(argumentNode); 2633 visit(argumentNode);
2623 HInstruction value = pop(); 2634 HInstruction value = pop();
2624 inputs.add(value); 2635 inputs.add(value);
2625 }); 2636 });
2626 HInstruction arguments = new HLiteralList(inputs); 2637 HInstruction arguments = new HLiteralList(inputs);
2627 add(arguments); 2638 add(arguments);
2628 pushInvokeHelper3(helper, receiver, name, arguments); 2639 pushInvokeHelper3(helper, receiver, name, arguments);
2640 } else if (message.kind === MessageKind.CANNOT_RESOLVE) {
2641 generateRuntimeError(node.send, message.message);
2629 } else { 2642 } else {
2630 compiler.cancel('Unimplemented unresolved constructor call', 2643 compiler.internalError('unexpected unresolved constructor call',
2631 node: node); 2644 node: node);
2632 } 2645 }
2633 } else if (node.isConst()) { 2646 } else if (node.isConst()) {
2634 // TODO(karlklose): add type representation 2647 // TODO(karlklose): add type representation
2635 ConstantHandler handler = compiler.constantHandler; 2648 ConstantHandler handler = compiler.constantHandler;
2636 Constant constant = handler.compileNodeWithDefinitions(node, elements); 2649 Constant constant = handler.compileNodeWithDefinitions(node, elements);
2637 stack.add(graph.addConstant(constant)); 2650 stack.add(graph.addConstant(constant));
2638 } else { 2651 } else {
2639 visitNewSend(node.send); 2652 visitNewSend(node.send);
2640 } 2653 }
2641 } 2654 }
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
3936 new HSubGraphBlockInformation(elseBranch.graph)); 3949 new HSubGraphBlockInformation(elseBranch.graph));
3937 3950
3938 HBasicBlock conditionStartBlock = conditionBranch.block; 3951 HBasicBlock conditionStartBlock = conditionBranch.block;
3939 conditionStartBlock.setBlockFlow(info, joinBlock); 3952 conditionStartBlock.setBlockFlow(info, joinBlock);
3940 SubGraph conditionGraph = conditionBranch.graph; 3953 SubGraph conditionGraph = conditionBranch.graph;
3941 HIf branch = conditionGraph.end.last; 3954 HIf branch = conditionGraph.end.last;
3942 assert(branch is HIf); 3955 assert(branch is HIf);
3943 branch.blockInformation = conditionStartBlock.blockFlow; 3956 branch.blockInformation = conditionStartBlock.blockFlow;
3944 } 3957 }
3945 } 3958 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698