| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of tree_ir.optimization; | 5 part of tree_ir.optimization; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Performs the following transformations on the tree: | 8 * Performs the following transformations on the tree: |
| 9 * - Assignment inlining | 9 * - Assignment inlining |
| 10 * - Assignment expression propagation | 10 * - Assignment expression propagation |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 node.next = visitStatement(node.next); | 336 node.next = visitStatement(node.next); |
| 337 } else { | 337 } else { |
| 338 inEmptyEnvironment(() { | 338 inEmptyEnvironment(() { |
| 339 node.next = visitStatement(node.next); | 339 node.next = visitStatement(node.next); |
| 340 }); | 340 }); |
| 341 } | 341 } |
| 342 node.value = visitExpression(node.value); | 342 node.value = visitExpression(node.value); |
| 343 return node; | 343 return node; |
| 344 } | 344 } |
| 345 | 345 |
| 346 /// Process nodes right-to-left, the opposite of evaluation order in the case |
| 347 /// of argument lists.. |
| 348 void _rewriteList(List<Node> nodes) { |
| 349 for (int i = nodes.length - 1; i >= 0; --i) { |
| 350 nodes[i] = visitExpression(nodes[i]); |
| 351 } |
| 352 } |
| 353 |
| 346 Expression visitInvokeStatic(InvokeStatic node) { | 354 Expression visitInvokeStatic(InvokeStatic node) { |
| 347 // Process arguments right-to-left, the opposite of evaluation order. | 355 _rewriteList(node.arguments); |
| 348 for (int i = node.arguments.length - 1; i >= 0; --i) { | |
| 349 node.arguments[i] = visitExpression(node.arguments[i]); | |
| 350 } | |
| 351 return node; | 356 return node; |
| 352 } | 357 } |
| 353 | 358 |
| 354 Expression visitInvokeMethod(InvokeMethod node) { | 359 Expression visitInvokeMethod(InvokeMethod node) { |
| 355 for (int i = node.arguments.length - 1; i >= 0; --i) { | 360 _rewriteList(node.arguments); |
| 356 node.arguments[i] = visitExpression(node.arguments[i]); | |
| 357 } | |
| 358 node.receiver = visitExpression(node.receiver); | 361 node.receiver = visitExpression(node.receiver); |
| 359 return node; | 362 return node; |
| 360 } | 363 } |
| 361 | 364 |
| 362 Expression visitInvokeMethodDirectly(InvokeMethodDirectly node) { | 365 Expression visitInvokeMethodDirectly(InvokeMethodDirectly node) { |
| 363 for (int i = node.arguments.length - 1; i >= 0; --i) { | 366 _rewriteList(node.arguments); |
| 364 node.arguments[i] = visitExpression(node.arguments[i]); | |
| 365 } | |
| 366 node.receiver = visitExpression(node.receiver); | 367 node.receiver = visitExpression(node.receiver); |
| 367 return node; | 368 return node; |
| 368 } | 369 } |
| 369 | 370 |
| 370 Expression visitInvokeConstructor(InvokeConstructor node) { | 371 Expression visitInvokeConstructor(InvokeConstructor node) { |
| 371 for (int i = node.arguments.length - 1; i >= 0; --i) { | 372 _rewriteList(node.arguments); |
| 372 node.arguments[i] = visitExpression(node.arguments[i]); | |
| 373 } | |
| 374 return node; | 373 return node; |
| 375 } | 374 } |
| 376 | 375 |
| 377 Expression visitConcatenateStrings(ConcatenateStrings node) { | 376 Expression visitConcatenateStrings(ConcatenateStrings node) { |
| 378 for (int i = node.arguments.length - 1; i >= 0; --i) { | 377 _rewriteList(node.arguments); |
| 379 node.arguments[i] = visitExpression(node.arguments[i]); | |
| 380 } | |
| 381 return node; | 378 return node; |
| 382 } | 379 } |
| 383 | 380 |
| 384 Expression visitConditional(Conditional node) { | 381 Expression visitConditional(Conditional node) { |
| 385 // Conditional expressions do not exist in the input, but they are | 382 // Conditional expressions do not exist in the input, but they are |
| 386 // introduced by if-to-conditional conversion. | 383 // introduced by if-to-conditional conversion. |
| 387 // Their subexpressions have already been processed; do not reprocess them. | 384 // Their subexpressions have already been processed; do not reprocess them. |
| 388 // | 385 // |
| 389 // Note that this can only happen for conditional expressions. It is an | 386 // Note that this can only happen for conditional expressions. It is an |
| 390 // error for any other type of expression to be visited twice or to be | 387 // error for any other type of expression to be visited twice or to be |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 551 |
| 555 Expression visitThis(This node) { | 552 Expression visitThis(This node) { |
| 556 return node; | 553 return node; |
| 557 } | 554 } |
| 558 | 555 |
| 559 Expression visitReifyTypeVar(ReifyTypeVar node) { | 556 Expression visitReifyTypeVar(ReifyTypeVar node) { |
| 560 return node; | 557 return node; |
| 561 } | 558 } |
| 562 | 559 |
| 563 Expression visitLiteralList(LiteralList node) { | 560 Expression visitLiteralList(LiteralList node) { |
| 564 // Process values right-to-left, the opposite of evaluation order. | 561 _rewriteList(node.values); |
| 565 for (int i = node.values.length - 1; i >= 0; --i) { | |
| 566 node.values[i] = visitExpression(node.values[i]); | |
| 567 } | |
| 568 return node; | 562 return node; |
| 569 } | 563 } |
| 570 | 564 |
| 571 Expression visitLiteralMap(LiteralMap node) { | 565 Expression visitLiteralMap(LiteralMap node) { |
| 572 // Process arguments right-to-left, the opposite of evaluation order. | 566 // Process arguments right-to-left, the opposite of evaluation order. |
| 573 for (LiteralMapEntry entry in node.entries.reversed) { | 567 for (LiteralMapEntry entry in node.entries.reversed) { |
| 574 entry.value = visitExpression(entry.value); | 568 entry.value = visitExpression(entry.value); |
| 575 entry.key = visitExpression(entry.key); | 569 entry.key = visitExpression(entry.key); |
| 576 } | 570 } |
| 577 return node; | 571 return node; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 600 Expression visitSetStatic(SetStatic node) { | 594 Expression visitSetStatic(SetStatic node) { |
| 601 node.value = visitExpression(node.value); | 595 node.value = visitExpression(node.value); |
| 602 return node; | 596 return node; |
| 603 } | 597 } |
| 604 | 598 |
| 605 Expression visitCreateBox(CreateBox node) { | 599 Expression visitCreateBox(CreateBox node) { |
| 606 return node; | 600 return node; |
| 607 } | 601 } |
| 608 | 602 |
| 609 Expression visitCreateInstance(CreateInstance node) { | 603 Expression visitCreateInstance(CreateInstance node) { |
| 610 for (int i = node.arguments.length - 1; i >= 0; --i) { | 604 _rewriteList(node.arguments); |
| 611 node.arguments[i] = visitExpression(node.arguments[i]); | |
| 612 } | |
| 613 return node; | 605 return node; |
| 614 } | 606 } |
| 615 | 607 |
| 616 Expression visitReifyRuntimeType(ReifyRuntimeType node) { | 608 Expression visitReifyRuntimeType(ReifyRuntimeType node) { |
| 617 node.value = visitExpression(node.value); | 609 node.value = visitExpression(node.value); |
| 618 return node; | 610 return node; |
| 619 } | 611 } |
| 620 | 612 |
| 621 Expression visitReadTypeVariable(ReadTypeVariable node) { | 613 Expression visitReadTypeVariable(ReadTypeVariable node) { |
| 622 node.target = visitExpression(node.target); | 614 node.target = visitExpression(node.target); |
| 623 return node; | 615 return node; |
| 624 } | 616 } |
| 625 | 617 |
| 626 Expression visitTypeExpression(TypeExpression node) { | 618 Expression visitTypeExpression(TypeExpression node) { |
| 627 for (int i = node.arguments.length - 1; i >= 0; --i) { | 619 _rewriteList(node.arguments); |
| 628 node.arguments[i] = visitExpression(node.arguments[i]); | |
| 629 } | |
| 630 return node; | 620 return node; |
| 631 } | 621 } |
| 632 | 622 |
| 633 Expression visitCreateInvocationMirror(CreateInvocationMirror node) { | 623 Expression visitCreateInvocationMirror(CreateInvocationMirror node) { |
| 634 for (int i = node.arguments.length - 1; i >= 0; --i) { | 624 _rewriteList(node.arguments); |
| 635 node.arguments[i] = visitExpression(node.arguments[i]); | |
| 636 } | |
| 637 return node; | 625 return node; |
| 638 } | 626 } |
| 639 | 627 |
| 640 /// If [s] and [t] are similar statements we extract their subexpressions | 628 /// If [s] and [t] are similar statements we extract their subexpressions |
| 641 /// and returns a new statement of the same type using expressions combined | 629 /// and returns a new statement of the same type using expressions combined |
| 642 /// with the [combine] callback. For example: | 630 /// with the [combine] callback. For example: |
| 643 /// | 631 /// |
| 644 /// combineStatements(Return E1, Return E2) = Return combine(E1, E2) | 632 /// combineStatements(Return E1, Return E2) = Return combine(E1, E2) |
| 645 /// | 633 /// |
| 646 /// If [combine] returns E1 then the unified statement is equivalent to [s], | 634 /// If [combine] returns E1 then the unified statement is equivalent to [s], |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 } | 922 } |
| 935 | 923 |
| 936 /// Result of combining two expressions that do not affect reference counting. | 924 /// Result of combining two expressions that do not affect reference counting. |
| 937 class GenericCombinedExpressions implements CombinedExpressions { | 925 class GenericCombinedExpressions implements CombinedExpressions { |
| 938 Expression combined; | 926 Expression combined; |
| 939 | 927 |
| 940 GenericCombinedExpressions(this.combined); | 928 GenericCombinedExpressions(this.combined); |
| 941 | 929 |
| 942 void uncombine() {} | 930 void uncombine() {} |
| 943 } | 931 } |
| OLD | NEW |