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