IntervalPartition & IntervalIterator classes have been split out into
[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 class SymTabValue;
17
18 // ItemParentType ItemParent - I call setParent() on all of my 
19 // "ValueSubclass" items, and this is the value that I pass in.
20 //
21 template<class ValueSubclass, class ItemParentType> 
22 class ValueHolder {
23   // TODO: Should I use a deque instead of a vector?
24   vector<ValueSubclass*> ValueList;
25
26   ItemParentType *ItemParent;
27   SymTabValue *Parent;
28
29   ValueHolder(const ValueHolder &V);   // DO NOT IMPLEMENT
30 public:
31   inline ValueHolder(ItemParentType *IP, SymTabValue *parent = 0) { 
32     assert(IP && "Item parent may not be null!");
33     ItemParent = IP;
34     Parent = 0;
35     setParent(parent); 
36   }
37
38   inline ~ValueHolder() {
39     // The caller should have called delete_all first...
40     assert(empty() && "ValueHolder contains definitions!");
41     assert(Parent == 0 && "Should have been unlinked from method!");
42   }
43
44   inline const SymTabValue *getParent() const { return Parent; }
45   inline SymTabValue *getParent() { return Parent; }
46   void setParent(SymTabValue *Parent);  // Defined in ValueHolderImpl.h
47
48   inline unsigned size() const { return ValueList.size(); }
49   inline bool empty()    const { return ValueList.empty(); }
50   inline const ValueSubclass *front() const { return ValueList.front(); }
51   inline       ValueSubclass *front()       { return ValueList.front(); }
52   inline const ValueSubclass *back()  const { return ValueList.back(); }
53   inline       ValueSubclass *back()        { return ValueList.back(); }
54
55   //===--------------------------------------------------------------------===//
56   // sub-Definition iterator code
57   //===--------------------------------------------------------------------===//
58   // 
59   typedef vector<ValueSubclass*>::iterator               iterator;
60   typedef vector<ValueSubclass*>::const_iterator   const_iterator;
61   typedef reverse_iterator<const_iterator> const_reverse_iterator;
62   typedef reverse_iterator<iterator>             reverse_iterator;
63
64   inline iterator                begin()       { return ValueList.begin(); }
65   inline const_iterator          begin() const { return ValueList.begin(); }
66   inline iterator                end  ()       { return ValueList.end();   }
67   inline const_iterator          end  () const { return ValueList.end();   }
68
69   inline reverse_iterator       rbegin()       { return ValueList.rbegin(); }
70   inline const_reverse_iterator rbegin() const { return ValueList.rbegin(); }
71   inline reverse_iterator       rend  ()       { return ValueList.rend();   }
72   inline const_reverse_iterator rend  () const { return ValueList.rend();   }
73   
74   void delete_all() {            // Delete all removes and deletes all elements
75     while (!empty()) {
76       iterator it = end();
77       delete remove(--it);          // Delete all instructions...
78     }
79   }
80
81   // ValueHolder::remove(iterator &) this removes the element at the location 
82   // specified by the iterator, and leaves the iterator pointing to the element 
83   // that used to follow the element deleted.
84   //
85   ValueSubclass *remove(iterator &DI);        // Defined in ValueHolderImpl.h
86   ValueSubclass *remove(const iterator &DI);  // Defined in ValueHolderImpl.h
87   void     remove(ValueSubclass *D);          // Defined in ValueHolderImpl.h
88
89   inline void push_front(ValueSubclass *Inst); // Defined in ValueHolderImpl.h
90   inline void push_back(ValueSubclass *Inst);  // Defined in ValueHolderImpl.h
91 };
92
93 #endif