More constification of things. More comments added. No functionality
[oota-llvm.git] / include / llvm / TypeSymbolTable.h
1 //===-- llvm/TypeSymbolTable.h - Implement a Type Symtab --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the name/type symbol table for LLVM.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TYPE_SYMBOL_TABLE_H
15 #define LLVM_TYPE_SYMBOL_TABLE_H
16
17 #include "llvm/Type.h"
18 #include <map>
19
20 namespace llvm {
21
22 /// This class provides a symbol table of name/type pairs with operations to
23 /// support constructing, searching and iterating over the symbol table. The
24 /// class derives from AbstractTypeUser so that the contents of the symbol
25 /// table can be updated when abstract types become concrete.
26 class TypeSymbolTable : public AbstractTypeUser {
27
28 /// @name Types
29 /// @{
30 public:
31
32   /// @brief A mapping of names to types.
33   typedef std::map<const std::string, const Type*> TypeMap;
34
35   /// @brief An iterator over the TypeMap.
36   typedef TypeMap::iterator iterator;
37
38   /// @brief A const_iterator over the TypeMap.
39   typedef TypeMap::const_iterator const_iterator;
40
41 /// @}
42 /// @name Constructors
43 /// @{
44 public:
45
46   TypeSymbolTable():LastUnique(0) {}
47   ~TypeSymbolTable();
48
49 /// @}
50 /// @name Accessors
51 /// @{
52 public:
53
54   /// Generates a unique name for a type based on the \p BaseName by
55   /// incrementing an integer and appending it to the name, if necessary
56   /// @returns the unique name
57   /// @brief Get a unique name for a type
58   std::string getUniqueName(const std::string &BaseName) const;
59
60   /// This method finds the type with the given \p name in the type map
61   /// and returns it.
62   /// @returns null if the name is not found, otherwise the Type
63   /// associated with the \p name.
64   /// @brief Lookup a type by name.
65   Type* lookup(const std::string& name) const;
66
67   /// @returns true iff the symbol table is empty.
68   /// @brief Determine if the symbol table is empty
69   inline bool empty() const { return tmap.empty(); }
70
71   /// @returns the size of the symbol table
72   /// @brief The number of name/type pairs is returned.
73   inline unsigned size() const { return unsigned(tmap.size()); }
74
75   /// This function can be used from the debugger to display the
76   /// content of the symbol table while debugging.
77   /// @brief Print out symbol table on stderr
78   void dump() const;
79
80 /// @}
81 /// @name Iteration
82 /// @{
83 public:
84   /// Get an iterator to the start of the symbol table
85   inline iterator begin() { return tmap.begin(); }
86
87   /// @brief Get a const_iterator to the start of the symbol table
88   inline const_iterator begin() const { return tmap.begin(); }
89
90   /// Get an iterator to the end of the symbol talbe. 
91   inline iterator end() { return tmap.end(); }
92
93   /// Get a const_iterator to the end of the symbol table.
94   inline const_iterator end() const { return tmap.end(); }
95
96 /// @}
97 /// @name Mutators
98 /// @{
99 public:
100
101   /// Inserts a type into the symbol table with the specified name. There can be
102   /// a many-to-one mapping between names and types. This method allows a type
103   /// with an existing entry in the symbol table to get a new name.
104   /// @brief Insert a type under a new name.
105   void insert(const std::string &Name, const Type *Typ);
106
107   /// Remove a type at the specified position in the symbol table.
108   /// @returns the removed Type.
109   /// @returns the Type that was erased from the symbol table.
110   Type* remove(iterator TI);
111
112 /// @}
113 /// @name AbstractTypeUser Methods
114 /// @{
115 private:
116   /// This function is called when one of the types in the type plane
117   /// is refined.
118   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
119
120   /// This function markes a type as being concrete (defined).
121   virtual void typeBecameConcrete(const DerivedType *AbsTy);
122
123 /// @}
124 /// @name Internal Data
125 /// @{
126 private:
127   TypeMap tmap; ///< This is the mapping of names to types.
128   mutable uint32_t LastUnique; ///< Counter for tracking unique names
129
130 /// @}
131
132 };
133
134 } // End llvm namespace
135
136 #endif
137