|
21 | 21 | #include "clang/AST/RecursiveASTVisitor.h"
|
22 | 22 | #include "llvm/ADT/DenseMap.h"
|
23 | 23 | #include "llvm/ADT/StringMap.h"
|
24 |
| -#include "llvm/Support/PrettyStackTrace.h" |
25 | 24 | #include "llvm/Support/Timer.h"
|
26 | 25 | #include <deque>
|
27 | 26 | #include <memory>
|
@@ -761,67 +760,11 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
|
761 | 760 | D);
|
762 | 761 | }
|
763 | 762 |
|
764 |
| - class TraceReporter : llvm::PrettyStackTraceEntry { |
765 |
| - public: |
766 |
| - TraceReporter(const MatchASTVisitor &MV) : MV(MV) {} |
767 |
| - void print(raw_ostream &OS) const override { |
768 |
| - if (!MV.CurMatched) { |
769 |
| - OS << "ASTMatcher: Not currently matching\n"; |
770 |
| - return; |
771 |
| - } |
772 |
| - assert(MV.ActiveASTContext && |
773 |
| - "ActiveASTContext should be set if there is a matched callback"); |
774 |
| - |
775 |
| - OS << "ASTMatcher: Processing '" << MV.CurMatched->getID() << "'\n"; |
776 |
| - const BoundNodes::IDToNodeMap &Map = MV.CurBoundNodes->getMap(); |
777 |
| - if (Map.empty()) { |
778 |
| - OS << "No bound nodes\n"; |
779 |
| - return; |
780 |
| - } |
781 |
| - OS << "--- Bound Nodes Begin ---\n"; |
782 |
| - for (const auto &Item : Map) { |
783 |
| - OS << " " << Item.first << " - { "; |
784 |
| - if (const auto *D = Item.second.get<Decl>()) { |
785 |
| - OS << D->getDeclKindName() << "Decl "; |
786 |
| - if (const auto *ND = dyn_cast<NamedDecl>(D)) { |
787 |
| - ND->printQualifiedName(OS); |
788 |
| - OS << " : "; |
789 |
| - } else |
790 |
| - OS << ": "; |
791 |
| - D->getSourceRange().print(OS, |
792 |
| - MV.ActiveASTContext->getSourceManager()); |
793 |
| - } else if (const auto *S = Item.second.get<Stmt>()) { |
794 |
| - OS << S->getStmtClassName() << " : "; |
795 |
| - S->getSourceRange().print(OS, |
796 |
| - MV.ActiveASTContext->getSourceManager()); |
797 |
| - } else if (const auto *T = Item.second.get<Type>()) { |
798 |
| - OS << T->getTypeClassName() << "Type : "; |
799 |
| - QualType(T, 0).print(OS, MV.ActiveASTContext->getPrintingPolicy()); |
800 |
| - } else if (const auto *QT = Item.second.get<QualType>()) { |
801 |
| - OS << "QualType : "; |
802 |
| - QT->print(OS, MV.ActiveASTContext->getPrintingPolicy()); |
803 |
| - } else { |
804 |
| - OS << Item.second.getNodeKind().asStringRef() << " : "; |
805 |
| - Item.second.getSourceRange().print( |
806 |
| - OS, MV.ActiveASTContext->getSourceManager()); |
807 |
| - } |
808 |
| - OS << " }\n"; |
809 |
| - } |
810 |
| - OS << "--- Bound Nodes End ---\n"; |
811 |
| - } |
812 |
| - |
813 |
| - private: |
814 |
| - const MatchASTVisitor &MV; |
815 |
| - }; |
816 |
| - |
817 | 763 | private:
|
818 | 764 | bool TraversingASTNodeNotSpelledInSource = false;
|
819 | 765 | bool TraversingASTNodeNotAsIs = false;
|
820 | 766 | bool TraversingASTChildrenNotSpelledInSource = false;
|
821 | 767 |
|
822 |
| - const MatchCallback *CurMatched = nullptr; |
823 |
| - const BoundNodes *CurBoundNodes = nullptr; |
824 |
| - |
825 | 768 | struct ASTNodeNotSpelledInSourceScope {
|
826 | 769 | ASTNodeNotSpelledInSourceScope(MatchASTVisitor *V, bool B)
|
827 | 770 | : MV(V), MB(V->TraversingASTNodeNotSpelledInSource) {
|
@@ -888,7 +831,7 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
|
888 | 831 | Timer.setBucket(&TimeByBucket[MP.second->getID()]);
|
889 | 832 | BoundNodesTreeBuilder Builder;
|
890 | 833 | if (MP.first.matches(Node, this, &Builder)) {
|
891 |
| - MatchVisitor Visitor(*this, ActiveASTContext, MP.second); |
| 834 | + MatchVisitor Visitor(ActiveASTContext, MP.second); |
892 | 835 | Builder.visitMatches(&Visitor);
|
893 | 836 | }
|
894 | 837 | }
|
@@ -920,7 +863,7 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
|
920 | 863 | }
|
921 | 864 |
|
922 | 865 | if (MP.first.matches(DynNode, this, &Builder)) {
|
923 |
| - MatchVisitor Visitor(*this, ActiveASTContext, MP.second); |
| 866 | + MatchVisitor Visitor(ActiveASTContext, MP.second); |
924 | 867 | Builder.visitMatches(&Visitor);
|
925 | 868 | }
|
926 | 869 | }
|
@@ -1106,36 +1049,18 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
|
1106 | 1049 | // Implements a BoundNodesTree::Visitor that calls a MatchCallback with
|
1107 | 1050 | // the aggregated bound nodes for each match.
|
1108 | 1051 | class MatchVisitor : public BoundNodesTreeBuilder::Visitor {
|
1109 |
| - struct CurBoundScope { |
1110 |
| - CurBoundScope(MatchASTVisitor &MV, const BoundNodes &BN) : MV(MV) { |
1111 |
| - assert(MV.CurMatched && !MV.CurBoundNodes); |
1112 |
| - MV.CurBoundNodes = &BN; |
1113 |
| - } |
1114 |
| - |
1115 |
| - ~CurBoundScope() { MV.CurBoundNodes = nullptr; } |
1116 |
| - |
1117 |
| - private: |
1118 |
| - MatchASTVisitor &MV; |
1119 |
| - }; |
1120 |
| - |
1121 | 1052 | public:
|
1122 |
| - MatchVisitor(MatchASTVisitor &MV, ASTContext *Context, |
1123 |
| - MatchFinder::MatchCallback *Callback) |
1124 |
| - : MV(MV), Context(Context), Callback(Callback) { |
1125 |
| - assert(!MV.CurMatched && !MV.CurBoundNodes); |
1126 |
| - MV.CurMatched = Callback; |
1127 |
| - } |
1128 |
| - |
1129 |
| - ~MatchVisitor() { MV.CurMatched = nullptr; } |
| 1053 | + MatchVisitor(ASTContext* Context, |
| 1054 | + MatchFinder::MatchCallback* Callback) |
| 1055 | + : Context(Context), |
| 1056 | + Callback(Callback) {} |
1130 | 1057 |
|
1131 | 1058 | void visitMatch(const BoundNodes& BoundNodesView) override {
|
1132 | 1059 | TraversalKindScope RAII(*Context, Callback->getCheckTraversalKind());
|
1133 |
| - CurBoundScope RAII2(MV, BoundNodesView); |
1134 | 1060 | Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
|
1135 | 1061 | }
|
1136 | 1062 |
|
1137 | 1063 | private:
|
1138 |
| - MatchASTVisitor &MV; |
1139 | 1064 | ASTContext* Context;
|
1140 | 1065 | MatchFinder::MatchCallback* Callback;
|
1141 | 1066 | };
|
@@ -1545,7 +1470,6 @@ void MatchFinder::match(const clang::DynTypedNode &Node, ASTContext &Context) {
|
1545 | 1470 |
|
1546 | 1471 | void MatchFinder::matchAST(ASTContext &Context) {
|
1547 | 1472 | internal::MatchASTVisitor Visitor(&Matchers, Options);
|
1548 |
| - internal::MatchASTVisitor::TraceReporter StackTrace(Visitor); |
1549 | 1473 | Visitor.set_active_ast_context(&Context);
|
1550 | 1474 | Visitor.onStartOfTranslationUnit();
|
1551 | 1475 | Visitor.TraverseAST(Context);
|
|
0 commit comments