5#include <GraphDotOutput.h>
6#include <VirtualGraphCreate.h>
8#include "AstDiagnostics.h"
15#include <boost/foreach.hpp>
16#include <boost/unordered_map.hpp>
18#include "ClassHierarchyGraph.h"
27namespace CallTargetSet
41 std::vector<SgFunctionDeclaration*> solveFunctionPointerCall (
SgPointerDerefExp *);
60 Rose_STL_Container<SgFunctionDeclaration*> solveFunctionPointerCallsFunctional(
SgNode* node,
SgFunctionType* functionType );
64 std::vector<SgFunctionDeclaration*> solveMemberFunctionCall (
71 ROSE_DLL_API
void getPropertiesForExpression(
SgExpression* exp,
73 Rose_STL_Container<SgFunctionDeclaration*>& propList,
74 bool includePureVirtualFunc =
false);
82 Rose_STL_Container<SgFunctionDefinition*>& calleeList);
88 Rose_STL_Container<SgFunctionDeclaration*>& calleeList,
89 bool includePureVirtualFunc =
false);
96 Rose_STL_Container<SgExpression*>& exps);
127 using result_type = bool;
135 using result_type = bool;
146 template<
typename Predicate>
147 void buildCallGraph(Predicate pred);
153 boost::unordered_map<SgFunctionDeclaration*, SgGraphNode*>& getGraphNodesMapping(){
return graphNodes; }
164 typedef boost::unordered_map<SgFunctionDeclaration*, SgGraphNode*> GraphNodes;
165 GraphNodes graphNodes;
175 using result_type = Rose_STL_Container<SgNode*>;
176 result_type operator()(
SgNode* node);
179template<
typename Predicate>
186 isSelected(Predicate &pred): pred(pred) {}
187 bool operator()(
SgNode *node) {
193 if(isSgTemplateFunctionDeclaration(f)||isSgTemplateMemberFunctionDeclaration(f)) {
194 std::cerr<<
"Error: CallGraphBuilder: call referring to node "<<f->
class_name()<<
" :: function-name:"<<f->get_qualified_name()<<std::endl;
204 std::vector<FunctionData> callGraphData;
207 VariantVector vv(V_SgFunctionDeclaration);
209 std::vector<SgNode*> fdecl_nodes = NodeQuery::queryMemoryPool(defFunc, &vv);
210 BOOST_FOREACH(
SgNode *node, fdecl_nodes) {
214 printf (
"In buildCallGraph(): loop over functions from memory pool: fdecl = %p = %s name = %s \n",fdecl,fdecl->
class_name().c_str(),fdecl->get_name().str());
215 printf (
"In buildCallGraph(): loop over functions from memory pool: unique = %p = %s name = %s \n",unique,unique->
class_name().c_str(),unique->get_name().str());
220 printf (
"Collect function calls in unique function: unique = %p \n",unique);
223 callGraphData.push_back(fdata);
224 std::string functionName = unique->get_qualified_name().getString();
226 graphNode->set_SgNode(unique);
227 graphNodes[unique] = graphNode;
229 printf(
"Added function %s %p\n", functionName.c_str(), unique);
234 printf (
"Function not selected for processing: unique = %p \n",unique);
235 printf (
" --- isSelected(pred)(unique) = %s \n",isSelected(pred)(unique) ?
"true" :
"false");
236 printf (
" --- graphNodes.find(unique)==graphNodes.end() = %s \n",graphNodes.find(unique)==graphNodes.end() ?
"true" :
"false");
242 BOOST_FOREACH(
FunctionData ¤tFunction, callGraphData) {
244 std::string curFuncName = curFuncDecl->get_qualified_name().getString();
246 ROSE_ASSERT(srcNode != NULL);
247 std::vector<SgFunctionDeclaration*> & callees = currentFunction.
functionList;
249 if (isSelected(pred)(callee)) {
251 ROSE_ASSERT(dstNode != NULL);
252 if (graph->checkIfDirectedGraphEdgeExists(srcNode, dstNode) ==
false)
SgIncidenceDirectedGraph * getGraph()
Grab the call graph built.
SgGraphNode * hasGraphNodeFor(SgFunctionDeclaration *fdecl) const
Retrieve the node matching a function declaration using firstNondefiningDeclaration (does not work ac...
void buildCallGraph()
Default builder filtering nothing in the call graph.
SgGraphNode * getGraphNodeFor(SgFunctionDeclaration *fdecl) const
Retrieve the node matching a function declaration (using mangled name to resolve across translation u...
Rose_STL_Container< SgFunctionDeclaration * > functionList
All the callees of this function.
This class represents the call of a class constructor to initialize a variable. For example "Foo foo;...
SgDeclarationStatement * get_firstNondefiningDeclaration() const
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
This class represents the concept of a function declaration statement.
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
This class represents a type for all functions.
SgGraphNode * addNode(const std::string &name="", SgNode *sg_node=NULL)
Support for adding SgGraphNode to SgGraph.
SgDirectedGraphEdge * addDirectedEdge(SgGraphNode *a, SgGraphNode *b, const std::string &name="")
Support for adding SgGraphEdge to SgGraph.
This class represents the concept of a member function declaration statement.
This class represents the base class for all IR nodes within Sage III.
This class represents a source project, with a list of SgFile objects and global information about th...
A function object to filter out builtin functions in a call graph (only non-builtin functions will be...
A function object to be used as a predicate to filter out functions in a call graph: it does not filt...