From 7e0ae6fcf322101962715b1477c8105983034bba Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Fri, 19 Aug 2016 21:20:13 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279326 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Analysis/Analyses/Dominators.h | 11 ++-- include/clang/Analysis/CFG.h | 69 +++----------------- include/clang/Analysis/CallGraph.h | 14 ++-- 3 files changed, 20 insertions(+), 74 deletions(-) diff --git a/include/clang/Analysis/Analyses/Dominators.h b/include/clang/Analysis/Analyses/Dominators.h index c64a3ca255..df6118dc2e 100644 --- a/include/clang/Analysis/Analyses/Dominators.h +++ b/include/clang/Analysis/Analyses/Dominators.h @@ -181,14 +181,15 @@ template <> struct GraphTraits< ::clang::DomTreeNode* > { return N->end(); } - typedef df_iterator< ::clang::DomTreeNode* > nodes_iterator; + typedef llvm::pointer_iterator> + 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::DominatorTree* > } 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 diff --git a/include/clang/Analysis/CFG.h b/include/clang/Analysis/CFG.h index 02fbf37e9f..29d20089f4 100644 --- a/include/clang/Analysis/CFG.h +++ b/include/clang/Analysis/CFG.h @@ -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::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::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 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 > { 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::CFG* > template <> struct GraphTraits : public GraphTraits { - 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 template <> struct GraphTraits > : public GraphTraits > { - 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 > template <> struct GraphTraits > : public GraphTraits > { - 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) { diff --git a/include/clang/Analysis/CallGraph.h b/include/clang/Analysis/CallGraph.h index 241ecd54d3..303fbcec52 100644 --- a/include/clang/Analysis/CallGraph.h +++ b/include/clang/Analysis/CallGraph.h @@ -205,7 +205,8 @@ template <> struct GraphTraits return CGN->getRoot(); // Start at the external node! } typedef std::pair PairTy; - typedef std::pointer_to_unary_function DerefFun; + typedef std::pointer_to_unary_function + DerefFun; // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef mapped_iterator nodes_iterator; @@ -215,9 +216,7 @@ template <> struct GraphTraits 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 : return CGN->getRoot(); } typedef std::pair PairTy; - typedef std::pointer_to_unary_function DerefFun; + typedef std::pointer_to_unary_function + DerefFun; // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef mapped_iterator nodes_iterator; @@ -241,9 +241,7 @@ template <> struct GraphTraits : 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(); -- 2.40.0