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 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1235 includeBackendMembers: true, | 1235 includeBackendMembers: true, |
| 1236 includeSuperMembers: true, | 1236 includeSuperMembers: true, |
| 1237 f: (ClassElement enclosingClass, Element member) { | 1237 f: (ClassElement enclosingClass, Element member) { |
| 1238 constructorArguments.add( | 1238 constructorArguments.add( |
| 1239 potentiallyCheckType(fieldValues[member], member)); | 1239 potentiallyCheckType(fieldValues[member], member)); |
| 1240 }); | 1240 }); |
| 1241 | 1241 |
| 1242 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); | 1242 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); |
| 1243 add(newObject); | 1243 add(newObject); |
| 1244 | 1244 |
| 1245 // If the class has type variables, create the runtime type | 1245 // Create the runtime type information, if needed. |
| 1246 // information with the type parameters provided. | |
| 1247 InterfaceType type = classElement.computeType(compiler); | 1246 InterfaceType type = classElement.computeType(compiler); |
| 1248 if (compiler.world.needsRti(type.element)) { | 1247 List<HInstruction> inputs = <HInstruction>[]; |
| 1249 List<HInstruction> rtiInputs = <HInstruction>[]; | 1248 if (compiler.world.needsRti(classElement)) { |
| 1250 classElement.typeVariables.forEach((TypeVariableType typeVariable) { | 1249 classElement.typeVariables.forEach((TypeVariableType typeVariable) { |
| 1251 rtiInputs.add(localsHandler.directLocals[typeVariable.element]); | 1250 inputs.add(localsHandler.directLocals[typeVariable.element]); |
| 1252 }); | 1251 }); |
| 1253 callSetRuntimeTypeInfo(classElement, rtiInputs, newObject); | 1252 callSetRuntimeTypeInfo(classElement, inputs, newObject); |
| 1254 } | 1253 } |
| 1255 | 1254 |
| 1256 // Generate calls to the constructor bodies. | 1255 // Generate calls to the constructor bodies. |
| 1257 for (int index = constructors.length - 1; index >= 0; index--) { | 1256 for (int index = constructors.length - 1; index >= 0; index--) { |
| 1258 FunctionElement constructor = constructors[index]; | 1257 FunctionElement constructor = constructors[index]; |
| 1259 ConstructorBodyElement body = getConstructorBody(constructor); | 1258 ConstructorBodyElement body = getConstructorBody(constructor); |
| 1260 if (body === null) continue; | 1259 if (body === null) continue; |
| 1261 List bodyCallInputs = <HInstruction>[]; | 1260 List bodyCallInputs = <HInstruction>[]; |
| 1262 bodyCallInputs.add(newObject); | 1261 bodyCallInputs.add(newObject); |
| 1263 int arity = body.functionSignature.parameterCount; | 1262 int arity = body.functionSignature.parameterCount; |
| (...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2644 } else { | 2643 } else { |
| 2645 // The type variable is a type (e.g. int). | 2644 // The type variable is a type (e.g. int). |
| 2646 return graph.addConstantString( | 2645 return graph.addConstantString( |
| 2647 new LiteralDartString('$argument'), currentNode, constantSystem); | 2646 new LiteralDartString('$argument'), currentNode, constantSystem); |
| 2648 } | 2647 } |
| 2649 } | 2648 } |
| 2650 | 2649 |
| 2651 void handleListConstructor(InterfaceType type, | 2650 void handleListConstructor(InterfaceType type, |
| 2652 Node currentNode, | 2651 Node currentNode, |
| 2653 HInstruction newObject) { | 2652 HInstruction newObject) { |
| 2654 if (type.arguments.isEmpty()) return; | 2653 if (!compiler.world.needsRti(type.element)) return; |
| 2655 List<HInstruction> inputs = <HInstruction>[]; | 2654 List<HInstruction> inputs = <HInstruction>[]; |
| 2656 type.arguments.forEach((DartType argument) { | 2655 type.arguments.forEach((DartType argument) { |
| 2657 inputs.add(analyzeTypeArgument(argument, currentNode)); | 2656 inputs.add(analyzeTypeArgument(argument, currentNode)); |
| 2658 }); | 2657 }); |
| 2659 callSetRuntimeTypeInfo(type.element, inputs, newObject); | 2658 callSetRuntimeTypeInfo(type.element, inputs, newObject); |
| 2660 } | 2659 } |
| 2661 | 2660 |
| 2662 void callSetRuntimeTypeInfo(ClassElement element, | 2661 void callSetRuntimeTypeInfo(ClassElement element, |
| 2663 List<HInstruction> inputs, | 2662 List<HInstruction> rtiInputs, |
| 2664 HInstruction newObject) { | 2663 HInstruction newObject) { |
| 2665 List<String> typeVariables = <String>[]; | 2664 bool needsRti = compiler.world.needsRti(element) && rtiInputs.length > 0; |
|
ngeoffray
2012/09/19 08:43:09
isEmpty?
karlklose
2012/09/19 08:44:27
Done.
| |
| 2666 element.typeVariables.forEach((TypeVariableType typeVariable) { | 2665 bool runtimeTypeIsUsed = compiler.enabledRuntimeType; |
| 2667 typeVariables.add("'$typeVariable': #"); | 2666 if (!needsRti && !runtimeTypeIsUsed) return; |
| 2668 }); | 2667 |
| 2668 HInstruction createForeign(String template, | |
| 2669 List<HInstruction> arguments, | |
| 2670 [String type = 'String']) { | |
| 2671 return new HForeign(new LiteralDartString(template), | |
| 2672 new LiteralDartString(type), | |
| 2673 arguments); | |
| 2674 } | |
| 2669 | 2675 |
| 2670 String jsCode = '{ ${Strings.join(typeVariables, ', ')} }'; | 2676 // Construct the runtime type information. |
| 2671 HInstruction typeInfo = new HForeign(new LiteralDartString(jsCode), | 2677 StringBuffer runtimeCode = new StringBuffer(); |
| 2672 new LiteralDartString('Object'), | 2678 List<HInstruction> runtimeCodeInputs = <HInstruction>[]; |
| 2673 inputs); | 2679 if (runtimeTypeIsUsed) { |
| 2674 add(typeInfo); | 2680 String runtimeTypeString = |
| 2681 RuntimeTypeInformation.generateRuntimeTypeString(element, | |
| 2682 rtiInputs.length); | |
| 2683 HInstruction runtimeType = createForeign(runtimeTypeString, rtiInputs); | |
| 2684 add(runtimeType); | |
| 2685 runtimeCodeInputs.add(runtimeType); | |
| 2686 runtimeCode.add('runtimeType: #'); | |
| 2687 } | |
| 2688 if (needsRti) { | |
| 2689 if (runtimeTypeIsUsed) runtimeCode.add(', '); | |
| 2690 String typeVariablesString = | |
| 2691 RuntimeTypeInformation.generateTypeVariableString(element, | |
| 2692 rtiInputs.length); | |
| 2693 HInstruction typeInfo = createForeign(typeVariablesString, rtiInputs); | |
| 2694 add(typeInfo); | |
| 2695 runtimeCodeInputs.add(typeInfo); | |
| 2696 runtimeCode.add('#'); | |
| 2697 } | |
| 2698 HInstruction runtimeInfo = | |
| 2699 createForeign("{$runtimeCode}", runtimeCodeInputs, 'Object'); | |
| 2700 add(runtimeInfo); | |
| 2701 | |
| 2702 // Set the runtime type information on the object. | |
| 2675 Element typeInfoSetterElement = interceptors.getSetRuntimeTypeInfo(); | 2703 Element typeInfoSetterElement = interceptors.getSetRuntimeTypeInfo(); |
| 2676 HInstruction typeInfoSetter = new HStatic(typeInfoSetterElement); | 2704 HInstruction typeInfoSetter = new HStatic(typeInfoSetterElement); |
| 2677 add(typeInfoSetter); | 2705 add(typeInfoSetter); |
| 2678 add(new HInvokeStatic(<HInstruction>[typeInfoSetter, newObject, typeInfo])); | 2706 add(new HInvokeStatic( |
| 2707 <HInstruction>[typeInfoSetter, newObject, runtimeInfo])); | |
| 2679 } | 2708 } |
| 2680 | 2709 |
| 2681 visitNewSend(Send node) { | 2710 visitNewSend(Send node) { |
| 2682 bool isListConstructor = false; | 2711 bool isListConstructor = false; |
| 2683 computeType(element) { | 2712 computeType(element) { |
| 2684 Element originalElement = elements[node]; | 2713 Element originalElement = elements[node]; |
| 2685 if (originalElement.getEnclosingClass() === compiler.listClass) { | 2714 if (originalElement.getEnclosingClass() === compiler.listClass) { |
| 2686 isListConstructor = true; | 2715 isListConstructor = true; |
| 2687 if (node.arguments.isEmpty()) { | 2716 if (node.arguments.isEmpty()) { |
| 2688 return HType.EXTENDABLE_ARRAY; | 2717 return HType.EXTENDABLE_ARRAY; |
| (...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4203 new HSubGraphBlockInformation(elseBranch.graph)); | 4232 new HSubGraphBlockInformation(elseBranch.graph)); |
| 4204 | 4233 |
| 4205 HBasicBlock conditionStartBlock = conditionBranch.block; | 4234 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 4206 conditionStartBlock.setBlockFlow(info, joinBlock); | 4235 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 4207 SubGraph conditionGraph = conditionBranch.graph; | 4236 SubGraph conditionGraph = conditionBranch.graph; |
| 4208 HIf branch = conditionGraph.end.last; | 4237 HIf branch = conditionGraph.end.last; |
| 4209 assert(branch is HIf); | 4238 assert(branch is HIf); |
| 4210 branch.blockInformation = conditionStartBlock.blockFlow; | 4239 branch.blockInformation = conditionStartBlock.blockFlow; |
| 4211 } | 4240 } |
| 4212 } | 4241 } |
| OLD | NEW |