diff options
| author | Stephen Kelly <steveire@gmail.com> | 2019-12-18 22:35:46 +0000 |
|---|---|---|
| committer | Stephen Kelly <steveire@gmail.com> | 2019-12-27 15:25:57 +0000 |
| commit | f0722333dd167245eb3c2b4263529a1ce3679b5c (patch) | |
| tree | e2bb3191dedf0f83247cbd6eedb7cf8af92d3f82 /clang-tools-extra/clang-query/Query.cpp | |
| parent | 2abda66848e5b7f502f978f030254118ec6751d6 (diff) | |
Allow newlines in AST Matchers in clang-query files
Reviewers: aaron.ballman
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D71842
Diffstat (limited to 'clang-tools-extra/clang-query/Query.cpp')
| -rw-r--r-- | clang-tools-extra/clang-query/Query.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-query/Query.cpp b/clang-tools-extra/clang-query/Query.cpp index 675fd968f46e..8eafc5eed750 100644 --- a/clang-tools-extra/clang-query/Query.cpp +++ b/clang-tools-extra/clang-query/Query.cpp @@ -101,9 +101,24 @@ 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'; + SmallVector<StringRef, 4> Lines; + Source.split(Lines, "\n"); + auto FirstLine = Lines[0]; + Lines.erase(Lines.begin(), Lines.begin() + 1); + while (!Lines.empty() && Lines.back().empty()) { + Lines.resize(Lines.size() - 1); + } + unsigned MaxLength = FirstLine.size(); + std::string PrefixText = "Matcher: "; + OS << "\n " << PrefixText << FirstLine; + + for (auto Line : Lines) { + OS << "\n" << std::string(PrefixText.size() + 2, ' ') << Line; + MaxLength = std::max<int>(MaxLength, Line.rtrim().size()); + } + + OS << "\n" + << " " << std::string(PrefixText.size() + MaxLength, '=') << "\n\n"; } for (auto MI = Matches.begin(), ME = Matches.end(); MI != ME; ++MI) { |
