Remove extranous #include
[oota-llvm.git] / include / llvm / ValueHolder.h
1 //===-- llvm/ValueHolder.h - Class to hold multiple values -------*- C++ -*--=//
2 //
3 // This defines a class that is used as a fancy Definition container.  It is 
4 // special because it helps keep the symbol table of the container method up to
5 // date with the goings on inside of it.
6 //
7 // This is used to represent things like the instructions of a basic block and
8 // the arguments to a method.
9 //
10 //===----------------------------------------------------------------------===//
11
12 #ifndef LLVM_VALUEHOLDER_H
13 #define LLVM_VALUEHOLDER_H
14
15 #include <vector>
16
17 // ValueSubClass  - The type of objects that I hold
18 // ItemParentType - I call setParent() on all of my "ValueSubclass" items, and
19 //                  this is the value that I pass in.
20 // SymTabType     - This is the class type (which should be derived from
21 //                  SymTabValue), whose symtab I insert my ValueSubClass items
22 //                  into.  Most of the time it is ItemParentType, but
23 //                  Instructions have item parents of bb's but symtabtype's of
24 //                  a Method
25 //
26 template<class ValueSubclass, class ItemParentType, class SymTabType> 
27 class ValueHolder {
28   std::vector<ValueSubclass*> ValueList;
29
30   ItemParentType *ItemParent;
31   SymTabType *Parent;
32
33   ValueHolder(const ValueHolder &V);   // DO NOT IMPLEMENT
34 public:
35   inline ValueHolder(ItemParentType *IP, SymTabType *parent = 0) { 
36     assert(IP && "Item parent may not be null!");
37     ItemParent = IP;
38     Parent = 0;
39     setParent(parent); 
40   }
41
42   inline ~ValueHolder() {
43     // The caller should have called delete_all first...
44     assert(empty() && "ValueHolder contains definitions!");
45     assert(Parent == 0 && "Should have been unlinked from method!");
46   }
47
48   inline const SymTabType *getParent() const { return Parent; }
49   inline SymTabType *getParent() { return Parent; }
50   void setParent(SymTabType *Parent);  // Defined in ValueHolderImpl.h
51
52   inline             unsigned size()  const { return ValueList.size();  }
53   inline                 bool empty() const { return ValueList.empty(); }
54   inline const ValueSubclass *front() const { return ValueList.front(); }
55   inline       ValueSubclass *front()       { return ValueList.front(); }
56   inline const ValueSubclass *back()  const { return ValueList.back();  }
57   inline       ValueSubclass *back()        { return ValueList.back();  }
58   inline const ValueSubclass *operator[](unsigned i) const {
59     return ValueList[i];
60   }
61   inline       ValueSubclass *operator[](unsigned i) {
62     return ValueList[i];
63   }
64
65   //===--------------------------------------------------------------------===//
66   // sub-Definition iterator code
67   //===--------------------------------------------------------------------===//
68   // 
69   typedef std::vector<ValueSubclass*>::iterator               iterator;
70   typedef std::vector<ValueSubclass*>::const_iterator   const_iterator;
71   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
72   typedef std::reverse_iterator<iterator>             reverse_iterator;
73
74   inline iterator                begin()       { return ValueList.begin(); }
75   inline const_iterator          begin() const { return ValueList.begin(); }
76   inline iterator                end  ()       { return ValueList.end();   }
77   inline const_iterator          end  () const { return ValueList.end();   }
78
79   inline reverse_iterator       rbegin()       { return ValueList.rbegin(); }
80   inline const_reverse_iterator rbegin() const { return ValueList.rbegin(); }
81   inline reverse_iterator       rend  ()       { return ValueList.rend();   }
82   inline const_reverse_iterator rend  () const { return ValueList.rend();   }
83   
84   // ValueHolder::remove(iterator &) this removes the element at the location 
85   // specified by the iterator, and leaves the iterator pointing to the element 
86   // that used to follow the element deleted.
87   //
88   ValueSubclass *remove(iterator &DI);         // Defined in ValueHolderImpl.h
89   ValueSubclass *remove(const iterator &DI);   // Defined in ValueHolderImpl.h
90   void           remove(ValueSubclass *D);     // Defined in ValueHolderImpl.h
91   ValueSubclass *pop_back();                   // Defined in ValueHolderImpl.h
92
93   // delete_span - Remove the elements from begin to end, deleting them as we
94   // go.  This leaves the iterator pointing to the element that used to be end.
95   //
96   iterator delete_span(iterator begin, iterator end) {
97     while (end != begin)
98       delete remove(--end);
99     return end;
100   }
101
102   void delete_all() {            // Delete all removes and deletes all elements
103     delete_span(begin(), end());
104   }
105
106   void push_front(ValueSubclass *Inst);        // Defined in ValueHolderImpl.h
107   void push_back(ValueSubclass *Inst);         // Defined in ValueHolderImpl.h
108
109   // ValueHolder::insert - This method inserts the specified value *BEFORE* the 
110   // indicated iterator position, and returns an interator to the newly inserted
111   // value.
112   //
113   iterator insert(iterator Pos, ValueSubclass *Inst);
114 };
115
116 #endif