ROSE  0.11.96.11
VirtualCFGIterator.h
1 #include <featureTests.h>
2 #ifdef ROSE_ENABLE_SOURCE_ANALYSIS
3 
4 #ifndef VIRTUAL_CFG_ITERATOR
5 #define VIRTUAL_CFG_ITERATOR
6 
7 #include "virtualCFG.h"
8 #include "DataflowCFG.h"
9 //#include "baseCFGIterator.h"
10 
11 #include <list>
12 #include <set>
13 #include <string>
14 
15 namespace VirtualCFG{
16 
17 // Iterates over DataflowNodes in a VirtualCFG, respecting dependences in the graph.
18 // Supports both forward and backward iteration.
19 class iterator/* : public virtual BaseCFG::iterator*/
20 {
21  //protected:
22  public:
23 
24  std::list<DataflowNode> remainingNodes;
25  //map<DataflowNode, bool> visited;
26  std::set<DataflowNode> visited;
27  bool initialized;
28 
29  public:
30  iterator();
31 
32  iterator(const DataflowNode &start);
33  virtual ~iterator() { }
34 
35  void init(const DataflowNode &start);
36 
37  protected:
38  // returns true if the given DataflowNode is in the remainingNodes list and false otherwise
39  bool isRemaining(DataflowNode n);
40 
41  // advances this iterator in the given direction. Forwards if fwDir=true and backwards if fwDir=false.
42  // if pushAllChildren=true, all of the current node's unvisited children (predecessors or successors,
43  // depending on fwDir) are pushed onto remainingNodes
44  void advance(bool fwDir, bool pushAllChildren);
45 
46  public:
47  virtual void operator ++ (int);
48 
49  bool eq(const iterator& other_it) const;
50 
51  bool operator==(const iterator& other_it) const;
52 
53  bool operator!=(const iterator& it) const;
54 
55  DataflowNode& operator * ();
56 
57  // Returns a fresh iterator that starts at node n
58  static iterator begin(DataflowNode n);
59 
60  // Returns an empty iterator that can be compared to any other iterator to
61  // check if it has completed passing over its iteration space
62  static iterator end();
63 
64  // Contains the state of an iterator, allowing iterators to be
65  // checkpointed and restarted.
66  class checkpoint/* : public virtual BaseCFG::iterator::checkpoint*/
67  {
68  std::list<DataflowNode> remainingNodes;
69  std::set<DataflowNode> visited;
70 
71  public:
72  checkpoint(const std::list<DataflowNode>& remainingNodes, const std::set<DataflowNode>& visited);
73 
74  checkpoint(const checkpoint& that);
75 
76  std::string str(std::string indent="");
77 
78  friend class iterator;
79  };
80 
81  // Returns a checkpoint of this iterator's progress.
82  checkpoint getChkpt();
83 
84  // Loads this iterator's state from the given checkpoint.
85  void restartFromChkpt(checkpoint& chkpt);
86 
87  std::string str(std::string indent="");
88 };
89 
90 class back_iterator : /*public virtual BaseCFG::backiterator, */public virtual iterator
91 {
92  public:
93  back_iterator(): iterator() {}
94 
95  back_iterator(const DataflowNode &end): iterator(end) { }
96 
97  void operator ++ (int);
98 };
99 
100 class dataflow : /*public virtual BaseCFG::dataflow, */public virtual iterator
101 {
102  DataflowNode terminator;
103  public:
104  //dataflow(): iterator() {}
105 
106  dataflow(const DataflowNode &terminator_arg);
107 
108  //dataflow(const DataflowNode &start) : iterator(start) {}
109  dataflow(const DataflowNode &start, const DataflowNode &terminator_arg);
110 
111  void init(const DataflowNode &start_arg, const DataflowNode &terminator_arg);
112 
113  // Initializes this iterator's terminator node
114  /*void setTerminator(const DataflowNode &terminator) {
115  initialized = true;
116  this->terminator = terminator;
117  }*/
118 
119  void add(const DataflowNode &next);
120 
121  //void operator ++ (int);
122 
123  // Contains the state of an dataflow iterator, allowing dataflow
124  // iterators to be checkpointed and restarted.
125  class checkpoint/* : public virtual BaseCFG::dataflow::checkpoint*/
126  {
127  iterator::checkpoint iChkpt;
128  DataflowNode terminator;
129 
130  public:
131  checkpoint(const iterator::checkpoint& iChkpt, const DataflowNode& terminator);
132 
133  checkpoint(const checkpoint &that);
134 
135  std::string str(std::string indent="");
136 
137  friend class dataflow;
138  };
139 
140  // Returns a checkpoint of this dataflow iterator's progress.
141  checkpoint getChkpt();
142 
143  // Loads this dataflow iterator's state from the given checkpoint.
144  void restartFromChkpt(checkpoint& chkpt);
145 
146  std::string str(std::string indent="");
147 };
148 
149 class back_dataflow: /*public virtual BaseCFG::back_dataflow,*/ public virtual dataflow
150 {
151  public:
152  //back_dataflow(): back_iterator() {}
153 
154  back_dataflow(const DataflowNode &terminator_arg) : dataflow(terminator_arg) {}
155 
156  //back_dataflow(const DataflowNode &end) : iterator(end) {}
157 
158  back_dataflow(const DataflowNode &end, const DataflowNode &terminator_arg);
159 
160  void operator ++ (int);
161 };
162 }
163 #endif
164 #endif
VirtualCFG::iterator
Definition: VirtualCFGIterator.h:19
VirtualCFG::back_dataflow
Definition: VirtualCFGIterator.h:149
VirtualCFG::iterator::checkpoint
Definition: VirtualCFGIterator.h:66
VirtualCFG::DataflowNode
Definition: DataflowCFG.h:19
VirtualCFG::back_iterator
Definition: VirtualCFGIterator.h:90
VirtualCFG::dataflow
Definition: VirtualCFGIterator.h:100
VirtualCFG::dataflow::checkpoint
Definition: VirtualCFGIterator.h:125