diff options
Diffstat (limited to 'include/clang/Analysis/CFG.h')
-rw-r--r-- | include/clang/Analysis/CFG.h | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/include/clang/Analysis/CFG.h b/include/clang/Analysis/CFG.h index 34dedc074a..dab718cbac 100644 --- a/include/clang/Analysis/CFG.h +++ b/include/clang/Analysis/CFG.h @@ -65,27 +65,27 @@ class CFGBlock { /// statements in the block. When this variable is non-NULL, it is /// either an instance of LabelStmt or SwitchCase. Stmt *Label; - + /// Terminator - The terminator for a basic block that /// indicates the type of control-flow that occurs between a block /// and its successors. Stmt *Terminator; - + /// LoopTarget - Some blocks are used to represent the "loop edge" to /// the start of a loop from within the loop body. This Stmt* will be /// refer to the loop statement for such blocks (and be null otherwise). - const Stmt *LoopTarget; - + const Stmt *LoopTarget; + /// BlockID - A numerical ID assigned to a CFGBlock during construction /// of the CFG. unsigned BlockID; - + /// Predecessors/Successors - Keep track of the predecessor / successor /// CFG blocks. typedef std::vector<CFGBlock*> AdjacentBlocks; AdjacentBlocks Preds; AdjacentBlocks Succs; - + public: explicit CFGBlock(unsigned blockid) : Label(NULL), Terminator(NULL), LoopTarget(NULL), BlockID(blockid) {} @@ -96,25 +96,25 @@ public: typedef StatementListTy::const_iterator const_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; - + Stmt* front() const { return Stmts.front(); } Stmt* back() const { return Stmts.back(); } - + iterator begin() { return Stmts.begin(); } iterator end() { return Stmts.end(); } const_iterator begin() const { return Stmts.begin(); } - const_iterator end() const { return Stmts.end(); } + const_iterator end() const { return Stmts.end(); } reverse_iterator rbegin() { return Stmts.rbegin(); } reverse_iterator rend() { return Stmts.rend(); } const_reverse_iterator rbegin() const { return Stmts.rbegin(); } const_reverse_iterator rend() const { return Stmts.rend(); } - + unsigned size() const { return Stmts.size(); } bool empty() const { return Stmts.empty(); } Stmt* operator[](size_t i) const { assert (i < size()); return Stmts[i]; } - + // CFG iterators typedef AdjacentBlocks::iterator pred_iterator; typedef AdjacentBlocks::const_iterator const_pred_iterator; @@ -125,22 +125,22 @@ public: typedef AdjacentBlocks::const_iterator const_succ_iterator; typedef AdjacentBlocks::reverse_iterator succ_reverse_iterator; typedef AdjacentBlocks::const_reverse_iterator const_succ_reverse_iterator; - + pred_iterator pred_begin() { return Preds.begin(); } pred_iterator pred_end() { return Preds.end(); } const_pred_iterator pred_begin() const { return Preds.begin(); } const_pred_iterator pred_end() const { return Preds.end(); } - + pred_reverse_iterator pred_rbegin() { return Preds.rbegin(); } - pred_reverse_iterator pred_rend() { return Preds.rend(); } + pred_reverse_iterator pred_rend() { return Preds.rend(); } const_pred_reverse_iterator pred_rbegin() const { return Preds.rbegin(); } const_pred_reverse_iterator pred_rend() const { return Preds.rend(); } - succ_iterator succ_begin() { return Succs.begin(); } + succ_iterator succ_begin() { return Succs.begin(); } succ_iterator succ_end() { return Succs.end(); } const_succ_iterator succ_begin() const { return Succs.begin(); } - const_succ_iterator succ_end() const { return Succs.end(); } - + const_succ_iterator succ_end() const { return Succs.end(); } + succ_reverse_iterator succ_rbegin() { return Succs.rbegin(); } succ_reverse_iterator succ_rend() { return Succs.rend(); } const_succ_reverse_iterator succ_rbegin() const { return Succs.rbegin(); } @@ -151,9 +151,9 @@ public: unsigned pred_size() const { return Preds.size(); } bool pred_empty() const { return Preds.empty(); } - + // Manipulation of block contents - + void appendStmt(Stmt* Statement) { Stmts.push_back(Statement); } void setTerminator(Stmt* Statement) { Terminator = Statement; } void setLabel(Stmt* Statement) { Label = Statement; } @@ -161,35 +161,35 @@ public: Stmt* getTerminator() { return Terminator; } const Stmt* getTerminator() const { return Terminator; } - + Stmt* getTerminatorCondition(); - + const Stmt* getTerminatorCondition() const { return const_cast<CFGBlock*>(this)->getTerminatorCondition(); } - + const Stmt *getLoopTarget() const { return LoopTarget; } - + bool hasBinaryBranchTerminator() const; - + Stmt* getLabel() { return Label; } const Stmt* getLabel() const { return Label; } - + void reverseStmts(); - + void addSuccessor(CFGBlock* Block) { if (Block) Block->Preds.push_back(this); Succs.push_back(Block); } - + unsigned getBlockID() const { return BlockID; } - + void dump(const CFG *cfg, const LangOptions &LO) const; void print(llvm::raw_ostream &OS, const CFG* cfg, const LangOptions &LO) const; void printTerminator(llvm::raw_ostream &OS, const LangOptions &LO) const; }; - + /// CFG - Represents a source-level, intra-procedural CFG that represents the /// control-flow of a Stmt. The Stmt can represent an entire function body, @@ -205,28 +205,28 @@ public: //===--------------------------------------------------------------------===// /// buildCFG - Builds a CFG from an AST. The responsibility to free the - /// constructed CFG belongs to the caller. - static CFG* buildCFG(Stmt* AST, ASTContext *C); - + /// constructed CFG belongs to the caller. + static CFG* buildCFG(Stmt* AST, ASTContext *C); + /// createBlock - Create a new block in the CFG. The CFG owns the block; /// the caller should not directly free it. CFGBlock* createBlock(); - + /// setEntry - Set the entry block of the CFG. This is typically used /// only during CFG construction. Most CFG clients expect that the /// entry block has no predecessors and contains no statements. void setEntry(CFGBlock *B) { Entry = B; } - + /// setIndirectGotoBlock - Set the block used for indirect goto jumps. /// This is typically used only during CFG construction. void setIndirectGotoBlock(CFGBlock* B) { IndirectGotoBlock = B; } - + //===--------------------------------------------------------------------===// // Block Iterators //===--------------------------------------------------------------------===// typedef std::list<CFGBlock> CFGBlockListTy; - + typedef CFGBlockListTy::iterator iterator; typedef CFGBlockListTy::const_iterator const_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; @@ -234,17 +234,17 @@ public: CFGBlock& front() { return Blocks.front(); } CFGBlock& back() { return Blocks.back(); } - + iterator begin() { return Blocks.begin(); } iterator end() { return Blocks.end(); } const_iterator begin() const { return Blocks.begin(); } - const_iterator end() const { return Blocks.end(); } - + const_iterator end() const { return Blocks.end(); } + reverse_iterator rbegin() { return Blocks.rbegin(); } reverse_iterator rend() { return Blocks.rend(); } const_reverse_iterator rbegin() const { return Blocks.rbegin(); } const_reverse_iterator rend() const { return Blocks.rend(); } - + CFGBlock& getEntry() { return *Entry; } const CFGBlock& getEntry() const { return *Entry; } CFGBlock& getExit() { return *Exit; } @@ -252,18 +252,18 @@ public: CFGBlock* getIndirectGotoBlock() { return IndirectGotoBlock; } const CFGBlock* getIndirectGotoBlock() const { return IndirectGotoBlock; } - + //===--------------------------------------------------------------------===// // Member templates useful for various batch operations over CFGs. //===--------------------------------------------------------------------===// - + template <typename CALLBACK> void VisitBlockStmts(CALLBACK& O) const { for (const_iterator I=begin(), E=end(); I != E; ++I) for (CFGBlock::const_iterator BI=I->begin(), BE=I->end(); BI != BE; ++BI) O(*BI); - } - + } + //===--------------------------------------------------------------------===// // CFG Introspection. //===--------------------------------------------------------------------===// @@ -275,11 +275,11 @@ public: operator bool() const { return Idx >= 0; } operator unsigned() const { assert(Idx >=0); return (unsigned) Idx; } }; - + bool isBlkExpr(const Stmt* S) { return getBlkExprNum(S); } BlkExprNumTy getBlkExprNum(const Stmt* S); unsigned getNumBlkExprs(); - + /// getNumBlockIDs - Returns the total number of BlockIDs allocated (which /// start at 0). unsigned getNumBlockIDs() const { return NumBlockIDs; } @@ -296,15 +296,15 @@ public: // Internal: constructors and data. //===--------------------------------------------------------------------===// - CFG() : Entry(NULL), Exit(NULL), IndirectGotoBlock(NULL), NumBlockIDs(0), + CFG() : Entry(NULL), Exit(NULL), IndirectGotoBlock(NULL), NumBlockIDs(0), BlkExprMap(NULL) {}; - + ~CFG(); - + llvm::BumpPtrAllocator& getAllocator() { return Alloc; } - + private: CFGBlock* Entry; CFGBlock* Exit; @@ -312,14 +312,14 @@ private: // for indirect gotos CFGBlockListTy Blocks; unsigned NumBlockIDs; - + // BlkExprMap - An opaque pointer to prevent inclusion of DenseMap.h. - // It represents a map from Expr* to integers to record the set of + // It represents a map from Expr* to integers to record the set of // block-level expressions and their "statement number" in the CFG. void* BlkExprMap; - + /// Alloc - An internal allocator. - llvm::BumpPtrAllocator Alloc; + llvm::BumpPtrAllocator Alloc; }; } // end namespace clang @@ -334,13 +334,13 @@ namespace llvm { template <> struct GraphTraits<clang::CFGBlock* > { typedef clang::CFGBlock NodeType; typedef clang::CFGBlock::succ_iterator ChildIteratorType; - + static NodeType* getEntryNode(clang::CFGBlock* BB) { return BB; } static inline ChildIteratorType child_begin(NodeType* N) { return N->succ_begin(); } - + static inline ChildIteratorType child_end(NodeType* N) { return N->succ_end(); } }; @@ -348,13 +348,13 @@ template <> struct GraphTraits<clang::CFGBlock* > { template <> struct GraphTraits<const clang::CFGBlock* > { typedef const clang::CFGBlock NodeType; typedef clang::CFGBlock::const_succ_iterator ChildIteratorType; - + static NodeType* getEntryNode(const clang::CFGBlock* BB) { return BB; } - + static inline ChildIteratorType child_begin(NodeType* N) { return N->succ_begin(); } - + static inline ChildIteratorType child_end(NodeType* N) { return N->succ_end(); } }; @@ -368,27 +368,27 @@ template <> struct GraphTraits<Inverse<const clang::CFGBlock*> > { static inline ChildIteratorType child_begin(NodeType* N) { return N->pred_begin(); } - + static inline ChildIteratorType child_end(NodeType* N) { return N->pred_end(); } }; // Traits for: CFG -template <> struct GraphTraits<clang::CFG* > +template <> struct GraphTraits<clang::CFG* > : public GraphTraits<clang::CFGBlock* > { typedef clang::CFG::iterator nodes_iterator; - - static NodeType *getEntryNode(clang::CFG* F) { return &F->getEntry(); } + + static NodeType *getEntryNode(clang::CFG* F) { return &F->getEntry(); } static nodes_iterator nodes_begin(clang::CFG* F) { return F->begin(); } static nodes_iterator nodes_end(clang::CFG* F) { return F->end(); } }; -template <> struct GraphTraits< const clang::CFG* > +template <> struct GraphTraits< const clang::CFG* > : public GraphTraits< const clang::CFGBlock* > { - typedef clang::CFG::const_iterator nodes_iterator; + typedef clang::CFG::const_iterator nodes_iterator; static NodeType *getEntryNode( const clang::CFG* F) { return &F->getEntry(); } static nodes_iterator nodes_begin( const clang::CFG* F) { return F->begin(); } @@ -404,7 +404,7 @@ template <> struct GraphTraits<Inverse<const clang::CFG*> > static nodes_iterator nodes_begin(const clang::CFG* F) { return F->begin();} static nodes_iterator nodes_end(const clang::CFG* F) { return F->end(); } }; - + } // end llvm namespace #endif |