ROSE  0.11.96.11
DataflowCFG.h
1 #include <featureTests.h>
2 #ifdef ROSE_ENABLE_SOURCE_ANALYSIS
3 
4 #ifndef DATAFLOW_CFG_H
5 #define DATAFLOW_CFG_H
6 
7 #include "genericDataflowCommon.h"
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 namespace VirtualCFG {
13 
14 // "Interesting" node and edge filters for use with dataflow analyses
15 class DataflowEdge;
16 
17 bool defaultFilter (CFGNode cfgn);
18 
19 class DataflowNode {
20  public:
21  CFGNode n;
22  bool (*filter) (CFGNode cfgn); // a filter function to decide which raw CFG node to show (if return true) or hide (otherwise)
23 
24  // We enforce the user codes (the framework) of DataflowNode to explicitly set filter, or provide default filter on their own
25  DataflowNode(CFGNode n, bool (*f) (CFGNode)): n(n), filter(f) {}
26  // By default, the default filter function is used unless otherwise specified
27 // DataflowNode(CFGNode n, bool (*f) (CFGNode) = defaultFilter): n(n), filter(f) {}
28  DataflowNode(const DataflowNode& dfn): n(dfn.n), filter (dfn.filter) {}
29 
30  std::string toString() const {return n.toString();}
31  std::string toStringForDebugging() const {return n.toStringForDebugging();}
32  std::string id() const {return n.id();}
33  SgNode* getNode() const {return n.getNode();}
34  unsigned int getIndex() const {return n.getIndex();}
35  std::vector<DataflowEdge> outEdges() const;
36  std::vector<DataflowEdge> inEdges() const;
37  bool isInteresting() const;
38  bool operator==(const DataflowNode& o) const {return n == o.n;}
39  bool operator!=(const DataflowNode& o) const {return !(*this == o);}
40  bool operator<(const DataflowNode& o) const {return n < o.n;}
41 
42  std::string str(std::string indent="") const;
43 };
44 
45 typedef std::map<SgNode*, DataflowNode> m_AST2CFG;
46 
47 class DataflowEdge {
48  CFGPath p;
49  bool (*filter) (CFGNode cfgn);
50 
51  public:
52 // DataflowEdge(CFGPath p, bool (*f) (CFGNode) = defaultFilter): p(p), filter(f) {}
53  DataflowEdge(CFGPath p, bool (*f) (CFGNode) ): p(p), filter(f) {}
54  DataflowEdge(const DataflowEdge& dfe): p(dfe.p), filter(dfe.filter) {}
55 
56  std::string toString() const {return p.toString();}
57  std::string toStringForDebugging() const {return p.toStringForDebugging();}
58  std::string id() const {return p.id();}
59  DataflowNode source() const {return DataflowNode(p.source(), filter);}
60  DataflowNode target() const {return DataflowNode(p.target(), filter);}
61  EdgeConditionKind condition() const {return p.condition();}
62  SgExpression* caseLabel() const {return p.caseLabel();}
63  SgExpression* conditionBasedOn() const {return p.conditionBasedOn();}
64  std::vector<SgInitializedName*> scopesBeingExited() const {return p.scopesBeingExited();}
65  std::vector<SgInitializedName*> scopesBeingEntered() const {return p.scopesBeingEntered();}
66  bool operator==(const DataflowEdge& o) const {return p == o.p;}
67  bool operator!=(const DataflowEdge& o) const {return p != o.p;}
68  //bool operator<(const DataflowEdge& o) const {return p < o.p;}
69 };
70 
71 //inline DataflowNode makeDataflowCfg(SgNode* start, bool (*f) (CFGNode) = defaultFilter) {
72 inline DataflowNode makeDataflowCfg(SgNode* start, bool (*f) (CFGNode) ) {
73  // Returns CFG node for just before start
74  return DataflowNode(cfgBeginningOfConstruct(start), f);
75 }
76 
77 bool isDataflowInteresting(CFGNode cn);
78 }
79 
80 #endif
81 #endif
VirtualCFG::CFGNode::id
std::string id() const
ID to use for Dot, etc.
VirtualCFG::DataflowNode
Definition: DataflowCFG.h:19
VirtualCFG::CFGNode::toStringForDebugging
std::string toStringForDebugging() const
String for debugging graphs.
VirtualCFG::CFGNode
A node in the control flow graph.
Definition: virtualCFG.h:70
VirtualCFG::DataflowEdge
Definition: DataflowCFG.h:47
VirtualCFG::CFGPath
Definition: virtualCFG.h:157
SgExpression
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
Definition: Cxx_Grammar.h:229045
VirtualCFG::CFGNode::toString
std::string toString() const
Pretty string for Dot node labels, etc.
SgNode
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:6739
VirtualCFG::CFGNode::getIndex
unsigned int getIndex() const
An identifying index within the AST node given by getNode()
Definition: virtualCFG.h:91
VirtualCFG::CFGNode::getNode
SgNode * getNode() const
The underlying AST node.
Definition: virtualCFG.h:89