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>
21 typedef Rose_STL_Container<SgFunctionDeclaration *> SgFunctionDeclarationPtrList;
22 typedef Rose_STL_Container<SgClassDefinition *> SgClassDefinitionPtrList;
27 #include "ClassHierarchyGraph.h"
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);
131 struct dummyFilter :
public std::unary_function<bool,SgFunctionDeclaration*>
138 struct ROSE_DLL_API
builtinFilter :
public std::unary_function<bool,SgFunctionDeclaration*>
148 void buildCallGraph();
150 template<
typename Predicate>
151 void buildCallGraph(Predicate pred);
157 boost::unordered_map<SgFunctionDeclaration*, SgGraphNode*>& getGraphNodesMapping(){
return graphNodes; }
168 typedef boost::unordered_map<SgFunctionDeclaration*, SgGraphNode*> GraphNodes;
169 GraphNodes graphNodes;
180 result_type operator()(
SgNode* node );
183 template<
typename Predicate>
190 isSelected(Predicate &pred): pred(pred) {}
191 bool operator()(
SgNode *node) {
197 if(isSgTemplateFunctionDeclaration(f)||isSgTemplateMemberFunctionDeclaration(f)) {
198 std::cerr<<
"Error: CallGraphBuilder: call referring to node "<<f->
class_name()<<
" :: function-name:"<<f->get_qualified_name()<<std::endl;
208 std::vector<FunctionData> callGraphData;
211 VariantVector vv(V_SgFunctionDeclaration);
213 std::vector<SgNode*> fdecl_nodes = NodeQuery::queryMemoryPool(defFunc, &vv);
214 BOOST_FOREACH(
SgNode *node, fdecl_nodes) {
218 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());
219 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());
224 printf (
"Collect function calls in unique function: unique = %p \n",unique);
227 callGraphData.push_back(fdata);
228 std::string functionName = unique->get_qualified_name().getString();
230 graphNode->set_SgNode(unique);
231 graphNodes[unique] = graphNode;
233 printf(
"Added function %s %p\n", functionName.c_str(), unique);
238 printf (
"Function not selected for processing: unique = %p \n",unique);
239 printf (
" --- isSelected(pred)(unique) = %s \n",isSelected(pred)(unique) ?
"true" :
"false");
240 printf (
" --- graphNodes.find(unique)==graphNodes.end() = %s \n",graphNodes.find(unique)==graphNodes.end() ?
"true" :
"false");
246 BOOST_FOREACH(
FunctionData ¤tFunction, callGraphData) {
248 std::string curFuncName = curFuncDecl->get_qualified_name().getString();
250 ROSE_ASSERT(srcNode != NULL);
251 std::vector<SgFunctionDeclaration*> & callees = currentFunction.
functionList;
253 if (isSelected(pred)(callee)) {
255 ROSE_ASSERT(dstNode != NULL);
256 if (graph->checkIfDirectedGraphEdgeExists(srcNode, dstNode) ==
false)
virtual std::string class_name() const override
returns a string representing the class name
SgGraphNode * getGraphNodeFor(SgFunctionDeclaration *fdecl) const
Retrieve the node matching a function declaration (using mangled name to resolve across translation u...
A function object to filter out builtin functions in a call graph (only non-builtin functions will be...
Rose_STL_Container< SgFunctionDeclaration * > functionList
All the callees of this function.
This class represents the concept of a member function declaration statement.
This class represents the concept of a function declaration statement.
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
void buildCallGraph()
Default builder filtering nothing in the call graph.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code.
This class represents the base class for all IR nodes within Sage III.
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.
SgGraphNode * hasGraphNodeFor(SgFunctionDeclaration *fdecl) const
Retrieve the node matching a function declaration using firstNondefiningDeclaration (does not work ac...
This class represents a type for all functions.
This class represents a source project, with a list of SgFile objects and global information about th...
A function object to be used as a predicate to filter out functions in a call graph: it does not filt...
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 ...