Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: lib/compiler/implementation/ssa/builder.dart

Issue 10908142: Add runtimeType() to Object which returns canonicalized instances of Type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address more comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 1367 matching lines...) Expand 10 before | Expand all | Expand 10 after
2631 } else { 2630 } else {
2632 // The type variable is a type (e.g. int). 2631 // The type variable is a type (e.g. int).
2633 return graph.addConstantString( 2632 return graph.addConstantString(
2634 new LiteralDartString('$argument'), currentNode, constantSystem); 2633 new LiteralDartString('$argument'), currentNode, constantSystem);
2635 } 2634 }
2636 } 2635 }
2637 2636
2638 void handleListConstructor(InterfaceType type, 2637 void handleListConstructor(InterfaceType type,
2639 Node currentNode, 2638 Node currentNode,
2640 HInstruction newObject) { 2639 HInstruction newObject) {
2641 if (type.arguments.isEmpty()) return; 2640 if (!compiler.world.needsRti(type.element)) return;
2642 List<HInstruction> inputs = <HInstruction>[]; 2641 List<HInstruction> inputs = <HInstruction>[];
2643 type.arguments.forEach((DartType argument) { 2642 type.arguments.forEach((DartType argument) {
2644 inputs.add(analyzeTypeArgument(argument, currentNode)); 2643 inputs.add(analyzeTypeArgument(argument, currentNode));
2645 }); 2644 });
2646 callSetRuntimeTypeInfo(type.element, inputs, newObject); 2645 callSetRuntimeTypeInfo(type.element, inputs, newObject);
2647 } 2646 }
2648 2647
2649 void callSetRuntimeTypeInfo(ClassElement element, 2648 void callSetRuntimeTypeInfo(ClassElement element,
2650 List<HInstruction> inputs, 2649 List<HInstruction> rtiInputs,
2651 HInstruction newObject) { 2650 HInstruction newObject) {
2652 List<String> typeVariables = <String>[]; 2651 bool classHasTypeVariables = !element.typeVariables.isEmpty();
2653 element.typeVariables.forEach((TypeVariableType typeVariable) { 2652 bool runtimeTypeIsUsed = compiler.enabledRuntimeType;
2654 typeVariables.add("'$typeVariable': #");
2655 });
2656 2653
2657 String jsCode = '{ ${Strings.join(typeVariables, ', ')} }'; 2654 HInstruction createForeign(String template,
2658 HInstruction typeInfo = new HForeign(new LiteralDartString(jsCode), 2655 List<HInstruction> arguments,
2659 new LiteralDartString('Object'), 2656 [String type = 'String']) {
2660 inputs); 2657 return new HForeign(new LiteralDartString(template),
2661 add(typeInfo); 2658 new LiteralDartString(type),
2659 arguments);
2660 }
2661
2662 // Construct the runtime type information.
2663 StringBuffer runtimeCode = new StringBuffer();
2664 List<HInstruction> runtimeCodeInputs = <HInstruction>[];
2665 if (runtimeTypeIsUsed) {
2666 String runtimeTypeString =
2667 RuntimeTypeInformation.generateRuntimeTypeString(element,
2668 rtiInputs.length);
2669 HInstruction runtimeType = createForeign(runtimeTypeString, rtiInputs);
2670 add(runtimeType);
2671 runtimeCodeInputs.add(runtimeType);
2672 runtimeCode.add('runtimeType: #');
2673 }
2674 if (classHasTypeVariables) {
2675 if (runtimeTypeIsUsed) runtimeCode.add(', ');
2676 String typeVariablesString =
2677 RuntimeTypeInformation.generateTypeVariableString(element,
2678 rtiInputs.length);
2679 HInstruction typeInfo = createForeign(typeVariablesString, rtiInputs);
2680 add(typeInfo);
2681 runtimeCodeInputs.add(typeInfo);
2682 runtimeCode.add('#');
2683 }
2684 HInstruction runtimeInfo =
2685 createForeign("{$runtimeCode}", runtimeCodeInputs, 'Object');
2686 add(runtimeInfo);
2687
2688 // Set the runtime type information on the object.
2662 Element typeInfoSetterElement = interceptors.getSetRuntimeTypeInfo(); 2689 Element typeInfoSetterElement = interceptors.getSetRuntimeTypeInfo();
2663 HInstruction typeInfoSetter = new HStatic(typeInfoSetterElement); 2690 HInstruction typeInfoSetter = new HStatic(typeInfoSetterElement);
2664 add(typeInfoSetter); 2691 add(typeInfoSetter);
2665 add(new HInvokeStatic(<HInstruction>[typeInfoSetter, newObject, typeInfo])); 2692 add(new HInvokeStatic(
2693 <HInstruction>[typeInfoSetter, newObject, runtimeInfo]));
2666 } 2694 }
2667 2695
2668 visitNewSend(Send node) { 2696 visitNewSend(Send node) {
2669 bool isListConstructor = false; 2697 bool isListConstructor = false;
2670 computeType(element) { 2698 computeType(element) {
2671 Element originalElement = elements[node]; 2699 Element originalElement = elements[node];
2672 if (originalElement.getEnclosingClass() === compiler.listClass) { 2700 if (originalElement.getEnclosingClass() === compiler.listClass) {
2673 isListConstructor = true; 2701 isListConstructor = true;
2674 if (node.arguments.isEmpty()) { 2702 if (node.arguments.isEmpty()) {
2675 return HType.EXTENDABLE_ARRAY; 2703 return HType.EXTENDABLE_ARRAY;
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after
4190 new HSubGraphBlockInformation(elseBranch.graph)); 4218 new HSubGraphBlockInformation(elseBranch.graph));
4191 4219
4192 HBasicBlock conditionStartBlock = conditionBranch.block; 4220 HBasicBlock conditionStartBlock = conditionBranch.block;
4193 conditionStartBlock.setBlockFlow(info, joinBlock); 4221 conditionStartBlock.setBlockFlow(info, joinBlock);
4194 SubGraph conditionGraph = conditionBranch.graph; 4222 SubGraph conditionGraph = conditionBranch.graph;
4195 HIf branch = conditionGraph.end.last; 4223 HIf branch = conditionGraph.end.last;
4196 assert(branch is HIf); 4224 assert(branch is HIf);
4197 branch.blockInformation = conditionStartBlock.blockFlow; 4225 branch.blockInformation = conditionStartBlock.blockFlow;
4198 } 4226 }
4199 } 4227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698