summaryrefslogtreecommitdiff
path: root/lib/VMCore/ValueHolderImpl.h
blob: ecafd470f188a2f726c4a740aefa5a5558584414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 <algorithm>

template<class ValueSubclass, class ItemParentType>
void ValueHolder<ValueSubclass,ItemParentType>::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<class ValueSubclass, class ItemParentType>
void ValueHolder<ValueSubclass,ItemParentType>::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<class ValueSubclass, class ItemParentType>
ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>::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<class ValueSubclass, class ItemParentType>
void ValueHolder<ValueSubclass,ItemParentType>::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<class ValueSubclass, class ItemParentType>
void ValueHolder<ValueSubclass,ItemParentType>::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