From: Martin Bohme Date: Mon, 12 Sep 2016 08:28:21 +0000 (+0000) Subject: [CFG] Add iterator_ranges to CFG and CFGBlock. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a0d69445f0a6c2921d671e4471d77fcfba13c842;p=clang [CFG] Add iterator_ranges to CFG and CFGBlock. Summary: (Needed for D23353.) Reviewers: alexfh Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D23842 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281200 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/CFG.h b/include/clang/Analysis/CFG.h index 6ee6ce10dd..d23ed77ded 100644 --- a/include/clang/Analysis/CFG.h +++ b/include/clang/Analysis/CFG.h @@ -22,6 +22,7 @@ #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Casting.h" #include "llvm/Support/raw_ostream.h" @@ -522,11 +523,15 @@ public: typedef AdjacentBlocks::const_iterator const_pred_iterator; typedef AdjacentBlocks::reverse_iterator pred_reverse_iterator; typedef AdjacentBlocks::const_reverse_iterator const_pred_reverse_iterator; + typedef llvm::iterator_range pred_range; + typedef llvm::iterator_range pred_const_range; typedef AdjacentBlocks::iterator succ_iterator; typedef AdjacentBlocks::const_iterator const_succ_iterator; typedef AdjacentBlocks::reverse_iterator succ_reverse_iterator; typedef AdjacentBlocks::const_reverse_iterator const_succ_reverse_iterator; + typedef llvm::iterator_range succ_range; + typedef llvm::iterator_range succ_const_range; pred_iterator pred_begin() { return Preds.begin(); } pred_iterator pred_end() { return Preds.end(); } @@ -538,6 +543,13 @@ public: const_pred_reverse_iterator pred_rbegin() const { return Preds.rbegin(); } const_pred_reverse_iterator pred_rend() const { return Preds.rend(); } + pred_range preds() { + return pred_range(pred_begin(), pred_end()); + } + pred_const_range preds() const { + return pred_const_range(pred_begin(), pred_end()); + } + succ_iterator succ_begin() { return Succs.begin(); } succ_iterator succ_end() { return Succs.end(); } const_succ_iterator succ_begin() const { return Succs.begin(); } @@ -548,6 +560,13 @@ public: const_succ_reverse_iterator succ_rbegin() const { return Succs.rbegin(); } const_succ_reverse_iterator succ_rend() const { return Succs.rend(); } + succ_range succs() { + return succ_range(succ_begin(), succ_end()); + } + succ_const_range succs() const { + return succ_const_range(succ_begin(), succ_end()); + } + unsigned succ_size() const { return Succs.size(); } bool succ_empty() const { return Succs.empty(); } @@ -840,6 +859,7 @@ public: typedef llvm::DenseMap::const_iterator synthetic_stmt_iterator; + typedef llvm::iterator_range synthetic_stmt_range; /// Iterates over synthetic DeclStmts in the CFG. /// @@ -855,6 +875,11 @@ public: return SyntheticDeclStmts.end(); } + /// \sa synthetic_stmt_begin + synthetic_stmt_range synthetic_stmts() const { + return synthetic_stmt_range(synthetic_stmt_begin(), synthetic_stmt_end()); + } + //===--------------------------------------------------------------------===// // Member templates useful for various batch operations over CFGs. //===--------------------------------------------------------------------===//