From 009505452b713ed2e3a8e99c5545a6e721c65495 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 6 Jun 2001 20:29:01 +0000 Subject: Initial revision git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ValueHolderImpl.h | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 lib/VMCore/ValueHolderImpl.h (limited to 'lib/VMCore/ValueHolderImpl.h') diff --git a/lib/VMCore/ValueHolderImpl.h b/lib/VMCore/ValueHolderImpl.h new file mode 100644 index 0000000000..ecafd470f1 --- /dev/null +++ b/lib/VMCore/ValueHolderImpl.h @@ -0,0 +1,85 @@ +//===-- 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 + +template +void ValueHolder::setParent(SymTabValue *P) { + if (Parent) { // Remove all of the items from the old symbol table.. + SymbolTable *SymTab = Parent->getSymbolTable(); + for (iterator I = begin(); I != end(); I++) + if ((*I)->hasName()) SymTab->remove(*I); + } + + Parent = P; + + if (Parent) { // Remove all of the items from the old symbol table.. + SymbolTable *SymTab = Parent->getSymbolTableSure(); + for (iterator I = begin(); I != end(); I++) + if ((*I)->hasName()) SymTab->insert(*I); + } +} + + +template +void ValueHolder::remove(ValueSubclass *D) { + iterator I(find(begin(), end(), D)); + assert(I != end() && "Value not in ValueHolder!!"); + remove(I); +} + +// 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. +// +template +ValueSubclass *ValueHolder::remove(iterator &DI) { + assert(DI != ValueList.end() && + "Trying to remove the end of the def list!!!"); + + 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; +} + +template +void ValueHolder::push_front(ValueSubclass *Inst) { + 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); +} + +template +void ValueHolder::push_back(ValueSubclass *Inst) { + assert(Inst->getParent() == 0 && "Value already has parent!"); + Inst->setParent(ItemParent); + + ValueList.push_back(Inst); + + if (Inst->hasName() && Parent) + Parent->getSymbolTableSure()->insert(Inst); +} + +#endif -- cgit v1.2.3