Commit ec11e63
Switch from Visit to Traverse functions in TBR.
Currently, `TBRAnalyzer` is implemented as a `RecursiveASTVisitor`, meaning it automatically visits all sub-stmts recursively. However, in TBR, we often need to visit sub-stmts in a specific way, e.g.
When analyzing
```
x = y;
```
we should visit ``x`` with settings according to the fact that ``x`` is being overwritten, and then reset the settings. The same goes for ``y``.
Therefore, we cannot perform the analysis in the order, in which `RecursiveASTVisitor` visits this stmt: `x = y`, then `x`, then `y`. Instead, we call ``TraverseStmt`` manually inside ``VisitBinaryOperator``. Because of this we traverse stmts more times than we need to:
```
1) x = y; -> also x and y manually
2) x -> automatically, unnecessary
3) y -> automatically, unnecessary
```
We can show that for nested stmts, this will bump complexity from linear to quadratic. The same problem also occurs for other stmts like ``CallExpr``, where we visit the ``DeclRefExpr`` of the function.
This can be solved by switching from ``Visit`` functions to ``Traverse`` and returning ``false`` to prevent the visitor from entering the child nodes (returning ``false`` in ``Visit`` functions stops the whole visitation). The only downside is that ``Traverse`` only works with exact node type matches, e.g. ``TraverseCallExpr`` is not called for a ``CXXMemberCallExpr`` even though it's a subclass of ``CallExpr``.
We can solve this by introducing dummy functions like
```
TBRAnalyzer::TraverseCXXMemberCallExpr(const CXXMemberCallExpr* MCE) {
TBRAnalyzer::TraverseCallExpr(MCE);
return false;
}
```1 parent 4a00a64 commit ec11e63
2 files changed
Lines changed: 51 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | 267 | | |
273 | 268 | | |
274 | 269 | | |
| |||
566 | 561 | | |
567 | 562 | | |
568 | 563 | | |
569 | | - | |
| 564 | + | |
570 | 565 | | |
571 | | - | |
| 566 | + | |
572 | 567 | | |
573 | 568 | | |
574 | | - | |
| 569 | + | |
575 | 570 | | |
576 | 571 | | |
577 | 572 | | |
| |||
590 | 585 | | |
591 | 586 | | |
592 | 587 | | |
593 | | - | |
| 588 | + | |
594 | 589 | | |
595 | 590 | | |
596 | | - | |
| 591 | + | |
597 | 592 | | |
598 | 593 | | |
599 | 594 | | |
| |||
609 | 604 | | |
610 | 605 | | |
611 | 606 | | |
612 | | - | |
| 607 | + | |
613 | 608 | | |
614 | 609 | | |
615 | | - | |
| 610 | + | |
616 | 611 | | |
617 | 612 | | |
618 | 613 | | |
| |||
705 | 700 | | |
706 | 701 | | |
707 | 702 | | |
708 | | - | |
| 703 | + | |
709 | 704 | | |
710 | 705 | | |
711 | | - | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
712 | 713 | | |
713 | 714 | | |
714 | 715 | | |
| |||
733 | 734 | | |
734 | 735 | | |
735 | 736 | | |
736 | | - | |
| 737 | + | |
737 | 738 | | |
738 | 739 | | |
739 | | - | |
| 740 | + | |
740 | 741 | | |
741 | 742 | | |
742 | 743 | | |
| |||
769 | 770 | | |
770 | 771 | | |
771 | 772 | | |
772 | | - | |
| 773 | + | |
773 | 774 | | |
774 | 775 | | |
775 | | - | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
776 | 787 | | |
777 | 788 | | |
778 | 789 | | |
| |||
796 | 807 | | |
797 | 808 | | |
798 | 809 | | |
799 | | - | |
| 810 | + | |
800 | 811 | | |
801 | 812 | | |
802 | | - | |
| 813 | + | |
803 | 814 | | |
804 | | - | |
| 815 | + | |
805 | 816 | | |
806 | 817 | | |
807 | | - | |
| 818 | + | |
808 | 819 | | |
809 | 820 | | |
810 | 821 | | |
811 | 822 | | |
812 | 823 | | |
813 | 824 | | |
814 | 825 | | |
815 | | - | |
| 826 | + | |
816 | 827 | | |
817 | 828 | | |
818 | | - | |
| 829 | + | |
819 | 830 | | |
820 | 831 | | |
821 | 832 | | |
822 | 833 | | |
823 | | - | |
| 834 | + | |
824 | 835 | | |
825 | 836 | | |
826 | 837 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
299 | 301 | | |
300 | 302 | | |
301 | 303 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
312 | 317 | | |
313 | 318 | | |
314 | 319 | | |
| |||
0 commit comments