]> granicus.if.org Git - clang/commitdiff
CallGraph: Add getNode() method, constify.
authorAnna Zaks <ganna@apple.com>
Fri, 9 Mar 2012 21:13:53 +0000 (21:13 +0000)
committerAnna Zaks <ganna@apple.com>
Fri, 9 Mar 2012 21:13:53 +0000 (21:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152439 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/CallGraph.h
lib/Analysis/CallGraph.cpp

index 156f890e4b145242c077e7249c380517de4a4f91..81926b9f87cc87b3907097ea4e5817ae259145b4 100644 (file)
@@ -27,7 +27,7 @@ class CallGraphNode;
 
 class CallGraph {
   friend class CallGraphNode;
-  typedef llvm::DenseMap<Decl *, CallGraphNode *> FunctionMapTy;
+  typedef llvm::DenseMap<const Decl *, CallGraphNode *> FunctionMapTy;
 
   /// FunctionMap owns all CallGraphNodes.
   FunctionMapTy FunctionMap;
@@ -51,6 +51,9 @@ public:
   /// \brief Populate the call graph with the functions in the given DeclContext.
   void addToCallGraph(DeclContext *DC);
 
+  /// \brief Lookup the node for the given declaration.
+  CallGraphNode *getNode(const Decl *) const;
+
   /// \brief Lookup the node for the given declaration. If none found, insert
   /// one into the graph.
   CallGraphNode *getOrInsertFunction(Decl *);
@@ -165,7 +168,7 @@ template <> struct GraphTraits<clang::CallGraph*>
   static NodeType *getEntryNode(clang::CallGraph *CGN) {
     return CGN->getRoot();  // Start at the external node!
   }
-  typedef std::pair<clang::Decl*, clang::CallGraphNode*> PairTy;
+  typedef std::pair<const clang::Decl*, clang::CallGraphNode*> PairTy;
   typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode&> DerefFun;
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
   typedef mapped_iterator<clang::CallGraph::iterator, DerefFun> nodes_iterator;
@@ -190,7 +193,7 @@ template <> struct GraphTraits<const clang::CallGraph*> :
   static NodeType *getEntryNode(const clang::CallGraph *CGN) {
     return CGN->getRoot();
   }
-  typedef std::pair<clang::Decl*, clang::CallGraphNode*> PairTy;
+  typedef std::pair<const clang::Decl*, clang::CallGraphNode*> PairTy;
   typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode&> DerefFun;
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
   typedef mapped_iterator<clang::CallGraph::const_iterator,
index ca73c4a161103d7825febe97eb59d0fd6fab8ee4..cc6e62c388ed96a744c10bcd7a69616dd6aa27cc 100644 (file)
@@ -136,6 +136,10 @@ void CallGraph::addToCallGraph(DeclContext *DC) {
   }
 }
 
+CallGraphNode *CallGraph::getNode(const Decl *F) const {
+  return FunctionMap.find(F)->second;
+}
+
 CallGraphNode *CallGraph::getOrInsertFunction(Decl *F) {
   CallGraphNode *&Node = FunctionMap[F];
   if (Node)