1 //===-- llvm/ValueHolderImpl.h - Implement ValueHolder template --*- C++ -*--=//
3 // This file implements the ValueHolder class. This is kept out of line because
4 // it tends to pull in a lot of dependencies on other headers and most files
5 // don't need all that crud.
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_VALUEHOLDER_IMPL_H
10 #define LLVM_VALUEHOLDER_IMPL_H
12 #include "llvm/ValueHolder.h"
13 #include "llvm/SymbolTable.h"
16 template<class ValueSubclass, class ItemParentType>
17 void ValueHolder<ValueSubclass,ItemParentType>::setParent(SymTabValue *P) {
18 if (Parent) { // Remove all of the items from the old symbol table..
19 SymbolTable *SymTab = Parent->getSymbolTable();
20 for (iterator I = begin(); I != end(); ++I)
21 if ((*I)->hasName()) SymTab->remove(*I);
26 if (Parent) { // Remove all of the items from the old symbol table..
27 SymbolTable *SymTab = Parent->getSymbolTableSure();
28 for (iterator I = begin(); I != end(); ++I)
29 if ((*I)->hasName()) SymTab->insert(*I);
34 template<class ValueSubclass, class ItemParentType>
35 void ValueHolder<ValueSubclass,ItemParentType>::remove(ValueSubclass *D) {
36 iterator I(find(begin(), end(), D));
37 assert(I != end() && "Value not in ValueHolder!!");
41 // ValueHolder::remove(iterator &) this removes the element at the location
42 // specified by the iterator, and leaves the iterator pointing to the element
43 // that used to follow the element deleted.
45 template<class ValueSubclass, class ItemParentType>
46 ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>::remove(iterator &DI) {
47 assert(DI != ValueList.end() &&
48 "Trying to remove the end of the def list!!!");
50 ValueSubclass *i = *DI;
51 DI = ValueList.erase(DI);
53 i->setParent(0); // I don't own you anymore... byebye...
55 // You don't get to be in the symbol table anymore... byebye
56 if (i->hasName() && Parent)
57 Parent->getSymbolTable()->remove(i);
62 template<class ValueSubclass, class ItemParentType>
63 ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>
64 ::remove(const iterator &DI) {
65 assert(DI != ValueList.end() &&
66 "Trying to remove the end of the def list!!!");
68 ValueSubclass *i = *DI;
71 i->setParent(0); // I don't own you anymore... byebye...
73 // You don't get to be in the symbol table anymore... byebye
74 if (i->hasName() && Parent)
75 Parent->getSymbolTable()->remove(i);
80 template<class ValueSubclass, class ItemParentType>
81 void ValueHolder<ValueSubclass,ItemParentType>::push_front(ValueSubclass *Inst) {
82 assert(Inst->getParent() == 0 && "Value already has parent!");
83 Inst->setParent(ItemParent);
85 //ValueList.push_front(Inst);
86 ValueList.insert(ValueList.begin(), Inst);
88 if (Inst->hasName() && Parent)
89 Parent->getSymbolTableSure()->insert(Inst);
92 template<class ValueSubclass, class ItemParentType>
93 void ValueHolder<ValueSubclass,ItemParentType>::push_back(ValueSubclass *Inst) {
94 assert(Inst->getParent() == 0 && "Value already has parent!");
95 Inst->setParent(ItemParent);
97 ValueList.push_back(Inst);
99 if (Inst->hasName() && Parent)
100 Parent->getSymbolTableSure()->insert(Inst);
103 // ValueHolder::insert - This method inserts the specified value *BEFORE* the
104 // indicated iterator position, and returns an interator to the newly inserted
107 template<class ValueSubclass, class ItemParentType>
108 ValueHolder<ValueSubclass,ItemParentType>::iterator
109 ValueHolder<ValueSubclass,ItemParentType>::insert(iterator Pos,
110 ValueSubclass *Inst){
111 assert(Inst->getParent() == 0 && "Value already has parent!");
112 Inst->setParent(ItemParent);
114 iterator I = ValueList.insert(Pos, Inst);
115 if (Inst->hasName() && Parent)
116 Parent->getSymbolTableSure()->insert(Inst);