[PATCH] D37000: [clang-diff] Remove NodeCountVisitor, NFC

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 25 02:52:32 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL311770: [clang-diff] Remove NodeCountVisitor, NFC (authored by krobelus).

Changed prior to commit:
  https://reviews.llvm.org/D37000?vs=112132&id=112670#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37000

Files:
  cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp


Index: cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp
===================================================================
--- cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -127,6 +127,8 @@
 
   SyntaxTree *Parent;
   ASTContext *
+  /// Nodes in preorder.
+  std::vector<Node> Nodes;
   std::vector<NodeId> Leaves;
   // Maps preorder indices to postorder ones.
   std::vector<int> PostorderIds;
@@ -155,9 +157,6 @@
   std::string getStmtValue(const Stmt *S) const;
 
 private:
-  /// Nodes in preorder.
-  std::vector<Node> Nodes;
-
   void initTree();
   void setLeftMostDescendants();
 };
@@ -182,32 +181,6 @@
 }
 
 namespace {
-/// Counts the number of nodes that will be compared.
-struct NodeCountVisitor : public RecursiveASTVisitor<NodeCountVisitor> {
-  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<NodeCountVisitor>::TraverseDecl(D);
-    return true;
-  }
-  bool TraverseStmt(Stmt *S) {
-    if (S)
-      S = S->IgnoreImplicit();
-    if (isNodeExcluded(Tree.AST.getSourceManager(), S))
-      return true;
-    ++Count;
-    RecursiveASTVisitor<NodeCountVisitor>::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<PreorderVisitor> {
   int Id = 0, Depth = 0;
@@ -218,6 +191,7 @@
 
   template <class T> std::tuple<NodeId, NodeId> PreTraverse(T *ASTNode) {
     NodeId MyId = Id;
+    Tree.Nodes.emplace_back();
     Node &N = Tree.getMutableNode(MyId);
     N.Parent = Parent;
     N.Depth = Depth;
@@ -274,19 +248,13 @@
 
 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();
 }
 
 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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37000.112670.patch
Type: text/x-patch
Size: 2505 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170825/cd316381/attachment.bin>


More information about the cfe-commits mailing list