From: Justin Lebar Date: Mon, 10 Oct 2016 16:26:48 +0000 (+0000) Subject: [Analysis] Use unique_ptr for CallGraph::FunctionMap. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b28828e8b38c7e208386f783e6502305c42cb479;p=clang [Analysis] Use unique_ptr for CallGraph::FunctionMap. Reviewers: timshen Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25427 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283775 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/CallGraph.h b/include/clang/Analysis/CallGraph.h index 6ff1e7f939..ea1c4a01e1 100644 --- a/include/clang/Analysis/CallGraph.h +++ b/include/clang/Analysis/CallGraph.h @@ -34,7 +34,8 @@ class CallGraphNode; class CallGraph : public RecursiveASTVisitor { friend class CallGraphNode; - typedef llvm::DenseMap FunctionMapTy; + typedef llvm::DenseMap> + FunctionMapTy; /// FunctionMap owns all CallGraphNodes. FunctionMapTy FunctionMap; @@ -198,9 +199,11 @@ template <> struct GraphTraits static NodeType *getEntryNode(clang::CallGraph *CGN) { return CGN->getRoot(); // Start at the external node! } - typedef std::pair PairTy; - static clang::CallGraphNode *CGGetValue(PairTy P) { return P.second; } + static clang::CallGraphNode * + CGGetValue(clang::CallGraph::const_iterator::value_type &P) { + return P.second.get(); + } // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef mapped_iterator @@ -223,9 +226,11 @@ template <> struct GraphTraits : static NodeType *getEntryNode(const clang::CallGraph *CGN) { return CGN->getRoot(); } - typedef std::pair PairTy; - static clang::CallGraphNode *CGGetValue(PairTy P) { return P.second; } + static clang::CallGraphNode * + CGGetValue(clang::CallGraph::const_iterator::value_type &P) { + return P.second.get(); + } // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef mapped_iteratorsecond; + return I->second.get(); } CallGraphNode *CallGraph::getOrInsertNode(Decl *F) { if (F && !isa(F)) F = F->getCanonicalDecl(); - CallGraphNode *&Node = FunctionMap[F]; + std::unique_ptr &Node = FunctionMap[F]; if (Node) - return Node; + return Node.get(); - Node = new CallGraphNode(F); + Node = llvm::make_unique(F); // Make Root node a parent of all functions to make sure all are reachable. if (F) - Root->addCallee(Node, this); - return Node; + Root->addCallee(Node.get(), this); + return Node.get(); } void CallGraph::print(raw_ostream &OS) const {