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