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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 updateLocal(boxedVariable, oldValue); | 321 updateLocal(boxedVariable, oldValue); |
| 322 } | 322 } |
| 323 updateLocal(boxElement, newBox); | 323 updateLocal(boxElement, newBox); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void startFunction(FunctionElement function, | 326 void startFunction(FunctionElement function, |
| 327 FunctionExpression node) { | 327 FunctionExpression node) { |
| 328 Compiler compiler = builder.compiler; | 328 Compiler compiler = builder.compiler; |
| 329 closureData = compiler.closureToClassMapper.computeClosureToClassMapping( | 329 closureData = compiler.closureToClassMapper.computeClosureToClassMapping( |
| 330 node, builder.elements); | 330 node, builder.elements); |
| 331 | |
| 332 FunctionSignature signature = function.computeSignature(compiler); | 331 FunctionSignature signature = function.computeSignature(compiler); |
| 333 signature.forEachParameter((Element element) { | 332 signature.forEachParameter((Element element) { |
| 334 HInstruction parameter = new HParameterValue(element); | 333 HInstruction parameter = new HParameterValue(element); |
| 335 builder.add(parameter); | 334 builder.add(parameter); |
| 336 builder.parameters[element] = parameter; | 335 builder.parameters[element] = parameter; |
| 337 directLocals[element] = parameter; | 336 directLocals[element] = parameter; |
| 338 parameter.guaranteedType = | 337 parameter.guaranteedType = |
| 339 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element)); | 338 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element)); |
| 340 }); | 339 }); |
| 341 | 340 |
| (...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2462 } | 2461 } |
| 2463 | 2462 |
| 2464 HInstruction analyzeTypeArgument(DartType argument, Node currentNode) { | 2463 HInstruction analyzeTypeArgument(DartType argument, Node currentNode) { |
| 2465 if (argument.element.isTypeVariable()) { | 2464 if (argument.element.isTypeVariable()) { |
| 2466 if (work.element.isFactoryConstructor() | 2465 if (work.element.isFactoryConstructor() |
| 2467 || work.element.isGenerativeConstructor()) { | 2466 || work.element.isGenerativeConstructor()) { |
| 2468 // The type variable is stored in a parameter of the | 2467 // The type variable is stored in a parameter of the |
| 2469 // factory. | 2468 // factory. |
| 2470 return localsHandler.readLocal(argument.element); | 2469 return localsHandler.readLocal(argument.element); |
| 2471 } else if (work.element.isInstanceMember()) { | 2470 } else if (work.element.isInstanceMember()) { |
| 2471 Element thisElement = localsHandler.closureData.thisElement; | |
| 2472 if (!localsHandler.hasValueForDirectLocal(thisElement)) { | |
| 2473 HInstruction thisValue = new HThis(); | |
|
ngeoffray
2012/09/03 12:57:23
I don't think this is right, you should use [thisI
karlklose
2012/09/03 13:55:19
This was actually unnecessary. Removed.
| |
| 2474 add(thisValue); | |
| 2475 } | |
| 2472 // The type variable is stored in [this]. | 2476 // The type variable is stored in [this]. |
| 2473 pushInvokeHelper1(interceptors.getGetRuntimeTypeInfo(), | 2477 pushInvokeHelper1(interceptors.getGetRuntimeTypeInfo(), |
| 2474 localsHandler.readThis()); | 2478 localsHandler.readThis()); |
| 2475 HInstruction typeInfo = pop(); | 2479 HInstruction typeInfo = pop(); |
| 2476 HInstruction foreign = new HForeign( | 2480 HInstruction foreign = new HForeign( |
| 2477 new LiteralDartString('#.$argument'), | 2481 new LiteralDartString('#.$argument'), |
| 2478 new LiteralDartString('String'), | 2482 new LiteralDartString('String'), |
| 2479 <HInstruction>[typeInfo]); | 2483 <HInstruction>[typeInfo]); |
| 2480 add(foreign); | 2484 add(foreign); |
| 2481 return foreign; | 2485 return foreign; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2521 var inputs = <HInstruction>[]; | 2525 var inputs = <HInstruction>[]; |
| 2522 inputs.add(target); | 2526 inputs.add(target); |
| 2523 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments, | 2527 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments, |
| 2524 constructor, inputs); | 2528 constructor, inputs); |
| 2525 if (!succeeded) { | 2529 if (!succeeded) { |
| 2526 // TODO(ngeoffray): Match the VM behavior and throw an | 2530 // TODO(ngeoffray): Match the VM behavior and throw an |
| 2527 // exception at runtime. | 2531 // exception at runtime. |
| 2528 compiler.cancel('Unimplemented non-matching static call', node: node); | 2532 compiler.cancel('Unimplemented non-matching static call', node: node); |
| 2529 } | 2533 } |
| 2530 | 2534 |
| 2531 TypeAnnotation annotation = getTypeAnnotationFromSend(node); | 2535 TypeAnnotation annotation = node.getTypeAnnotation(); |
| 2532 elements.getType(annotation).arguments.forEach((DartType argument) { | 2536 if (annotation == null) { |
| 2537 compiler.internalError("malformed send in new expression"); | |
| 2538 } | |
| 2539 InterfaceType type = elements.getType(annotation); | |
| 2540 type.arguments.forEach((DartType argument) { | |
| 2533 inputs.add(analyzeTypeArgument(argument, node)); | 2541 inputs.add(analyzeTypeArgument(argument, node)); |
| 2534 }); | 2542 }); |
| 2535 | 2543 |
| 2536 HType elementType = computeType(constructor); | 2544 HType elementType = computeType(constructor); |
| 2537 HInstruction newInstance = new HInvokeStatic(inputs, elementType); | 2545 HInstruction newInstance = new HInvokeStatic(inputs, elementType); |
| 2538 pushWithPosition(newInstance, node); | 2546 pushWithPosition(newInstance, node); |
| 2539 } | 2547 } |
| 2540 | 2548 |
| 2541 visitStaticSend(Send node) { | 2549 visitStaticSend(Send node) { |
| 2542 Selector selector = elements.getSelector(node); | 2550 Selector selector = elements.getSelector(node); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2582 | 2590 |
| 2583 visitGetterSend(Send node) { | 2591 visitGetterSend(Send node) { |
| 2584 generateGetter(node, elements[node]); | 2592 generateGetter(node, elements[node]); |
| 2585 } | 2593 } |
| 2586 | 2594 |
| 2587 // TODO(antonm): migrate rest of SsaBuilder to internalError. | 2595 // TODO(antonm): migrate rest of SsaBuilder to internalError. |
| 2588 internalError(String reason, [Node node]) { | 2596 internalError(String reason, [Node node]) { |
| 2589 compiler.internalError(reason, node: node); | 2597 compiler.internalError(reason, node: node); |
| 2590 } | 2598 } |
| 2591 | 2599 |
| 2592 // TODO(karlklose): share with resolver. | |
| 2593 TypeAnnotation getTypeAnnotationFromSend(Send send) { | |
| 2594 if (send.selector is TypeAnnotation) { | |
| 2595 return send.selector; | |
| 2596 } else if (send.selector is Send) { | |
| 2597 Send selector = send.selector; | |
| 2598 if (selector.receiver is TypeAnnotation) { | |
| 2599 return selector.receiver; | |
| 2600 } | |
| 2601 } else { | |
| 2602 compiler.internalError("malformed send in new expression"); | |
| 2603 } | |
| 2604 } | |
| 2605 | |
| 2606 void generateRuntimeError(Node node, String message) { | 2600 void generateRuntimeError(Node node, String message) { |
| 2607 DartString messageObject = new DartString.literal(message); | 2601 DartString messageObject = new DartString.literal(message); |
| 2608 HInstruction errorMessage = graph.addConstantString(messageObject, node); | 2602 HInstruction errorMessage = graph.addConstantString(messageObject, node); |
| 2609 Element helper = interceptors.getThrowRuntimeError(); | 2603 Element helper = interceptors.getThrowRuntimeError(); |
| 2610 pushInvokeHelper1(helper, errorMessage); | 2604 pushInvokeHelper1(helper, errorMessage); |
| 2611 } | 2605 } |
| 2612 | 2606 |
| 2613 visitNewExpression(NewExpression node) { | 2607 visitNewExpression(NewExpression node) { |
| 2614 Element element = elements[node.send]; | 2608 Element element = elements[node.send]; |
| 2615 if (element != null && element.isErroneous()) { | 2609 if (element != null && element.isErroneous()) { |
| (...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3944 new HSubGraphBlockInformation(elseBranch.graph)); | 3938 new HSubGraphBlockInformation(elseBranch.graph)); |
| 3945 | 3939 |
| 3946 HBasicBlock conditionStartBlock = conditionBranch.block; | 3940 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 3947 conditionStartBlock.setBlockFlow(info, joinBlock); | 3941 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 3948 SubGraph conditionGraph = conditionBranch.graph; | 3942 SubGraph conditionGraph = conditionBranch.graph; |
| 3949 HIf branch = conditionGraph.end.last; | 3943 HIf branch = conditionGraph.end.last; |
| 3950 assert(branch is HIf); | 3944 assert(branch is HIf); |
| 3951 branch.blockInformation = conditionStartBlock.blockFlow; | 3945 branch.blockInformation = conditionStartBlock.blockFlow; |
| 3952 } | 3946 } |
| 3953 } | 3947 } |
| OLD | NEW |