1 #include <featureTests.h>
2 #ifdef ROSE_ENABLE_SOURCE_ANALYSIS
4 #ifndef CALL_GRAPH_TRAVERSE_H
5 #define CALL_GRAPH_TRAVERSE_H
51 bool operator == (
const Function &that)
const;
52 bool operator != (
const Function &that)
const;
55 bool lessThan(
const Function &that)
const;
57 bool operator < (
const Function &that)
const;
58 bool operator > (
const Function &that)
const;
59 bool operator <= (
const Function &that)
const;
60 bool operator >= (
const Function &that)
const;
74 SgInitializedNamePtrList get_params()
const;
76 std::string str(std::string indent=
"")
const;
82 std::set<SgGraphNode*> cgNodes;
101 bool operator == (
const CGFunction &that)
const;
102 bool operator != (
const CGFunction &that)
const;
104 bool operator < (
const CGFunction &that)
const;
105 bool operator > (
const CGFunction &that)
const;
106 bool operator <= (
const CGFunction &that)
const;
107 bool operator >= (
const CGFunction &that)
const;
124 enum direction {fw=0, bw=1};
128 std::set<SgGraphNode*>::iterator itn;
129 std::set<SgDirectedGraphEdge*> edges;
130 std::set<SgDirectedGraphEdge*>::iterator ite;
134 std::set<SgGraphNode*> visitedCGNodes;
154 itn = func->cgNodes.begin();
155 if(dir == fw) edges = func->graph->computeEdgeSetOut(*itn);
156 else edges = func->graph->computeEdgeSetIn(*itn);
159 advanceToNextValidPoint();
164 const CGFunction* getTarget(std::set<CGFunction> &functions)
167 SgGraphNode* target = (dir == fw ? (*ite)->get_to() : (*ite)->get_from());
168 ROSE_ASSERT(isSgFunctionDeclaration(target->get_SgNode()));
169 assert(!isSgTemplateFunctionDeclaration(target->get_SgNode()));
175 for(std::set<CGFunction>::const_iterator it = functions.begin(); it!=functions.end(); it++)
179 if((&(*it))->cgNodes.find(target) != (&(*it))->cgNodes.end())
186 ROSE_ASSERT(!
"Error finding the target function of a call graph edge when the target is not compiler generated!");
193 SgGraphNode* target = (dir == fw ? (*ite)->get_to() : (*ite)->get_from());
194 ROSE_ASSERT(isSgFunctionDeclaration(target->get_SgNode()));
195 assert(!isSgTemplateFunctionDeclaration(target->get_SgNode()));
196 Function result(isSgFunctionDeclaration(target->get_SgNode()));
200 void operator ++(
int )
204 advanceToNextValidPoint();
209 void advanceToNextValidPoint()
216 if(ite == edges.end())
223 if(itn != func->cgNodes.end())
226 if(dir == fw) edges = func->graph->computeEdgeSetOut(*itn);
227 else edges = func->graph->computeEdgeSetIn(*itn);
240 SgGraphNode* target = (dir == fw ? (*ite)->get_to() : (*ite)->get_from());
242 if(visitedCGNodes.find(target) != visitedCGNodes.end())
246 visitedCGNodes.insert(target);
253 bool operator == (
const iterator& that)
256 if(finished)
return that.finished;
257 else if(that.finished)
return finished;
260 return (dir == that.dir) &&
262 (edges == that.edges) &&
267 bool operator != (
const iterator& that)
268 {
return !((*this) == that); }
277 iterator successors()
const
279 iterator b(
this, iterator::fw);
284 iterator callers()
const
286 iterator b(
this, iterator::bw);
289 iterator predecessors()
const
291 iterator b(
this, iterator::bw);
311 std::set<CGFunction> functions;
315 std::map<const CGFunction*, int> numCallers;
321 std::set<const CGFunction*> noPred;
348 template <
class InheritedAttribute>
355 std::list<InheritedAttribute> fromCallers;
363 virtual InheritedAttribute visit(
const CGFunction* func, std::list<InheritedAttribute>& fromCallers)=0;
365 virtual InheritedAttribute defaultAttrVal() { InheritedAttribute val;
return val; }
369 std::map<const CGFunction*, funcRecord> &visitRecords,
370 std::set<std::pair<const CGFunction*, const CGFunction*> > &touchedEdges,
371 InheritedAttribute &fromCaller);
378 template <
class SynthesizedAttribute>
386 virtual SynthesizedAttribute visit(
const CGFunction* func, std::list<SynthesizedAttribute> fromCallees)=0;
388 virtual SynthesizedAttribute defaultAttrVal() { SynthesizedAttribute val;
return val; }
391 SynthesizedAttribute traverse_rec(
const CGFunction* fd,
392 std::map<const CGFunction*, SynthesizedAttribute> &visitRecords,
393 std::set<std::pair<const CGFunction*, const CGFunction*> > &touchedEdges);
406 std::list<const CGFunction*> remaining;
441 this->numCallers = numCallers;
446 this->numCallers = that.numCallers;
460 int getNumCallers(
const Function* fDecl);