================ @@ -68,32 +70,60 @@ static std::string getDREAncestorString(const DeclRefExpr *DRE, if (StParents.size() > 1) return "unavailable due to multiple parents"; - if (StParents.size() == 0) + if (StParents.empty()) break; St = StParents.begin()->get<Stmt>(); if (St) SS << " ==> "; } while (St); return SS.str(); } + } // namespace #endif /* NDEBUG */ -namespace clang::ast_matchers { +namespace { +// Using a custom matcher instead of ASTMatchers to achieve better performance. +class FastMatcher { +public: + virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx, + const UnsafeBufferUsageHandler &Handler) = 0; + virtual ~FastMatcher() = default; +}; + +class MatchResult { + +public: + template <typename T> const T *getNodeAs(StringRef ID) const { + auto It = Nodes.find(std::string(ID)); + if (It == Nodes.end()) { + return nullptr; + } + return It->second.get<T>(); + } + + void addNode(StringRef ID, const DynTypedNode &Node) { + Nodes[std::string(ID)] = Node; + } + +private: + llvm::StringMap<DynTypedNode> + Nodes; // DynTypedNode needed to store different types of Nodes, not ---------------- ivanaivanovska wrote:
Done. https://github.com/llvm/llvm-project/pull/124554 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits