OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ExprTree.hpp
Go to the documentation of this file.
1 
15 #ifndef ExprTree_H
16 #define ExprTree_H
17 #include<set>
18 #include <map>
19 
20 // OpenAnalysis headers
24 //#include <OpenAnalysis/ReachConsts/Interface.hpp>
26 
27 
28 namespace OA {
29 using namespace std;
30 
31 class ExprTree;
32 
33 // to avoid circular reference in header files
34 class ExprTreeVisitor;
35 
36 typedef std::set<OA_ptr<ExprTree> > ExprTreeSet;
37 
39 OA_ptr<std::set<OA_ptr<ExprTree> > >
40 intersectExprTreeSets(std::set<OA_ptr<ExprTree> >& set1,
41  std::set<OA_ptr<ExprTree> >& set2);
42 
44 OA_ptr<std::set<OA_ptr<ExprTree> > >
46  std::set<OA_ptr<ExprTree> >& set1,
47  std::set<OA_ptr<ExprTree> >& set2);
48 
49 
50 
51 //--------------------------------------------------------------------
55  class ExprTree : public Tree {
56 public:
57  class Node;
58  class Edge;
59 private:
60 static const int sOrder = -200;
61 
62 public:
63  ExprTree();
64  virtual ~ExprTree();
65 
68  return n.convert<Node>();
69  }
70 
71 
73  void acceptVisitor(ExprTreeVisitor& pVisitor);
74 
75  //-------------------------------------
76  // construction
77  //-------------------------------------
79  { OA_ptr<Edge> e; e = new Edge(src,dst); addEdge(e); }
80  void disconnect(OA_ptr<Edge> e) { removeEdge(e.convert<Tree::Edge>()); }
81  void copyAndConnectSubTree(OA_ptr<Node> src, OA_ptr<ExprTree> subtree);
82 
84  bool operator<(ExprTree &other);
85 
86 
89  bool operator==(ExprTree &other);
90  virtual int getOrder() { return sOrder; }
91 
92 
93  //--------------------------------------------------------
94  class Node : public Tree::Node {
95  public:
96  Node()
97  : Tree::Node() { }
98  Node(const std::string& x)
99  : Tree::Node(), mName(x) { }
100  virtual ~Node() { }
101 
102  // A name for this node (useful for debugging)
103  std::string& getName() { return mName; }
104 
106  virtual OA_ptr<Node> copy() = 0;
107 
109  virtual bool isaOpNode() { return false; }
110  virtual bool isaCallNode() { return false; }
111  virtual bool isaMemRefNode() { return false; }
112  virtual bool isaConstSymNode() { return false; }
113  virtual bool isaConstValNode() { return false; }
114 
116  // NOTE: could give this a default implementation if wanted to
117  // have ExprTree visitors have default implementation for nodes
118  // they don't know about
119  virtual void acceptVisitor(ExprTreeVisitor&) = 0;
120  virtual void dump(std::ostream& os) { Tree::Node::dump(os); }
121  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
122 
123  //*****************************************************************
124  // Annotation Interface
125  //*****************************************************************
126  virtual void output(IRHandlesIRInterface& ir) { Tree::Node::output(ir); }
128  virtual bool operator<(Node& other);
129 
132  virtual bool operator==(Node& other);
133 
134  virtual int getOrder() { return sOrder; }
135 
136 
137  private:
138  static const int sOrder = -100;
139  std::string mName;
140  //std::string mAttr;
141  }; // end of Node
142 
143  class OpNode : public Node {
144  public:
145  OpNode() : Node("OpNode") { }
146  OpNode(OpHandle h) : Node("OpNode"), mHandle(h) {}
147  virtual ~OpNode() { }
148 
151  { OA_ptr<Node> ret; ret = new OpNode(mHandle); return ret; }
152 
153  bool isaOpNode() { return true; }
154  OpHandle getHandle() { return mHandle; }
155  void dump(std::ostream& os) { Node::dump(os); }
156  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
157 
158  void acceptVisitor(ExprTreeVisitor& pVisitor);
159 
160  //*****************************************************************
161  // Annotation Interface
162  //*****************************************************************
163  void output(IRHandlesIRInterface& ir) ;
165  bool operator<(Node& other);
166 
169  bool operator==(Node& other);
170  virtual int getOrder() { return sOrder; }
171 
172  private:
173  static const int sOrder = 100;
174  OpHandle mHandle;
175 
176  };
177 
178  class CallNode : public Node {
179  public:
180  CallNode() : Node("CallNode") { }
181  CallNode(CallHandle h) : Node("CallNode"), mHandle(h) {}
182  virtual ~CallNode() { }
183 
186  { OA_ptr<Node> ret; ret = new CallNode(mHandle); return ret; }
187 
188  bool isaCallNode() { return true; }
189  CallHandle getHandle() { return mHandle; }
190  void dump(std::ostream& os) { Node::dump(os); }
191  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
192 
193  void acceptVisitor(ExprTreeVisitor& pVisitor);
194 
195  //*****************************************************************
196  // Annotation Interface
197  //*****************************************************************
198  void output(IRHandlesIRInterface& ir) ;
200  bool operator<(Node& other);
201 
204  bool operator==(Node& other);
205  virtual int getOrder() { return sOrder; }
206 
207  private:
208  //Changed from ExprHandle to CallHandle by LMR. 6.8.06
209  static const int sOrder = 500;
210  CallHandle mHandle;
211  };
212 
213  class MemRefNode : public Node {
214  public:
215  MemRefNode() : Node("MemRefNode") { }
216  MemRefNode(MemRefHandle h) : Node("MemRefNode"), mHandle(h) {}
217  virtual ~MemRefNode() { }
218 
221  { OA_ptr<Node> ret; ret = new MemRefNode(mHandle); return ret; }
222 
223  bool isaMemRefNode() { return true; }
224  MemRefHandle getHandle() { return mHandle; }
225  void dump(std::ostream& os) { Node::dump(os); }
226  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
227 
228  void acceptVisitor(ExprTreeVisitor& pVisitor);
229 
230  //*****************************************************************
231  // Annotation Interface
232  //*****************************************************************
233  void output(IRHandlesIRInterface& ir) ;
235  bool operator<(Node& other);
236 
239  bool operator==(Node& other);
240  virtual int getOrder() { return sOrder; }
241 
242  private:
243  static const int sOrder = 200;
244  MemRefHandle mHandle;
245  };
246 
247  class ConstSymNode : public Node {
248  public:
249  ConstSymNode() : Node("ConstSymNode") { }
250  ConstSymNode(ConstSymHandle h) : Node("ConstSymNode"), mHandle(h) {}
251  virtual ~ConstSymNode() { }
252 
255  { OA_ptr<Node> ret; ret = new ConstSymNode(mHandle); return ret; }
256 
257  bool isaConstSymNode() { return true; }
258  ConstSymHandle getHandle() { return mHandle; }
259  void dump(std::ostream& os) { Node::dump(os); }
260  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
261 
262  void acceptVisitor(ExprTreeVisitor& pVisitor);
263 
264  //*****************************************************************
265  // Annotation Interface
266  //*****************************************************************
267  void output(IRHandlesIRInterface& ir) ;
269  bool operator<(Node& other);
270 
273  bool operator==(Node& other);
274  virtual int getOrder() { return sOrder; }
275 
276  private:
277  static const int sOrder = 300;
278  ConstSymHandle mHandle;
279  };
280 
281  class ConstValNode : public Node {
282  public:
283  ConstValNode() : Node("ConstValNode") { }
284  ConstValNode(ConstValHandle h) : Node("ConstValNode"), mHandle(h) {}
285  virtual ~ConstValNode() { }
286 
289  { OA_ptr<Node> ret; ret = new ConstValNode(mHandle); return ret; }
290 
291  bool isaConstValNode() { return true; }
292  ConstValHandle getHandle() { return mHandle; }
293  void dump(std::ostream& os) { Node::dump(os); }
294  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
295 
296  void acceptVisitor(ExprTreeVisitor& pVisitor);
297 
298  //*****************************************************************
299  // Annotation Interface
300  //*****************************************************************
301  void output(IRHandlesIRInterface& ir) ;
303  bool operator<(Node& other);
304 
307  bool operator==(Node& other);
308  virtual int getOrder() { return sOrder; }
309 
310  private:
311  static const int sOrder = 400;
312  ConstValHandle mHandle;
313  };
314 
315  //--------------------------------------------------------
316  class Edge : public Tree::Edge {
317  public:
319  : Tree::Edge(n1, n2) { }
320  virtual ~Edge() { }
321 
322  // included here to return subclass node type
323  OA_ptr<Node> parent () const {
325  return n.convert<Node>();
326  }
327  OA_ptr<Node> source () const { return parent(); }
328  OA_ptr<Node> tail () const { return parent(); }
329  OA_ptr<Node> child () const {
331  return n.convert<Node>();
332  }
333  OA_ptr<Node> sink () const { return child(); }
334  OA_ptr<Node> head () const { return child(); }
335 
336  void dump(std::ostream& os);
337  void dump() { dump(std::cout); }
338 
339  private:
340  };
341  //--------------------------------------------------------
342 
343  //------------------------------------------------------------------
350  class NodesIterator : public Tree::NodesIterator {
351  public:
353  virtual ~NodesIterator () {}
356  return n.convert<Node>();
357  }
358  };
359 
360  //------------------------------------------------------------------
367  class EdgesIterator : public Tree::EdgesIterator {
368  public:
370  virtual ~EdgesIterator () {}
373  return e.convert<Edge>();
374  }
375  };
376 
377  //------------------------------------------------------------------
381  class OutEdgesIterator : public Tree::OutEdgesIterator {
382  public:
384  virtual ~OutEdgesIterator () {}
387  return e.convert<Edge>();
388  }
389  };
390 
391  //------------------------------------------------------------------
396  class ChildNodesIterator : public Tree::ChildNodesIterator {
397  public:
402  return n.convert<Node>();
403  }
404  };
405 
406  void str(std::ostream& os);
407 
408  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
409  //void dump() { dump(std::cout); }
410 
411  //*****************************************************************
412  // Annotation Interface
413  //*****************************************************************
414  void output(IRHandlesIRInterface& ir) ;
415 
416  //------------------------------------------------------------------
420  class PreOrderIterator : public Tree::PreOrderIterator {
421  public:
423  virtual ~PreOrderIterator () {}
425  OA_ptr<Tree::Node> n = PreOrderIterator::current();
426  return n.convert<Node>();
427  }
428  };
429  //------------------------------------------------------------------
433  class PostOrderIterator : public Tree::PostOrderIterator {
434  public:
436  virtual ~PostOrderIterator () {}
438  OA_ptr<Tree::Node> n = PostOrderIterator::current();
439  return n.convert<Node>();
440  }
441  };
442  //------------------------------------------------------------------
446  class ReversePostOrderIterator : public Tree::ReversePostOrderIterator {
447  public:
452  return n.convert<Node>();
453  }
454  };
455  //--------------------------------------------------------------------
456 
457 };
458 
459 
460 } // end of OA namespace
461 
462 #endif