From b9acdb79a5792a20b6b749a532ee0c347cf4d915 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 26 Apr 2014 22:43:56 +0000 Subject: [LCG] Switch the node iterator to use the new fancy adaptor base. This is *much* cleaner, makes the iterator a full random access iterator, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207335 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/LazyCallGraph.h | 56 ++++++++--------------------------- 1 file changed, 13 insertions(+), 43 deletions(-) (limited to 'include') diff --git a/include/llvm/Analysis/LazyCallGraph.h b/include/llvm/Analysis/LazyCallGraph.h index 07ba0004bd..99e6fc25d9 100644 --- a/include/llvm/Analysis/LazyCallGraph.h +++ b/include/llvm/Analysis/LazyCallGraph.h @@ -113,60 +113,30 @@ public: /// be scanned for "calls" or uses of functions and its child information /// will be constructed. All of these results are accumulated and cached in /// the graph. - class iterator : public std::iterator { + class iterator : public iterator_adaptor_base< + iterator, NodeVectorImplT::iterator, Node> { friend class LazyCallGraph; friend class LazyCallGraph::Node; - /// \brief Nonce type to select the constructor for the end iterator. - struct IsAtEndT {}; - LazyCallGraph *G; NodeVectorImplT::iterator NI; - // Build the begin iterator for a node. - explicit iterator(LazyCallGraph &G, NodeVectorImplT &Nodes) - : G(&G), NI(Nodes.begin()) {} - - // Build the end iterator for a node. This is selected purely by overload. - iterator(LazyCallGraph &G, NodeVectorImplT &Nodes, IsAtEndT /*Nonce*/) - : G(&G), NI(Nodes.end()) {} + // Build the iterator for a specific position in a node list. + iterator(LazyCallGraph &G, NodeVectorImplT::iterator NI) + : iterator_adaptor_base(NI), G(&G) {} public: iterator() {} - bool operator==(const iterator &Arg) const { return NI == Arg.NI; } - bool operator!=(const iterator &Arg) const { return !operator==(Arg); } - reference operator*() const { - if (NI->is()) - return *NI->get(); + if (I->is()) + return *I->get(); - Function *F = NI->get(); + Function *F = I->get(); Node &ChildN = G->get(*F); - *NI = &ChildN; + *I = &ChildN; return ChildN; } - pointer operator->() const { return &operator*(); } - - iterator &operator++() { - ++NI; - return *this; - } - iterator operator++(int) { - iterator prev = *this; - ++*this; - return prev; - } - - iterator &operator--() { - --NI; - return *this; - } - iterator operator--(int) { - iterator next = *this; - --*this; - return next; - } }; /// \brief A node in the call graph. @@ -200,8 +170,8 @@ public: return F; }; - iterator begin() const { return iterator(*G, Callees); } - iterator end() const { return iterator(*G, Callees, iterator::IsAtEndT()); } + iterator begin() const { return iterator(*G, Callees.begin()); } + iterator end() const { return iterator(*G, Callees.end()); } /// Equality is defined as address equality. bool operator==(const Node &N) const { return this == &N; } @@ -309,8 +279,8 @@ public: LazyCallGraph(LazyCallGraph &&G); LazyCallGraph &operator=(LazyCallGraph &&RHS); - iterator begin() { return iterator(*this, EntryNodes); } - iterator end() { return iterator(*this, EntryNodes, iterator::IsAtEndT()); } + iterator begin() { return iterator(*this, EntryNodes.begin()); } + iterator end() { return iterator(*this, EntryNodes.end()); } postorder_scc_iterator postorder_scc_begin() { return postorder_scc_iterator(*this); -- cgit v1.2.3