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"
24 template<typename ValueSubClass
, typename ItemParentClass
,typename SymTabClass
,
26 void SymbolTableListTraits
<ValueSubClass
,ItemParentClass
,SymTabClass
,SubClass
>
27 ::setParent(SymTabClass
*STO
) {
28 iplist
<ValueSubClass
> &List
= SubClass::getList(ItemParent
);
30 // Remove all of the items from the old symtab..
31 if (SymTabObject
&& !List
.empty()) {
32 SymbolTable
&SymTab
= SymTabObject
->getSymbolTable();
33 for (typename iplist
<ValueSubClass
>::iterator I
= List
.begin();
35 if (I
->hasName()) SymTab
.remove(I
);
40 // Add all of the items to the new symtab...
41 if (SymTabObject
&& !List
.empty()) {
42 SymbolTable
&SymTab
= SymTabObject
->getSymbolTable();
43 for (typename iplist
<ValueSubClass
>::iterator I
= List
.begin();
45 if (I
->hasName()) SymTab
.insert(I
);
49 template<typename ValueSubClass
, typename ItemParentClass
, typename SymTabClass
,
51 void SymbolTableListTraits
<ValueSubClass
,ItemParentClass
,SymTabClass
,SubClass
>
52 ::addNodeToList(ValueSubClass
*V
) {
53 assert(V
->getParent() == 0 && "Value already in a container!!");
54 V
->setParent(ItemParent
);
55 if (V
->hasName() && SymTabObject
)
56 SymTabObject
->getSymbolTable().insert(V
);
59 template<typename ValueSubClass
, typename ItemParentClass
, typename SymTabClass
,
61 void SymbolTableListTraits
<ValueSubClass
,ItemParentClass
,SymTabClass
,SubClass
>
62 ::removeNodeFromList(ValueSubClass
*V
) {
64 if (V
->hasName() && SymTabObject
)
65 SymTabObject
->getSymbolTable().remove(V
);
68 template<typename ValueSubClass
, typename ItemParentClass
, typename SymTabClass
,
70 void SymbolTableListTraits
<ValueSubClass
,ItemParentClass
,SymTabClass
,SubClass
>
71 ::transferNodesFromList(iplist
<ValueSubClass
, ilist_traits
<ValueSubClass
> > &L2
,
72 ilist_iterator
<ValueSubClass
> first
,
73 ilist_iterator
<ValueSubClass
> last
) {
74 // We only have to do work here if transferring instructions between BBs
75 ItemParentClass
*NewIP
= ItemParent
, *OldIP
= L2
.ItemParent
;
76 if (NewIP
== OldIP
) return; // No work to do at all...
78 // We only have to update symbol table entries if we are transferring the
79 // instructions to a different symtab object...
80 SymTabClass
*NewSTO
= SymTabObject
, *OldSTO
= L2
.SymTabObject
;
81 if (NewSTO
!= OldSTO
) {
82 for (; first
!= last
; ++first
) {
83 ValueSubClass
&V
= *first
;
84 bool HasName
= V
.hasName();
85 if (OldSTO
&& HasName
)
86 OldSTO
->getSymbolTable().remove(&V
);
88 if (NewSTO
&& HasName
)
89 NewSTO
->getSymbolTable().insert(&V
);
92 // Just transferring between blocks in the same function, simply update the
93 // parent fields in the instructions...
94 for (; first
!= last
; ++first
)
95 first
->setParent(NewIP
);
99 } // End llvm namespace