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 (
80 ROSE_DLL_API
void getPropertiesForExpression(
SgExpression* exp,
82 Rose_STL_Container<SgFunctionDeclaration*>& propList,
83 bool includePureVirtualFunc =
false);
91 Rose_STL_Container<SgFunctionDefinition*>& calleeList);
97 Rose_STL_Container<SgFunctionDeclaration*>& calleeList,
98 bool includePureVirtualFunc =
false);
105 Rose_STL_Container<SgExpression*>& exps);
134 struct dummyFilter :
public std::unary_function<bool,SgFunctionDeclaration*>
141 struct ROSE_DLL_API
builtinFilter :
public std::unary_function<bool,SgFunctionDeclaration*>
151 void buildCallGraph();
153 template<
typename Predicate>
154 void buildCallGraph(Predicate pred);
160 boost::unordered_map<SgFunctionDeclaration*, SgGraphNode*>& getGraphNodesMapping(){
return graphNodes; }
171 typedef boost::unordered_map<SgFunctionDeclaration*, SgGraphNode*> GraphNodes;
172 GraphNodes graphNodes;
183 result_type operator()(
SgNode* node );
186 template<
typename Predicate>
193 isSelected(Predicate &pred): pred(pred) {}
194 bool operator()(
SgNode *node) {
200 if(isSgTemplateFunctionDeclaration(f)||isSgTemplateMemberFunctionDeclaration(f)) {
201 std::cerr<<
"Error: CallGraphBuilder: call referring to node "<<f->
class_name()<<
" :: function-name:"<<f->get_qualified_name()<<std::endl;
211 std::vector<FunctionData> callGraphData;
214 VariantVector vv(V_SgFunctionDeclaration);
216 std::vector<SgNode*> fdecl_nodes = NodeQuery::queryMemoryPool(defFunc, &vv);
217 BOOST_FOREACH(
SgNode *node, fdecl_nodes) {
221 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());
222 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());
227 printf (
"Collect function calls in unique function: unique = %p \n",unique);
230 callGraphData.push_back(fdata);
231 std::string functionName = unique->get_qualified_name().getString();
233 graphNode->set_SgNode(unique);
234 graphNodes[unique] = graphNode;
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 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)
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.
virtual std::string class_name() const ROSE_OVERRIDE
returns a string representing the class name
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 notion of an initializer for a variable declaration or expression in a func...
SgDeclarationStatement * get_firstNondefiningDeclaration() const
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member ...