1 //===-- llvm/SymbolTable.h - Implement a type planed symtab -------*- C++ -*-=//
3 // This file implements a symbol table that has planed broken up by type.
4 // Identical types may have overlapping symbol names as long as they are
7 // Note that this implements a chained symbol table. If a name being 'lookup'd
8 // isn't found in the current symbol table, then the parent symbol table is
11 // This chaining behavior does NOT affect iterators though: only the lookup
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_SYMBOL_TABLE_H
17 #define LLVM_SYMBOL_TABLE_H
26 // TODO: Change this back to vector<map<const string, Value *> >
27 // Make the vector be a data member, and base it on UniqueID's
28 // That should be much more efficient!
30 class SymbolTable : public map<const Type *, map<const string, Value *> > {
31 typedef map<const string, Value *> VarMap;
32 typedef map<const Type *, VarMap> super;
34 SymbolTable *ParentSymTab;
36 friend class SymTabValue;
37 inline void setParentSymTab(SymbolTable *P) { ParentSymTab = P; }
40 typedef VarMap::iterator type_iterator;
41 typedef VarMap::const_iterator type_const_iterator;
43 inline SymbolTable(SymbolTable *P = 0) { ParentSymTab = P; }
46 SymbolTable *getParentSymTab() { return ParentSymTab; }
48 // lookup - Returns null on failure...
49 Value *lookup(const Type *Ty, const string &name);
51 // find - returns end(Ty->getIDNumber()) on failure...
52 type_iterator type_find(const Type *Ty, const string &name);
53 type_iterator type_find(const Value *D);
55 // insert - Add named definition to the symbol table...
56 void insert(Value *N);
58 void remove(Value *N);
59 Value *type_remove(const type_iterator &It);
61 inline unsigned type_size(const Type *TypeID) const {
62 return find(TypeID)->second.size();
65 // Note that type_begin / type_end only work if you know that an element of
66 // TypeID is already in the symbol table!!!
68 inline type_iterator type_begin(const Type *TypeID) {
69 return find(TypeID)->second.begin();
71 inline type_const_iterator type_begin(const Type *TypeID) const {
72 return find(TypeID)->second.begin();
75 inline type_iterator type_end(const Type *TypeID) {
76 return find(TypeID)->second.end();
78 inline type_const_iterator type_end(const Type *TypeID) const {
79 return find(TypeID)->second.end();