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

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

Issue 10942028: Support class and typedef literals as expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix two long lines. Created 8 years, 2 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 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 f: (ClassElement enclosingClass, Element member) { 1313 f: (ClassElement enclosingClass, Element member) {
1314 constructorArguments.add( 1314 constructorArguments.add(
1315 potentiallyCheckType(fieldValues[member], member)); 1315 potentiallyCheckType(fieldValues[member], member));
1316 }); 1316 });
1317 1317
1318 HForeignNew newObject = new HForeignNew(classElement, constructorArguments); 1318 HForeignNew newObject = new HForeignNew(classElement, constructorArguments);
1319 add(newObject); 1319 add(newObject);
1320 1320
1321 // Create the runtime type information, if needed. 1321 // Create the runtime type information, if needed.
1322 InterfaceType type = classElement.computeType(compiler); 1322 InterfaceType type = classElement.computeType(compiler);
1323 List<HInstruction> inputs = <HInstruction>[]; 1323 List<HInstruction> inputs = <HInstruction>[];
1324 if (compiler.world.needsRti(classElement)) { 1324 classElement.typeVariables.forEach((TypeVariableType typeVariable) {
ngeoffray 2012/10/10 07:32:24 I don't think you should remove this check.
karlklose 2012/10/23 10:33:52 Done.
1325 classElement.typeVariables.forEach((TypeVariableType typeVariable) { 1325 inputs.add(localsHandler.directLocals[typeVariable.element]);
1326 inputs.add(localsHandler.directLocals[typeVariable.element]); 1326 });
1327 }); 1327 callSetRuntimeTypeInfo(classElement, inputs, newObject);
1328 callSetRuntimeTypeInfo(classElement, inputs, newObject);
1329 }
1330 1328
1331 // Generate calls to the constructor bodies. 1329 // Generate calls to the constructor bodies.
1332 for (int index = constructors.length - 1; index >= 0; index--) { 1330 for (int index = constructors.length - 1; index >= 0; index--) {
1333 FunctionElement constructor = constructors[index]; 1331 FunctionElement constructor = constructors[index];
1334 assert(invariant(functionElement, constructor.isImplementation)); 1332 assert(invariant(functionElement, constructor.isImplementation));
1335 ConstructorBodyElement body = getConstructorBody(constructor); 1333 ConstructorBodyElement body = getConstructorBody(constructor);
1336 if (body === null) continue; 1334 if (body === null) continue;
1337 List bodyCallInputs = <HInstruction>[]; 1335 List bodyCallInputs = <HInstruction>[];
1338 bodyCallInputs.add(newObject); 1336 bodyCallInputs.add(newObject);
1339 FunctionSignature functionSignature = body.computeSignature(compiler); 1337 FunctionSignature functionSignature = body.computeSignature(compiler);
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2701 visitSuperSend(Send node) { 2699 visitSuperSend(Send node) {
2702 Selector selector = elements.getSelector(node); 2700 Selector selector = elements.getSelector(node);
2703 Element element = elements[node]; 2701 Element element = elements[node];
2704 if (element === null) return generateSuperNoSuchMethodSend(node); 2702 if (element === null) return generateSuperNoSuchMethodSend(node);
2705 // TODO(5346): Try to avoid the need for calling [declaration] before 2703 // TODO(5346): Try to avoid the need for calling [declaration] before
2706 // creating an [HStatic]. 2704 // creating an [HStatic].
2707 HInstruction target = new HStatic(element.declaration); 2705 HInstruction target = new HStatic(element.declaration);
2708 HInstruction context = localsHandler.readThis(); 2706 HInstruction context = localsHandler.readThis();
2709 add(target); 2707 add(target);
2710 var inputs = <HInstruction>[target, context]; 2708 var inputs = <HInstruction>[target, context];
2711 if (node.isPropertyAccess) { 2709 if (node.isPropertyAccessOrTypeReference) {
2712 push(new HInvokeSuper(inputs)); 2710 push(new HInvokeSuper(inputs));
2713 } else if (element.isFunction() || element.isGenerativeConstructor()) { 2711 } else if (element.isFunction() || element.isGenerativeConstructor()) {
2714 // TODO(5347): Try to avoid the need for calling [implementation] before 2712 // TODO(5347): Try to avoid the need for calling [implementation] before
2715 // calling [addStaticSendArgumentsToList]. 2713 // calling [addStaticSendArgumentsToList].
2716 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments, 2714 bool succeeded = addStaticSendArgumentsToList(selector, node.arguments,
2717 element.implementation, 2715 element.implementation,
2718 inputs); 2716 inputs);
2719 if (!succeeded) { 2717 if (!succeeded) {
2720 // TODO(ngeoffray): Match the VM behavior and throw an 2718 // TODO(ngeoffray): Match the VM behavior and throw an
2721 // exception at runtime. 2719 // exception at runtime.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2796 // Construct the runtime type information. 2794 // Construct the runtime type information.
2797 StringBuffer runtimeCode = new StringBuffer(); 2795 StringBuffer runtimeCode = new StringBuffer();
2798 List<HInstruction> runtimeCodeInputs = <HInstruction>[]; 2796 List<HInstruction> runtimeCodeInputs = <HInstruction>[];
2799 if (runtimeTypeIsUsed) { 2797 if (runtimeTypeIsUsed) {
2800 String runtimeTypeString = 2798 String runtimeTypeString =
2801 RuntimeTypeInformation.generateRuntimeTypeString(element, 2799 RuntimeTypeInformation.generateRuntimeTypeString(element,
2802 rtiInputs.length); 2800 rtiInputs.length);
2803 HInstruction runtimeType = createForeign(runtimeTypeString, rtiInputs); 2801 HInstruction runtimeType = createForeign(runtimeTypeString, rtiInputs);
2804 add(runtimeType); 2802 add(runtimeType);
2805 runtimeCodeInputs.add(runtimeType); 2803 runtimeCodeInputs.add(runtimeType);
2806 runtimeCode.add('runtimeType: #'); 2804 runtimeCode.add("runtimeType: '#'");
2807 } 2805 }
2808 if (needsRti) { 2806 if (needsRti) {
2809 if (runtimeTypeIsUsed) runtimeCode.add(', '); 2807 if (runtimeTypeIsUsed) runtimeCode.add(', ');
2810 String typeVariablesString = 2808 String typeVariablesString =
2811 RuntimeTypeInformation.generateTypeVariableString(element, 2809 RuntimeTypeInformation.generateTypeVariableString(element,
2812 rtiInputs.length); 2810 rtiInputs.length);
2813 HInstruction typeInfo = createForeign(typeVariablesString, rtiInputs); 2811 HInstruction typeInfo = createForeign(typeVariablesString, rtiInputs);
2814 add(typeInfo); 2812 add(typeInfo);
2815 runtimeCodeInputs.add(typeInfo); 2813 runtimeCodeInputs.add(typeInfo);
2816 runtimeCode.add('#'); 2814 runtimeCode.add('#');
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2869 // exception at runtime. 2867 // exception at runtime.
2870 compiler.cancel('Unimplemented non-matching static call', node: node); 2868 compiler.cancel('Unimplemented non-matching static call', node: node);
2871 } 2869 }
2872 2870
2873 TypeAnnotation annotation = node.getTypeAnnotation(); 2871 TypeAnnotation annotation = node.getTypeAnnotation();
2874 if (annotation == null) { 2872 if (annotation == null) {
2875 compiler.internalError("malformed send in new expression"); 2873 compiler.internalError("malformed send in new expression");
2876 } 2874 }
2877 InterfaceType type = elements.getType(annotation); 2875 InterfaceType type = elements.getType(annotation);
2878 if (compiler.world.needsRti(constructor.enclosingElement)) { 2876 if (compiler.world.needsRti(constructor.enclosingElement)) {
2879 type.arguments.forEach((DartType argument) { 2877 if (!type.arguments.isEmpty()) {
2880 inputs.add(analyzeTypeArgument(argument, node)); 2878 type.arguments.forEach((DartType argument) {
2881 }); 2879 inputs.add(analyzeTypeArgument(argument, node));
2880 });
2881 } else if (compiler.enabledRuntimeType) {
2882 Link<DartType> variables =
2883 constructor.getEnclosingClass().typeVariables;
2884 if (!variables.isEmpty()) {
ngeoffray 2012/10/10 07:32:24 Please add a comment that you need to put runtime
karlklose 2012/10/23 10:33:52 Here I add 'dynamic' as type argument for type var
2885 DartString stringDynamic = new DartString.literal('dynamic');
2886 HInstruction input = graph.addConstantString(stringDynamic,
2887 node,
2888 constantSystem);
2889 variables.forEach((_) => inputs.add(input));
2890 }
2891 }
2882 } 2892 }
2883 2893
2884 HType elementType = computeType(constructor); 2894 HType elementType = computeType(constructor);
2885 HInstruction newInstance = new HInvokeStatic(inputs, elementType); 2895 HInstruction newInstance = new HInvokeStatic(inputs, elementType);
2886 pushWithPosition(newInstance, node); 2896 pushWithPosition(newInstance, node);
2887 2897
2888 // The List constructor forwards to a Dart static method that does 2898 // The List constructor forwards to a Dart static method that does
2889 // not know about the type argument. Therefore we special case 2899 // not know about the type argument. Therefore we special case
2890 // this constructor to have the setRuntimeTypeInfo called where 2900 // this constructor to have the setRuntimeTypeInfo called where
2891 // the 'new' is done. 2901 // the 'new' is done.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2933 if (returnType != null) instruction.guaranteedType = returnType; 2943 if (returnType != null) instruction.guaranteedType = returnType;
2934 pushWithPosition(instruction, node); 2944 pushWithPosition(instruction, node);
2935 } else { 2945 } else {
2936 generateGetter(node, element); 2946 generateGetter(node, element);
2937 List<HInstruction> inputs = <HInstruction>[pop()]; 2947 List<HInstruction> inputs = <HInstruction>[pop()];
2938 addDynamicSendArgumentsToList(node, inputs); 2948 addDynamicSendArgumentsToList(node, inputs);
2939 pushWithPosition(new HInvokeClosure(selector, inputs), node); 2949 pushWithPosition(new HInvokeClosure(selector, inputs), node);
2940 } 2950 }
2941 } 2951 }
2942 2952
2953 visitClassLiteralSend(Send node) {
2954 ClassElement element = elements[node];
2955 String string =
2956 RuntimeTypeInformation.generateRuntimeTypeString(element, 0);
2957 DartString className = new DartString.literal(string);
2958 Element helper =
2959 compiler.findHelper(const SourceString('getOrCreateCachedRuntimeType'));
2960 Constant typeName = constantSystem.createString(className, node.selector);
2961 pushInvokeHelper1(helper, graph.addConstant(typeName));
2962 }
2963
2943 visitGetterSend(Send node) { 2964 visitGetterSend(Send node) {
2944 generateGetter(node, elements[node]); 2965 generateGetter(node, elements[node]);
2945 } 2966 }
2946 2967
2947 // TODO(antonm): migrate rest of SsaBuilder to internalError. 2968 // TODO(antonm): migrate rest of SsaBuilder to internalError.
2948 internalError(String reason, [Node node]) { 2969 internalError(String reason, [Node node]) {
2949 compiler.internalError(reason, node: node); 2970 compiler.internalError(reason, node: node);
2950 } 2971 }
2951 2972
2952 void generateRuntimeError(Node node, String message) { 2973 void generateRuntimeError(Node node, String message) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3083 } else { 3104 } else {
3084 assert(const SourceString("++") == op.source || 3105 assert(const SourceString("++") == op.source ||
3085 const SourceString("--") == op.source || 3106 const SourceString("--") == op.source ||
3086 node.assignmentOperator.source.stringValue.endsWith("=")); 3107 node.assignmentOperator.source.stringValue.endsWith("="));
3087 Element element = elements[node]; 3108 Element element = elements[node];
3088 bool isCompoundAssignment = !node.arguments.isEmpty(); 3109 bool isCompoundAssignment = !node.arguments.isEmpty();
3089 bool isPrefix = !node.isPostfix; // Compound assignments are prefix. 3110 bool isPrefix = !node.isPostfix; // Compound assignments are prefix.
3090 3111
3091 // [receiver] is only used if the node is an instance send. 3112 // [receiver] is only used if the node is an instance send.
3092 HInstruction receiver = null; 3113 HInstruction receiver = null;
3093 if (Elements.isInstanceSend(node, elements)) { 3114 Element selectorElement = elements[node.selector];
3115 if (!Elements.isUnresolved(selectorElement)
3116 && selectorElement.kind == ElementKind.CLASS) {
3117 visitClassLiteralSend(node);
ngeoffray 2012/10/10 07:32:24 What is this about? Object = 42?
karlklose 2012/10/23 10:33:52 also for ++ and --.
3118 } else if (Elements.isInstanceSend(node, elements)) {
3094 receiver = generateInstanceSendReceiver(node); 3119 receiver = generateInstanceSendReceiver(node);
3095 generateInstanceGetterWithCompiledReceiver(node, receiver); 3120 generateInstanceGetterWithCompiledReceiver(node, receiver);
3096 } else { 3121 } else {
3097 generateGetter(node, elements[node.selector]); 3122 generateGetter(node, elements[node.selector]);
3098 } 3123 }
3099 HInstruction left = pop(); 3124 HInstruction left = pop();
3100 HInstruction right; 3125 HInstruction right;
3101 if (isCompoundAssignment) { 3126 if (isCompoundAssignment) {
3102 visit(node.argumentsNode); 3127 visit(node.argumentsNode);
3103 right = pop(); 3128 right = pop();
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
4398 new HSubGraphBlockInformation(elseBranch.graph)); 4423 new HSubGraphBlockInformation(elseBranch.graph));
4399 4424
4400 HBasicBlock conditionStartBlock = conditionBranch.block; 4425 HBasicBlock conditionStartBlock = conditionBranch.block;
4401 conditionStartBlock.setBlockFlow(info, joinBlock); 4426 conditionStartBlock.setBlockFlow(info, joinBlock);
4402 SubGraph conditionGraph = conditionBranch.graph; 4427 SubGraph conditionGraph = conditionBranch.graph;
4403 HIf branch = conditionGraph.end.last; 4428 HIf branch = conditionGraph.end.last;
4404 assert(branch is HIf); 4429 assert(branch is HIf);
4405 branch.blockInformation = conditionStartBlock.blockFlow; 4430 branch.blockInformation = conditionStartBlock.blockFlow;
4406 } 4431 }
4407 } 4432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698