ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataflowCFG.h
Go to the documentation of this file.
1 #ifndef DATAFLOW_CFG_H
2 #define DATAFLOW_CFG_H
3 
5 #include <map>
6 #include <string>
7 #include <vector>
8 
9 namespace VirtualCFG {
10 
11 // "Interesting" node and edge filters for use with dataflow analyses
12 class DataflowEdge;
13 
14 bool defaultFilter (CFGNode cfgn);
15 
16 class DataflowNode {
17  public:
19  bool (*filter) (CFGNode cfgn); // a filter function to decide which raw CFG node to show (if return true) or hide (otherwise)
20 
21  // We enforce the user codes (the framework) of DataflowNode to explicitly set filter, or provide default filter on their own
22  DataflowNode(CFGNode n, bool (*f) (CFGNode)): n(n), filter(f) {}
23  // By default, the default filter function is used unless otherwise specified
24 // DataflowNode(CFGNode n, bool (*f) (CFGNode) = defaultFilter): n(n), filter(f) {}
25  DataflowNode(const DataflowNode& dfn): n(dfn.n), filter (dfn.filter) {}
26 
27  std::string toString() const {return n.toString();}
28  std::string toStringForDebugging() const {return n.toStringForDebugging();}
29  std::string id() const {return n.id();}
30  SgNode* getNode() const {return n.getNode();}
31  unsigned int getIndex() const {return n.getIndex();}
32  std::vector<DataflowEdge> outEdges() const;
33  std::vector<DataflowEdge> inEdges() const;
34  bool isInteresting() const;
35  bool operator==(const DataflowNode& o) const {return n == o.n;}
36  bool operator!=(const DataflowNode& o) const {return !(*this == o);}
37  bool operator<(const DataflowNode& o) const {return n < o.n;}
38 
39  std::string str(std::string indent="") const;
40 };
41 
42 typedef std::map<SgNode*, DataflowNode> m_AST2CFG;
43 
44 class DataflowEdge {
46  bool (*filter) (CFGNode cfgn);
47 
48  public:
49 // DataflowEdge(CFGPath p, bool (*f) (CFGNode) = defaultFilter): p(p), filter(f) {}
50  DataflowEdge(CFGPath p, bool (*f) (CFGNode) ): p(p), filter(f) {}
51  DataflowEdge(const DataflowEdge& dfe): p(dfe.p), filter(dfe.filter) {}
52 
53  std::string toString() const {return p.toString();}
54  std::string toStringForDebugging() const {return p.toStringForDebugging();}
55  std::string id() const {return p.id();}
56  DataflowNode source() const {return DataflowNode(p.source(), filter);}
57  DataflowNode target() const {return DataflowNode(p.target(), filter);}
58  EdgeConditionKind condition() const {return p.condition();}
59  SgExpression* caseLabel() const {return p.caseLabel();}
61  std::vector<SgInitializedName*> scopesBeingExited() const {return p.scopesBeingExited();}
62  std::vector<SgInitializedName*> scopesBeingEntered() const {return p.scopesBeingEntered();}
63  bool operator==(const DataflowEdge& o) const {return p == o.p;}
64  bool operator!=(const DataflowEdge& o) const {return p != o.p;}
65  //bool operator<(const DataflowEdge& o) const {return p < o.p;}
66 };
67 
68 //inline DataflowNode makeDataflowCfg(SgNode* start, bool (*f) (CFGNode) = defaultFilter) {
69 inline DataflowNode makeDataflowCfg(SgNode* start, bool (*f) (CFGNode) ) {
70  // Returns CFG node for just before start
71  return DataflowNode(cfgBeginningOfConstruct(start), f);
72 }
73 
75 }
76 
77 #endif