1 //===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the stickier parts of the SymbolTableListTraits class,
11 // and is explicitly instantiated where needed to avoid defining all this code
12 // in a widely used header.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
17 #define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
19 #include "llvm/SymbolTableListTraits.h"
20 #include "llvm/SymbolTable.h"
22 template<typename ValueSubClass, typename ItemParentClass,typename SymTabClass,
24 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
25 ::setParent(SymTabClass *STO) {
26 iplist<ValueSubClass> &List = SubClass::getList(ItemParent);
28 // Remove all of the items from the old symtab..
29 if (SymTabObject && !List.empty()) {
30 SymbolTable &SymTab = SymTabObject->getSymbolTable();
31 for (typename iplist<ValueSubClass>::iterator I = List.begin();
33 if (I->hasName()) SymTab.remove(I);
38 // Add all of the items to the new symtab...
39 if (SymTabObject && !List.empty()) {
40 SymbolTable &SymTab = SymTabObject->getSymbolTable();
41 for (typename iplist<ValueSubClass>::iterator I = List.begin();
43 if (I->hasName()) SymTab.insert(I);
47 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
49 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
50 ::addNodeToList(ValueSubClass *V) {
51 assert(V->getParent() == 0 && "Value already in a container!!");
52 V->setParent(ItemParent);
53 if (V->hasName() && SymTabObject)
54 SymTabObject->getSymbolTable().insert(V);
57 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
59 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
60 ::removeNodeFromList(ValueSubClass *V) {
62 if (V->hasName() && SymTabObject)
63 SymTabObject->getSymbolTable().remove(V);
66 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
68 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
69 ::transferNodesFromList(iplist<ValueSubClass, ilist_traits<ValueSubClass> > &L2,
70 ilist_iterator<ValueSubClass> first,
71 ilist_iterator<ValueSubClass> last) {
72 // We only have to do work here if transferring instructions between BBs
73 ItemParentClass *NewIP = ItemParent, *OldIP = L2.ItemParent;
74 if (NewIP == OldIP) return; // No work to do at all...
76 // We only have to update symbol table entries if we are transferring the
77 // instructions to a different symtab object...
78 SymTabClass *NewSTO = SymTabObject, *OldSTO = L2.SymTabObject;
79 if (NewSTO != OldSTO) {
80 for (; first != last; ++first) {
81 ValueSubClass &V = *first;
82 bool HasName = V.hasName();
83 if (OldSTO && HasName)
84 OldSTO->getSymbolTable().remove(&V);
86 if (NewSTO && HasName)
87 NewSTO->getSymbolTable().insert(&V);
90 // Just transferring between blocks in the same function, simply update the
91 // parent fields in the instructions...
92 for (; first != last; ++first)
93 first->setParent(NewIP);