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