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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 1088933004: Use CallStructure instead of Selector in SemanticSendVisitor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart2js.ir_builder; 5 library dart2js.ir_builder;
6 6
7 import '../constants/expressions.dart'; 7 import '../constants/expressions.dart';
8 import '../constants/values.dart' show PrimitiveConstantValue; 8 import '../constants/values.dart' show PrimitiveConstantValue;
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../dart2jslib.dart'; 10 import '../dart2jslib.dart';
11 import '../elements/elements.dart'; 11 import '../elements/elements.dart';
12 import '../io/source_information.dart'; 12 import '../io/source_information.dart';
13 import '../tree/tree.dart' as ast; 13 import '../tree/tree.dart' as ast;
14 import '../closure.dart' hide ClosureScope; 14 import '../closure.dart' hide ClosureScope;
15 import '../universe/universe.dart' show SelectorKind;
15 import 'cps_ir_nodes.dart' as ir; 16 import 'cps_ir_nodes.dart' as ir;
16 import 'cps_ir_builder_task.dart' show DartCapturedVariables, 17 import 'cps_ir_builder_task.dart' show DartCapturedVariables,
17 GlobalProgramInformation; 18 GlobalProgramInformation;
18 19
19 /// A mapping from variable elements to their compile-time values. 20 /// A mapping from variable elements to their compile-time values.
20 /// 21 ///
21 /// Map elements denoted by parameters and local variables to the 22 /// Map elements denoted by parameters and local variables to the
22 /// [ir.Primitive] that is their value. Parameters and locals are 23 /// [ir.Primitive] that is their value. Parameters and locals are
23 /// assigned indexes which can be used to refer to them. 24 /// assigned indexes which can be used to refer to them.
24 class Environment { 25 class Environment {
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 Selector selector, 641 Selector selector,
641 List<ir.Primitive> arguments, 642 List<ir.Primitive> arguments,
642 {SourceInformation sourceInformation}) { 643 {SourceInformation sourceInformation}) {
643 assert(isOpen); 644 assert(isOpen);
644 return _continueWithExpression( 645 return _continueWithExpression(
645 (k) => new ir.InvokeMethod(receiver, selector, k, arguments, 646 (k) => new ir.InvokeMethod(receiver, selector, k, arguments,
646 sourceInformation: sourceInformation)); 647 sourceInformation: sourceInformation));
647 } 648 }
648 649
649 ir.Primitive _buildInvokeCall(ir.Primitive target, 650 ir.Primitive _buildInvokeCall(ir.Primitive target,
650 Selector selector, 651 CallStructure callStructure,
651 List<ir.Definition> arguments, 652 List<ir.Definition> arguments,
652 {SourceInformation sourceInformation}) { 653 {SourceInformation sourceInformation}) {
653 Selector callSelector = new Selector.callClosureFrom(selector); 654 Selector selector = callStructure.callSelector;
654 return _buildInvokeDynamic(target, callSelector, arguments, 655 return _buildInvokeDynamic(target, selector, arguments,
655 sourceInformation: sourceInformation); 656 sourceInformation: sourceInformation);
656 } 657 }
657 658
658 659
659 /// Create a constant literal from [constant]. 660 /// Create a constant literal from [constant].
660 ir.Constant buildConstantLiteral(ConstantExpression constant) { 661 ir.Constant buildConstantLiteral(ConstantExpression constant) {
661 assert(isOpen); 662 assert(isOpen);
662 return addPrimitive(new ir.Constant(constant)); 663 return addPrimitive(new ir.Constant(constant));
663 } 664 }
664 665
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 ir.ConstructorDefinition makeConstructorDefinition( 862 ir.ConstructorDefinition makeConstructorDefinition(
862 List<ConstantExpression> defaults, List<ir.Initializer> initializers) { 863 List<ConstantExpression> defaults, List<ir.Initializer> initializers) {
863 FunctionElement element = state.currentElement; 864 FunctionElement element = state.currentElement;
864 ir.Body body = makeBody(); 865 ir.Body body = makeBody();
865 return new ir.ConstructorDefinition( 866 return new ir.ConstructorDefinition(
866 element, state.thisParameter, state.functionParameters, body, initialize rs, 867 element, state.thisParameter, state.functionParameters, body, initialize rs,
867 state.localConstants, defaults); 868 state.localConstants, defaults);
868 } 869 }
869 870
870 /// Create a invocation of the [method] on the super class where the call 871 /// Create a invocation of the [method] on the super class where the call
871 /// structure is defined [selector] and the argument values are defined by 872 /// structure is defined [callStructure] and the argument values are defined
872 /// [arguments]. 873 /// by [arguments].
873 ir.Primitive buildSuperMethodInvocation(MethodElement method, 874 ir.Primitive buildSuperMethodInvocation(MethodElement method,
874 Selector selector, 875 CallStructure callStructure,
875 List<ir.Primitive> arguments) { 876 List<ir.Primitive> arguments) {
877 Selector selector =
878 new Selector(SelectorKind.CALL, method.memberName, callStructure);
876 return _buildInvokeSuper(method, selector, arguments); 879 return _buildInvokeSuper(method, selector, arguments);
877 } 880 }
878 881
879 /// Create a call invocation on the value of [field] on the super class where 882 /// Create a call invocation on the value of [field] on the super class where
880 /// the call structure is defined [selector] and the argument values are 883 /// the call structure is defined [callStructure] and the argument values are
881 /// defined by [arguments]. 884 /// defined by [arguments].
882 ir.Primitive buildSuperFieldInvocation(FieldElement field, 885 ir.Primitive buildSuperFieldInvocation(FieldElement field,
883 Selector selector, 886 CallStructure callStructure,
884 List<ir.Primitive> arguments) { 887 List<ir.Primitive> arguments) {
885 // TODO(johnniwinther): Maybe this should have its own ir node. 888 // TODO(johnniwinther): Maybe this should have its own ir node.
886 return buildCallInvocation( 889 return buildCallInvocation(
887 buildSuperFieldGet(field), 890 buildSuperFieldGet(field),
888 selector, 891 callStructure,
889 arguments); 892 arguments);
890 } 893 }
891 894
892 /// Create a call invocation on the value returned from the [getter] on the 895 /// Create a call invocation on the value returned from the [getter] on the
893 /// super class where the call structure is defined [selector] and the 896 /// super class where the call structure is defined [selector] and the
894 /// argument values are defined by [arguments]. 897 /// argument values are defined by [arguments].
895 ir.Primitive buildSuperGetterInvocation(MethodElement getter, 898 ir.Primitive buildSuperGetterInvocation(MethodElement getter,
896 Selector selector, 899 CallStructure callStructure,
897 List<ir.Primitive> arguments) { 900 List<ir.Primitive> arguments) {
898 // TODO(johnniwinther): Maybe this should have its own ir node. 901 // TODO(johnniwinther): Maybe this should have its own ir node.
899 return buildCallInvocation( 902 return buildCallInvocation(
900 buildSuperGetterGet(getter), 903 buildSuperGetterGet(getter),
901 selector, 904 callStructure,
902 arguments); 905 arguments);
903 } 906 }
904 907
905 /// Create a read access of the [field] on the super class. 908 /// Create a read access of the [field] on the super class.
906 ir.Primitive buildSuperFieldGet(FieldElement field) { 909 ir.Primitive buildSuperFieldGet(FieldElement field) {
907 // TODO(johnniwinther): This should have its own ir node. 910 // TODO(johnniwinther): This should have its own ir node.
908 return _buildInvokeSuper( 911 return _buildInvokeSuper(
909 field, 912 field,
910 new Selector.getter(field.name, field.library), 913 new Selector.getter(field.name, field.library),
911 const <ir.Primitive>[]); 914 const <ir.Primitive>[]);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 ir.Primitive buildLocalFunctionGet(LocalFunctionElement function) { 1014 ir.Primitive buildLocalFunctionGet(LocalFunctionElement function) {
1012 // TODO(johnniwinther): Separate function access from variable access. 1015 // TODO(johnniwinther): Separate function access from variable access.
1013 return _buildLocalGet(function); 1016 return _buildLocalGet(function);
1014 } 1017 }
1015 1018
1016 /// Create a write access to the [local] variable or parameter with the 1019 /// Create a write access to the [local] variable or parameter with the
1017 /// provided [value]. 1020 /// provided [value].
1018 ir.Primitive buildLocalVariableSet(LocalElement local, ir.Primitive value); 1021 ir.Primitive buildLocalVariableSet(LocalElement local, ir.Primitive value);
1019 1022
1020 /// Create an invocation of the the [local] variable or parameter where 1023 /// Create an invocation of the the [local] variable or parameter where
1021 /// argument structure is defined by [selector] and the argument values are 1024 /// argument structure is defined by [callStructure] and the argument values
1022 /// defined by [arguments]. 1025 /// are defined by [arguments].
1023 ir.Primitive buildLocalVariableInvocation(LocalVariableElement local, 1026 ir.Primitive buildLocalVariableInvocation(LocalVariableElement local,
1024 Selector selector, 1027 CallStructure callStructure,
1025 List<ir.Primitive> arguments) { 1028 List<ir.Primitive> arguments) {
1026 return buildCallInvocation( 1029 return buildCallInvocation(
1027 buildLocalVariableGet(local), selector, arguments); 1030 buildLocalVariableGet(local), callStructure, arguments);
1028 } 1031 }
1029 1032
1030 /// Create an invocation of the local [function] where argument structure is 1033 /// Create an invocation of the local [function] where argument structure is
1031 /// defined by [selector] and the argument values are defined by [arguments]. 1034 /// defined by [callStructure] and the argument values are defined by
1035 /// [arguments].
1032 ir.Primitive buildLocalFunctionInvocation( 1036 ir.Primitive buildLocalFunctionInvocation(
1033 LocalFunctionElement function, 1037 LocalFunctionElement function,
1034 Selector selector, 1038 CallStructure callStructure,
1035 List<ir.Primitive> arguments) { 1039 List<ir.Primitive> arguments) {
1036 // TODO(johnniwinther): Maybe this should have its own ir node. 1040 // TODO(johnniwinther): Maybe this should have its own ir node.
1037 return buildCallInvocation( 1041 return buildCallInvocation(
1038 buildLocalFunctionGet(function), selector, arguments); 1042 buildLocalFunctionGet(function), callStructure, arguments);
1039 } 1043 }
1040 1044
1041 /// Create a static invocation of [function] where argument structure is 1045 /// Create a static invocation of [function] where argument structure is
1042 /// defined by [selector] and the argument values are defined by [arguments]. 1046 /// defined by [callStructure] and the argument values are defined by
1047 /// [arguments].
1043 ir.Primitive buildStaticFunctionInvocation( 1048 ir.Primitive buildStaticFunctionInvocation(
1044 MethodElement function, 1049 MethodElement function,
1045 Selector selector, 1050 CallStructure callStructure,
1046 List<ir.Primitive> arguments, 1051 List<ir.Primitive> arguments,
1047 {SourceInformation sourceInformation}) { 1052 {SourceInformation sourceInformation}) {
1048 return _buildInvokeStatic(function, selector, arguments, sourceInformation); 1053 Selector selector =
1054 new Selector(SelectorKind.CALL, function.memberName, callStructure);
1055 return _buildInvokeStatic(
1056 function, selector, arguments, sourceInformation);
1049 } 1057 }
1050 1058
1051 /// Create a call invocation of the value of the static [field] where argument 1059 /// Create a call invocation of the value of the static [field] where argument
1052 /// structure is defined by [selector] and the argument values are defined by 1060 /// structure is defined by [callStructure] and the argument values are
1053 /// [arguments]. 1061 /// defined by [arguments].
1054 ir.Primitive buildStaticFieldInvocation( 1062 ir.Primitive buildStaticFieldInvocation(
1055 FieldElement field, 1063 FieldElement field,
1056 Selector selector, 1064 CallStructure callStructure,
1057 List<ir.Primitive> arguments, 1065 List<ir.Primitive> arguments,
1058 {SourceInformation sourceInformation}) { 1066 {SourceInformation sourceInformation}) {
1059 // TODO(johnniwinther): Maybe this should have its own node. 1067 // TODO(johnniwinther): Maybe this should have its own node.
1060 return buildCallInvocation( 1068 return buildCallInvocation(
1061 buildStaticFieldGet(field), 1069 buildStaticFieldGet(field),
1062 selector, 1070 callStructure,
1063 arguments, 1071 arguments,
1064 sourceInformation: sourceInformation); 1072 sourceInformation: sourceInformation);
1065 } 1073 }
1066 1074
1067 /// Create a call invocation of the result of calling the static [getter] 1075 /// Create a call invocation of the result of calling the static [getter]
1068 /// where argument structure is defined by [selector] and the argument values 1076 /// where argument structure is defined by [callStructure] and the argument
1069 /// are defined by [arguments]. 1077 /// values are defined by [arguments].
1070 ir.Primitive buildStaticGetterInvocation( 1078 ir.Primitive buildStaticGetterInvocation(
1071 MethodElement getter, 1079 MethodElement getter,
1072 Selector selector, 1080 CallStructure callStructure,
1073 List<ir.Primitive> arguments, 1081 List<ir.Primitive> arguments,
1074 {SourceInformation sourceInformation}) { 1082 {SourceInformation sourceInformation}) {
1075 // TODO(johnniwinther): Maybe this should have its own node. 1083 // TODO(johnniwinther): Maybe this should have its own node.
1076 return buildCallInvocation( 1084 return buildCallInvocation(
1077 buildStaticGetterGet(getter), 1085 buildStaticGetterGet(getter),
1078 selector, 1086 callStructure,
1079 arguments, 1087 arguments,
1080 sourceInformation: sourceInformation); 1088 sourceInformation: sourceInformation);
1081 } 1089 }
1082 1090
1083 /// Create a read access of the static [field]. 1091 /// Create a read access of the static [field].
1084 ir.Primitive buildStaticFieldGet(FieldElement field, 1092 ir.Primitive buildStaticFieldGet(FieldElement field,
1085 {SourceInformation sourceInformation}) { 1093 {SourceInformation sourceInformation}) {
1086 Selector selector = new Selector.getter(field.name, field.library); 1094 Selector selector = new Selector.getter(field.name, field.library);
1087 // TODO(karlklose,sigurdm): build different nodes for getters. 1095 // TODO(karlklose,sigurdm): build different nodes for getters.
1088 return _buildInvokeStatic( 1096 return _buildInvokeStatic(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 } 1140 }
1133 1141
1134 /// Create an erroneous invocation where argument structure is defined by 1142 /// Create an erroneous invocation where argument structure is defined by
1135 /// [selector] and the argument values are defined by [arguments]. 1143 /// [selector] and the argument values are defined by [arguments].
1136 // TODO(johnniwinther): Make this more fine-grained. 1144 // TODO(johnniwinther): Make this more fine-grained.
1137 ir.Primitive buildErroneousInvocation( 1145 ir.Primitive buildErroneousInvocation(
1138 Element element, 1146 Element element,
1139 Selector selector, 1147 Selector selector,
1140 List<ir.Primitive> arguments) { 1148 List<ir.Primitive> arguments) {
1141 // TODO(johnniwinther): This should have its own ir node. 1149 // TODO(johnniwinther): This should have its own ir node.
1142 return _buildInvokeStatic( element, selector, arguments, null); 1150 return _buildInvokeStatic(element, selector, arguments, null);
1143 } 1151 }
1144 1152
1145 /// Create a constructor invocation of [element] on [type] where the 1153 /// Create a constructor invocation of [element] on [type] where the
1146 /// constructor name and argument structure are defined by [selector] and the 1154 /// constructor name and argument structure are defined by [callStructure] and
1147 /// argument values are defined by [arguments]. 1155 /// the argument values are defined by [arguments].
1148 ir.Primitive buildConstructorInvocation(FunctionElement element, 1156 ir.Primitive buildConstructorInvocation(FunctionElement element,
1149 Selector selector, 1157 CallStructure callStructure,
1150 DartType type, 1158 DartType type,
1151 List<ir.Primitive> arguments); 1159 List<ir.Primitive> arguments);
1152 1160
1153 /// Create a string concatenation of the [arguments]. 1161 /// Create a string concatenation of the [arguments].
1154 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) { 1162 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) {
1155 assert(isOpen); 1163 assert(isOpen);
1156 return _continueWithExpression( 1164 return _continueWithExpression(
1157 (k) => new ir.ConcatenateStrings(k, arguments)); 1165 (k) => new ir.ConcatenateStrings(k, arguments));
1158 } 1166 }
1159 1167
1160 /// Create an invocation of the `call` method of [functionExpression], where 1168 /// Create an invocation of the `call` method of [functionExpression], where
1161 /// the named arguments are given by [selector]. 1169 /// the structure of arguments are given by [callStructure].
1162 ir.Primitive buildCallInvocation( 1170 ir.Primitive buildCallInvocation(
1163 ir.Primitive functionExpression, 1171 ir.Primitive functionExpression,
1164 Selector selector, 1172 CallStructure callStructure,
1165 List<ir.Definition> arguments, 1173 List<ir.Definition> arguments,
1166 {SourceInformation sourceInformation}) { 1174 {SourceInformation sourceInformation}) {
1167 return _buildInvokeCall(functionExpression, selector, arguments, 1175 return _buildInvokeCall(functionExpression, callStructure, arguments,
1168 sourceInformation: sourceInformation); 1176 sourceInformation: sourceInformation);
1169 } 1177 }
1170 1178
1171 /// Creates an if-then-else statement with the provided [condition] where the 1179 /// Creates an if-then-else statement with the provided [condition] where the
1172 /// then and else branches are created through the [buildThenPart] and 1180 /// then and else branches are created through the [buildThenPart] and
1173 /// [buildElsePart] functions, respectively. 1181 /// [buildElsePart] functions, respectively.
1174 /// 1182 ///
1175 /// An if-then statement is created if [buildElsePart] is a no-op. 1183 /// An if-then statement is created if [buildElsePart] is a no-op.
1176 // TODO(johnniwinther): Unify implementation with [buildConditional] and 1184 // TODO(johnniwinther): Unify implementation with [buildConditional] and
1177 // [_buildLogicalOperator]. 1185 // [_buildLogicalOperator].
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 environment.update(local, value); 2266 environment.update(local, value);
2259 } 2267 }
2260 return value; 2268 return value;
2261 } 2269 }
2262 2270
2263 ir.Primitive buildThis() { 2271 ir.Primitive buildThis() {
2264 return state.enclosingMethodThisParameter; 2272 return state.enclosingMethodThisParameter;
2265 } 2273 }
2266 2274
2267 @override 2275 @override
2268 ir.Primitive buildConstructorInvocation(FunctionElement element, 2276 ir.Primitive buildConstructorInvocation(ConstructorElement element,
2269 Selector selector, 2277 CallStructure callStructure,
2270 DartType type, 2278 DartType type,
2271 List<ir.Primitive> arguments) { 2279 List<ir.Primitive> arguments) {
2272 assert(isOpen); 2280 assert(isOpen);
2281 Selector selector =
2282 new Selector(SelectorKind.CALL, element.memberName, callStructure);
2273 return _continueWithExpression( 2283 return _continueWithExpression(
2274 (k) => new ir.InvokeConstructor(type, element, selector, k, 2284 (k) => new ir.InvokeConstructor(type, element, selector, k,
2275 arguments)); 2285 arguments));
2276 } 2286 }
2277 } 2287 }
2278 2288
2279 /// State shared between JsIrBuilders within the same function. 2289 /// State shared between JsIrBuilders within the same function.
2280 /// 2290 ///
2281 /// Note that this is not shared between builders of nested functions. 2291 /// Note that this is not shared between builders of nested functions.
2282 class JsIrBuilderSharedState { 2292 class JsIrBuilderSharedState {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 ir.Parameter parameter = createLocalParameter(param); 2551 ir.Parameter parameter = createLocalParameter(param);
2542 state.functionParameters.add(parameter); 2552 state.functionParameters.add(parameter);
2543 } 2553 }
2544 if (closureScope != null) { 2554 if (closureScope != null) {
2545 jsState.boxedVariables.addAll(closureScope.capturedVariables); 2555 jsState.boxedVariables.addAll(closureScope.capturedVariables);
2546 } 2556 }
2547 } 2557 }
2548 2558
2549 @override 2559 @override
2550 ir.Primitive buildConstructorInvocation(ConstructorElement element, 2560 ir.Primitive buildConstructorInvocation(ConstructorElement element,
2551 Selector selector, 2561 CallStructure callStructure,
2552 DartType type, 2562 DartType type,
2553 List<ir.Primitive> arguments) { 2563 List<ir.Primitive> arguments) {
2554 assert(isOpen); 2564 assert(isOpen);
2555 2565 Selector selector =
2566 new Selector(SelectorKind.CALL, element.memberName, callStructure);
2556 ClassElement cls = element.enclosingClass; 2567 ClassElement cls = element.enclosingClass;
2557 if (program.requiresRuntimeTypesFor(cls)) { 2568 if (program.requiresRuntimeTypesFor(cls)) {
2558 InterfaceType interface = type; 2569 InterfaceType interface = type;
2559 Iterable<ir.Primitive> typeArguments = 2570 Iterable<ir.Primitive> typeArguments =
2560 interface.typeArguments.map((DartType argument) { 2571 interface.typeArguments.map((DartType argument) {
2561 return type.treatAsRaw 2572 return type.treatAsRaw
2562 ? buildNullLiteral() 2573 ? buildNullLiteral()
2563 : buildTypeExpression(argument); 2574 : buildTypeExpression(argument);
2564 }); 2575 });
2565 arguments = new List<ir.Primitive>.from(arguments) 2576 arguments = new List<ir.Primitive>.from(arguments)
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2676 } 2687 }
2677 2688
2678 /// Synthetic parameter to a JavaScript factory method that takes the type 2689 /// Synthetic parameter to a JavaScript factory method that takes the type
2679 /// argument given for the type variable [variable]. 2690 /// argument given for the type variable [variable].
2680 class TypeInformationParameter implements Local { 2691 class TypeInformationParameter implements Local {
2681 final TypeVariableElement variable; 2692 final TypeVariableElement variable;
2682 final ExecutableElement executableContext; 2693 final ExecutableElement executableContext;
2683 TypeInformationParameter(this.variable, this.executableContext); 2694 TypeInformationParameter(this.variable, this.executableContext);
2684 String get name => variable.name; 2695 String get name => variable.name;
2685 } 2696 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698