From 4a5b01ddd7dd12f9a5826741e57104e8bf54748b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 20 Oct 2018 09:13:59 +0000 Subject: [clang-query] Add option to print matcher expression Summary: This is useful if using clang-query -f with a file containing multiple matchers. Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52859 llvm-svn: 344840 --- clang-tools-extra/clang-query/Query.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'clang-tools-extra/clang-query/Query.cpp') diff --git a/clang-tools-extra/clang-query/Query.cpp b/clang-tools-extra/clang-query/Query.cpp index 63b4f3579b9..463e52c5806 100644 --- a/clang-tools-extra/clang-query/Query.cpp +++ b/clang-tools-extra/clang-query/Query.cpp @@ -41,6 +41,8 @@ bool HelpQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const { "as part of other expressions.\n" " set bind-root (true|false) " "Set whether to bind the root matcher to \"root\".\n" + " set print-matcher (true|false) " + "Set whether to print the current matcher,\n" " set output (diag|print|dump) " "Set whether to print bindings as diagnostics,\n" " " @@ -86,6 +88,12 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const { } Finder.matchAST(AST->getASTContext()); + if (QS.PrintMatcher) { + std::string prefixText = "Matcher: "; + OS << "\n " << prefixText << Source << "\n"; + OS << " " << std::string(prefixText.size() + Source.size(), '=') << '\n'; + } + for (auto MI = Matches.begin(), ME = Matches.end(); MI != ME; ++MI) { OS << "\nMatch #" << ++MatchCount << ":\n\n"; -- cgit v1.2.3