r279326 - [GraphTraits] Make nodes_iterator dereference to NodeType*/NodeRef

Tim Shen via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 19 14:20:13 PDT 2016


Author: timshen
Date: Fri Aug 19 16:20:13 2016
New Revision: 279326

URL: http://llvm.org/viewvc/llvm-project?rev=279326&view=rev
Log:
[GraphTraits] Make nodes_iterator dereference to NodeType*/NodeRef

Currently nodes_iterator may dereference to a NodeType* or a NodeType&. Make them all dereference to NodeType*, which is NodeRef later.

Differential Revision: https://reviews.llvm.org/D23704
Differential Revision: https://reviews.llvm.org/D23705

Modified:
    cfe/trunk/include/clang/Analysis/Analyses/Dominators.h
    cfe/trunk/include/clang/Analysis/CFG.h
    cfe/trunk/include/clang/Analysis/CallGraph.h

Modified: cfe/trunk/include/clang/Analysis/Analyses/Dominators.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/Dominators.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/Dominators.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/Dominators.h Fri Aug 19 16:20:13 2016
@@ -181,14 +181,15 @@ template <> struct GraphTraits< ::clang:
     return N->end();
   }
 
-  typedef df_iterator< ::clang::DomTreeNode* > nodes_iterator;
+  typedef llvm::pointer_iterator<df_iterator<::clang::DomTreeNode *>>
+      nodes_iterator;
 
   static nodes_iterator nodes_begin(::clang::DomTreeNode *N) {
-    return df_begin(getEntryNode(N));
+    return nodes_iterator(df_begin(getEntryNode(N)));
   }
 
   static nodes_iterator nodes_end(::clang::DomTreeNode *N) {
-    return df_end(getEntryNode(N));
+    return nodes_iterator(df_end(getEntryNode(N)));
   }
 };
 
@@ -199,11 +200,11 @@ template <> struct GraphTraits< ::clang:
   }
 
   static nodes_iterator nodes_begin(::clang::DominatorTree *N) {
-    return df_begin(getEntryNode(N));
+    return nodes_iterator(df_begin(getEntryNode(N)));
   }
 
   static nodes_iterator nodes_end(::clang::DominatorTree *N) {
-    return df_end(getEntryNode(N));
+    return nodes_iterator(df_end(getEntryNode(N)));
   }
 };
 } // end namespace llvm

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Fri Aug 19 16:20:13 2016
@@ -761,55 +761,6 @@ public:
         AddCXXNewAllocator(false), AddCXXDefaultInitExprInCtors(false) {}
   };
 
-  /// \brief Provides a custom implementation of the iterator class to have the
-  /// same interface as Function::iterator - iterator returns CFGBlock
-  /// (not a pointer to CFGBlock).
-  class graph_iterator {
-  public:
-    typedef CFGBlock                        value_type;
-    typedef value_type&                     reference;
-    typedef value_type*                     pointer;
-    typedef BumpVector<CFGBlock*>::iterator ImplTy;
-
-    graph_iterator(const ImplTy &i) : I(i) {}
-
-    bool operator==(const graph_iterator &X) const { return I == X.I; }
-    bool operator!=(const graph_iterator &X) const { return I != X.I; }
-
-    reference operator*()    const { return **I; }
-    pointer operator->()     const { return  *I; }
-    operator CFGBlock* ()          { return  *I; }
-
-    graph_iterator &operator++() { ++I; return *this; }
-    graph_iterator &operator--() { --I; return *this; }
-
-  private:
-    ImplTy I;
-  };
-
-  class const_graph_iterator {
-  public:
-    typedef const CFGBlock                  value_type;
-    typedef value_type&                     reference;
-    typedef value_type*                     pointer;
-    typedef BumpVector<CFGBlock*>::const_iterator ImplTy;
-
-    const_graph_iterator(const ImplTy &i) : I(i) {}
-
-    bool operator==(const const_graph_iterator &X) const { return I == X.I; }
-    bool operator!=(const const_graph_iterator &X) const { return I != X.I; }
-
-    reference operator*() const { return **I; }
-    pointer operator->()  const { return  *I; }
-    operator CFGBlock* () const { return  *I; }
-
-    const_graph_iterator &operator++() { ++I; return *this; }
-    const_graph_iterator &operator--() { --I; return *this; }
-
-  private:
-    ImplTy I;
-  };
-
   /// buildCFG - Builds a CFG from an AST.
   static std::unique_ptr<CFG> buildCFG(const Decl *D, Stmt *AST, ASTContext *C,
                                        const BuildOptions &BO);
@@ -845,14 +796,10 @@ public:
   const_iterator            begin()       const    { return Blocks.begin(); }
   const_iterator            end()         const    { return Blocks.end(); }
 
-  graph_iterator nodes_begin() { return graph_iterator(Blocks.begin()); }
-  graph_iterator nodes_end() { return graph_iterator(Blocks.end()); }
-  const_graph_iterator nodes_begin() const {
-    return const_graph_iterator(Blocks.begin());
-  }
-  const_graph_iterator nodes_end() const {
-    return const_graph_iterator(Blocks.end());
-  }
+  iterator nodes_begin() { return iterator(Blocks.begin()); }
+  iterator nodes_end() { return iterator(Blocks.end()); }
+  const_iterator nodes_begin() const { return const_iterator(Blocks.begin()); }
+  const_iterator nodes_end() const { return const_iterator(Blocks.end()); }
 
   reverse_iterator          rbegin()               { return Blocks.rbegin(); }
   reverse_iterator          rend()                 { return Blocks.rend(); }
@@ -1062,7 +1009,7 @@ template <> struct GraphTraits<Inverse<c
 template <> struct GraphTraits< ::clang::CFG* >
     : public GraphTraits< ::clang::CFGBlock *>  {
 
-  typedef ::clang::CFG::graph_iterator nodes_iterator;
+  typedef ::clang::CFG::iterator nodes_iterator;
 
   static NodeType     *getEntryNode(::clang::CFG* F) { return &F->getEntry(); }
   static nodes_iterator nodes_begin(::clang::CFG* F) { return F->nodes_begin();}
@@ -1073,7 +1020,7 @@ template <> struct GraphTraits< ::clang:
 template <> struct GraphTraits<const ::clang::CFG* >
     : public GraphTraits<const ::clang::CFGBlock *>  {
 
-  typedef ::clang::CFG::const_graph_iterator nodes_iterator;
+  typedef ::clang::CFG::const_iterator nodes_iterator;
 
   static NodeType *getEntryNode( const ::clang::CFG* F) {
     return &F->getEntry();
@@ -1092,7 +1039,7 @@ template <> struct GraphTraits<const ::c
 template <> struct GraphTraits<Inverse< ::clang::CFG*> >
   : public GraphTraits<Inverse< ::clang::CFGBlock*> > {
 
-  typedef ::clang::CFG::graph_iterator nodes_iterator;
+  typedef ::clang::CFG::iterator nodes_iterator;
 
   static NodeType *getEntryNode( ::clang::CFG* F) { return &F->getExit(); }
   static nodes_iterator nodes_begin( ::clang::CFG* F) {return F->nodes_begin();}
@@ -1102,7 +1049,7 @@ template <> struct GraphTraits<Inverse<
 template <> struct GraphTraits<Inverse<const ::clang::CFG*> >
   : public GraphTraits<Inverse<const ::clang::CFGBlock*> > {
 
-  typedef ::clang::CFG::const_graph_iterator nodes_iterator;
+  typedef ::clang::CFG::const_iterator nodes_iterator;
 
   static NodeType *getEntryNode(const ::clang::CFG* F) { return &F->getExit(); }
   static nodes_iterator nodes_begin(const ::clang::CFG* F) {

Modified: cfe/trunk/include/clang/Analysis/CallGraph.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CallGraph.h?rev=279326&r1=279325&r2=279326&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CallGraph.h (original)
+++ cfe/trunk/include/clang/Analysis/CallGraph.h Fri Aug 19 16:20:13 2016
@@ -205,7 +205,8 @@ template <> struct GraphTraits<clang::Ca
     return CGN->getRoot();  // Start at the external node!
   }
   typedef std::pair<const clang::Decl*, clang::CallGraphNode*> PairTy;
-  typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode&> DerefFun;
+  typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode *>
+      DerefFun;
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
   typedef mapped_iterator<clang::CallGraph::iterator, DerefFun> nodes_iterator;
 
@@ -215,9 +216,7 @@ template <> struct GraphTraits<clang::Ca
   static nodes_iterator nodes_end  (clang::CallGraph *CG) {
     return map_iterator(CG->end(), DerefFun(CGdereference));
   }
-  static clang::CallGraphNode &CGdereference(PairTy P) {
-    return *(P.second);
-  }
+  static clang::CallGraphNode *CGdereference(PairTy P) { return P.second; }
 
   static unsigned size(clang::CallGraph *CG) {
     return CG->size();
@@ -230,7 +229,8 @@ template <> struct GraphTraits<const cla
     return CGN->getRoot();
   }
   typedef std::pair<const clang::Decl*, clang::CallGraphNode*> PairTy;
-  typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode&> DerefFun;
+  typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode *>
+      DerefFun;
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
   typedef mapped_iterator<clang::CallGraph::const_iterator,
                           DerefFun> nodes_iterator;
@@ -241,9 +241,7 @@ template <> struct GraphTraits<const cla
   static nodes_iterator nodes_end(const clang::CallGraph *CG) {
     return map_iterator(CG->end(), DerefFun(CGdereference));
   }
-  static clang::CallGraphNode &CGdereference(PairTy P) {
-    return *(P.second);
-  }
+  static clang::CallGraphNode *CGdereference(PairTy P) { return P.second; }
 
   static unsigned size(const clang::CallGraph *CG) {
     return CG->size();




More information about the cfe-commits mailing list