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 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1232 | 1232 |
| 1233 // If the class has type variables, create the runtime type | 1233 // If the class has type variables, create the runtime type |
| 1234 // information with the type parameters provided. | 1234 // information with the type parameters provided. |
| 1235 if (!classElement.typeVariables.isEmpty()) { | 1235 if (!classElement.typeVariables.isEmpty()) { |
| 1236 List<String> typeVariables = <String>[]; | 1236 List<String> typeVariables = <String>[]; |
| 1237 List<HInstruction> rtiInputs = <HInstruction>[]; | 1237 List<HInstruction> rtiInputs = <HInstruction>[]; |
| 1238 classElement.typeVariables.forEach((TypeVariableType typeVariable) { | 1238 classElement.typeVariables.forEach((TypeVariableType typeVariable) { |
| 1239 typeVariables.add("'$typeVariable': #"); | 1239 typeVariables.add("'$typeVariable': #"); |
| 1240 rtiInputs.add(localsHandler.directLocals[typeVariable.element]); | 1240 rtiInputs.add(localsHandler.directLocals[typeVariable.element]); |
| 1241 }); | 1241 }); |
| 1242 String jsCode = '{ ${Strings.join(typeVariables, ', ')} }'; | 1242 callSetRuntimeTypeInfo(typeVariables, rtiInputs, newObject); |
| 1243 HInstruction typeInfo = new HForeign(new LiteralDartString(jsCode), | |
| 1244 new LiteralDartString('Object'), | |
| 1245 rtiInputs); | |
| 1246 add(typeInfo); | |
| 1247 Element typeInfoSetterElement = interceptors.getSetRuntimeTypeInfo(); | |
| 1248 HInstruction typeInfoSetter = new HStatic(typeInfoSetterElement); | |
| 1249 add(typeInfoSetter); | |
| 1250 add(new HInvokeStatic( | |
| 1251 <HInstruction>[typeInfoSetter, newObject, typeInfo])); | |
| 1252 } | 1243 } |
| 1253 | 1244 |
| 1254 // Generate calls to the constructor bodies. | 1245 // Generate calls to the constructor bodies. |
| 1255 for (int index = constructors.length - 1; index >= 0; index--) { | 1246 for (int index = constructors.length - 1; index >= 0; index--) { |
| 1256 FunctionElement constructor = constructors[index]; | 1247 FunctionElement constructor = constructors[index]; |
| 1257 ConstructorBodyElement body = getConstructorBody(constructor); | 1248 ConstructorBodyElement body = getConstructorBody(constructor); |
| 1258 if (body === null) continue; | 1249 if (body === null) continue; |
| 1259 List bodyCallInputs = <HInstruction>[]; | 1250 List bodyCallInputs = <HInstruction>[]; |
| 1260 bodyCallInputs.add(newObject); | 1251 bodyCallInputs.add(newObject); |
| 1261 int arity = body.functionSignature.parameterCount; | 1252 int arity = body.functionSignature.parameterCount; |
| (...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2620 compiler.cancel('Unimplemented unresolved type variable', | 2611 compiler.cancel('Unimplemented unresolved type variable', |
| 2621 node: currentNode); | 2612 node: currentNode); |
| 2622 } | 2613 } |
| 2623 } else { | 2614 } else { |
| 2624 // The type variable is a type (e.g. int). | 2615 // The type variable is a type (e.g. int). |
| 2625 return graph.addConstantString( | 2616 return graph.addConstantString( |
| 2626 new LiteralDartString('$argument'), currentNode, constantSystem); | 2617 new LiteralDartString('$argument'), currentNode, constantSystem); |
| 2627 } | 2618 } |
| 2628 } | 2619 } |
| 2629 | 2620 |
| 2621 void handleListConstructor(InterfaceType type, | |
| 2622 Node currentNode, | |
| 2623 HInstruction newObject) { | |
| 2624 if (type.arguments.isEmpty()) return; | |
| 2625 List<HInstruction> inputs = <HInstruction>[]; | |
| 2626 type.arguments.forEach((DartType argument) { | |
| 2627 inputs.add(analyzeTypeArgument(argument, currentNode)); | |
| 2628 }); | |
| 2629 | |
| 2630 List<String> typeVariables = <String>[]; | |
| 2631 type.element.typeVariables.forEach((TypeVariableType typeVariable) { | |
| 2632 typeVariables.add("'$typeVariable': #"); | |
| 2633 }); | |
| 2634 | |
| 2635 callSetRuntimeTypeInfo(typeVariables, inputs, newObject); | |
| 2636 } | |
| 2637 | |
| 2638 void callSetRuntimeTypeInfo(List<String> typeVariables, | |
| 2639 List<HInstruction> inputs, | |
| 2640 HInstruction newObject) { | |
| 2641 String jsCode = '{ ${Strings.join(typeVariables, ', ')} }'; | |
|
kasperl
2012/09/12 12:19:04
Somehow the decoupling of the way you turn the typ
ngeoffray
2012/09/12 12:30:39
Done.
| |
| 2642 HInstruction typeInfo = new HForeign(new LiteralDartString(jsCode), | |
| 2643 new LiteralDartString('Object'), | |
| 2644 inputs); | |
| 2645 add(typeInfo); | |
| 2646 Element typeInfoSetterElement = interceptors.getSetRuntimeTypeInfo(); | |
| 2647 HInstruction typeInfoSetter = new HStatic(typeInfoSetterElement); | |
| 2648 add(typeInfoSetter); | |
| 2649 add(new HInvokeStatic(<HInstruction>[typeInfoSetter, newObject, typeInfo])); | |
| 2650 } | |
| 2651 | |
| 2630 visitNewSend(Send node) { | 2652 visitNewSend(Send node) { |
| 2653 bool isListConstructor = false; | |
| 2631 computeType(element) { | 2654 computeType(element) { |
| 2632 Element originalElement = elements[node]; | 2655 Element originalElement = elements[node]; |
| 2633 if (originalElement.getEnclosingClass() === compiler.listClass) { | 2656 if (originalElement.getEnclosingClass() === compiler.listClass) { |
| 2657 isListConstructor = true; | |
| 2634 if (node.arguments.isEmpty()) { | 2658 if (node.arguments.isEmpty()) { |
| 2635 return HType.EXTENDABLE_ARRAY; | 2659 return HType.EXTENDABLE_ARRAY; |
| 2636 } else { | 2660 } else { |
| 2637 return HType.MUTABLE_ARRAY; | 2661 return HType.MUTABLE_ARRAY; |
| 2638 } | 2662 } |
| 2639 } else if (element.isGenerativeConstructor()) { | 2663 } else if (element.isGenerativeConstructor()) { |
| 2640 ClassElement cls = element.getEnclosingClass(); | 2664 ClassElement cls = element.getEnclosingClass(); |
| 2641 return new HBoundedType.exact(cls.type); | 2665 return new HBoundedType.exact(cls.type); |
| 2642 } else { | 2666 } else { |
| 2643 return HType.UNKNOWN; | 2667 return HType.UNKNOWN; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2668 compiler.internalError("malformed send in new expression"); | 2692 compiler.internalError("malformed send in new expression"); |
| 2669 } | 2693 } |
| 2670 InterfaceType type = elements.getType(annotation); | 2694 InterfaceType type = elements.getType(annotation); |
| 2671 type.arguments.forEach((DartType argument) { | 2695 type.arguments.forEach((DartType argument) { |
| 2672 inputs.add(analyzeTypeArgument(argument, node)); | 2696 inputs.add(analyzeTypeArgument(argument, node)); |
| 2673 }); | 2697 }); |
| 2674 | 2698 |
| 2675 HType elementType = computeType(constructor); | 2699 HType elementType = computeType(constructor); |
| 2676 HInstruction newInstance = new HInvokeStatic(inputs, elementType); | 2700 HInstruction newInstance = new HInvokeStatic(inputs, elementType); |
| 2677 pushWithPosition(newInstance, node); | 2701 pushWithPosition(newInstance, node); |
| 2702 | |
| 2703 // The List constructor forwards to a Dart static method that does | |
| 2704 // not know about the type argument. Therefore we special case | |
| 2705 // this constructor to have the setRuntimeTypeInfo called where | |
| 2706 // the 'new' is done. | |
| 2707 if (isListConstructor) { | |
| 2708 handleListConstructor(type, node, newInstance); | |
| 2709 } | |
| 2678 } | 2710 } |
| 2679 | 2711 |
| 2680 visitStaticSend(Send node) { | 2712 visitStaticSend(Send node) { |
| 2681 Selector selector = elements.getSelector(node); | 2713 Selector selector = elements.getSelector(node); |
| 2682 Element element = elements[node]; | 2714 Element element = elements[node]; |
| 2683 if (element.isErroneous()) { | 2715 if (element.isErroneous()) { |
| 2684 generateThrowNoSuchMethod(node, getTargetName(element), node.arguments); | 2716 generateThrowNoSuchMethod(node, getTargetName(element), node.arguments); |
| 2685 return; | 2717 return; |
| 2686 } | 2718 } |
| 2687 if (element === compiler.assertMethod && !compiler.enableUserAssertions) { | 2719 if (element === compiler.assertMethod && !compiler.enableUserAssertions) { |
| (...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4140 new HSubGraphBlockInformation(elseBranch.graph)); | 4172 new HSubGraphBlockInformation(elseBranch.graph)); |
| 4141 | 4173 |
| 4142 HBasicBlock conditionStartBlock = conditionBranch.block; | 4174 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 4143 conditionStartBlock.setBlockFlow(info, joinBlock); | 4175 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 4144 SubGraph conditionGraph = conditionBranch.graph; | 4176 SubGraph conditionGraph = conditionBranch.graph; |
| 4145 HIf branch = conditionGraph.end.last; | 4177 HIf branch = conditionGraph.end.last; |
| 4146 assert(branch is HIf); | 4178 assert(branch is HIf); |
| 4147 branch.blockInformation = conditionStartBlock.blockFlow; | 4179 branch.blockInformation = conditionStartBlock.blockFlow; |
| 4148 } | 4180 } |
| 4149 } | 4181 } |
| OLD | NEW |