@@ -331,32 +331,6 @@ template <typename Derived> class RecursiveASTVisitor {
331
331
struct has_same_member_pointer_type <R (T::*)(P...), R (U::*)(P...)>
332
332
: std::true_type {};
333
333
334
- template <bool has_same_type> struct is_same_method_impl {
335
- template <typename FirstMethodPtrTy, typename SecondMethodPtrTy>
336
- static bool isSameMethod (FirstMethodPtrTy FirstMethodPtr,
337
- SecondMethodPtrTy SecondMethodPtr) {
338
- return false ;
339
- }
340
- };
341
-
342
- template <> struct is_same_method_impl <true > {
343
- template <typename FirstMethodPtrTy, typename SecondMethodPtrTy>
344
- static bool isSameMethod (FirstMethodPtrTy FirstMethodPtr,
345
- SecondMethodPtrTy SecondMethodPtr) {
346
- return FirstMethodPtr == SecondMethodPtr;
347
- }
348
- };
349
-
350
- // / Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr
351
- // / are pointers to the same non-static member function.
352
- template <typename FirstMethodPtrTy, typename SecondMethodPtrTy>
353
- bool isSameMethod (FirstMethodPtrTy FirstMethodPtr,
354
- SecondMethodPtrTy SecondMethodPtr) {
355
- return is_same_method_impl<
356
- has_same_member_pointer_type<FirstMethodPtrTy, SecondMethodPtrTy>::
357
- value>::isSameMethod (FirstMethodPtr, SecondMethodPtr);
358
- }
359
-
360
334
// Traverse the given statement. If the most-derived traverse function takes a
361
335
// data recursion queue, pass it on; otherwise, discard it. Note that the
362
336
// first branch of this conditional must compile whether or not the derived
@@ -412,8 +386,6 @@ template <typename Derived> class RecursiveASTVisitor {
412
386
if (!getDerived ().shouldTraversePostOrder ()) \
413
387
TRY_TO (WalkUpFromUnary##NAME (S)); \
414
388
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT (S->getSubExpr ()); \
415
- if (!Queue && getDerived ().shouldTraversePostOrder ()) \
416
- TRY_TO (WalkUpFromUnary##NAME (S)); \
417
389
return true ; \
418
390
} \
419
391
bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
@@ -435,8 +407,6 @@ template <typename Derived> class RecursiveASTVisitor {
435
407
TRY_TO (WalkUpFromBin##NAME (S)); \
436
408
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT (S->getLHS ()); \
437
409
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT (S->getRHS ()); \
438
- if (!Queue && getDerived ().shouldTraversePostOrder ()) \
439
- TRY_TO (WalkUpFromBin##NAME (S)); \
440
410
return true ; \
441
411
} \
442
412
bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
@@ -593,13 +563,15 @@ bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
593
563
594
564
BINOP_LIST ()
595
565
#undef OPERATOR
566
+ #undef BINOP_LIST
596
567
597
568
#define OPERATOR (NAME ) \
598
569
case BO_##NAME##Assign: \
599
570
DISPATCH_STMT (Bin##NAME##Assign, CompoundAssignOperator, S);
600
571
601
572
CAO_LIST ()
602
573
#undef OPERATOR
574
+ #undef CAO_LIST
603
575
}
604
576
} else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
605
577
switch (UnOp->getOpcode ()) {
@@ -609,6 +581,7 @@ bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
609
581
610
582
UNARYOP_LIST ()
611
583
#undef OPERATOR
584
+ #undef UNARYOP_LIST
612
585
}
613
586
}
614
587
@@ -630,84 +603,23 @@ bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
630
603
631
604
template <typename Derived>
632
605
bool RecursiveASTVisitor<Derived>::PostVisitStmt (Stmt *S) {
633
- // In pre-order traversal mode, each Traverse##STMT method is responsible for
634
- // calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT and
635
- // does not call the default implementation, the WalkUpFrom callback is not
636
- // called. Post-order traversal mode should provide the same behavior
637
- // regarding method overrides.
638
- //
639
- // In post-order traversal mode the Traverse##STMT method, when it receives a
640
- // DataRecursionQueue, can't call WalkUpFrom after traversing children because
641
- // it only enqueues the children and does not traverse them. TraverseStmt
642
- // traverses the enqueued children, and we call WalkUpFrom here.
643
- //
644
- // However, to make pre-order and post-order modes identical with regards to
645
- // whether they call WalkUpFrom at all, we call WalkUpFrom if and only if the
646
- // user did not override the Traverse##STMT method. We implement the override
647
- // check with isSameMethod calls below.
648
-
649
- if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
650
- switch (BinOp->getOpcode ()) {
651
- #define OPERATOR (NAME ) \
652
- case BO_##NAME: \
653
- if (isSameMethod (&RecursiveASTVisitor::TraverseBin##NAME, \
654
- &Derived::TraverseBin##NAME)) { \
655
- TRY_TO (WalkUpFromBin##NAME (static_cast <BinaryOperator *>(S))); \
656
- } \
657
- return true ;
658
-
659
- BINOP_LIST ()
660
- #undef OPERATOR
661
-
662
- #define OPERATOR (NAME ) \
663
- case BO_##NAME##Assign: \
664
- if (isSameMethod (&RecursiveASTVisitor::TraverseBin##NAME##Assign, \
665
- &Derived::TraverseBin##NAME##Assign)) { \
666
- TRY_TO (WalkUpFromBin##NAME##Assign ( \
667
- static_cast <CompoundAssignOperator *>(S))); \
668
- } \
669
- return true ;
670
-
671
- CAO_LIST ()
672
- #undef OPERATOR
673
- }
674
- } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
675
- switch (UnOp->getOpcode ()) {
676
- #define OPERATOR (NAME ) \
677
- case UO_##NAME: \
678
- if (isSameMethod (&RecursiveASTVisitor::TraverseUnary##NAME, \
679
- &Derived::TraverseUnary##NAME)) { \
680
- TRY_TO (WalkUpFromUnary##NAME (static_cast <UnaryOperator *>(S))); \
681
- } \
682
- return true ;
683
-
684
- UNARYOP_LIST ()
685
- #undef OPERATOR
686
- }
687
- }
688
-
689
606
switch (S->getStmtClass ()) {
690
607
case Stmt::NoStmtClass:
691
608
break ;
692
609
#define ABSTRACT_STMT (STMT )
693
610
#define STMT (CLASS, PARENT ) \
694
611
case Stmt::CLASS##Class: \
695
- if (isSameMethod (&RecursiveASTVisitor::Traverse##CLASS, \
696
- &Derived::Traverse##CLASS)) { \
697
- TRY_TO (WalkUpFrom##CLASS (static_cast <CLASS *>(S))); \
698
- } \
699
- break ;
612
+ TRY_TO (WalkUpFrom##CLASS (static_cast <CLASS *>(S))); break ;
700
613
#define INITLISTEXPR (CLASS, PARENT ) \
701
614
case Stmt::CLASS##Class: \
702
- if (isSameMethod (&RecursiveASTVisitor::Traverse##CLASS, \
703
- &Derived::Traverse##CLASS)) { \
615
+ { \
704
616
auto ILE = static_cast <CLASS *>(S); \
705
617
if (auto Syn = ILE->isSemanticForm () ? ILE->getSyntacticForm () : ILE) \
706
618
TRY_TO (WalkUpFrom##CLASS (Syn)); \
707
619
if (auto Sem = ILE->isSemanticForm () ? ILE : ILE->getSemanticForm ()) \
708
620
TRY_TO (WalkUpFrom##CLASS (Sem)); \
709
- } \
710
- break ;
621
+ break ; \
622
+ }
711
623
#include " clang/AST/StmtNodes.inc"
712
624
}
713
625
@@ -2304,13 +2216,8 @@ DEF_TRAVERSE_DECL(RequiresExprBodyDecl, {})
2304
2216
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT (SubStmt); \
2305
2217
} \
2306
2218
} \
2307
- /* Call WalkUpFrom if TRY_TO_TRAVERSE_OR_ENQUEUE_STMT has traversed the \
2308
- * children already. If TRY_TO_TRAVERSE_OR_ENQUEUE_STMT only enqueued the \
2309
- * children, PostVisitStmt will call WalkUpFrom after we are done visiting \
2310
- * children. */ \
2311
- if (!Queue && ReturnValue && getDerived ().shouldTraversePostOrder ()) { \
2219
+ if (!Queue && ReturnValue && getDerived ().shouldTraversePostOrder ()) \
2312
2220
TRY_TO (WalkUpFrom##STMT (S)); \
2313
- } \
2314
2221
return ReturnValue; \
2315
2222
}
2316
2223
@@ -2481,9 +2388,6 @@ bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
2481
2388
for (Stmt *SubStmt : S->children ()) {
2482
2389
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT (SubStmt);
2483
2390
}
2484
-
2485
- if (!Queue && getDerived ().shouldTraversePostOrder ())
2486
- TRY_TO (WalkUpFromInitListExpr (S));
2487
2391
}
2488
2392
return true ;
2489
2393
}
@@ -3705,10 +3609,6 @@ bool RecursiveASTVisitor<Derived>::VisitOMPAffinityClause(
3705
3609
3706
3610
#undef TRY_TO
3707
3611
3708
- #undef UNARYOP_LIST
3709
- #undef BINOP_LIST
3710
- #undef CAO_LIST
3711
-
3712
3612
} // end namespace clang
3713
3613
3714
3614
#endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
0 commit comments