diff --git a/clang/include/clang/Tooling/Syntax/Tree.h b/clang/include/clang/Tooling/Syntax/Tree.h --- a/clang/include/clang/Tooling/Syntax/Tree.h +++ b/clang/include/clang/Tooling/Syntax/Tree.h @@ -107,8 +107,6 @@ /// Dumps the structure of a subtree. For debugging and testing purposes. std::string dump(const Arena &A) const; - /// Dumps the tokens forming this subtree. - std::string dumpTokens(const Arena &A) const; /// Asserts invariants on this node of the tree and its immediate children. /// Will not recurse into the subtree. No-op if NDEBUG is set. diff --git a/clang/lib/Tooling/Syntax/Tree.cpp b/clang/lib/Tooling/Syntax/Tree.cpp --- a/clang/lib/Tooling/Syntax/Tree.cpp +++ b/clang/lib/Tooling/Syntax/Tree.cpp @@ -135,24 +135,6 @@ } namespace { -static void dumpTokens(llvm::raw_ostream &OS, ArrayRef Tokens, - const SourceManager &SM) { - assert(!Tokens.empty()); - bool First = true; - for (const auto &T : Tokens) { - if (!First) - OS << " "; - else - First = false; - // Handle 'eof' separately, calling text() on it produces an empty string. - if (T.kind() == tok::eof) { - OS << ""; - continue; - } - OS << T.text(SM); - } -} - static void dumpTree(llvm::raw_ostream &OS, const syntax::Node *N, const syntax::Arena &A, std::vector IndentMask) { std::string Marks; @@ -166,7 +148,13 @@ OS << Marks << ": "; if (auto *L = llvm::dyn_cast(N)) { - dumpTokens(OS, *L->token(), A.sourceManager()); + auto *Token = L->token(); + assert(Token); + // Handle 'eof' separately, calling text() on it produces an empty string. + if (Token->kind() == tok::eof) + OS << ""; + else + OS << Token->text(A.sourceManager()); OS << "\n"; return; } @@ -174,7 +162,8 @@ auto *T = llvm::cast(N); OS << T->kind() << "\n"; - for (auto It = T->firstChild(); It != nullptr; It = It->nextSibling()) { + for (const auto *It = T->firstChild(); It != nullptr; + It = It->nextSibling()) { for (bool Filled : IndentMask) { if (Filled) OS << "| "; @@ -201,19 +190,6 @@ return std::move(OS.str()); } -std::string syntax::Node::dumpTokens(const Arena &A) const { - std::string Storage; - llvm::raw_string_ostream OS(Storage); - traverse(this, [&](const syntax::Node *N) { - auto *L = llvm::dyn_cast(N); - if (!L) - return; - ::dumpTokens(OS, *L->token(), A.sourceManager()); - OS << " "; - }); - return OS.str(); -} - void syntax::Node::assertInvariants() const { #ifndef NDEBUG if (isDetached())