diff options
Diffstat (limited to 'include/clang/Analysis/CallGraph.h')
-rw-r--r-- | include/clang/Analysis/CallGraph.h | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/include/clang/Analysis/CallGraph.h b/include/clang/Analysis/CallGraph.h index 509de7b..5015eb6 100644 --- a/include/clang/Analysis/CallGraph.h +++ b/include/clang/Analysis/CallGraph.h @@ -39,15 +39,9 @@ class CallGraph : public RecursiveASTVisitor<CallGraph> { /// FunctionMap owns all CallGraphNodes. FunctionMapTy FunctionMap; - /// This is a virtual root node that has edges to all the global functions - - /// 'main' or functions accessible from other translation units. + /// This is a virtual root node that has edges to all the functions. CallGraphNode *Root; - /// The list of nodes that have no parent. These are unreachable from Root. - /// Declarations can get to this list due to impressions in the graph, for - /// example, we do not track functions whose addresses were taken. - llvm::SetVector<CallGraphNode *> ParentlessNodes; - public: CallGraph(); ~CallGraph(); @@ -91,34 +85,35 @@ public: /// failing to add a call edge due to the analysis imprecision. typedef llvm::SetVector<CallGraphNode *>::iterator nodes_iterator; typedef llvm::SetVector<CallGraphNode *>::const_iterator const_nodes_iterator; - nodes_iterator parentless_begin() { return ParentlessNodes.begin(); } - nodes_iterator parentless_end() { return ParentlessNodes.end(); } - const_nodes_iterator - parentless_begin() const { return ParentlessNodes.begin(); } - const_nodes_iterator - parentless_end() const { return ParentlessNodes.end(); } void print(raw_ostream &os) const; void dump() const; void viewGraph() const; + void addNodesForBlocks(DeclContext *D); + /// Part of recursive declaration visitation. We recursively visit all the - /// Declarations to collect the root functions. + /// declarations to collect the root functions. bool VisitFunctionDecl(FunctionDecl *FD) { // We skip function template definitions, as their semantics is // only determined when they are instantiated. - if (includeInGraph(FD)) + if (includeInGraph(FD)) { + // Add all blocks declared inside this function to the graph. + addNodesForBlocks(FD); // If this function has external linkage, anything could call it. // Note, we are not precise here. For example, the function could have // its address taken. addNodeForDecl(FD, FD->isGlobal()); + } return true; } /// Part of recursive declaration visitation. bool VisitObjCMethodDecl(ObjCMethodDecl *MD) { - if (includeInGraph(MD)) + if (includeInGraph(MD)) { + addNodesForBlocks(MD); addNodeForDecl(MD, true); + } return true; } @@ -144,15 +139,13 @@ private: Decl *FD; /// \brief The list of functions called from this node. - // Small vector might be more efficient since we are only tracking functions - // whose definition is in the current TU. - llvm::SmallVector<CallRecord, 5> CalledFunctions; + SmallVector<CallRecord, 5> CalledFunctions; public: CallGraphNode(Decl *D) : FD(D) {} - typedef llvm::SmallVector<CallRecord, 5>::iterator iterator; - typedef llvm::SmallVector<CallRecord, 5>::const_iterator const_iterator; + typedef SmallVector<CallRecord, 5>::iterator iterator; + typedef SmallVector<CallRecord, 5>::const_iterator const_iterator; /// Iterators through all the callees/children of the node. inline iterator begin() { return CalledFunctions.begin(); } @@ -165,13 +158,10 @@ public: void addCallee(CallGraphNode *N, CallGraph *CG) { CalledFunctions.push_back(N); - CG->ParentlessNodes.remove(N); } Decl *getDecl() const { return FD; } - StringRef getName() const; - void print(raw_ostream &os) const; void dump() const; }; @@ -203,7 +193,7 @@ template <> struct GraphTraits<const clang::CallGraphNode*> { typedef NodeType::const_iterator ChildIteratorType; static NodeType *getEntryNode(const clang::CallGraphNode *CGN) { return CGN; } static inline ChildIteratorType child_begin(NodeType *N) { return N->begin();} - static inline ChildIteratorType child_end (NodeType *N) { return N->end(); } + static inline ChildIteratorType child_end(NodeType *N) { return N->end(); } }; template <> struct GraphTraits<clang::CallGraph*> |