OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
NewExprTree.hpp
Go to the documentation of this file.
1 
15 #ifndef NewExprTree_H
16 #define NewExprTree_H
17 #include <set>
18 #include <map>
19 
20 // OpenAnalysis headers
27 
29 
30 namespace OA {
31 using namespace std;
32 
33 class NewExprTree;
34 
35 // to avoid circular reference in header files
36 class NewExprTreeVisitor;
37 
38 
39 
40 //--------------------------------------------------------------------
44  class NewExprTree : public ExprTree {
45 public:
46  class Node;
47  class Edge;
48 
49 public:
50  NewExprTree();
51  virtual ~NewExprTree();
52 
55  return n.convert<Node>();
56  }
57 
58 
60  void acceptVisitor(NewExprTreeVisitor& pVisitor);
61 
62  //-------------------------------------
63  // construction
64  //-------------------------------------
66  { OA_ptr<Edge> e; e = new Edge(src,dst); addEdge(e); }
67  void disconnect(OA_ptr<Edge> e) { removeEdge(e.convert<Tree::Edge>()); }
68  void copyAndConnectSubTree(OA_ptr<Node> src, OA_ptr<NewExprTree> subtree);
69 
70 
71  //*****************************************************************
72  // Ordering Operations
73  //*****************************************************************
74  // an ordering for expression trees, needed for use within STL containers
75  bool operator<(NewExprTree &rhs);
76  bool operator==(NewExprTree &rhs);
77 private:
78  bool compareTreesRootedAt(OA_ptr<Node> rootLHS, OA_ptr<Node> rootRHS);
79 public:
80 
81  //--------------------------------------------------------
82  class Node : public Tree::Node {
83  public:
84  Node()
85  : Tree::Node() { }
86  Node(const std::string& x)
87  : Tree::Node(), mName(x) { }
88  virtual ~Node() { }
89 
90  // A name for this node (useful for debugging)
91  std::string& getName() { return mName; }
92 
94  virtual OA_ptr<Node> copy() = 0;
95 
97  virtual bool isaOpNode() { return false; }
98  virtual bool isaCallNode() { return false; }
99  virtual bool isaMemRefNode() { return false; }
100  virtual bool isaConstSymNode() { return false; }
101  virtual bool isaConstValNode() { return false; }
102 
104  // NOTE: could give this a default implementation if wanted to
105  // have ExprTree visitors have default implementation for nodes
106  // they don't know about
107  virtual void acceptVisitor(NewExprTreeVisitor&) = 0;
108  virtual void dump(std::ostream& os) { Tree::Node::dump(os); }
109  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
110 
111  //*****************************************************************
112  // Annotation Interface
113  //*****************************************************************
114  virtual void output(IRHandlesIRInterface& ir) { Tree::Node::output(ir); }
115 
116  //*****************************************************************
117  // Ordering Operations
118  //*****************************************************************
119  virtual bool operator<(Node& rhs) = 0;
120  virtual int getOrder() = 0;
121 
122  private:
124  //std::string mAttr;
125  }; // end of Node
126 
127  class OpNode : public Node {
128  public:
129  OpNode() : Node("OpNode") { }
130  OpNode(OA_ptr<OpBasicInterface> op) : Node("OpNode"), mOpInterface(op) {}
131  virtual ~OpNode() { }
132 
135  { OA_ptr<Node> ret; ret = new OpNode(mOpInterface); return ret; }
136 
137  bool isaOpNode() { return true; }
138  OA_ptr<OpBasicInterface> getOpInterface() { return mOpInterface; }
139  void dump(std::ostream& os) { Node::dump(os); }
140  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
141 
142  void acceptVisitor(NewExprTreeVisitor& pVisitor);
143 
144  //*****************************************************************
145  // Annotation Interface
146  //*****************************************************************
147  void output(IRHandlesIRInterface& ir);
148 
149  //*****************************************************************
150  // Ordering Operations
151  //*****************************************************************
152  bool operator<(Node& rhs);
153  bool operator<(OpNode& rhs);
154  virtual int getOrder() { return sOrder; }
155 
156  private:
157  static const int sOrder = 100;
159  };
160 
161  class CallNode : public Node {
162  public:
163  CallNode() : Node("CallNode") { }
164  CallNode(CallHandle h) : Node("CallNode"), mHandle(h) {}
165  virtual ~CallNode() { }
166 
169  { OA_ptr<Node> ret; ret = new CallNode(mHandle); return ret; }
170 
171  bool isaCallNode() { return true; }
172  CallHandle getHandle() { return mHandle; }
173  void dump(std::ostream& os) { Node::dump(os); }
174  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
175 
176  void acceptVisitor(NewExprTreeVisitor& pVisitor);
177 
178  //*****************************************************************
179  // Annotation Interface
180  //*****************************************************************
181  void output(IRHandlesIRInterface& ir) ;
182 
183  //*****************************************************************
184  // Ordering Operations
185  //*****************************************************************
186  bool operator<(Node& rhs);
187  bool operator<(CallNode& rhs);
188  virtual int getOrder() { return sOrder; }
189 
190  private:
191  //Changed from ExprHandle to CallHandle by LMR. 6.8.06
192  static const int sOrder = 500;
194  };
195 
196  class MemRefNode : public Node {
197  public:
198  MemRefNode() : Node("MemRefNode") { }
199  MemRefNode(OA_ptr<MemRefExpr> mre) : Node("MemRefNode"), mMRE(mre) {}
200  virtual ~MemRefNode() { }
201 
204  { OA_ptr<Node> ret; ret = new MemRefNode(mMRE); return ret; }
205 
206  bool isaMemRefNode() { return true; }
207  OA_ptr<MemRefExpr> getMRE() { return mMRE; }
208  void dump(std::ostream& os) { Node::dump(os); }
209  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
210 
211  void acceptVisitor(NewExprTreeVisitor& pVisitor);
212 
213  //*****************************************************************
214  // Annotation Interface
215  //*****************************************************************
216  void output(IRHandlesIRInterface& ir) ;
217 
218  //*****************************************************************
219  // Ordering Operations
220  //*****************************************************************
221  bool operator<(Node& rhs);
222  bool operator<(MemRefNode& rhs);
223  virtual int getOrder() { return sOrder; }
224 
225  private:
226  static const int sOrder = 200;
228  };
229 
230  class ConstSymNode : public Node {
231  public:
232  ConstSymNode() : Node("ConstSymNode") { }
233  ConstSymNode(ConstSymHandle h) : Node("ConstSymNode"), mHandle(h) {}
234  virtual ~ConstSymNode() { }
235 
238  { OA_ptr<Node> ret; ret = new ConstSymNode(mHandle); return ret; }
239 
240  bool isaConstSymNode() { return true; }
241  ConstSymHandle getHandle() { return mHandle; }
242  void dump(std::ostream& os) { Node::dump(os); }
243  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
244 
245  void acceptVisitor(NewExprTreeVisitor& pVisitor);
246 
247  //*****************************************************************
248  // Annotation Interface
249  //*****************************************************************
250  void output(IRHandlesIRInterface& ir) ;
251 
252  //*****************************************************************
253  // Ordering Operations
254  //*****************************************************************
255  bool operator<(Node& rhs);
256  bool operator<(ConstSymNode& rhs);
257  virtual int getOrder() { return sOrder; }
258 
259  private:
260  static const int sOrder = 300;
262  };
263 
264  class ConstValNode : public Node {
265  public:
266  ConstValNode() : Node("ConstValNode") { }
268  Node("ConstValNode"),
269  mConstValInter(constInter)
270  { }
271  virtual ~ConstValNode() { }
272 
275  { OA_ptr<Node> ret; ret = new ConstValNode(mConstValInter); return ret; }
276 
277  bool isaConstValNode() { return true; }
279  return mConstValInter;
280  }
281  void dump(std::ostream& os) { Node::dump(os); }
282  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
283 
284  void acceptVisitor(NewExprTreeVisitor& pVisitor);
285 
286  //*****************************************************************
287  // Annotation Interface
288  //*****************************************************************
289  void output(IRHandlesIRInterface& ir) ;
290 
291  //*****************************************************************
292  // Ordering Operations
293  //*****************************************************************
294  bool operator<(Node& rhs);
295  bool operator<(ConstValNode& rhs);
296  virtual int getOrder() { return sOrder; }
297 
298  private:
299  static const int sOrder = 400;
301  };
302 
303  //--------------------------------------------------------
304  class Edge : public Tree::Edge {
305  public:
307  : Tree::Edge(n1, n2) { }
308  virtual ~Edge() { }
309 
310  // included here to return subclass node type
311  OA_ptr<Node> parent () const {
313  return n.convert<Node>();
314  }
315  OA_ptr<Node> source () const { return parent(); }
316  OA_ptr<Node> tail () const { return parent(); }
317  OA_ptr<Node> child () const {
319  return n.convert<Node>();
320  }
321  OA_ptr<Node> sink () const { return child(); }
322  OA_ptr<Node> head () const { return child(); }
323 
324  void dump(std::ostream& os);
325  void dump() { dump(std::cout); }
326 
327  private:
328  };
329  //--------------------------------------------------------
330 
331  //------------------------------------------------------------------
339  public:
341  virtual ~NodesIterator () {}
344  return n.convert<Node>();
345  }
346  };
347 
348  //------------------------------------------------------------------
356  public:
358  virtual ~EdgesIterator () {}
361  return e.convert<Edge>();
362  }
363  };
364 
365  //------------------------------------------------------------------
370  public:
372  virtual ~OutEdgesIterator () {}
375  return e.convert<Edge>();
376  }
377  };
378 
379  //------------------------------------------------------------------
385  public:
390  return n.convert<Node>();
391  }
392  };
393 
394  void str(std::ostream& os);
395 
396  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
397  //void dump() { dump(std::cout); }
398 
399  //*****************************************************************
400  // Annotation Interface
401  //*****************************************************************
402  void output(IRHandlesIRInterface& ir) ;
403 
404  //------------------------------------------------------------------
409  public:
411  virtual ~PreOrderIterator () {}
413  OA_ptr<Tree::Node> n = PreOrderIterator::current();
414  return n.convert<Node>();
415  }
416  };
417  //------------------------------------------------------------------
422  public:
424  virtual ~PostOrderIterator () {}
426  OA_ptr<Tree::Node> n = PostOrderIterator::current();
427  return n.convert<Node>();
428  }
429  };
430  //------------------------------------------------------------------
435  public:
440  return n.convert<Node>();
441  }
442  };
443  //--------------------------------------------------------------------
444 };
445 
446 
447 } // end of OA namespace
448 
449 #endif