From: Johannes Altmanninger Date: Fri, 25 Aug 2017 09:49:49 +0000 (+0000) Subject: [clang-diff] Remove NodeCountVisitor, NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a74f265b5b1ae275ae0829c632b662ff63d42bc;p=clang [clang-diff] Remove NodeCountVisitor, NFC Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D37000 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311770 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Tooling/ASTDiff/ASTDiff.cpp b/lib/Tooling/ASTDiff/ASTDiff.cpp index 747c67ecdc..56832a30b7 100644 --- a/lib/Tooling/ASTDiff/ASTDiff.cpp +++ b/lib/Tooling/ASTDiff/ASTDiff.cpp @@ -127,6 +127,8 @@ public: SyntaxTree *Parent; ASTContext * + /// Nodes in preorder. + std::vector Nodes; std::vector Leaves; // Maps preorder indices to postorder ones. std::vector PostorderIds; @@ -155,9 +157,6 @@ public: std::string getStmtValue(const Stmt *S) const; private: - /// Nodes in preorder. - std::vector Nodes; - void initTree(); void setLeftMostDescendants(); }; @@ -181,32 +180,6 @@ static bool isNodeExcluded(const SourceManager &SrcMgr, T *N) { return isSpecializedNodeExcluded(N); } -namespace { -/// Counts the number of nodes that will be compared. -struct NodeCountVisitor : public RecursiveASTVisitor { - int Count = 0; - const SyntaxTree::Impl &Tree; - NodeCountVisitor(const SyntaxTree::Impl &Tree) : Tree(Tree) {} - bool TraverseDecl(Decl *D) { - if (isNodeExcluded(Tree.AST.getSourceManager(), D)) - return true; - ++Count; - RecursiveASTVisitor::TraverseDecl(D); - return true; - } - bool TraverseStmt(Stmt *S) { - if (S) - S = S->IgnoreImplicit(); - if (isNodeExcluded(Tree.AST.getSourceManager(), S)) - return true; - ++Count; - RecursiveASTVisitor::TraverseStmt(S); - return true; - } - bool TraverseType(QualType T) { return true; } -}; -} // end anonymous namespace - namespace { // Sets Height, Parent and Children for each node. struct PreorderVisitor : public RecursiveASTVisitor { @@ -218,6 +191,7 @@ struct PreorderVisitor : public RecursiveASTVisitor { template std::tuple PreTraverse(T *ASTNode) { NodeId MyId = Id; + Tree.Nodes.emplace_back(); Node &N = Tree.getMutableNode(MyId); N.Parent = Parent; N.Depth = Depth; @@ -274,9 +248,6 @@ struct PreorderVisitor : public RecursiveASTVisitor { SyntaxTree::Impl::Impl(SyntaxTree *Parent, Decl *N, ASTContext &AST) : Parent(Parent), AST(AST) { - NodeCountVisitor NodeCounter(*this); - NodeCounter.TraverseDecl(N); - Nodes.resize(NodeCounter.Count); PreorderVisitor PreorderWalker(*this); PreorderWalker.TraverseDecl(N); initTree(); @@ -284,9 +255,6 @@ SyntaxTree::Impl::Impl(SyntaxTree *Parent, Decl *N, ASTContext &AST) SyntaxTree::Impl::Impl(SyntaxTree *Parent, Stmt *N, ASTContext &AST) : Parent(Parent), AST(AST) { - NodeCountVisitor NodeCounter(*this); - NodeCounter.TraverseStmt(N); - Nodes.resize(NodeCounter.Count); PreorderVisitor PreorderWalker(*this); PreorderWalker.TraverseStmt(N); initTree();