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 (iplist<ValueSubClass>::iterator I = List.begin(); I != List.end(); ++I)
25 if (I->hasName()) SymTab->remove(I);
30 // Add all of the items to the new symtab...
31 if (SymTabObject && !List.empty()) {
32 SymbolTable *SymTab = SymTabObject->getSymbolTableSure();
33 for (iplist<ValueSubClass>::iterator I = List.begin(); I != List.end(); ++I)
34 if (I->hasName()) SymTab->insert(I);
38 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
40 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
41 ::addNodeToList(ValueSubClass *V) {
42 assert(V->getParent() == 0 && "Value already in a container!!");
43 V->setParent(ItemParent);
44 if (V->hasName() && SymTabObject)
45 SymTabObject->getSymbolTableSure()->insert(V);
48 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
50 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
51 ::removeNodeFromList(ValueSubClass *V) {
53 if (V->hasName() && SymTabObject)
54 SymTabObject->getSymbolTable()->remove(V);
57 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
59 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
60 ::transferNodesFromList(iplist<ValueSubClass, ilist_traits<ValueSubClass> > &L2,
61 ilist_iterator<ValueSubClass> first,
62 ilist_iterator<ValueSubClass> last) {
63 // We only have to do work here if transfering instructions between BB's
64 ItemParentClass *NewIP = ItemParent, *OldIP = L2.ItemParent;
65 if (NewIP == OldIP) return; // No work to do at all...
67 // We only have to update symbol table entries if we are transfering the
68 // instructions to a different symtab object...
69 SymTabClass *NewSTO = SymTabObject, *OldSTO = L2.SymTabObject;
70 if (NewSTO != OldSTO) {
71 for (; first != last; ++first) {
72 ValueSubClass &V = *first;
73 bool HasName = V.hasName();
74 if (OldSTO && HasName)
75 OldSTO->getSymbolTable()->remove(&V);
77 if (NewSTO && HasName)
78 NewSTO->getSymbolTableSure()->insert(&V);
81 // Just transfering between blocks in the same function, simply update the
82 // parent fields in the instructions...
83 for (; first != last; ++first)
84 first->setParent(NewIP);