johannes created this revision. Herald added a subscriber: klimek. https://reviews.llvm.org/D37000
Files: lib/Tooling/ASTDiff/ASTDiff.cpp Index: lib/Tooling/ASTDiff/ASTDiff.cpp =================================================================== --- lib/Tooling/ASTDiff/ASTDiff.cpp +++ lib/Tooling/ASTDiff/ASTDiff.cpp @@ -135,6 +135,8 @@ SyntaxTree *Parent; ASTUnit &AST; + /// Nodes in preorder. + std::vector<Node> Nodes; std::vector<NodeId> Leaves; // Maps preorder indices to postorder ones. std::vector<int> PostorderIds; @@ -163,9 +165,6 @@ std::string getStmtValue(const Stmt *S) const; private: - /// Nodes in preorder. - std::vector<Node> Nodes; - void initTree(); void setLeftMostDescendants(); }; @@ -207,32 +206,6 @@ return {SrcMgr.getExpansionLoc(BeginLoc), SrcMgr.getExpansionLoc(EndLoc)}; } -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, D)) - return true; - ++Count; - RecursiveASTVisitor<NodeCountVisitor>::TraverseDecl(D); - return true; - } - bool TraverseStmt(Stmt *S) { - if (S) - S = S->IgnoreImplicit(); - if (isNodeExcluded(Tree.AST, 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> { @@ -244,6 +217,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; @@ -300,19 +274,13 @@ SyntaxTree::Impl::Impl(SyntaxTree *Parent, Decl *N, ASTUnit &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, ASTUnit &AST) : Parent(Parent), AST(AST) { - NodeCountVisitor NodeCounter(*this); - NodeCounter.TraverseStmt(N); - Nodes.resize(NodeCounter.Count); PreorderVisitor PreorderWalker(*this); PreorderWalker.TraverseStmt(N); initTree();
Index: lib/Tooling/ASTDiff/ASTDiff.cpp =================================================================== --- lib/Tooling/ASTDiff/ASTDiff.cpp +++ lib/Tooling/ASTDiff/ASTDiff.cpp @@ -135,6 +135,8 @@ SyntaxTree *Parent; ASTUnit &AST; + /// Nodes in preorder. + std::vector<Node> Nodes; std::vector<NodeId> Leaves; // Maps preorder indices to postorder ones. std::vector<int> PostorderIds; @@ -163,9 +165,6 @@ std::string getStmtValue(const Stmt *S) const; private: - /// Nodes in preorder. - std::vector<Node> Nodes; - void initTree(); void setLeftMostDescendants(); }; @@ -207,32 +206,6 @@ return {SrcMgr.getExpansionLoc(BeginLoc), SrcMgr.getExpansionLoc(EndLoc)}; } -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, D)) - return true; - ++Count; - RecursiveASTVisitor<NodeCountVisitor>::TraverseDecl(D); - return true; - } - bool TraverseStmt(Stmt *S) { - if (S) - S = S->IgnoreImplicit(); - if (isNodeExcluded(Tree.AST, 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> { @@ -244,6 +217,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; @@ -300,19 +274,13 @@ SyntaxTree::Impl::Impl(SyntaxTree *Parent, Decl *N, ASTUnit &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, ASTUnit &AST) : Parent(Parent), AST(AST) { - NodeCountVisitor NodeCounter(*this); - NodeCounter.TraverseStmt(N); - Nodes.resize(NodeCounter.Count); PreorderVisitor PreorderWalker(*this); PreorderWalker.TraverseStmt(N); initTree();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits