r309738 - [clang-diff] Renames, NFC

Johannes Altmanninger via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 1 13:17:46 PDT 2017


Author: krobelus
Date: Tue Aug  1 13:17:46 2017
New Revision: 309738

URL: http://llvm.org/viewvc/llvm-project?rev=309738&view=rev
Log:
[clang-diff] Renames, NFC

Modified:
    cfe/trunk/include/clang/Tooling/ASTDiff/ASTDiff.h
    cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp

Modified: cfe/trunk/include/clang/Tooling/ASTDiff/ASTDiff.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/ASTDiff/ASTDiff.h?rev=309738&r1=309737&r2=309738&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/ASTDiff/ASTDiff.h (original)
+++ cfe/trunk/include/clang/Tooling/ASTDiff/ASTDiff.h Tue Aug  1 13:17:46 2017
@@ -64,7 +64,7 @@ struct Node {
 
 class ASTDiff {
 public:
-  ASTDiff(SyntaxTree &T1, SyntaxTree &T2, const ComparisonOptions &Options);
+  ASTDiff(SyntaxTree &Src, SyntaxTree &Dst, const ComparisonOptions &Options);
   ~ASTDiff();
 
   // Returns a list of matches.
@@ -92,7 +92,7 @@ public:
   /// Constructs a tree from any AST node.
   template <class T>
   SyntaxTree(T *Node, const ASTContext &AST)
-      : TreeImpl(llvm::make_unique<SyntaxTreeImpl>(this, Node, AST)) {}
+      : TreeImpl(llvm::make_unique<Impl>(this, Node, AST)) {}
   ~SyntaxTree();
 
   const Node &getNode(NodeId Id) const;
@@ -104,7 +104,8 @@ public:
 
   void printAsJson(raw_ostream &OS);
 
-  std::unique_ptr<SyntaxTreeImpl> TreeImpl;
+  class Impl;
+  std::unique_ptr<Impl> TreeImpl;
 };
 
 struct ComparisonOptions {

Modified: cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp?rev=309738&r1=309737&r2=309738&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp (original)
+++ cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp Tue Aug  1 13:17:46 2017
@@ -79,11 +79,12 @@ private:
 
 class ASTDiff::Impl {
 public:
-  SyntaxTreeImpl &T1, &T2;
+  SyntaxTree::Impl &T1, &T2;
   bool IsMappingDone = false;
   Mapping TheMapping;
 
-  Impl(SyntaxTreeImpl &T1, SyntaxTreeImpl &T2, const ComparisonOptions &Options)
+  Impl(SyntaxTree::Impl &T1, SyntaxTree::Impl &T2,
+       const ComparisonOptions &Options)
       : T1(T1), T2(T2), Options(Options) {}
 
   /// Matches nodes one-by-one based on their similarity.
@@ -97,12 +98,12 @@ public:
   void printChangeImpl(raw_ostream &OS, const Change &Chg) const;
   void printMatchImpl(raw_ostream &OS, const Match &M) const;
 
-  // Returns a mapping of isomorphic subtrees.
+  // Returns a mapping of identical subtrees.
   Mapping matchTopDown() const;
 
 private:
   // Returns true if the two subtrees are identical.
-  bool isomorphic(NodeId Id1, NodeId Id2) const;
+  bool identical(NodeId Id1, NodeId Id2) const;
 
   bool canBeAddedToMapping(const Mapping &M, NodeId Id1, NodeId Id2) const;
 
@@ -110,7 +111,7 @@ private:
   bool isMatchingPossible(NodeId Id1, NodeId Id2) const;
 
   // Adds all corresponding subtrees of the two nodes to the mapping.
-  // The two nodes must be isomorphic.
+  // The two nodes must be identical.
   void addIsomorphicSubTrees(Mapping &M, NodeId Id1, NodeId Id2) const;
 
   // Uses an optimal albeit slow algorithm to compute a mapping between two
@@ -133,25 +134,23 @@ private:
 };
 
 /// Represents the AST of a TranslationUnit.
-class SyntaxTreeImpl {
+class SyntaxTree::Impl {
 public:
   /// Constructs a tree from the entire translation unit.
-  SyntaxTreeImpl(SyntaxTree *Parent, const ASTContext &AST);
+  Impl(SyntaxTree *Parent, const ASTContext &AST);
   /// Constructs a tree from an AST node.
-  SyntaxTreeImpl(SyntaxTree *Parent, Decl *N, const ASTContext &AST);
-  SyntaxTreeImpl(SyntaxTree *Parent, Stmt *N, const ASTContext &AST);
+  Impl(SyntaxTree *Parent, Decl *N, const ASTContext &AST);
+  Impl(SyntaxTree *Parent, Stmt *N, const ASTContext &AST);
   template <class T>
-  SyntaxTreeImpl(
-      SyntaxTree *Parent,
-      typename std::enable_if<std::is_base_of<Stmt, T>::value, T>::type *Node,
-      const ASTContext &AST)
-      : SyntaxTreeImpl(Parent, dyn_cast<Stmt>(Node), AST) {}
+  Impl(SyntaxTree *Parent,
+       typename std::enable_if<std::is_base_of<Stmt, T>::value, T>::type *Node,
+       const ASTContext &AST)
+      : Impl(Parent, dyn_cast<Stmt>(Node), AST) {}
   template <class T>
-  SyntaxTreeImpl(
-      SyntaxTree *Parent,
-      typename std::enable_if<std::is_base_of<Decl, T>::value, T>::type *Node,
-      const ASTContext &AST)
-      : SyntaxTreeImpl(Parent, dyn_cast<Decl>(Node), AST) {}
+  Impl(SyntaxTree *Parent,
+       typename std::enable_if<std::is_base_of<Decl, T>::value, T>::type *Node,
+       const ASTContext &AST)
+      : Impl(Parent, dyn_cast<Decl>(Node), AST) {}
 
   SyntaxTree *Parent;
   const ASTContext &AST;
@@ -160,7 +159,7 @@ public:
   std::vector<int> PostorderIds;
 
   int getSize() const { return Nodes.size(); }
-  NodeId root() const { return 0; }
+  NodeId getRootId() const { return 0; }
 
   const Node &getNode(NodeId Id) const { return Nodes[Id]; }
   Node &getMutableNode(NodeId Id) { return Nodes[Id]; }
@@ -169,8 +168,8 @@ public:
   int getNumberOfDescendants(NodeId Id) const;
   bool isInSubtree(NodeId Id, NodeId SubtreeRoot) const;
 
-  std::string getNodeValueImpl(NodeId Id) const;
-  std::string getNodeValueImpl(const DynTypedNode &DTN) const;
+  std::string getNodeValue(NodeId Id) const;
+  std::string getNodeValue(const DynTypedNode &DTN) const;
   /// Prints the node as "<type>[: <value>](<postorder-id)"
   void printNode(NodeId Id) const { printNode(llvm::outs(), Id); }
   void printNode(raw_ostream &OS, NodeId Id) const;
@@ -202,17 +201,17 @@ namespace {
 /// Counts the number of nodes that will be compared.
 struct NodeCountVisitor : public RecursiveASTVisitor<NodeCountVisitor> {
   int Count = 0;
-  const SyntaxTreeImpl &Root;
-  NodeCountVisitor(const SyntaxTreeImpl &Root) : Root(Root) {}
+  const SyntaxTree::Impl &Tree;
+  NodeCountVisitor(const SyntaxTree::Impl &Tree) : Tree(Tree) {}
   bool TraverseDecl(Decl *D) {
-    if (isNodeExcluded(Root.AST.getSourceManager(), D))
+    if (isNodeExcluded(Tree.AST.getSourceManager(), D))
       return true;
     ++Count;
     RecursiveASTVisitor<NodeCountVisitor>::TraverseDecl(D);
     return true;
   }
   bool TraverseStmt(Stmt *S) {
-    if (isNodeExcluded(Root.AST.getSourceManager(), S))
+    if (isNodeExcluded(Tree.AST.getSourceManager(), S))
       return true;
     ++Count;
     RecursiveASTVisitor<NodeCountVisitor>::TraverseStmt(S);
@@ -227,26 +226,26 @@ namespace {
 struct PreorderVisitor : public RecursiveASTVisitor<PreorderVisitor> {
   int Id = 0, Depth = 0;
   NodeId Parent;
-  SyntaxTreeImpl &Root;
+  SyntaxTree::Impl &Tree;
 
-  PreorderVisitor(SyntaxTreeImpl &Root) : Root(Root) {}
+  PreorderVisitor(SyntaxTree::Impl &Tree) : Tree(Tree) {}
 
   template <class T> std::tuple<NodeId, NodeId> PreTraverse(T *ASTNode) {
     NodeId MyId = Id;
-    Node &N = Root.getMutableNode(MyId);
+    Node &N = Tree.getMutableNode(MyId);
     N.Parent = Parent;
     N.Depth = Depth;
     N.ASTNode = DynTypedNode::create(*ASTNode);
     assert(!N.ASTNode.getNodeKind().isNone() &&
            "Expected nodes to have a valid kind.");
     if (Parent.isValid()) {
-      Node &P = Root.getMutableNode(Parent);
+      Node &P = Tree.getMutableNode(Parent);
       P.Children.push_back(MyId);
     }
     Parent = MyId;
     ++Id;
     ++Depth;
-    return std::make_tuple(MyId, Root.getNode(MyId).Parent);
+    return std::make_tuple(MyId, Tree.getNode(MyId).Parent);
   }
   void PostTraverse(std::tuple<NodeId, NodeId> State) {
     NodeId MyId, PreviousParent;
@@ -254,16 +253,16 @@ struct PreorderVisitor : public Recursiv
     assert(MyId.isValid() && "Expecting to only traverse valid nodes.");
     Parent = PreviousParent;
     --Depth;
-    Node &N = Root.getMutableNode(MyId);
+    Node &N = Tree.getMutableNode(MyId);
     N.RightMostDescendant = Id;
     if (N.isLeaf())
-      Root.Leaves.push_back(MyId);
+      Tree.Leaves.push_back(MyId);
     N.Height = 1;
     for (NodeId Child : N.Children)
-      N.Height = std::max(N.Height, 1 + Root.getNode(Child).Height);
+      N.Height = std::max(N.Height, 1 + Tree.getNode(Child).Height);
   }
   bool TraverseDecl(Decl *D) {
-    if (isNodeExcluded(Root.AST.getSourceManager(), D))
+    if (isNodeExcluded(Tree.AST.getSourceManager(), D))
       return true;
     auto SavedState = PreTraverse(D);
     RecursiveASTVisitor<PreorderVisitor>::TraverseDecl(D);
@@ -271,7 +270,7 @@ struct PreorderVisitor : public Recursiv
     return true;
   }
   bool TraverseStmt(Stmt *S) {
-    if (isNodeExcluded(Root.AST.getSourceManager(), S))
+    if (isNodeExcluded(Tree.AST.getSourceManager(), S))
       return true;
     auto SavedState = PreTraverse(S);
     RecursiveASTVisitor<PreorderVisitor>::TraverseStmt(S);
@@ -282,11 +281,10 @@ struct PreorderVisitor : public Recursiv
 };
 } // end anonymous namespace
 
-SyntaxTreeImpl::SyntaxTreeImpl(SyntaxTree *Parent, const ASTContext &AST)
-    : SyntaxTreeImpl(Parent, AST.getTranslationUnitDecl(), AST) {}
+SyntaxTree::Impl::Impl(SyntaxTree *Parent, const ASTContext &AST)
+    : Impl(Parent, AST.getTranslationUnitDecl(), AST) {}
 
-SyntaxTreeImpl::SyntaxTreeImpl(SyntaxTree *Parent, Decl *N,
-                               const ASTContext &AST)
+SyntaxTree::Impl::Impl(SyntaxTree *Parent, Decl *N, const ASTContext &AST)
     : Parent(Parent), AST(AST) {
   NodeCountVisitor NodeCounter(*this);
   NodeCounter.TraverseDecl(N);
@@ -296,8 +294,7 @@ SyntaxTreeImpl::SyntaxTreeImpl(SyntaxTre
   initTree();
 }
 
-SyntaxTreeImpl::SyntaxTreeImpl(SyntaxTree *Parent, Stmt *N,
-                               const ASTContext &AST)
+SyntaxTree::Impl::Impl(SyntaxTree *Parent, Stmt *N, const ASTContext &AST)
     : Parent(Parent), AST(AST) {
   NodeCountVisitor NodeCounter(*this);
   NodeCounter.TraverseStmt(N);
@@ -307,7 +304,7 @@ SyntaxTreeImpl::SyntaxTreeImpl(SyntaxTre
   initTree();
 }
 
-void SyntaxTreeImpl::initTree() {
+void SyntaxTree::Impl::initTree() {
   setLeftMostDescendants();
   int PostorderId = 0;
   PostorderIds.resize(getSize());
@@ -317,10 +314,10 @@ void SyntaxTreeImpl::initTree() {
     PostorderIds[Id] = PostorderId;
     ++PostorderId;
   };
-  PostorderTraverse(root());
+  PostorderTraverse(getRootId());
 }
 
-void SyntaxTreeImpl::setLeftMostDescendants() {
+void SyntaxTree::Impl::setLeftMostDescendants() {
   for (NodeId Leaf : Leaves) {
     getMutableNode(Leaf).LeftMostDescendant = Leaf;
     NodeId Parent, Cur = Leaf;
@@ -332,7 +329,7 @@ void SyntaxTreeImpl::setLeftMostDescenda
   }
 }
 
-static std::vector<NodeId> getSubtreePostorder(const SyntaxTreeImpl &Tree,
+static std::vector<NodeId> getSubtreePostorder(const SyntaxTree::Impl &Tree,
                                                NodeId Root) {
   std::vector<NodeId> Postorder;
   std::function<void(NodeId)> Traverse = [&](NodeId Id) {
@@ -345,7 +342,7 @@ static std::vector<NodeId> getSubtreePos
   return Postorder;
 }
 
-static std::vector<NodeId> getSubtreeBfs(const SyntaxTreeImpl &Tree,
+static std::vector<NodeId> getSubtreeBfs(const SyntaxTree::Impl &Tree,
                                          NodeId Root) {
   std::vector<NodeId> Ids;
   size_t Expanded = 0;
@@ -356,21 +353,21 @@ static std::vector<NodeId> getSubtreeBfs
   return Ids;
 }
 
-int SyntaxTreeImpl::getNumberOfDescendants(NodeId Id) const {
+int SyntaxTree::Impl::getNumberOfDescendants(NodeId Id) const {
   return getNode(Id).RightMostDescendant - Id + 1;
 }
 
-bool SyntaxTreeImpl::isInSubtree(NodeId Id, NodeId SubtreeRoot) const {
+bool SyntaxTree::Impl::isInSubtree(NodeId Id, NodeId SubtreeRoot) const {
   NodeId Lower = SubtreeRoot;
   NodeId Upper = getNode(SubtreeRoot).RightMostDescendant;
   return Id >= Lower && Id <= Upper;
 }
 
-std::string SyntaxTreeImpl::getNodeValueImpl(NodeId Id) const {
-  return getNodeValueImpl(getNode(Id).ASTNode);
+std::string SyntaxTree::Impl::getNodeValue(NodeId Id) const {
+  return getNodeValue(getNode(Id).ASTNode);
 }
 
-std::string SyntaxTreeImpl::getNodeValueImpl(const DynTypedNode &DTN) const {
+std::string SyntaxTree::Impl::getNodeValue(const DynTypedNode &DTN) const {
   if (auto *X = DTN.get<BinaryOperator>())
     return X->getOpcodeStr();
   if (auto *X = DTN.get<AccessSpecDecl>()) {
@@ -416,12 +413,12 @@ std::string SyntaxTreeImpl::getNodeValue
   llvm_unreachable("Fatal: unhandled AST node.\n");
 }
 
-void SyntaxTreeImpl::printTree() const { printTree(root()); }
-void SyntaxTreeImpl::printTree(NodeId Root) const {
+void SyntaxTree::Impl::printTree() const { printTree(getRootId()); }
+void SyntaxTree::Impl::printTree(NodeId Root) const {
   printTree(llvm::outs(), Root);
 }
 
-void SyntaxTreeImpl::printTree(raw_ostream &OS, NodeId Root) const {
+void SyntaxTree::Impl::printTree(raw_ostream &OS, NodeId Root) const {
   const Node &N = getNode(Root);
   for (int I = 0; I < N.Depth; ++I)
     OS << " ";
@@ -431,22 +428,22 @@ void SyntaxTreeImpl::printTree(raw_ostre
     printTree(OS, Child);
 }
 
-void SyntaxTreeImpl::printNode(raw_ostream &OS, NodeId Id) const {
+void SyntaxTree::Impl::printNode(raw_ostream &OS, NodeId Id) const {
   if (Id.isInvalid()) {
     OS << "None";
     return;
   }
   OS << getNode(Id).getTypeLabel();
-  if (getNodeValueImpl(Id) != "")
-    OS << ": " << getNodeValueImpl(Id);
+  if (getNodeValue(Id) != "")
+    OS << ": " << getNodeValue(Id);
   OS << "(" << PostorderIds[Id] << ")";
 }
 
-void SyntaxTreeImpl::printNodeAsJson(raw_ostream &OS, NodeId Id) const {
+void SyntaxTree::Impl::printNodeAsJson(raw_ostream &OS, NodeId Id) const {
   auto N = getNode(Id);
   OS << R"({"type":")" << N.getTypeLabel() << R"(")";
-  if (getNodeValueImpl(Id) != "")
-    OS << R"(,"value":")" << getNodeValueImpl(Id) << R"(")";
+  if (getNodeValue(Id) != "")
+    OS << R"(,"value":")" << getNodeValue(Id) << R"(")";
   OS << R"(,"children":[)";
   if (N.Children.size() > 0) {
     printNodeAsJson(OS, N.Children[0]);
@@ -458,9 +455,9 @@ void SyntaxTreeImpl::printNodeAsJson(raw
   OS << "]}";
 }
 
-void SyntaxTreeImpl::printAsJsonImpl(raw_ostream &OS) const {
+void SyntaxTree::Impl::printAsJsonImpl(raw_ostream &OS) const {
   OS << R"({"root":)";
-  printNodeAsJson(OS, root());
+  printNodeAsJson(OS, getRootId());
   OS << "}\n";
 }
 
@@ -480,7 +477,7 @@ struct SNodeId {
 class Subtree {
 private:
   /// The parent tree.
-  const SyntaxTreeImpl &Tree;
+  const SyntaxTree::Impl &Tree;
   /// Maps SNodeIds to original ids.
   std::vector<NodeId> RootIds;
   /// Maps subtree nodes to their leftmost descendants wtihin the subtree.
@@ -489,7 +486,7 @@ private:
 public:
   std::vector<SNodeId> KeyRoots;
 
-  Subtree(const SyntaxTreeImpl &Tree, NodeId SubtreeRoot) : Tree(Tree) {
+  Subtree(const SyntaxTree::Impl &Tree, NodeId SubtreeRoot) : Tree(Tree) {
     RootIds = getSubtreePostorder(Tree, SubtreeRoot);
     int NumLeaves = setLeftMostDescendants();
     computeKeyRoots(NumLeaves);
@@ -511,7 +508,7 @@ public:
     return Tree.PostorderIds[getIdInRoot(SNodeId(1))];
   }
   std::string getNodeValue(SNodeId Id) const {
-    return Tree.getNodeValueImpl(getIdInRoot(Id));
+    return Tree.getNodeValue(getIdInRoot(Id));
   }
 
 private:
@@ -557,8 +554,8 @@ class ZhangShashaMatcher {
   std::unique_ptr<std::unique_ptr<double[]>[]> TreeDist, ForestDist;
 
 public:
-  ZhangShashaMatcher(const ASTDiff::Impl &DiffImpl, const SyntaxTreeImpl &T1,
-                     const SyntaxTreeImpl &T2, NodeId Id1, NodeId Id2)
+  ZhangShashaMatcher(const ASTDiff::Impl &DiffImpl, const SyntaxTree::Impl &T1,
+                     const SyntaxTree::Impl &T2, NodeId Id1, NodeId Id2)
       : DiffImpl(DiffImpl), S1(T1, Id1), S2(T2, Id2) {
     TreeDist = llvm::make_unique<std::unique_ptr<double[]>[]>(
         size_t(S1.getSize()) + 1);
@@ -682,8 +679,8 @@ private:
 namespace {
 // Compares nodes by their depth.
 struct HeightLess {
-  const SyntaxTreeImpl &Tree;
-  HeightLess(const SyntaxTreeImpl &Tree) : Tree(Tree) {}
+  const SyntaxTree::Impl &Tree;
+  HeightLess(const SyntaxTree::Impl &Tree) : Tree(Tree) {}
   bool operator()(NodeId Id1, NodeId Id2) const {
     return Tree.getNode(Id1).Height < Tree.getNode(Id2).Height;
   }
@@ -692,13 +689,13 @@ struct HeightLess {
 
 // Priority queue for nodes, sorted descendingly by their height.
 class PriorityList {
-  const SyntaxTreeImpl &Tree;
+  const SyntaxTree::Impl &Tree;
   HeightLess Cmp;
   std::vector<NodeId> Container;
   PriorityQueue<NodeId, std::vector<NodeId>, HeightLess> List;
 
 public:
-  PriorityList(const SyntaxTreeImpl &Tree)
+  PriorityList(const SyntaxTree::Impl &Tree)
       : Tree(Tree), Cmp(Tree), List(Cmp, Container) {}
 
   void push(NodeId id) { List.push(id); }
@@ -727,15 +724,15 @@ public:
   }
 };
 
-bool ASTDiff::Impl::isomorphic(NodeId Id1, NodeId Id2) const {
+bool ASTDiff::Impl::identical(NodeId Id1, NodeId Id2) const {
   const Node &N1 = T1.getNode(Id1);
   const Node &N2 = T2.getNode(Id2);
   if (N1.Children.size() != N2.Children.size() ||
       !isMatchingPossible(Id1, Id2) ||
-      T1.getNodeValueImpl(Id1) != T2.getNodeValueImpl(Id2))
+      T1.getNodeValue(Id1) != T2.getNodeValue(Id2))
     return false;
   for (size_t Id = 0, E = N1.Children.size(); Id < E; ++Id)
-    if (!isomorphic(N1.Children[Id], N2.Children[Id]))
+    if (!identical(N1.Children[Id], N2.Children[Id]))
       return false;
   return true;
 }
@@ -764,7 +761,7 @@ bool ASTDiff::Impl::isMatchingPossible(N
 
 void ASTDiff::Impl::addIsomorphicSubTrees(Mapping &M, NodeId Id1,
                                           NodeId Id2) const {
-  assert(isomorphic(Id1, Id2) && "Can only be called on isomorphic subtrees.");
+  assert(identical(Id1, Id2) && "Can only be called on identical subtrees.");
   M.link(Id1, Id2);
   const Node &N1 = T1.getNode(Id1);
   const Node &N2 = T2.getNode(Id2);
@@ -801,15 +798,15 @@ double ASTDiff::Impl::getSimilarity(cons
 
 NodeId ASTDiff::Impl::findCandidate(const Mapping &M, NodeId Id1) const {
   NodeId Candidate;
-  double MaxSimilarity = 0.0;
+  double HighestSimilarity = 0.0;
   for (NodeId Id2 = 0, E = T2.getSize(); Id2 < E; ++Id2) {
     if (!isMatchingPossible(Id1, Id2))
       continue;
     if (M.hasDst(Id2))
       continue;
     double Similarity = getSimilarity(M, Id1, Id2);
-    if (Similarity > MaxSimilarity) {
-      MaxSimilarity = Similarity;
+    if (Similarity > HighestSimilarity) {
+      HighestSimilarity = Similarity;
       Candidate = Id2;
     }
   }
@@ -817,12 +814,12 @@ NodeId ASTDiff::Impl::findCandidate(cons
 }
 
 void ASTDiff::Impl::matchBottomUp(Mapping &M) const {
-  std::vector<NodeId> Postorder = getSubtreePostorder(T1, T1.root());
+  std::vector<NodeId> Postorder = getSubtreePostorder(T1, T1.getRootId());
   for (NodeId Id1 : Postorder) {
-    if (Id1 == T1.root()) {
-      if (isMatchingPossible(T1.root(), T2.root())) {
-        M.link(T1.root(), T2.root());
-        addOptimalMapping(M, T1.root(), T2.root());
+    if (Id1 == T1.getRootId()) {
+      if (isMatchingPossible(T1.getRootId(), T2.getRootId())) {
+        M.link(T1.getRootId(), T2.getRootId());
+        addOptimalMapping(M, T1.getRootId(), T2.getRootId());
       }
       break;
     }
@@ -848,8 +845,8 @@ Mapping ASTDiff::Impl::matchTopDown() co
 
   Mapping M(T1.getSize(), T2.getSize());
 
-  L1.push(T1.root());
-  L2.push(T2.root());
+  L1.push(T1.getRootId());
+  L2.push(T2.getRootId());
 
   int Max1, Max2;
   while (std::min(Max1 = L1.peekMax(), Max2 = L2.peekMax()) >
@@ -869,7 +866,7 @@ Mapping ASTDiff::Impl::matchTopDown() co
     H2 = L2.pop();
     for (NodeId Id1 : H1) {
       for (NodeId Id2 : H2)
-        if (isomorphic(Id1, Id2) && canBeAddedToMapping(M, Id1, Id2))
+        if (identical(Id1, Id2) && canBeAddedToMapping(M, Id1, Id2))
           addIsomorphicSubTrees(M, Id1, Id2);
     }
     for (NodeId Id1 : H1) {
@@ -902,12 +899,12 @@ std::vector<Match> ASTDiff::Impl::getMat
 
 std::vector<Change> ASTDiff::Impl::computeChanges(Mapping &M) {
   std::vector<Change> Changes;
-  for (NodeId Id2 : getSubtreeBfs(T2, T2.root())) {
+  for (NodeId Id2 : getSubtreeBfs(T2, T2.getRootId())) {
     const Node &N2 = T2.getNode(Id2);
     NodeId Id1 = M.getSrc(Id2);
     if (Id1.isValid()) {
       assert(isMatchingPossible(Id1, Id2) && "Invalid matching.");
-      if (T1.getNodeValueImpl(Id1) != T2.getNodeValueImpl(Id2)) {
+      if (T1.getNodeValue(Id1) != T2.getNodeValue(Id2)) {
         Changes.emplace_back(Update, Id1, Id2);
       }
       continue;
@@ -956,7 +953,7 @@ void ASTDiff::Impl::printChangeImpl(raw_
   case Update:
     OS << "Update ";
     T1.printNode(OS, Chg.Src);
-    OS << " to " << T2.getNodeValueImpl(Chg.Dst) << "\n";
+    OS << " to " << T2.getNodeValue(Chg.Dst) << "\n";
     break;
   case Insert:
     OS << "Insert ";
@@ -983,10 +980,10 @@ ASTDiff::ASTDiff(SyntaxTree &T1, SyntaxT
                  const ComparisonOptions &Options)
     : DiffImpl(llvm::make_unique<Impl>(*T1.TreeImpl, *T2.TreeImpl, Options)) {}
 
-ASTDiff::~ASTDiff() {}
+ASTDiff::~ASTDiff() = default;
 
 SyntaxTree::SyntaxTree(const ASTContext &AST)
-    : TreeImpl(llvm::make_unique<SyntaxTreeImpl>(
+    : TreeImpl(llvm::make_unique<SyntaxTree::Impl>(
           this, AST.getTranslationUnitDecl(), AST)) {}
 
 std::vector<Match> ASTDiff::getMatches() {
@@ -1012,7 +1009,7 @@ SyntaxTree::~SyntaxTree() = default;
 void SyntaxTree::printAsJson(raw_ostream &OS) { TreeImpl->printAsJsonImpl(OS); }
 
 std::string SyntaxTree::getNodeValue(const DynTypedNode &DTN) const {
-  return TreeImpl->getNodeValueImpl(DTN);
+  return TreeImpl->getNodeValue(DTN);
 }
 
 } // end namespace diff




More information about the cfe-commits mailing list