5#include <AstInterface.h>
6#include <GraphDotOutput.h>
7#include <VirtualGraphCreate.h>
9#include "AstDiagnostics.h"
16#include <boost/foreach.hpp>
17#include <boost/unordered_map.hpp>
21typedef Rose_STL_Container<SgFunctionDeclaration *> SgFunctionDeclarationPtrList;
22typedef Rose_STL_Container<SgClassDefinition *> SgClassDefinitionPtrList;
27#include "ClassHierarchyGraph.h"
31namespace CallTargetSet
33 typedef Rose_STL_Container<SgFunctionDeclaration *> SgFunctionDeclarationPtrList;
34 typedef Rose_STL_Container<SgClassDefinition *> SgClassDefinitionPtrList;
47 std::vector<SgFunctionDeclaration*> solveFunctionPointerCall (
SgPointerDerefExp *);
66 Rose_STL_Container<SgFunctionDeclaration*> solveFunctionPointerCallsFunctional(
SgNode* node,
SgFunctionType* functionType );
70 std::vector<SgFunctionDeclaration*> solveMemberFunctionCall (
77 ROSE_DLL_API
void getPropertiesForExpression(
SgExpression* exp,
79 Rose_STL_Container<SgFunctionDeclaration*>& propList,
80 bool includePureVirtualFunc =
false);
88 Rose_STL_Container<SgFunctionDefinition*>& calleeList);
94 Rose_STL_Container<SgFunctionDeclaration*>& calleeList,
95 bool includePureVirtualFunc =
false);
102 Rose_STL_Container<SgExpression*>& exps);
133 using result_type = bool;
141 using result_type = bool;
152 template<
typename Predicate>
153 void buildCallGraph(Predicate pred);
159 boost::unordered_map<SgFunctionDeclaration*, SgGraphNode*>& getGraphNodesMapping(){
return graphNodes; }
170 typedef boost::unordered_map<SgFunctionDeclaration*, SgGraphNode*> GraphNodes;
171 GraphNodes graphNodes;
181 using result_type = Rose_STL_Container<SgNode*>;
182 result_type operator()(
SgNode* node);
185template<
typename Predicate>
192 isSelected(Predicate &pred): pred(pred) {}
193 bool operator()(
SgNode *node) {
199 if(isSgTemplateFunctionDeclaration(f)||isSgTemplateMemberFunctionDeclaration(f)) {
200 std::cerr<<
"Error: CallGraphBuilder: call referring to node "<<f->
class_name()<<
" :: function-name:"<<f->get_qualified_name()<<std::endl;
210 std::vector<FunctionData> callGraphData;
213 VariantVector vv(V_SgFunctionDeclaration);
215 std::vector<SgNode*> fdecl_nodes = NodeQuery::queryMemoryPool(defFunc, &vv);
216 BOOST_FOREACH(
SgNode *node, fdecl_nodes) {
220 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());
221 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());
226 printf (
"Collect function calls in unique function: unique = %p \n",unique);
229 callGraphData.push_back(fdata);
230 std::string functionName = unique->get_qualified_name().getString();
232 graphNode->set_SgNode(unique);
233 graphNodes[unique] = graphNode;
235 printf(
"Added function %s %p\n", functionName.c_str(), unique);
240 printf (
"Function not selected for processing: unique = %p \n",unique);
241 printf (
" --- isSelected(pred)(unique) = %s \n",isSelected(pred)(unique) ?
"true" :
"false");
242 printf (
" --- graphNodes.find(unique)==graphNodes.end() = %s \n",graphNodes.find(unique)==graphNodes.end() ?
"true" :
"false");
248 BOOST_FOREACH(
FunctionData ¤tFunction, callGraphData) {
250 std::string curFuncName = curFuncDecl->get_qualified_name().getString();
252 ROSE_ASSERT(srcNode != NULL);
253 std::vector<SgFunctionDeclaration*> & callees = currentFunction.
functionList;
255 if (isSelected(pred)(callee)) {
257 ROSE_ASSERT(dstNode != NULL);
258 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...