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

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

Issue 1182053010: Revert "Split TypedSelector into Selector and TypeMask." (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
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 '../compile_time_constants.dart' show BackendConstantEnvironment; 7 import '../compile_time_constants.dart' show BackendConstantEnvironment;
8 import '../constants/constant_system.dart'; 8 import '../constants/constant_system.dart';
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue; 10 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue;
11 import '../dart_types.dart'; 11 import '../dart_types.dart';
12 import '../dart2jslib.dart'; 12 import '../dart2jslib.dart';
13 import '../elements/elements.dart'; 13 import '../elements/elements.dart';
14 import '../io/source_information.dart'; 14 import '../io/source_information.dart';
15 import '../tree/tree.dart' as ast; 15 import '../tree/tree.dart' as ast;
16 import '../types/types.dart' show TypeMask;
17 import '../closure.dart' hide ClosureScope; 16 import '../closure.dart' hide ClosureScope;
18 import '../universe/universe.dart' show SelectorKind; 17 import '../universe/universe.dart' show SelectorKind;
19 import 'cps_ir_nodes.dart' as ir; 18 import 'cps_ir_nodes.dart' as ir;
20 import 'cps_ir_builder_task.dart' show DartCapturedVariables, 19 import 'cps_ir_builder_task.dart' show DartCapturedVariables,
21 GlobalProgramInformation; 20 GlobalProgramInformation;
22 21
23 /// A mapping from variable elements to their compile-time values. 22 /// A mapping from variable elements to their compile-time values.
24 /// 23 ///
25 /// Map elements denoted by parameters and local variables to the 24 /// Map elements denoted by parameters and local variables to the
26 /// [ir.Primitive] that is their value. Parameters and locals are 25 /// [ir.Primitive] that is their value. Parameters and locals are
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 List<ir.Primitive> arguments) { 646 List<ir.Primitive> arguments) {
648 assert(target.isInstanceMember); 647 assert(target.isInstanceMember);
649 assert(isOpen); 648 assert(isOpen);
650 return _continueWithExpression( 649 return _continueWithExpression(
651 (k) => new ir.InvokeMethodDirectly( 650 (k) => new ir.InvokeMethodDirectly(
652 buildThis(), target, selector, arguments, k)); 651 buildThis(), target, selector, arguments, k));
653 } 652 }
654 653
655 ir.Primitive _buildInvokeDynamic(ir.Primitive receiver, 654 ir.Primitive _buildInvokeDynamic(ir.Primitive receiver,
656 Selector selector, 655 Selector selector,
657 TypeMask mask,
658 List<ir.Primitive> arguments, 656 List<ir.Primitive> arguments,
659 {SourceInformation sourceInformation}) { 657 {SourceInformation sourceInformation}) {
660 assert(isOpen); 658 assert(isOpen);
661 return _continueWithExpression( 659 return _continueWithExpression(
662 (k) => new ir.InvokeMethod(receiver, selector, mask, arguments, k, 660 (k) => new ir.InvokeMethod(receiver, selector, arguments, k,
663 sourceInformation: sourceInformation)); 661 sourceInformation: sourceInformation));
664 } 662 }
665 663
666 ir.Primitive _buildInvokeCall(ir.Primitive target, 664 ir.Primitive _buildInvokeCall(ir.Primitive target,
667 CallStructure callStructure, 665 CallStructure callStructure,
668 TypeMask mask,
669 List<ir.Definition> arguments, 666 List<ir.Definition> arguments,
670 {SourceInformation sourceInformation}) { 667 {SourceInformation sourceInformation}) {
671 Selector selector = callStructure.callSelector; 668 Selector selector = callStructure.callSelector;
672 return _buildInvokeDynamic(target, selector, mask, arguments, 669 return _buildInvokeDynamic(target, selector, arguments,
673 sourceInformation: sourceInformation); 670 sourceInformation: sourceInformation);
674 } 671 }
675 672
676 673
677 /// Create a [ir.Constant] from [constant] and add it to the CPS term. 674 /// Create a [ir.Constant] from [constant] and add it to the CPS term.
678 // TODO(johnniwinther): Remove [value] when [ConstantValue] can be computed 675 // TODO(johnniwinther): Remove [value] when [ConstantValue] can be computed
679 // directly from [constant]. 676 // directly from [constant].
680 ir.Constant buildConstant(ConstantExpression constant, ConstantValue value) { 677 ir.Constant buildConstant(ConstantExpression constant, ConstantValue value) {
681 assert(isOpen); 678 assert(isOpen);
682 return addPrimitive(new ir.Constant(constant, value)); 679 return addPrimitive(new ir.Constant(constant, value));
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 _buildInvokeSuper(method, new Selector.indexSet(), 914 _buildInvokeSuper(method, new Selector.indexSet(),
918 <ir.Primitive>[index, value]); 915 <ir.Primitive>[index, value]);
919 return value; 916 return value;
920 } 917 }
921 918
922 /// Create a dynamic invocation on [receiver] where the method name and 919 /// Create a dynamic invocation on [receiver] where the method name and
923 /// argument structure are defined by [selector] and the argument values are 920 /// argument structure are defined by [selector] and the argument values are
924 /// defined by [arguments]. 921 /// defined by [arguments].
925 ir.Primitive buildDynamicInvocation(ir.Primitive receiver, 922 ir.Primitive buildDynamicInvocation(ir.Primitive receiver,
926 Selector selector, 923 Selector selector,
927 TypeMask mask,
928 List<ir.Primitive> arguments) { 924 List<ir.Primitive> arguments) {
929 return _buildInvokeDynamic(receiver, selector, mask, arguments); 925 return _buildInvokeDynamic(receiver, selector, arguments);
930 } 926 }
931 927
932 /// Create an if-null expression. This is equivalent to a conditional 928 /// Create an if-null expression. This is equivalent to a conditional
933 /// expression whose result is either [value] if [value] is not null, or 929 /// expression whose result is either [value] if [value] is not null, or
934 /// `right` if [value] is null. Only when [value] is null, [buildRight] is 930 /// `right` if [value] is null. Only when [value] is null, [buildRight] is
935 /// evaluated to produce the `right` value. 931 /// evaluated to produce the `right` value.
936 ir.Primitive buildIfNull(ir.Primitive value, 932 ir.Primitive buildIfNull(ir.Primitive value,
937 ir.Primitive buildRight(IrBuilder builder)); 933 ir.Primitive buildRight(IrBuilder builder));
938 934
939 /// Create a conditional send. This is equivalent to a conditional expression 935 /// Create a conditional send. This is equivalent to a conditional expression
940 /// that checks if [receiver] is null, if so, it returns null, otherwise it 936 /// that checks if [receiver] is null, if so, it returns null, otherwise it
941 /// evaluates the [buildSend] expression. 937 /// evaluates the [buildSend] expression.
942 ir.Primitive buildIfNotNullSend(ir.Primitive receiver, 938 ir.Primitive buildIfNotNullSend(ir.Primitive receiver,
943 ir.Primitive buildSend(IrBuilder builder)); 939 ir.Primitive buildSend(IrBuilder builder));
944 940
945 /// Create a dynamic getter invocation on [receiver] where the getter name is 941 /// Create a dynamic getter invocation on [receiver] where the getter name is
946 /// defined by [selector]. 942 /// defined by [selector].
947 ir.Primitive buildDynamicGet(ir.Primitive receiver, 943 ir.Primitive buildDynamicGet(ir.Primitive receiver, Selector selector) {
948 Selector selector,
949 TypeMask mask) {
950 assert(selector.isGetter); 944 assert(selector.isGetter);
951 return _buildInvokeDynamic( 945 return _buildInvokeDynamic(receiver, selector, const <ir.Primitive>[]);
952 receiver, selector, mask, const <ir.Primitive>[]);
953 } 946 }
954 947
955 /// Create a dynamic setter invocation on [receiver] where the setter name and 948 /// Create a dynamic setter invocation on [receiver] where the setter name and
956 /// argument are defined by [selector] and [value], respectively. 949 /// argument are defined by [selector] and [value], respectively.
957 ir.Primitive buildDynamicSet(ir.Primitive receiver, 950 ir.Primitive buildDynamicSet(ir.Primitive receiver,
958 Selector selector, 951 Selector selector,
959 TypeMask mask,
960 ir.Primitive value) { 952 ir.Primitive value) {
961 assert(selector.isSetter); 953 assert(selector.isSetter);
962 _buildInvokeDynamic(receiver, selector, mask, <ir.Primitive>[value]); 954 _buildInvokeDynamic(receiver, selector, <ir.Primitive>[value]);
963 return value; 955 return value;
964 } 956 }
965 957
966 /// Create a dynamic index set invocation on [receiver] with the provided 958 /// Create a dynamic index set invocation on [receiver] with the provided
967 /// [index] and [value]. 959 /// [index] and [value].
968 ir.Primitive buildDynamicIndexSet(ir.Primitive receiver, 960 ir.Primitive buildDynamicIndexSet(ir.Primitive receiver,
969 TypeMask mask,
970 ir.Primitive index, 961 ir.Primitive index,
971 ir.Primitive value) { 962 ir.Primitive value) {
972 _buildInvokeDynamic( 963 _buildInvokeDynamic(
973 receiver, new Selector.indexSet(), mask, <ir.Primitive>[index, value]); 964 receiver, new Selector.indexSet(), <ir.Primitive>[index, value]);
974 return value; 965 return value;
975 } 966 }
976 967
977 ir.Primitive _buildLocalGet(LocalElement element); 968 ir.Primitive _buildLocalGet(LocalElement element);
978 969
979 /// Create a read access of the [local] variable or parameter. 970 /// Create a read access of the [local] variable or parameter.
980 ir.Primitive buildLocalVariableGet(LocalElement local) { 971 ir.Primitive buildLocalVariableGet(LocalElement local) {
981 // TODO(johnniwinther): Separate function access from variable access. 972 // TODO(johnniwinther): Separate function access from variable access.
982 return _buildLocalGet(local); 973 return _buildLocalGet(local);
983 } 974 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 1088
1098 /// Create a string concatenation of the [arguments]. 1089 /// Create a string concatenation of the [arguments].
1099 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) { 1090 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) {
1100 assert(isOpen); 1091 assert(isOpen);
1101 return _continueWithExpression( 1092 return _continueWithExpression(
1102 (k) => new ir.ConcatenateStrings(arguments, k)); 1093 (k) => new ir.ConcatenateStrings(arguments, k));
1103 } 1094 }
1104 1095
1105 /// Create an invocation of the `call` method of [functionExpression], where 1096 /// Create an invocation of the `call` method of [functionExpression], where
1106 /// the structure of arguments are given by [callStructure]. 1097 /// the structure of arguments are given by [callStructure].
1107 // TODO(johnniwinther): This should take a [TypeMask].
1108 ir.Primitive buildCallInvocation( 1098 ir.Primitive buildCallInvocation(
1109 ir.Primitive functionExpression, 1099 ir.Primitive functionExpression,
1110 CallStructure callStructure, 1100 CallStructure callStructure,
1111 List<ir.Definition> arguments, 1101 List<ir.Definition> arguments,
1112 {SourceInformation sourceInformation}) { 1102 {SourceInformation sourceInformation}) {
1113 return _buildInvokeCall(functionExpression, callStructure, null, arguments, 1103 return _buildInvokeCall(functionExpression, callStructure, arguments,
1114 sourceInformation: sourceInformation); 1104 sourceInformation: sourceInformation);
1115 } 1105 }
1116 1106
1117 /// Creates an if-then-else statement with the provided [condition] where the 1107 /// Creates an if-then-else statement with the provided [condition] where the
1118 /// then and else branches are created through the [buildThenPart] and 1108 /// then and else branches are created through the [buildThenPart] and
1119 /// [buildElsePart] functions, respectively. 1109 /// [buildElsePart] functions, respectively.
1120 /// 1110 ///
1121 /// An if-then statement is created if [buildElsePart] is a no-op. 1111 /// An if-then statement is created if [buildElsePart] is a no-op.
1122 // TODO(johnniwinther): Unify implementation with [buildConditional] and 1112 // TODO(johnniwinther): Unify implementation with [buildConditional] and
1123 // [_buildLogicalOperator]. 1113 // [_buildLogicalOperator].
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 /// variable element, and [variableSelector] defines its write access, 1344 /// variable element, and [variableSelector] defines its write access,
1355 /// 3) `v` is an instance variable in which case [variableSelector] 1345 /// 3) `v` is an instance variable in which case [variableSelector]
1356 /// defines its write access. 1346 /// defines its write access.
1357 /// [buildBody] creates the body, `b`, of the loop. The jump [target] is used 1347 /// [buildBody] creates the body, `b`, of the loop. The jump [target] is used
1358 /// to identify which `break` and `continue` statements that have this for-in 1348 /// to identify which `break` and `continue` statements that have this for-in
1359 /// statement as their target. 1349 /// statement as their target.
1360 void buildForIn({SubbuildFunction buildExpression, 1350 void buildForIn({SubbuildFunction buildExpression,
1361 SubbuildFunction buildVariableDeclaration, 1351 SubbuildFunction buildVariableDeclaration,
1362 Element variableElement, 1352 Element variableElement,
1363 Selector variableSelector, 1353 Selector variableSelector,
1364 TypeMask variableMask,
1365 TypeMask currentMask,
1366 TypeMask iteratorMask,
1367 TypeMask moveNextMask,
1368 SubbuildFunction buildBody, 1354 SubbuildFunction buildBody,
1369 JumpTarget target, 1355 JumpTarget target,
1370 ClosureScope closureScope}) { 1356 ClosureScope closureScope}) {
1371 // The for-in loop 1357 // The for-in loop
1372 // 1358 //
1373 // for (a in e) s; 1359 // for (a in e) s;
1374 // 1360 //
1375 // Is compiled analogously to: 1361 // Is compiled analogously to:
1376 // 1362 //
1377 // it = e.iterator; 1363 // it = e.iterator;
1378 // while (it.moveNext()) { 1364 // while (it.moveNext()) {
1379 // var a = it.current; 1365 // var a = it.current;
1380 // s; 1366 // s;
1381 // } 1367 // }
1382 1368
1383 // Fill the current hole with: 1369 // Fill the current hole with:
1384 // let prim expressionReceiver = [[e]] in 1370 // let prim expressionReceiver = [[e]] in
1385 // let cont iteratorInvoked(iterator) = 1371 // let cont iteratorInvoked(iterator) =
1386 // [ ] 1372 // [ ]
1387 // in expressionReceiver.iterator () iteratorInvoked 1373 // in expressionReceiver.iterator () iteratorInvoked
1388 ir.Primitive expressionReceiver = buildExpression(this); 1374 ir.Primitive expressionReceiver = buildExpression(this);
1389 List<ir.Primitive> emptyArguments = <ir.Primitive>[]; 1375 List<ir.Primitive> emptyArguments = <ir.Primitive>[];
1390 ir.Parameter iterator = new ir.Parameter(null); 1376 ir.Parameter iterator = new ir.Parameter(null);
1391 ir.Continuation iteratorInvoked = new ir.Continuation([iterator]); 1377 ir.Continuation iteratorInvoked = new ir.Continuation([iterator]);
1392 add(new ir.LetCont(iteratorInvoked, 1378 add(new ir.LetCont(iteratorInvoked,
1393 new ir.InvokeMethod(expressionReceiver, 1379 new ir.InvokeMethod(expressionReceiver,
1394 new Selector.getter("iterator", null), 1380 new Selector.getter("iterator", null),
1395 iteratorMask,
1396 emptyArguments, 1381 emptyArguments,
1397 iteratorInvoked))); 1382 iteratorInvoked)));
1398 1383
1399 // Fill with: 1384 // Fill with:
1400 // let cont loop(x, ...) = 1385 // let cont loop(x, ...) =
1401 // let cont moveNextInvoked(condition) = 1386 // let cont moveNextInvoked(condition) =
1402 // [ ] 1387 // [ ]
1403 // in iterator.moveNext () moveNextInvoked 1388 // in iterator.moveNext () moveNextInvoked
1404 // in loop(v, ...) 1389 // in loop(v, ...)
1405 JumpCollector loop = new BackwardJumpCollector(environment, target: target); 1390 JumpCollector loop = new BackwardJumpCollector(environment, target: target);
1406 addRecursiveContinuation(loop); 1391 addRecursiveContinuation(loop);
1407 ir.Parameter condition = new ir.Parameter(null); 1392 ir.Parameter condition = new ir.Parameter(null);
1408 ir.Continuation moveNextInvoked = new ir.Continuation([condition]); 1393 ir.Continuation moveNextInvoked = new ir.Continuation([condition]);
1409 add(new ir.LetCont(moveNextInvoked, 1394 add(new ir.LetCont(moveNextInvoked,
1410 new ir.InvokeMethod(iterator, 1395 new ir.InvokeMethod(iterator,
1411 new Selector.call("moveNext", null, 0), 1396 new Selector.call("moveNext", null, 0),
1412 moveNextMask,
1413 emptyArguments, 1397 emptyArguments,
1414 moveNextInvoked))); 1398 moveNextInvoked)));
1415 1399
1416 // As a delimited term, build: 1400 // As a delimited term, build:
1417 // <<BODY>> = 1401 // <<BODY>> =
1418 // _enterScope(); 1402 // _enterScope();
1419 // [[variableDeclaration]] 1403 // [[variableDeclaration]]
1420 // let cont currentInvoked(currentValue) = 1404 // let cont currentInvoked(currentValue) =
1421 // [[a = currentValue]]; 1405 // [[a = currentValue]];
1422 // [ ] 1406 // [ ]
1423 // in iterator.current () currentInvoked 1407 // in iterator.current () currentInvoked
1424 IrBuilder bodyBuilder = makeDelimitedBuilder(); 1408 IrBuilder bodyBuilder = makeDelimitedBuilder();
1425 bodyBuilder._enterScope(closureScope); 1409 bodyBuilder._enterScope(closureScope);
1426 if (buildVariableDeclaration != null) { 1410 if (buildVariableDeclaration != null) {
1427 buildVariableDeclaration(bodyBuilder); 1411 buildVariableDeclaration(bodyBuilder);
1428 } 1412 }
1429 ir.Parameter currentValue = new ir.Parameter(null); 1413 ir.Parameter currentValue = new ir.Parameter(null);
1430 ir.Continuation currentInvoked = new ir.Continuation([currentValue]); 1414 ir.Continuation currentInvoked = new ir.Continuation([currentValue]);
1431 bodyBuilder.add(new ir.LetCont(currentInvoked, 1415 bodyBuilder.add(new ir.LetCont(currentInvoked,
1432 new ir.InvokeMethod( 1416 new ir.InvokeMethod(iterator, new Selector.getter("current", null),
1433 iterator,
1434 new Selector.getter("current", null),
1435 currentMask,
1436 emptyArguments, currentInvoked))); 1417 emptyArguments, currentInvoked)));
1437 // TODO(sra): Does this cover all cases? The general setter case include 1418 // TODO(sra): Does this cover all cases? The general setter case include
1438 // super. 1419 // super.
1439 // TODO(johnniwinther): Extract this as a provided strategy. 1420 // TODO(johnniwinther): Extract this as a provided strategy.
1440 if (Elements.isLocal(variableElement)) { 1421 if (Elements.isLocal(variableElement)) {
1441 bodyBuilder.buildLocalVariableSet(variableElement, currentValue); 1422 bodyBuilder.buildLocalVariableSet(variableElement, currentValue);
1442 } else if (Elements.isErroneous(variableElement)) { 1423 } else if (Elements.isErroneous(variableElement)) {
1443 bodyBuilder.buildErroneousInvocation(variableElement, 1424 bodyBuilder.buildErroneousInvocation(variableElement,
1444 new Selector.setter(variableElement.name, variableElement.library), 1425 new Selector.setter(variableElement.name, variableElement.library),
1445 <ir.Primitive>[currentValue]); 1426 <ir.Primitive>[currentValue]);
1446 } else if (Elements.isStaticOrTopLevel(variableElement)) { 1427 } else if (Elements.isStaticOrTopLevel(variableElement)) {
1447 if (variableElement.isField) { 1428 if (variableElement.isField) {
1448 bodyBuilder.buildStaticFieldSet(variableElement, currentValue); 1429 bodyBuilder.buildStaticFieldSet(variableElement, currentValue);
1449 } else { 1430 } else {
1450 bodyBuilder.buildStaticSetterSet(variableElement, currentValue); 1431 bodyBuilder.buildStaticSetterSet(variableElement, currentValue);
1451 } 1432 }
1452 } else { 1433 } else {
1453 ir.Primitive receiver = bodyBuilder.buildThis(); 1434 ir.Primitive receiver = bodyBuilder.buildThis();
1454 assert(receiver != null); 1435 assert(receiver != null);
1455 bodyBuilder.buildDynamicSet( 1436 bodyBuilder.buildDynamicSet(receiver, variableSelector, currentValue);
1456 receiver, variableSelector, variableMask, currentValue);
1457 } 1437 }
1458 1438
1459 // Translate the body in the hole in the delimited term above, and add 1439 // Translate the body in the hole in the delimited term above, and add
1460 // a jump to the loop if control flow is live after the body. 1440 // a jump to the loop if control flow is live after the body.
1461 JumpCollector breakCollector = 1441 JumpCollector breakCollector =
1462 new ForwardJumpCollector(environment, target: target); 1442 new ForwardJumpCollector(environment, target: target);
1463 state.breakCollectors.add(breakCollector); 1443 state.breakCollectors.add(breakCollector);
1464 state.continueCollectors.add(loop); 1444 state.continueCollectors.add(loop);
1465 buildBody(bodyBuilder); 1445 buildBody(bodyBuilder);
1466 assert(state.breakCollectors.last == breakCollector); 1446 assert(state.breakCollectors.last == breakCollector);
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
2544 final DartType type; 2524 final DartType type;
2545 final LocalVariableElement exceptionVariable; 2525 final LocalVariableElement exceptionVariable;
2546 final LocalVariableElement stackTraceVariable; 2526 final LocalVariableElement stackTraceVariable;
2547 final SubbuildFunction buildCatchBlock; 2527 final SubbuildFunction buildCatchBlock;
2548 2528
2549 CatchClauseInfo({this.type, 2529 CatchClauseInfo({this.type,
2550 this.exceptionVariable, 2530 this.exceptionVariable,
2551 this.stackTraceVariable, 2531 this.stackTraceVariable,
2552 this.buildCatchBlock}); 2532 this.buildCatchBlock});
2553 } 2533 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/compiler.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698