OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Source information system mapping that attempts a semantic mapping between | 5 /// Source information system mapping that attempts a semantic mapping between |
6 /// offsets of JavaScript code points to offsets of Dart code points. | 6 /// offsets of JavaScript code points to offsets of Dart code points. |
7 | 7 |
8 library dart2js.source_information.position; | 8 library dart2js.source_information.position; |
9 | 9 |
10 import '../common.dart'; | 10 import '../common.dart'; |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 | 513 |
514 /// [TraceListener] that register [SourceLocation]s with a [SourceMapper]. | 514 /// [TraceListener] that register [SourceLocation]s with a [SourceMapper]. |
515 class PositionTraceListener extends TraceListener | 515 class PositionTraceListener extends TraceListener |
516 with NodeToSourceInformationMixin { | 516 with NodeToSourceInformationMixin { |
517 final SourceMapper sourceMapper; | 517 final SourceMapper sourceMapper; |
518 | 518 |
519 PositionTraceListener(this.sourceMapper); | 519 PositionTraceListener(this.sourceMapper); |
520 | 520 |
521 @override | 521 @override |
522 void onStep(js.Node node, Offset offset, StepKind kind) { | 522 void onStep(js.Node node, Offset offset, StepKind kind) { |
| 523 int codeLocation = offset.value; |
| 524 if (codeLocation == null) return; |
| 525 |
| 526 if (kind == StepKind.NO_INFO) { |
| 527 sourceMapper.register(node, codeLocation, const NoSourceLocationMarker()); |
| 528 return; |
| 529 } |
| 530 |
523 SourceInformation sourceInformation = computeSourceInformation(node); | 531 SourceInformation sourceInformation = computeSourceInformation(node); |
524 if (sourceInformation == null) return; | 532 if (sourceInformation == null) return; |
525 int codeLocation = offset.value; | |
526 if (codeLocation == null) return; | |
527 | 533 |
528 void registerPosition(SourcePositionKind sourcePositionKind) { | 534 void registerPosition(SourcePositionKind sourcePositionKind) { |
529 SourceLocation sourceLocation = | 535 SourceLocation sourceLocation = |
530 getSourceLocation(sourceInformation, sourcePositionKind); | 536 getSourceLocation(sourceInformation, sourcePositionKind); |
531 if (sourceLocation != null) { | 537 if (sourceLocation != null) { |
532 sourceMapper.register(node, codeLocation, sourceLocation); | 538 sourceMapper.register(node, codeLocation, sourceLocation); |
533 } | 539 } |
534 } | 540 } |
535 | 541 |
536 switch (kind) { | 542 switch (kind) { |
(...skipping 18 matching lines...) Expand all Loading... |
555 case StepKind.EXPRESSION_STATEMENT: | 561 case StepKind.EXPRESSION_STATEMENT: |
556 case StepKind.IF_CONDITION: | 562 case StepKind.IF_CONDITION: |
557 case StepKind.FOR_INITIALIZER: | 563 case StepKind.FOR_INITIALIZER: |
558 case StepKind.FOR_CONDITION: | 564 case StepKind.FOR_CONDITION: |
559 case StepKind.FOR_UPDATE: | 565 case StepKind.FOR_UPDATE: |
560 case StepKind.WHILE_CONDITION: | 566 case StepKind.WHILE_CONDITION: |
561 case StepKind.DO_CONDITION: | 567 case StepKind.DO_CONDITION: |
562 case StepKind.SWITCH_EXPRESSION: | 568 case StepKind.SWITCH_EXPRESSION: |
563 registerPosition(SourcePositionKind.START); | 569 registerPosition(SourcePositionKind.START); |
564 break; | 570 break; |
| 571 case StepKind.NO_INFO: |
| 572 break; |
565 } | 573 } |
566 } | 574 } |
567 } | 575 } |
568 | 576 |
569 /// The position of a [js.Call] node. | 577 /// The position of a [js.Call] node. |
570 class CallPosition { | 578 class CallPosition { |
571 final js.Node node; | 579 final js.Node node; |
572 final CodePositionKind codePositionKind; | 580 final CodePositionKind codePositionKind; |
573 final SourcePositionKind sourcePositionKind; | 581 final SourcePositionKind sourcePositionKind; |
574 | 582 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 CONTINUE, | 711 CONTINUE, |
704 THROW, | 712 THROW, |
705 EXPRESSION_STATEMENT, | 713 EXPRESSION_STATEMENT, |
706 IF_CONDITION, | 714 IF_CONDITION, |
707 FOR_INITIALIZER, | 715 FOR_INITIALIZER, |
708 FOR_CONDITION, | 716 FOR_CONDITION, |
709 FOR_UPDATE, | 717 FOR_UPDATE, |
710 WHILE_CONDITION, | 718 WHILE_CONDITION, |
711 DO_CONDITION, | 719 DO_CONDITION, |
712 SWITCH_EXPRESSION, | 720 SWITCH_EXPRESSION, |
| 721 NO_INFO, |
713 } | 722 } |
714 | 723 |
715 /// Listener for the [JavaScriptTracer]. | 724 /// Listener for the [JavaScriptTracer]. |
716 abstract class TraceListener { | 725 abstract class TraceListener { |
717 /// Called before [root] node is procesed by the [JavaScriptTracer]. | 726 /// Called before [root] node is procesed by the [JavaScriptTracer]. |
718 void onStart(js.Node root) {} | 727 void onStart(js.Node root) {} |
719 | 728 |
720 /// Called after [root] node has been procesed by the [JavaScriptTracer]. | 729 /// Called after [root] node has been procesed by the [JavaScriptTracer]. |
721 void onEnd(js.Node root) {} | 730 void onEnd(js.Node root) {} |
722 | 731 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 listeners.forEach((listener) => listener.pushBranch(kind, value)); | 777 listeners.forEach((listener) => listener.pushBranch(kind, value)); |
769 } | 778 } |
770 } | 779 } |
771 | 780 |
772 void notifyPopBranch() { | 781 void notifyPopBranch() { |
773 if (active) { | 782 if (active) { |
774 listeners.forEach((listener) => listener.popBranch()); | 783 listeners.forEach((listener) => listener.popBranch()); |
775 } | 784 } |
776 } | 785 } |
777 | 786 |
778 void notifyStep(js.Node node, Offset offset, StepKind kind) { | 787 void notifyStep(js.Node node, Offset offset, StepKind kind, |
779 if (active) { | 788 {bool force: false}) { |
| 789 if (active || force) { |
780 listeners.forEach((listener) => listener.onStep(node, offset, kind)); | 790 listeners.forEach((listener) => listener.onStep(node, offset, kind)); |
781 } | 791 } |
782 } | 792 } |
783 | 793 |
784 void apply(js.Node node) { | 794 void apply(js.Node node) { |
785 notifyStart(node); | 795 notifyStart(node); |
| 796 |
| 797 int startPosition = getSyntaxOffset(node, kind: CodePositionKind.START); |
| 798 Offset startOffset = getOffsetForNode(node, startPosition); |
| 799 notifyStep(node, startOffset, StepKind.NO_INFO, force: true); |
| 800 |
786 node.accept(this); | 801 node.accept(this); |
787 notifyEnd(node); | 802 notifyEnd(node); |
788 } | 803 } |
789 | 804 |
790 @override | 805 @override |
791 visitNode(js.Node node) { | 806 visitNode(js.Node node) { |
792 node.visitChildren(this); | 807 node.visitChildren(this); |
793 } | 808 } |
794 | 809 |
795 visit(js.Node node, [BranchKind branch, value]) { | 810 visit(js.Node node, [BranchKind branch, value]) { |
(...skipping 26 matching lines...) Expand all Loading... |
822 statementOffset = getSyntaxOffset(node, kind: CodePositionKind.START); | 837 statementOffset = getSyntaxOffset(node, kind: CodePositionKind.START); |
823 Offset entryOffset = getOffsetForNode(node, statementOffset); | 838 Offset entryOffset = getOffsetForNode(node, statementOffset); |
824 notifyStep(node, entryOffset, StepKind.FUN_ENTRY); | 839 notifyStep(node, entryOffset, StepKind.FUN_ENTRY); |
825 | 840 |
826 visit(node.body); | 841 visit(node.body); |
827 | 842 |
828 leftToRightOffset = | 843 leftToRightOffset = |
829 statementOffset = getSyntaxOffset(node, kind: CodePositionKind.CLOSING); | 844 statementOffset = getSyntaxOffset(node, kind: CodePositionKind.CLOSING); |
830 Offset exitOffset = getOffsetForNode(node, statementOffset); | 845 Offset exitOffset = getOffsetForNode(node, statementOffset); |
831 notifyStep(node, exitOffset, StepKind.FUN_EXIT); | 846 notifyStep(node, exitOffset, StepKind.FUN_EXIT); |
| 847 if (active && !activeBefore) { |
| 848 int endPosition = getSyntaxOffset(node, kind: CodePositionKind.END); |
| 849 Offset endOffset = getOffsetForNode(node, endPosition); |
| 850 notifyStep(node, endOffset, StepKind.NO_INFO); |
| 851 } |
832 active = activeBefore; | 852 active = activeBefore; |
833 } | 853 } |
834 | 854 |
835 @override | 855 @override |
836 visitBlock(js.Block node) { | 856 visitBlock(js.Block node) { |
837 for (js.Statement statement in node.statements) { | 857 for (js.Statement statement in node.statements) { |
838 visit(statement); | 858 visit(statement); |
839 } | 859 } |
840 } | 860 } |
841 | 861 |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 | 1305 |
1286 @override | 1306 @override |
1287 CodePosition operator [](js.Node node) { | 1307 CodePosition operator [](js.Node node) { |
1288 CodePosition codePosition = codePositions[node]; | 1308 CodePosition codePosition = codePositions[node]; |
1289 if (codePosition == null) { | 1309 if (codePosition == null) { |
1290 coverage.registerNodesWithoutOffset(node); | 1310 coverage.registerNodesWithoutOffset(node); |
1291 } | 1311 } |
1292 return codePosition; | 1312 return codePosition; |
1293 } | 1313 } |
1294 } | 1314 } |
OLD | NEW |