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

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

Issue 1068233002: Revert "Extract CallStructure from Selector." (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
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/dart2jslib.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_task; 5 library dart2js.ir_builder_task;
6 6
7 import '../closure.dart' as closurelib; 7 import '../closure.dart' as closurelib;
8 import '../closure.dart' hide ClosureScope; 8 import '../closure.dart' hide ClosureScope;
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
11 import '../dart2jslib.dart'; 11 import '../dart2jslib.dart';
12 import '../elements/elements.dart'; 12 import '../elements/elements.dart';
13 import '../elements/modelx.dart' show SynthesizedConstructorElementX, 13 import '../elements/modelx.dart' show SynthesizedConstructorElementX,
14 ConstructorBodyElementX, FunctionSignatureX; 14 ConstructorBodyElementX, FunctionSignatureX;
15 import '../io/source_file.dart'; 15 import '../io/source_file.dart';
16 import '../io/source_information.dart'; 16 import '../io/source_information.dart';
17 import '../js_backend/js_backend.dart' show JavaScriptBackend; 17 import '../js_backend/js_backend.dart' show JavaScriptBackend;
18 import '../resolution/semantic_visitor.dart'; 18 import '../resolution/semantic_visitor.dart';
19 import '../resolution/operators.dart' as op; 19 import '../resolution/operators.dart' as op;
20 import '../scanner/scannerlib.dart' show Token, isUserDefinableOperator; 20 import '../scanner/scannerlib.dart' show Token, isUserDefinableOperator;
21 import '../tree/tree.dart' as ast; 21 import '../tree/tree.dart' as ast;
22 import '../universe/universe.dart' show SelectorKind, CallStructure; 22 import '../universe/universe.dart' show SelectorKind;
23 import 'cps_ir_nodes.dart' as ir; 23 import 'cps_ir_nodes.dart' as ir;
24 import 'cps_ir_builder.dart'; 24 import 'cps_ir_builder.dart';
25 25
26 /** 26 /**
27 * This task iterates through all resolved elements and builds [ir.Node]s. The 27 * This task iterates through all resolved elements and builds [ir.Node]s. The
28 * nodes are stored in the [nodes] map and accessible through [hasIr] and 28 * nodes are stored in the [nodes] map and accessible through [hasIr] and
29 * [getIr]. 29 * [getIr].
30 * 30 *
31 * The functionality of the IrNodes is added gradually, therefore elements might 31 * The functionality of the IrNodes is added gradually, therefore elements might
32 * have an IR or not, depending on the language features that are used. For 32 * have an IR or not, depending on the language features that are used. For
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 ClosureEnvironment getClosureEnvironment(); 180 ClosureEnvironment getClosureEnvironment();
181 181
182 /// Normalizes the argument list to a static invocation (i.e. where the target 182 /// Normalizes the argument list to a static invocation (i.e. where the target
183 /// element is known). 183 /// element is known).
184 /// 184 ///
185 /// For the JS backend, inserts default arguments and normalizes order of 185 /// For the JS backend, inserts default arguments and normalizes order of
186 /// named arguments. 186 /// named arguments.
187 /// 187 ///
188 /// For the Dart backend, returns [arguments]. 188 /// For the Dart backend, returns [arguments].
189 List<ir.Primitive> normalizeStaticArguments( 189 List<ir.Primitive> normalizeStaticArguments(
190 CallStructure callStructure, 190 Selector selector,
191 FunctionElement target, 191 FunctionElement target,
192 List<ir.Primitive> arguments); 192 List<ir.Primitive> arguments);
193 193
194 /// Normalizes the argument list of a dynamic invocation (i.e. where the 194 /// Normalizes the argument list of a dynamic invocation (i.e. where the
195 /// target element is unknown). 195 /// target element is unknown).
196 /// 196 ///
197 /// For the JS backend, normalizes order of named arguments. 197 /// For the JS backend, normalizes order of named arguments.
198 /// 198 ///
199 /// For the Dart backend, returns [arguments]. 199 /// For the Dart backend, returns [arguments].
200 List<ir.Primitive> normalizeDynamicArguments( 200 List<ir.Primitive> normalizeDynamicArguments(
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 ast.Node argument, 917 ast.Node argument,
918 _) { 918 _) {
919 return irBuilder.buildNegation( 919 return irBuilder.buildNegation(
920 translateSuperBinary(function, op.BinaryOperator.NOT_EQ, argument)); 920 translateSuperBinary(function, op.BinaryOperator.NOT_EQ, argument));
921 } 921 }
922 922
923 @override 923 @override
924 ir.Primitive visitUnary(ast.Send node, 924 ir.Primitive visitUnary(ast.Send node,
925 op.UnaryOperator operator, ast.Node expression, _) { 925 op.UnaryOperator operator, ast.Node expression, _) {
926 // TODO(johnniwinther): Clean up the creation of selectors. 926 // TODO(johnniwinther): Clean up the creation of selectors.
927 Selector selector = new Selector( 927 Selector selector =
928 SelectorKind.OPERATOR, 928 new Selector(SelectorKind.OPERATOR, operator.selectorName, null, 0);
929 new PublicName(operator.selectorName),
930 CallStructure.NO_ARGS);
931 ir.Primitive receiver = translateReceiver(expression); 929 ir.Primitive receiver = translateReceiver(expression);
932 return irBuilder.buildDynamicInvocation(receiver, selector, const []); 930 return irBuilder.buildDynamicInvocation(receiver, selector, const []);
933 } 931 }
934 932
935 @override 933 @override
936 ir.Primitive visitSuperUnary( 934 ir.Primitive visitSuperUnary(
937 ast.Send node, 935 ast.Send node,
938 op.UnaryOperator operator, 936 op.UnaryOperator operator,
939 FunctionElement function, 937 FunctionElement function,
940 _) { 938 _) {
941 // TODO(johnniwinther): Clean up the creation of selectors. 939 // TODO(johnniwinther): Clean up the creation of selectors.
942 Selector selector = new Selector( 940 Selector selector =
943 SelectorKind.OPERATOR, 941 new Selector(SelectorKind.OPERATOR, operator.selectorName, null, 0);
944 new PublicName(operator.selectorName),
945 CallStructure.NO_ARGS);
946 return irBuilder.buildSuperInvocation(function, selector, const []); 942 return irBuilder.buildSuperInvocation(function, selector, const []);
947 } 943 }
948 944
949 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct 945 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct
950 // semantic correlation between arguments and invocation. 946 // semantic correlation between arguments and invocation.
951 List<ir.Primitive> translateDynamicArguments(ast.NodeList nodeList, 947 List<ir.Primitive> translateDynamicArguments(ast.NodeList nodeList,
952 Selector selector) { 948 Selector selector) {
953 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); 949 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit);
954 return normalizeDynamicArguments(selector, arguments); 950 return normalizeDynamicArguments(selector, arguments);
955 } 951 }
956 952
957 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct 953 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct
958 // semantic correlation between arguments and invocation. 954 // semantic correlation between arguments and invocation.
959 List<ir.Primitive> translateStaticArguments(ast.NodeList nodeList, 955 List<ir.Primitive> translateStaticArguments(ast.NodeList nodeList,
960 Element element, 956 Element element,
961 CallStructure callStructure) { 957 Selector selector) {
962 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); 958 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit);
963 return normalizeStaticArguments(callStructure, element, arguments); 959 return normalizeStaticArguments(selector, element, arguments);
964 } 960 }
965 961
966 ir.Primitive translateCallInvoke(ir.Primitive target, 962 ir.Primitive translateCallInvoke(ir.Primitive target,
967 ast.NodeList arguments, 963 ast.NodeList arguments,
968 Selector selector) { 964 Selector selector) {
969 965
970 return irBuilder.buildCallInvocation(target, selector, 966 return irBuilder.buildCallInvocation(target, selector,
971 translateDynamicArguments(arguments, selector)); 967 translateDynamicArguments(arguments, selector));
972 } 968 }
973 969
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 ast.Send node, 1025 ast.Send node,
1030 MethodElement function, 1026 MethodElement function,
1031 ast.NodeList arguments, 1027 ast.NodeList arguments,
1032 Selector selector, 1028 Selector selector,
1033 _) { 1029 _) {
1034 // TODO(karlklose): support foreign functions. 1030 // TODO(karlklose): support foreign functions.
1035 if (function.isForeign(compiler.backend)) { 1031 if (function.isForeign(compiler.backend)) {
1036 return giveup(node, 'handleStaticFunctionInvoke: foreign: $function'); 1032 return giveup(node, 'handleStaticFunctionInvoke: foreign: $function');
1037 } 1033 }
1038 return irBuilder.buildStaticInvocation(function, selector, 1034 return irBuilder.buildStaticInvocation(function, selector,
1039 translateStaticArguments(arguments, function, selector.callStructure), 1035 translateStaticArguments(arguments, function, selector),
1040 sourceInformation: sourceInformationBuilder.buildCall(node)); 1036 sourceInformation: sourceInformationBuilder.buildCall(node));
1041 } 1037 }
1042 1038
1043 @override 1039 @override
1044 ir.Primitive handleStaticGetterInvoke( 1040 ir.Primitive handleStaticGetterInvoke(
1045 ast.Send node, 1041 ast.Send node,
1046 FunctionElement getter, 1042 FunctionElement getter,
1047 ast.NodeList arguments, 1043 ast.NodeList arguments,
1048 Selector selector, 1044 Selector selector,
1049 _) { 1045 _) {
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 1707
1712 @override 1708 @override
1713 ir.Primitive handleConstructorInvoke( 1709 ir.Primitive handleConstructorInvoke(
1714 ast.NewExpression node, 1710 ast.NewExpression node,
1715 ConstructorElement constructor, 1711 ConstructorElement constructor,
1716 DartType type, 1712 DartType type,
1717 ast.NodeList arguments, 1713 ast.NodeList arguments,
1718 Selector selector, _) { 1714 Selector selector, _) {
1719 List<ir.Primitive> arguments = 1715 List<ir.Primitive> arguments =
1720 node.send.arguments.mapToList(visit, growable:false); 1716 node.send.arguments.mapToList(visit, growable:false);
1721 arguments = normalizeStaticArguments( 1717 arguments = normalizeStaticArguments(selector, constructor, arguments);
1722 selector.callStructure, constructor, arguments);
1723 return irBuilder.buildConstructorInvocation( 1718 return irBuilder.buildConstructorInvocation(
1724 constructor, selector, type, arguments); 1719 constructor, selector, type, arguments);
1725 } 1720 }
1726 1721
1727 ir.Primitive visitStringJuxtaposition(ast.StringJuxtaposition node) { 1722 ir.Primitive visitStringJuxtaposition(ast.StringJuxtaposition node) {
1728 assert(irBuilder.isOpen); 1723 assert(irBuilder.isOpen);
1729 ir.Primitive first = visit(node.first); 1724 ir.Primitive first = visit(node.first);
1730 ir.Primitive second = visit(node.second); 1725 ir.Primitive second = visit(node.second);
1731 return irBuilder.buildStringConcatenation([first, second]); 1726 return irBuilder.buildStringConcatenation([first, second]);
1732 } 1727 }
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
2012 giveup(null, 'cannot handle synthetic forwarding constructors'); 2007 giveup(null, 'cannot handle synthetic forwarding constructors');
2013 } 2008 }
2014 } 2009 }
2015 2010
2016 IrBuilder builder = makeIRBuilder(node, element); 2011 IrBuilder builder = makeIRBuilder(node, element);
2017 2012
2018 return withBuilder(builder, () => _makeFunctionBody(element, node)); 2013 return withBuilder(builder, () => _makeFunctionBody(element, node));
2019 } 2014 }
2020 2015
2021 List<ir.Primitive> normalizeStaticArguments( 2016 List<ir.Primitive> normalizeStaticArguments(
2022 CallStructure callStructure, 2017 Selector selector,
2023 FunctionElement target, 2018 FunctionElement target,
2024 List<ir.Primitive> arguments) { 2019 List<ir.Primitive> arguments) {
2025 return arguments; 2020 return arguments;
2026 } 2021 }
2027 2022
2028 List<ir.Primitive> normalizeDynamicArguments( 2023 List<ir.Primitive> normalizeDynamicArguments(
2029 Selector selector, 2024 Selector selector,
2030 List<ir.Primitive> arguments) { 2025 List<ir.Primitive> arguments) {
2031 return arguments; 2026 return arguments;
2032 } 2027 }
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 ir.Primitive translateDefaultValue(ParameterElement parameter) { 2538 ir.Primitive translateDefaultValue(ParameterElement parameter) {
2544 if (parameter.initializer == null) { 2539 if (parameter.initializer == null) {
2545 return irBuilder.buildNullLiteral(); 2540 return irBuilder.buildNullLiteral();
2546 } else { 2541 } else {
2547 return inlineConstant(parameter.executableContext, parameter.initializer); 2542 return inlineConstant(parameter.executableContext, parameter.initializer);
2548 } 2543 }
2549 } 2544 }
2550 2545
2551 /// Inserts default arguments and normalizes order of named arguments. 2546 /// Inserts default arguments and normalizes order of named arguments.
2552 List<ir.Primitive> normalizeStaticArguments( 2547 List<ir.Primitive> normalizeStaticArguments(
2553 CallStructure callStructure, 2548 Selector selector,
2554 FunctionElement target, 2549 FunctionElement target,
2555 List<ir.Primitive> arguments) { 2550 List<ir.Primitive> arguments) {
2556 target = target.implementation; 2551 target = target.implementation;
2557 FunctionSignature signature = target.functionSignature; 2552 FunctionSignature signature = target.functionSignature;
2558 if (!signature.optionalParametersAreNamed && 2553 if (!signature.optionalParametersAreNamed &&
2559 signature.parameterCount == arguments.length) { 2554 signature.parameterCount == arguments.length) {
2560 // Optimization: don't copy the argument list for trivial cases. 2555 // Optimization: don't copy the argument list for trivial cases.
2561 return arguments; 2556 return arguments;
2562 } 2557 }
2563 2558
(...skipping 12 matching lines...) Expand all
2576 } else { 2571 } else {
2577 result.add(translateDefaultValue(element)); 2572 result.add(translateDefaultValue(element));
2578 } 2573 }
2579 }); 2574 });
2580 } else { 2575 } else {
2581 int offset = i; 2576 int offset = i;
2582 // Iterate over the optional parameters of the signature, and try to 2577 // Iterate over the optional parameters of the signature, and try to
2583 // find them in [compiledNamedArguments]. If found, we use the 2578 // find them in [compiledNamedArguments]. If found, we use the
2584 // value in the temporary list, otherwise the default value. 2579 // value in the temporary list, otherwise the default value.
2585 signature.orderedOptionalParameters.forEach((ParameterElement element) { 2580 signature.orderedOptionalParameters.forEach((ParameterElement element) {
2586 int nameIndex = callStructure.namedArguments.indexOf(element.name); 2581 int nameIndex = selector.namedArguments.indexOf(element.name);
2587 if (nameIndex != -1) { 2582 if (nameIndex != -1) {
2588 int translatedIndex = offset + nameIndex; 2583 int translatedIndex = offset + nameIndex;
2589 result.add(arguments[translatedIndex]); 2584 result.add(arguments[translatedIndex]);
2590 } else { 2585 } else {
2591 result.add(translateDefaultValue(element)); 2586 result.add(translateDefaultValue(element));
2592 } 2587 }
2593 }); 2588 });
2594 } 2589 }
2595 return result; 2590 return result;
2596 } 2591 }
2597 2592
2598 /// Normalizes order of named arguments. 2593 /// Normalizes order of named arguments.
2599 List<ir.Primitive> normalizeDynamicArguments( 2594 List<ir.Primitive> normalizeDynamicArguments(
2600 Selector selector, 2595 Selector selector,
2601 List<ir.Primitive> arguments) { 2596 List<ir.Primitive> arguments) {
2602 CallStructure callStructure = selector.callStructure; 2597 assert(arguments.length == selector.argumentCount);
2603 assert(arguments.length == callStructure.argumentCount);
2604 // Optimization: don't copy the argument list for trivial cases. 2598 // Optimization: don't copy the argument list for trivial cases.
2605 if (callStructure.namedArguments.isEmpty) return arguments; 2599 if (selector.namedArguments.isEmpty) return arguments;
2606 List<ir.Primitive> result = <ir.Primitive>[]; 2600 List<ir.Primitive> result = <ir.Primitive>[];
2607 for (int i=0; i < callStructure.positionalArgumentCount; i++) { 2601 for (int i=0; i < selector.positionalArgumentCount; i++) {
2608 result.add(arguments[i]); 2602 result.add(arguments[i]);
2609 } 2603 }
2610 for (String argName in callStructure.getOrderedNamedArguments()) { 2604 for (String argName in selector.getOrderedNamedArguments()) {
2611 int nameIndex = callStructure.namedArguments.indexOf(argName); 2605 int nameIndex = selector.namedArguments.indexOf(argName);
2612 int translatedIndex = callStructure.positionalArgumentCount + nameIndex; 2606 int translatedIndex = selector.positionalArgumentCount + nameIndex;
2613 result.add(arguments[translatedIndex]); 2607 result.add(arguments[translatedIndex]);
2614 } 2608 }
2615 return result; 2609 return result;
2616 } 2610 }
2617 2611
2618 @override 2612 @override
2619 ir.Primitive buildReifyTypeVariable(ir.Primitive target, 2613 ir.Primitive buildReifyTypeVariable(ir.Primitive target,
2620 TypeVariableType variable) { 2614 TypeVariableType variable) {
2621 ir.Primitive typeArgument = 2615 ir.Primitive typeArgument =
2622 irBuilder.buildTypeVariableAccess(target, variable); 2616 irBuilder.buildTypeVariableAccess(target, variable);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 SourceInformation buildCall(ast.Node node) { 2654 SourceInformation buildCall(ast.Node node) {
2661 return new PositionSourceInformation( 2655 return new PositionSourceInformation(
2662 new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); 2656 new TokenSourceLocation(sourceFile, node.getBeginToken(), name));
2663 } 2657 }
2664 2658
2665 @override 2659 @override
2666 SourceInformationBuilder forContext(AstElement element) { 2660 SourceInformationBuilder forContext(AstElement element) {
2667 return new PositionSourceInformationBuilder(element); 2661 return new PositionSourceInformationBuilder(element);
2668 } 2662 }
2669 } 2663 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/dart2jslib.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698