Skip to content

Commit da6d04c

Browse files
author
git apple-llvm automerger
committed
Merge commit '307fbb031fb6' from apple/master into swift/master-next
2 parents 7fb3f15 + 307fbb0 commit da6d04c

File tree

3 files changed

+62
-142
lines changed

3 files changed

+62
-142
lines changed

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 8 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -331,32 +331,6 @@ template <typename Derived> class RecursiveASTVisitor {
331331
struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
332332
: std::true_type {};
333333

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-
360334
// Traverse the given statement. If the most-derived traverse function takes a
361335
// data recursion queue, pass it on; otherwise, discard it. Note that the
362336
// first branch of this conditional must compile whether or not the derived
@@ -412,8 +386,6 @@ template <typename Derived> class RecursiveASTVisitor {
412386
if (!getDerived().shouldTraversePostOrder()) \
413387
TRY_TO(WalkUpFromUnary##NAME(S)); \
414388
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \
415-
if (!Queue && getDerived().shouldTraversePostOrder()) \
416-
TRY_TO(WalkUpFromUnary##NAME(S)); \
417389
return true; \
418390
} \
419391
bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
@@ -435,8 +407,6 @@ template <typename Derived> class RecursiveASTVisitor {
435407
TRY_TO(WalkUpFromBin##NAME(S)); \
436408
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS()); \
437409
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS()); \
438-
if (!Queue && getDerived().shouldTraversePostOrder()) \
439-
TRY_TO(WalkUpFromBin##NAME(S)); \
440410
return true; \
441411
} \
442412
bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
@@ -593,13 +563,15 @@ bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
593563

594564
BINOP_LIST()
595565
#undef OPERATOR
566+
#undef BINOP_LIST
596567

597568
#define OPERATOR(NAME) \
598569
case BO_##NAME##Assign: \
599570
DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
600571

601572
CAO_LIST()
602573
#undef OPERATOR
574+
#undef CAO_LIST
603575
}
604576
} else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
605577
switch (UnOp->getOpcode()) {
@@ -609,6 +581,7 @@ bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
609581

610582
UNARYOP_LIST()
611583
#undef OPERATOR
584+
#undef UNARYOP_LIST
612585
}
613586
}
614587

@@ -630,84 +603,23 @@ bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
630603

631604
template <typename Derived>
632605
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-
689606
switch (S->getStmtClass()) {
690607
case Stmt::NoStmtClass:
691608
break;
692609
#define ABSTRACT_STMT(STMT)
693610
#define STMT(CLASS, PARENT) \
694611
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;
700613
#define INITLISTEXPR(CLASS, PARENT) \
701614
case Stmt::CLASS##Class: \
702-
if (isSameMethod(&RecursiveASTVisitor::Traverse##CLASS, \
703-
&Derived::Traverse##CLASS)) { \
615+
{ \
704616
auto ILE = static_cast<CLASS *>(S); \
705617
if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE) \
706618
TRY_TO(WalkUpFrom##CLASS(Syn)); \
707619
if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) \
708620
TRY_TO(WalkUpFrom##CLASS(Sem)); \
709-
} \
710-
break;
621+
break; \
622+
}
711623
#include "clang/AST/StmtNodes.inc"
712624
}
713625

@@ -2304,13 +2216,8 @@ DEF_TRAVERSE_DECL(RequiresExprBodyDecl, {})
23042216
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt); \
23052217
} \
23062218
} \
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()) \
23122220
TRY_TO(WalkUpFrom##STMT(S)); \
2313-
} \
23142221
return ReturnValue; \
23152222
}
23162223

@@ -2481,9 +2388,6 @@ bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
24812388
for (Stmt *SubStmt : S->children()) {
24822389
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);
24832390
}
2484-
2485-
if (!Queue && getDerived().shouldTraversePostOrder())
2486-
TRY_TO(WalkUpFromInitListExpr(S));
24872391
}
24882392
return true;
24892393
}
@@ -3705,10 +3609,6 @@ bool RecursiveASTVisitor<Derived>::VisitOMPAffinityClause(
37053609

37063610
#undef TRY_TO
37073611

3708-
#undef UNARYOP_LIST
3709-
#undef BINOP_LIST
3710-
#undef CAO_LIST
3711-
37123612
} // end namespace clang
37133613

37143614
#endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H

clang/lib/Tooling/Syntax/BuildTree.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -578,19 +578,15 @@ class BuildTreeVisitor : public RecursiveASTVisitor<BuildTreeVisitor> {
578578
// RAV traverses it as a statement, we produce invalid node kinds in that
579579
// case.
580580
// FIXME: should do this in RAV instead?
581-
bool Result = [&, this]() {
582-
if (S->getInit() && !TraverseStmt(S->getInit()))
583-
return false;
584-
if (S->getLoopVariable() && !TraverseDecl(S->getLoopVariable()))
585-
return false;
586-
if (S->getRangeInit() && !TraverseStmt(S->getRangeInit()))
587-
return false;
588-
if (S->getBody() && !TraverseStmt(S->getBody()))
589-
return false;
590-
return true;
591-
}();
592-
WalkUpFromCXXForRangeStmt(S);
593-
return Result;
581+
if (S->getInit() && !TraverseStmt(S->getInit()))
582+
return false;
583+
if (S->getLoopVariable() && !TraverseDecl(S->getLoopVariable()))
584+
return false;
585+
if (S->getRangeInit() && !TraverseStmt(S->getRangeInit()))
586+
return false;
587+
if (S->getBody() && !TraverseStmt(S->getBody()))
588+
return false;
589+
return true;
594590
}
595591

596592
bool TraverseStmt(Stmt *S) {

0 commit comments

Comments
 (0)