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

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

Issue 11013010: Throw AbstractClassInstantiationError on abstract class instantiation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merged with 10990108. Created 8 years, 2 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 113
114 Element getExceptionUnwrapper() { 114 Element getExceptionUnwrapper() {
115 return compiler.findHelper(const SourceString('unwrapException')); 115 return compiler.findHelper(const SourceString('unwrapException'));
116 } 116 }
117 117
118 Element getThrowRuntimeError() { 118 Element getThrowRuntimeError() {
119 return compiler.findHelper(const SourceString('throwRuntimeError')); 119 return compiler.findHelper(const SourceString('throwRuntimeError'));
120 } 120 }
121 121
122 Element getThrowAbstractClassInstantiationError() {
123 return compiler.findHelper(
124 const SourceString('throwAbstractClassInstantiationError'));
125 }
126
122 Element getClosureConverter() { 127 Element getClosureConverter() {
123 return compiler.findHelper(const SourceString('convertDartClosureToJS')); 128 return compiler.findHelper(const SourceString('convertDartClosureToJS'));
124 } 129 }
125 130
126 Element getTraceFromException() { 131 Element getTraceFromException() {
127 return compiler.findHelper(const SourceString('getTraceFromException')); 132 return compiler.findHelper(const SourceString('getTraceFromException'));
128 } 133 }
129 134
130 Element getEqualsInterceptor() { 135 Element getEqualsInterceptor() {
131 return compiler.findHelper(const SourceString('eq')); 136 return compiler.findHelper(const SourceString('eq'));
(...skipping 2798 matching lines...) Expand 10 before | Expand all | Expand 10 after
2930 // TODO(ngeoffray): Match the VM behavior and throw an 2935 // TODO(ngeoffray): Match the VM behavior and throw an
2931 // exception at runtime. 2936 // exception at runtime.
2932 compiler.cancel('Unimplemented non-matching static call', node: node); 2937 compiler.cancel('Unimplemented non-matching static call', node: node);
2933 } 2938 }
2934 2939
2935 TypeAnnotation annotation = node.getTypeAnnotation(); 2940 TypeAnnotation annotation = node.getTypeAnnotation();
2936 if (annotation == null) { 2941 if (annotation == null) {
2937 compiler.internalError("malformed send in new expression"); 2942 compiler.internalError("malformed send in new expression");
2938 } 2943 }
2939 InterfaceType type = elements.getType(annotation); 2944 InterfaceType type = elements.getType(annotation);
2945 if (type.element.modifiers.isAbstract() &&
2946 constructor.isGenerativeConstructor()) {
2947 generateAbstractClassInstantiationError(node, type.name.slowToString());
2948 return;
2949 }
2940 if (compiler.world.needsRti(constructor.enclosingElement)) { 2950 if (compiler.world.needsRti(constructor.enclosingElement)) {
2941 type.arguments.forEach((DartType argument) { 2951 type.arguments.forEach((DartType argument) {
2942 inputs.add(analyzeTypeArgument(argument, node)); 2952 inputs.add(analyzeTypeArgument(argument, node));
2943 }); 2953 });
2944 } 2954 }
2945 2955
2946 HType elementType = computeType(constructor); 2956 HType elementType = computeType(constructor);
2947 HInstruction newInstance = new HInvokeStatic(inputs, elementType); 2957 HInstruction newInstance = new HInvokeStatic(inputs, elementType);
2948 pushWithPosition(newInstance, node); 2958 pushWithPosition(newInstance, node);
2949 2959
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3004 3014
3005 visitGetterSend(Send node) { 3015 visitGetterSend(Send node) {
3006 generateGetter(node, elements[node]); 3016 generateGetter(node, elements[node]);
3007 } 3017 }
3008 3018
3009 // TODO(antonm): migrate rest of SsaBuilder to internalError. 3019 // TODO(antonm): migrate rest of SsaBuilder to internalError.
3010 internalError(String reason, [Node node]) { 3020 internalError(String reason, [Node node]) {
3011 compiler.internalError(reason, node: node); 3021 compiler.internalError(reason, node: node);
3012 } 3022 }
3013 3023
3014 void generateRuntimeError(Node node, String message) { 3024 void generateError(Node node, String message, Element helper) {
3015 DartString messageObject = new DartString.literal(message); 3025 DartString messageObject = new DartString.literal(message);
3016 Constant messageConstant = 3026 Constant messageConstant =
3017 constantSystem.createString(messageObject, node); 3027 constantSystem.createString(messageObject, node);
3018 HInstruction errorMessage = graph.addConstant(messageConstant); 3028 HInstruction errorMessage = graph.addConstant(messageConstant);
3019 Element helper = interceptors.getThrowRuntimeError();
3020 pushInvokeHelper1(helper, errorMessage); 3029 pushInvokeHelper1(helper, errorMessage);
3021 } 3030 }
3022 3031
3032 void generateRuntimeError(Node node, String message) {
3033 generateError(node, message, interceptors.getThrowRuntimeError());
3034 }
3035
3036 void generateAbstractClassInstantiationError(Node node, String message) {
3037 generateError(node,
3038 message,
3039 interceptors.getThrowAbstractClassInstantiationError());
3040 }
3041
3023 void generateThrowNoSuchMethod(Node diagnosticNode, 3042 void generateThrowNoSuchMethod(Node diagnosticNode,
3024 String methodName, 3043 String methodName,
3025 [Link<Node> argumentNodes, 3044 [Link<Node> argumentNodes,
3026 List<HInstruction> argumentValues]) { 3045 List<HInstruction> argumentValues]) {
3027 Element helper = 3046 Element helper =
3028 compiler.findHelper(const SourceString('throwNoSuchMethod')); 3047 compiler.findHelper(const SourceString('throwNoSuchMethod'));
3029 Constant receiverConstant = 3048 Constant receiverConstant =
3030 constantSystem.createString(new DartString.empty(), diagnosticNode); 3049 constantSystem.createString(new DartString.empty(), diagnosticNode);
3031 HInstruction receiver = graph.addConstant(receiverConstant); 3050 HInstruction receiver = graph.addConstant(receiverConstant);
3032 DartString dartString = new DartString.literal(methodName); 3051 DartString dartString = new DartString.literal(methodName);
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after
4463 new HSubGraphBlockInformation(elseBranch.graph)); 4482 new HSubGraphBlockInformation(elseBranch.graph));
4464 4483
4465 HBasicBlock conditionStartBlock = conditionBranch.block; 4484 HBasicBlock conditionStartBlock = conditionBranch.block;
4466 conditionStartBlock.setBlockFlow(info, joinBlock); 4485 conditionStartBlock.setBlockFlow(info, joinBlock);
4467 SubGraph conditionGraph = conditionBranch.graph; 4486 SubGraph conditionGraph = conditionBranch.graph;
4468 HIf branch = conditionGraph.end.last; 4487 HIf branch = conditionGraph.end.last;
4469 assert(branch is HIf); 4488 assert(branch is HIf);
4470 branch.blockInformation = conditionStartBlock.blockFlow; 4489 branch.blockInformation = conditionStartBlock.blockFlow;
4471 } 4490 }
4472 } 4491 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698