Made the following changes:
[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   // TODO: Should I use a deque instead of a vector?
29   vector<ValueSubclass*> ValueList;
30
31   ItemParentType *ItemParent;
32   SymTabType *Parent;
33
34   ValueHolder(const ValueHolder &V);   // DO NOT IMPLEMENT
35 public:
36   inline ValueHolder(ItemParentType *IP, SymTabType *parent = 0) { 
37     assert(IP && "Item parent may not be null!");
38     ItemParent = IP;
39     Parent = 0;
40     setParent(parent); 
41   }
42
43   inline ~ValueHolder() {
44     // The caller should have called delete_all first...
45     assert(empty() && "ValueHolder contains definitions!");
46     assert(Parent == 0 && "Should have been unlinked from method!");
47   }
48
49   inline const SymTabType *getParent() const { return Parent; }
50   inline SymTabType *getParent() { return Parent; }
51   void setParent(SymTabType *Parent);  // Defined in ValueHolderImpl.h
52
53   inline unsigned size() const { return ValueList.size(); }
54   inline bool empty()    const { return ValueList.empty(); }
55   inline const ValueSubclass *front() const { return ValueList.front(); }
56   inline       ValueSubclass *front()       { return ValueList.front(); }
57   inline const ValueSubclass *back()  const { return ValueList.back(); }
58   inline       ValueSubclass *back()        { return ValueList.back(); }
59
60   //===--------------------------------------------------------------------===//
61   // sub-Definition iterator code
62   //===--------------------------------------------------------------------===//
63   // 
64   typedef vector<ValueSubclass*>::iterator               iterator;
65   typedef vector<ValueSubclass*>::const_iterator   const_iterator;
66   typedef reverse_iterator<const_iterator> const_reverse_iterator;
67   typedef reverse_iterator<iterator>             reverse_iterator;
68
69   inline iterator                begin()       { return ValueList.begin(); }
70   inline const_iterator          begin() const { return ValueList.begin(); }
71   inline iterator                end  ()       { return ValueList.end();   }
72   inline const_iterator          end  () const { return ValueList.end();   }
73
74   inline reverse_iterator       rbegin()       { return ValueList.rbegin(); }
75   inline const_reverse_iterator rbegin() const { return ValueList.rbegin(); }
76   inline reverse_iterator       rend  ()       { return ValueList.rend();   }
77   inline const_reverse_iterator rend  () const { return ValueList.rend();   }
78   
79   void delete_all() {            // Delete all removes and deletes all elements
80     while (!empty()) {
81       iterator it = end();
82       delete remove(--it);          // Delete all instructions...
83     }
84   }
85
86   // ValueHolder::remove(iterator &) this removes the element at the location 
87   // specified by the iterator, and leaves the iterator pointing to the element 
88   // that used to follow the element deleted.
89   //
90   ValueSubclass *remove(iterator &DI);         // Defined in ValueHolderImpl.h
91   ValueSubclass *remove(const iterator &DI);   // Defined in ValueHolderImpl.h
92   void           remove(ValueSubclass *D);     // Defined in ValueHolderImpl.h
93   ValueSubclass *pop_back();                   // Defined in ValueHolderImpl.h
94
95   void push_front(ValueSubclass *Inst);        // Defined in ValueHolderImpl.h
96   void push_back(ValueSubclass *Inst);         // Defined in ValueHolderImpl.h
97
98   // ValueHolder::insert - This method inserts the specified value *BEFORE* the 
99   // indicated iterator position, and returns an interator to the newly inserted
100   // value.
101   //
102   iterator insert(iterator Pos, ValueSubclass *Inst);
103 };
104
105 #endif