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 specified
42 // by the iterator, and leaves the iterator pointing to the element that used to follow
43 // 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 void ValueHolder<ValueSubclass,ItemParentType>::push_front(ValueSubclass *Inst) {
64 assert(Inst->getParent() == 0 && "Value already has parent!");
65 Inst->setParent(ItemParent);
67 //ValueList.push_front(Inst);
68 ValueList.insert(ValueList.begin(), Inst);
70 if (Inst->hasName() && Parent)
71 Parent->getSymbolTableSure()->insert(Inst);
74 template<class ValueSubclass, class ItemParentType>
75 void ValueHolder<ValueSubclass,ItemParentType>::push_back(ValueSubclass *Inst) {
76 assert(Inst->getParent() == 0 && "Value already has parent!");
77 Inst->setParent(ItemParent);
79 ValueList.push_back(Inst);
81 if (Inst->hasName() && Parent)
82 Parent->getSymbolTableSure()->insert(Inst);