2001-06-06 20:29:01 +00:00
|
|
|
//===-- llvm/ValueHolderImpl.h - Implement ValueHolder template --*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// This file implements the ValueHolder class. This is kept out of line because
|
|
|
|
// it tends to pull in a lot of dependencies on other headers and most files
|
|
|
|
// don't need all that crud.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_VALUEHOLDER_IMPL_H
|
|
|
|
#define LLVM_VALUEHOLDER_IMPL_H
|
|
|
|
|
|
|
|
#include "llvm/ValueHolder.h"
|
|
|
|
#include "llvm/SymbolTable.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
2001-07-14 06:07:58 +00:00
|
|
|
template<class ValueSubclass, class ItemParentType, class SymTabType>
|
|
|
|
void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
|
|
|
|
::setParent(SymTabType *P) {
|
2001-06-06 20:29:01 +00:00
|
|
|
if (Parent) { // Remove all of the items from the old symbol table..
|
|
|
|
SymbolTable *SymTab = Parent->getSymbolTable();
|
2001-06-27 23:28:02 +00:00
|
|
|
for (iterator I = begin(); I != end(); ++I)
|
2001-06-06 20:29:01 +00:00
|
|
|
if ((*I)->hasName()) SymTab->remove(*I);
|
|
|
|
}
|
|
|
|
|
|
|
|
Parent = P;
|
|
|
|
|
|
|
|
if (Parent) { // Remove all of the items from the old symbol table..
|
|
|
|
SymbolTable *SymTab = Parent->getSymbolTableSure();
|
2001-06-27 23:28:02 +00:00
|
|
|
for (iterator I = begin(); I != end(); ++I)
|
2001-06-06 20:29:01 +00:00
|
|
|
if ((*I)->hasName()) SymTab->insert(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-14 06:07:58 +00:00
|
|
|
template<class ValueSubclass, class ItemParentType, class SymTabType>
|
|
|
|
void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
|
|
|
|
::remove(ValueSubclass *D) {
|
2001-06-06 20:29:01 +00:00
|
|
|
iterator I(find(begin(), end(), D));
|
|
|
|
assert(I != end() && "Value not in ValueHolder!!");
|
|
|
|
remove(I);
|
|
|
|
}
|
|
|
|
|
2001-06-07 16:58:36 +00:00
|
|
|
// ValueHolder::remove(iterator &) this removes the element at the location
|
|
|
|
// specified by the iterator, and leaves the iterator pointing to the element
|
|
|
|
// that used to follow the element deleted.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2001-07-14 06:07:58 +00:00
|
|
|
template<class ValueSubclass, class ItemParentType, class SymTabType>
|
|
|
|
ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
|
|
|
|
::remove(iterator &DI) {
|
2001-06-06 20:29:01 +00:00
|
|
|
assert(DI != ValueList.end() &&
|
2001-08-23 17:06:38 +00:00
|
|
|
"Trying to remove the end of the value list!!!");
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
ValueSubclass *i = *DI;
|
|
|
|
DI = ValueList.erase(DI);
|
|
|
|
|
|
|
|
i->setParent(0); // I don't own you anymore... byebye...
|
|
|
|
|
|
|
|
// You don't get to be in the symbol table anymore... byebye
|
|
|
|
if (i->hasName() && Parent)
|
|
|
|
Parent->getSymbolTable()->remove(i);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2001-07-14 06:07:58 +00:00
|
|
|
template<class ValueSubclass, class ItemParentType, class SymTabType>
|
|
|
|
ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
|
|
|
|
::pop_back() {
|
2001-06-30 04:35:21 +00:00
|
|
|
assert(!ValueList.empty() && "Can't pop_back an empty valuelist!");
|
|
|
|
ValueSubclass *i = ValueList.back();
|
|
|
|
ValueList.pop_back();
|
|
|
|
i->setParent(0); // I don't own you anymore... byebye...
|
|
|
|
|
|
|
|
// You don't get to be in the symbol table anymore... byebye
|
|
|
|
if (i->hasName() && Parent)
|
|
|
|
Parent->getSymbolTable()->remove(i);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-14 06:07:58 +00:00
|
|
|
template<class ValueSubclass, class ItemParentType, class SymTabType>
|
|
|
|
ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
|
2001-06-07 16:58:36 +00:00
|
|
|
::remove(const iterator &DI) {
|
|
|
|
assert(DI != ValueList.end() &&
|
|
|
|
"Trying to remove the end of the def list!!!");
|
|
|
|
|
|
|
|
ValueSubclass *i = *DI;
|
|
|
|
ValueList.erase(DI);
|
|
|
|
|
|
|
|
i->setParent(0); // I don't own you anymore... byebye...
|
|
|
|
|
|
|
|
// You don't get to be in the symbol table anymore... byebye
|
|
|
|
if (i->hasName() && Parent)
|
|
|
|
Parent->getSymbolTable()->remove(i);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2001-07-14 06:07:58 +00:00
|
|
|
template<class ValueSubclass, class ItemParentType, class SymTabType>
|
|
|
|
void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
|
|
|
|
::push_front(ValueSubclass *Inst) {
|
2001-06-06 20:29:01 +00:00
|
|
|
assert(Inst->getParent() == 0 && "Value already has parent!");
|
|
|
|
Inst->setParent(ItemParent);
|
|
|
|
|
|
|
|
//ValueList.push_front(Inst);
|
|
|
|
ValueList.insert(ValueList.begin(), Inst);
|
|
|
|
|
|
|
|
if (Inst->hasName() && Parent)
|
|
|
|
Parent->getSymbolTableSure()->insert(Inst);
|
|
|
|
}
|
|
|
|
|
2001-07-14 06:07:58 +00:00
|
|
|
template<class ValueSubclass, class ItemParentType, class SymTabType>
|
|
|
|
void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
|
|
|
|
::push_back(ValueSubclass *Inst) {
|
2001-06-06 20:29:01 +00:00
|
|
|
assert(Inst->getParent() == 0 && "Value already has parent!");
|
|
|
|
Inst->setParent(ItemParent);
|
|
|
|
|
|
|
|
ValueList.push_back(Inst);
|
|
|
|
|
|
|
|
if (Inst->hasName() && Parent)
|
|
|
|
Parent->getSymbolTableSure()->insert(Inst);
|
|
|
|
}
|
|
|
|
|
2001-06-25 07:31:05 +00:00
|
|
|
// ValueHolder::insert - This method inserts the specified value *BEFORE* the
|
|
|
|
// indicated iterator position, and returns an interator to the newly inserted
|
|
|
|
// value.
|
|
|
|
//
|
2001-07-14 06:07:58 +00:00
|
|
|
template<class ValueSubclass, class ItemParentType, class SymTabType>
|
|
|
|
ValueHolder<ValueSubclass,ItemParentType,SymTabType>::iterator
|
|
|
|
ValueHolder<ValueSubclass,ItemParentType,SymTabType>
|
|
|
|
::insert(iterator Pos, ValueSubclass *Inst) {
|
2001-06-25 07:31:05 +00:00
|
|
|
assert(Inst->getParent() == 0 && "Value already has parent!");
|
|
|
|
Inst->setParent(ItemParent);
|
|
|
|
|
|
|
|
iterator I = ValueList.insert(Pos, Inst);
|
|
|
|
if (Inst->hasName() && Parent)
|
|
|
|
Parent->getSymbolTableSure()->insert(Inst);
|
|
|
|
return I;
|
|
|
|
}
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|