[PATCH] D85305: [SyntaxTree] Remove dead code on dump functions
Eduardo Caldas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 5 07:02:56 PDT 2020
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.
- `Node::dumpTokens` was never used.
- `::dumpTokens(llvm::raw_ostream, ArrayRef<syntax::Token>, const
SourceManager &SM)` was used twice, once by `Node::dumpTokens`.
Additionally it always received as parameter a `syntax::Token *` pointing to one token only, instead of an `ArrayRef`
I removed the first and inlined the simplified version of the second in its only caller
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85305
Files:
clang/include/clang/Tooling/Syntax/Tree.h
clang/lib/Tooling/Syntax/Tree.cpp
Index: clang/lib/Tooling/Syntax/Tree.cpp
===================================================================
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -135,24 +135,6 @@
}
namespace {
-static void dumpTokens(llvm::raw_ostream &OS, ArrayRef<syntax::Token> 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 << "<eof>";
- continue;
- }
- OS << T.text(SM);
- }
-}
-
static void dumpTree(llvm::raw_ostream &OS, const syntax::Node *N,
const syntax::Arena &A, std::vector<bool> IndentMask) {
std::string Marks;
@@ -166,7 +148,13 @@
OS << Marks << ": ";
if (auto *L = llvm::dyn_cast<syntax::Leaf>(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 << "<eof>";
+ else
+ OS << Token->text(A.sourceManager());
OS << "\n";
return;
}
@@ -174,7 +162,8 @@
auto *T = llvm::cast<syntax::Tree>(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<syntax::Leaf>(N);
- if (!L)
- return;
- ::dumpTokens(OS, *L->token(), A.sourceManager());
- OS << " ";
- });
- return OS.str();
-}
-
void syntax::Node::assertInvariants() const {
#ifndef NDEBUG
if (isDetached())
Index: clang/include/clang/Tooling/Syntax/Tree.h
===================================================================
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85305.283223.patch
Type: text/x-patch
Size: 2722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200805/12798c19/attachment-0001.bin>
More information about the cfe-commits
mailing list