1 //===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
3 // This file implements the stickier parts of the SymbolTableListTraits class,
4 // and is explicitly instantiated where needed to avoid defining all this code
5 // in a widely used header.
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
10 #define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
12 #include "llvm/SymbolTableListTraits.h"
13 #include "llvm/SymbolTable.h"
15 template<typename ValueSubClass, typename ItemParentClass,typename SymTabClass,
17 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
18 ::setParent(SymTabClass *STO) {
19 iplist<ValueSubClass> &List = SubClass::getList(ItemParent);
21 // Remove all of the items from the old symtab..
22 if (SymTabObject && !List.empty()) {
23 SymbolTable &SymTab = SymTabObject->getSymbolTable();
24 for (typename iplist<ValueSubClass>::iterator I = List.begin();
26 if (I->hasName()) SymTab.remove(I);
31 // Add all of the items to the new symtab...
32 if (SymTabObject && !List.empty()) {
33 SymbolTable &SymTab = SymTabObject->getSymbolTable();
34 for (typename iplist<ValueSubClass>::iterator I = List.begin();
36 if (I->hasName()) SymTab.insert(I);
40 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
42 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
43 ::addNodeToList(ValueSubClass *V) {
44 assert(V->getParent() == 0 && "Value already in a container!!");
45 V->setParent(ItemParent);
46 if (V->hasName() && SymTabObject)
47 SymTabObject->getSymbolTable().insert(V);
50 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
52 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
53 ::removeNodeFromList(ValueSubClass *V) {
55 if (V->hasName() && SymTabObject)
56 SymTabObject->getSymbolTable().remove(V);
59 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
61 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
62 ::transferNodesFromList(iplist<ValueSubClass, ilist_traits<ValueSubClass> > &L2,
63 ilist_iterator<ValueSubClass> first,
64 ilist_iterator<ValueSubClass> last) {
65 // We only have to do work here if transfering instructions between BB's
66 ItemParentClass *NewIP = ItemParent, *OldIP = L2.ItemParent;
67 if (NewIP == OldIP) return; // No work to do at all...
69 // We only have to update symbol table entries if we are transfering the
70 // instructions to a different symtab object...
71 SymTabClass *NewSTO = SymTabObject, *OldSTO = L2.SymTabObject;
72 if (NewSTO != OldSTO) {
73 for (; first != last; ++first) {
74 ValueSubClass &V = *first;
75 bool HasName = V.hasName();
76 if (OldSTO && HasName)
77 OldSTO->getSymbolTable().remove(&V);
79 if (NewSTO && HasName)
80 NewSTO->getSymbolTable().insert(&V);
83 // Just transfering between blocks in the same function, simply update the
84 // parent fields in the instructions...
85 for (; first != last; ++first)
86 first->setParent(NewIP);