LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tree.hxx
Go to the documentation of this file.
1 
6 #ifndef TREE_TREE_HXX
7 # define TREE_TREE_HXX
8 
9 # include <algorithm>
10 # include <iostream>
11 
12 # include <misc/contract.hh>
13 # include <misc/ref.hh>
14 # include <tree/tree.hh>
15 
16 namespace tree
17 {
18 
19  inline
20  Tree::Tree (const tree_list_type& children)
21  : children_ (children)
22  {}
23 
24  inline
26  : children_ ()
27  {}
28 
29  inline void
30  Tree::child_push_back (const rTree& tree)
31  {
32  children_.push_back (tree);
33  if (tree)
34  tree->parent_set (this);
35  }
36 
37  inline tree_list_type&
39  {
40  return children_;
41  }
42 
43  inline const tree_list_type&
45  {
46  return children_;
47  }
48 
49  inline void
50  Tree::child_set (rTree& dst, const rTree& src)
51  {
52  dst = src;
53  if (src)
54  src->parent_set (this);
55  }
56 
57  // Start at 0, of course.
58  inline rTree&
59  Tree::child_get (int nth)
60  {
61  tree_list_type::iterator ichild = children_.begin ();
62  advance (ichild, nth);
63  postcondition (*ichild);
64  return *ichild;
65  }
66 
67  inline rTree
68  Tree::child_get (int nth) const
69  {
70  tree_list_type::const_iterator ichild = children_.begin ();
71  advance (ichild, nth);
72  postcondition (*ichild);
73  return *ichild;
74  }
75 
76  inline rTree&
78  {
79  return child_get (0);
80  }
81 
82  inline rTree&
84  {
85  return child_get (1);
86  }
87 
88  inline Tree*
90  {
91  return parent_;
92  }
93 
94  inline const Tree*
96  {
97  return parent_;
98  }
99 
100  inline void
102  {
103  parent_ = parent;
104  }
105 
106  inline temp::Temp&
108  {
109  if (not temp_)
110  temp_ = new temp::Temp ();
111  return *temp_;
112  }
113 
114  inline void
115  Tree::asm_set (const temp::Temp& temp)
116  {
117  temp_ = new temp::Temp (temp);
118  }
119 
120  inline void*
122  {
123  return state_;
124  }
125 
126  inline void*&
128  {
129  return state_;
130  }
131 
132  inline bool
134  {
135  return reducible_;
136  }
137 
138  inline void
140  {
141  if (reducible_ == b)
142  return;
143  reducible_ = b;
144  for (const rTree& tree : children_)
145  tree->reducible_set (b);
146  }
147 
148  inline std::ostream&
149  operator<< (std::ostream& ostr, const Tree& tree)
150  {
151  return tree.dump (ostr);
152  }
153 
154 }
155 
156 #endif // !TREE_TREE_HXX