Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 2183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2297 push(new HInvokeSuper(inputs)); | 2301 push(new HInvokeSuper(inputs)); |
| 2298 } else { | 2302 } else { |
| 2299 target = new HInvokeSuper(inputs); | 2303 target = new HInvokeSuper(inputs); |
| 2300 add(target); | 2304 add(target); |
| 2301 inputs = <HInstruction>[target]; | 2305 inputs = <HInstruction>[target]; |
| 2302 addDynamicSendArgumentsToList(node, inputs); | 2306 addDynamicSendArgumentsToList(node, inputs); |
| 2303 push(new HInvokeClosure(selector, inputs)); | 2307 push(new HInvokeClosure(selector, inputs)); |
| 2304 } | 2308 } |
| 2305 } | 2309 } |
| 2306 | 2310 |
| 2307 visitNewSend(Send node) { | 2311 visitNewSend(Send node, Element constructor) { |
|
ngeoffray
2012/08/24 15:43:48
I'd rather not have this new parameter. The send a
karlklose
2012/08/28 09:09:15
Done.
| |
| 2308 computeType(element) { | 2312 computeType(element) { |
| 2309 Element originalElement = elements[node]; | 2313 Element originalElement = elements[node]; |
| 2310 if (originalElement.getEnclosingClass() === compiler.listClass) { | 2314 if (originalElement.getEnclosingClass() === compiler.listClass) { |
| 2311 if (node.arguments.isEmpty()) { | 2315 if (node.arguments.isEmpty()) { |
| 2312 return HType.EXTENDABLE_ARRAY; | 2316 return HType.EXTENDABLE_ARRAY; |
| 2313 } else { | 2317 } else { |
| 2314 return HType.MUTABLE_ARRAY; | 2318 return HType.MUTABLE_ARRAY; |
| 2315 } | 2319 } |
| 2316 } else if (element.isGenerativeConstructor()) { | 2320 } else if (element.isGenerativeConstructor()) { |
| 2317 ClassElement cls = element.getEnclosingClass(); | 2321 ClassElement cls = element.getEnclosingClass(); |
| 2318 return new HBoundedType.exact(cls.type); | 2322 return new HBoundedType.exact(cls.type); |
| 2319 } else { | 2323 } else { |
| 2320 return HType.UNKNOWN; | 2324 return HType.UNKNOWN; |
| 2321 } | 2325 } |
| 2322 } | 2326 } |
| 2323 | 2327 |
| 2324 Selector selector = elements.getSelector(node); | 2328 Selector selector = elements.getSelector(node); |
| 2325 Element element = elements[node]; | 2329 if (compiler.enqueuer.resolution.getCachedElements(constructor) === null) { |
| 2326 if (compiler.enqueuer.resolution.getCachedElements(element) === null) { | 2330 compiler.internalError("Unresolved element: $constructor", node: node); |
| 2327 compiler.internalError("Unresolved element: $element", node: node); | |
| 2328 } | 2331 } |
| 2329 FunctionElement functionElement = element; | 2332 FunctionElement functionElement = constructor; |
| 2330 element = functionElement.defaultImplementation; | 2333 constructor = functionElement.defaultImplementation; |
| 2331 HInstruction target = new HStatic(element); | 2334 HInstruction target = new HStatic(constructor); |
| 2332 add(target); | 2335 add(target); |
| 2333 var inputs = <HInstruction>[]; | 2336 var inputs = <HInstruction>[]; |
| 2334 inputs.add(target); | 2337 inputs.add(target); |
| 2335 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments, | 2338 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments, |
| 2336 element, inputs); | 2339 constructor, inputs); |
| 2337 if (!succeeded) { | 2340 if (!succeeded) { |
| 2338 // TODO(ngeoffray): Match the VM behavior and throw an | 2341 // TODO(ngeoffray): Match the VM behavior and throw an |
| 2339 // exception at runtime. | 2342 // exception at runtime. |
| 2340 compiler.cancel('Unimplemented non-matching static call', node: node); | 2343 compiler.cancel('Unimplemented non-matching static call', node: node); |
| 2341 } | 2344 } |
| 2342 | 2345 |
| 2343 HType elementType = computeType(element); | 2346 HType elementType = computeType(constructor); |
| 2344 HInstruction newInstance = new HInvokeStatic(inputs, elementType); | 2347 HInstruction newInstance = new HInvokeStatic(inputs, elementType); |
| 2345 pushWithPosition(newInstance, node); | 2348 pushWithPosition(newInstance, node); |
| 2346 | 2349 |
| 2347 TypeAnnotation annotation = getTypeAnnotationFromSend(node); | 2350 TypeAnnotation annotation = getTypeAnnotationFromSend(node); |
| 2348 Type type = elements.getType(annotation); | 2351 Type type = elements.getType(annotation); |
| 2349 generateSetRuntimeTypeInformation(newInstance, type); | 2352 generateSetRuntimeTypeInformation(newInstance, type); |
| 2350 } | 2353 } |
| 2351 | 2354 |
| 2352 generateSetRuntimeTypeInformation(HInstruction instance, Type type) { | 2355 generateSetRuntimeTypeInformation(HInstruction instance, Type type) { |
| 2353 if (compiler.codegenWorld.rti.hasTypeArguments(type)) { | 2356 if (compiler.codegenWorld.rti.hasTypeArguments(type)) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2417 } else if (send.selector is Send) { | 2420 } else if (send.selector is Send) { |
| 2418 Send selector = send.selector; | 2421 Send selector = send.selector; |
| 2419 if (selector.receiver is TypeAnnotation) { | 2422 if (selector.receiver is TypeAnnotation) { |
| 2420 return selector.receiver; | 2423 return selector.receiver; |
| 2421 } | 2424 } |
| 2422 } else { | 2425 } else { |
| 2423 compiler.internalError("malformed send in new expression"); | 2426 compiler.internalError("malformed send in new expression"); |
| 2424 } | 2427 } |
| 2425 } | 2428 } |
| 2426 | 2429 |
| 2430 void generateRuntimeError(Node node, String message) { | |
| 2431 final messageObject = new DartString.literal(message.toString()); | |
|
ngeoffray
2012/08/24 15:43:48
final -> DartString (for consistency)
ngeoffray
2012/08/24 15:43:48
message is already a String.
karlklose
2012/08/28 09:09:15
Done.
karlklose
2012/08/28 09:09:15
Done.
| |
| 2432 HInstruction errorMessage = graph.addConstantString(messageObject, node); | |
| 2433 Element helper = interceptors.getThrowRuntimeError(); | |
| 2434 pushInvokeHelper1(helper, errorMessage); | |
| 2435 } | |
| 2436 | |
| 2427 visitNewExpression(NewExpression node) { | 2437 visitNewExpression(NewExpression node) { |
| 2428 Element element = elements[node.send]; | 2438 Element element = elements[node.send]; |
| 2429 if (Element.isInvalid(element)) { | 2439 if (Element.isInvalid(element)) { |
| 2430 ErroneousElement error = element; | 2440 ErroneousElement error = element; |
| 2431 Message message = error.errorMessage; | 2441 Message message = error.errorMessage; |
| 2432 if (message.kind === MessageKind.CANNOT_FIND_CONSTRUCTOR) { | 2442 if (message.kind === MessageKind.CANNOT_FIND_CONSTRUCTOR) { |
| 2433 Element helper = | 2443 Element helper = |
| 2434 compiler.findHelper(const SourceString('throwNoSuchMethod')); | 2444 compiler.findHelper(const SourceString('throwNoSuchMethod')); |
| 2435 DartString receiverLiteral = new DartString.literal(''); | 2445 DartString receiverLiteral = new DartString.literal(''); |
| 2436 HInstruction receiver = graph.addConstantString(receiverLiteral, node); | 2446 HInstruction receiver = graph.addConstantString(receiverLiteral, node); |
| 2437 String constructorName = 'constructor ${message.arguments[0]}'; | 2447 String constructorName = 'constructor ${message.arguments[0]}'; |
| 2438 DartString nameLiteral = new DartString.literal(constructorName); | 2448 DartString nameLiteral = new DartString.literal(constructorName); |
| 2439 HInstruction name = graph.addConstantString(nameLiteral, node.send); | 2449 HInstruction name = graph.addConstantString(nameLiteral, node.send); |
| 2440 List<HInstruction> inputs = <HInstruction>[]; | 2450 List<HInstruction> inputs = <HInstruction>[]; |
| 2441 node.send.arguments.forEach((argumentNode) { | 2451 node.send.arguments.forEach((argumentNode) { |
| 2442 visit(argumentNode); | 2452 visit(argumentNode); |
| 2443 HInstruction value = pop(); | 2453 HInstruction value = pop(); |
| 2444 inputs.add(value); | 2454 inputs.add(value); |
| 2445 }); | 2455 }); |
| 2446 HInstruction arguments = new HLiteralList(inputs); | 2456 HInstruction arguments = new HLiteralList(inputs); |
| 2447 add(arguments); | 2457 add(arguments); |
| 2448 pushInvokeHelper3(helper, receiver, name, arguments); | 2458 pushInvokeHelper3(helper, receiver, name, arguments); |
| 2459 } else if (message.kind === MessageKind.CANNOT_RESOLVE) { | |
| 2460 generateRuntimeError(node.send, message.message); | |
| 2449 } else { | 2461 } else { |
| 2450 compiler.cancel('Unimplemented unresolved constructor call', | 2462 compiler.cancel('Unimplemented unresolved constructor call', |
|
ngeoffray
2012/08/24 15:43:48
Can this still happen?
karlklose
2012/08/28 09:09:15
It should not. I changed it to an internal error s
| |
| 2451 node: node); | 2463 node: node); |
| 2452 } | 2464 } |
| 2453 } else if (node.isConst()) { | 2465 } else if (node.isConst()) { |
| 2454 // TODO(karlklose): add type representation | 2466 // TODO(karlklose): add type representation |
| 2455 ConstantHandler handler = compiler.constantHandler; | 2467 ConstantHandler handler = compiler.constantHandler; |
| 2456 Constant constant = handler.compileNodeWithDefinitions(node, elements); | 2468 Constant constant = handler.compileNodeWithDefinitions(node, elements); |
| 2457 stack.add(graph.addConstant(constant)); | 2469 stack.add(graph.addConstant(constant)); |
| 2458 } else { | 2470 } else { |
| 2459 visitNewSend(node.send); | 2471 visitNewSend(node.send, element); |
| 2460 } | 2472 } |
| 2461 } | 2473 } |
| 2462 | 2474 |
| 2463 visitSendSet(SendSet node) { | 2475 visitSendSet(SendSet node) { |
| 2464 Operator op = node.assignmentOperator; | 2476 Operator op = node.assignmentOperator; |
| 2465 if (node.isSuperCall) { | 2477 if (node.isSuperCall) { |
| 2466 Element element = elements[node]; | 2478 Element element = elements[node]; |
| 2467 if (element === null) return generateSuperNoSuchMethodSend(node); | 2479 if (element === null) return generateSuperNoSuchMethodSend(node); |
| 2468 HInstruction target = new HStatic(element); | 2480 HInstruction target = new HStatic(element); |
| 2469 HInstruction context = localsHandler.readThis(); | 2481 HInstruction context = localsHandler.readThis(); |
| (...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3674 new HSubGraphBlockInformation(elseBranch.graph)); | 3686 new HSubGraphBlockInformation(elseBranch.graph)); |
| 3675 | 3687 |
| 3676 HBasicBlock conditionStartBlock = conditionBranch.block; | 3688 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 3677 conditionStartBlock.setBlockFlow(info, joinBlock); | 3689 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 3678 SubGraph conditionGraph = conditionBranch.graph; | 3690 SubGraph conditionGraph = conditionBranch.graph; |
| 3679 HIf branch = conditionGraph.end.last; | 3691 HIf branch = conditionGraph.end.last; |
| 3680 assert(branch is HIf); | 3692 assert(branch is HIf); |
| 3681 branch.blockInformation = conditionStartBlock.blockFlow; | 3693 branch.blockInformation = conditionStartBlock.blockFlow; |
| 3682 } | 3694 } |
| 3683 } | 3695 } |
| OLD | NEW |