Fix a ton of comment typos found by codespell. Patch by
[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 "llvm/ADT/StringRef.h"
19 #include "llvm/Support/DataTypes.h"
20 #include <map>
21
22 namespace llvm {
23
24 /// This class provides a symbol table of name/type pairs with operations to
25 /// support constructing, searching and iterating over the symbol table. The
26 /// class derives from AbstractTypeUser so that the contents of the symbol
27 /// table can be updated when abstract types become concrete.
28 class TypeSymbolTable : public AbstractTypeUser {
29
30 /// @name Types
31 /// @{
32 public:
33
34   /// @brief A mapping of names to types.
35   typedef std::map<const std::string, const Type*> TypeMap;
36
37   /// @brief An iterator over the TypeMap.
38   typedef TypeMap::iterator iterator;
39
40   /// @brief A const_iterator over the TypeMap.
41   typedef TypeMap::const_iterator const_iterator;
42
43 /// @}
44 /// @name Constructors
45 /// @{
46 public:
47
48   TypeSymbolTable():LastUnique(0) {}
49   ~TypeSymbolTable();
50
51 /// @}
52 /// @name Accessors
53 /// @{
54 public:
55
56   /// Generates a unique name for a type based on the \p BaseName by
57   /// incrementing an integer and appending it to the name, if necessary
58   /// @returns the unique name
59   /// @brief Get a unique name for a type
60   std::string getUniqueName(StringRef BaseName) const;
61
62   /// This method finds the type with the given \p name in the type map
63   /// and returns it.
64   /// @returns null if the name is not found, otherwise the Type
65   /// associated with the \p name.
66   /// @brief Lookup a type by name.
67   Type *lookup(StringRef name) const;
68
69   /// Lookup the type associated with name.
70   /// @returns end() if the name is not found, or an iterator at the entry for
71   /// Type.
72   iterator find(StringRef Name) {
73     return tmap.find(Name);
74   }
75
76   /// Lookup the type associated with name.
77   /// @returns end() if the name is not found, or an iterator at the entry for
78   /// Type.
79   const_iterator find(StringRef Name) const {
80     return tmap.find(Name);
81   }
82
83   /// @returns true iff the symbol table is empty.
84   /// @brief Determine if the symbol table is empty
85   inline bool empty() const { return tmap.empty(); }
86
87   /// @returns the size of the symbol table
88   /// @brief The number of name/type pairs is returned.
89   inline unsigned size() const { return unsigned(tmap.size()); }
90
91   /// This function can be used from the debugger to display the
92   /// content of the symbol table while debugging.
93   /// @brief Print out symbol table on stderr
94   void dump() const;
95
96 /// @}
97 /// @name Iteration
98 /// @{
99 public:
100   /// Get an iterator to the start of the symbol table
101   inline iterator begin() { return tmap.begin(); }
102
103   /// @brief Get a const_iterator to the start of the symbol table
104   inline const_iterator begin() const { return tmap.begin(); }
105
106   /// Get an iterator to the end of the symbol table.
107   inline iterator end() { return tmap.end(); }
108
109   /// Get a const_iterator to the end of the symbol table.
110   inline const_iterator end() const { return tmap.end(); }
111
112 /// @}
113 /// @name Mutators
114 /// @{
115 public:
116
117   /// Inserts a type into the symbol table with the specified name. There can be
118   /// a many-to-one mapping between names and types. This method allows a type
119   /// with an existing entry in the symbol table to get a new name.
120   /// @brief Insert a type under a new name.
121   void insert(StringRef Name, const Type *Typ);
122
123   /// Remove a type at the specified position in the symbol table.
124   /// @returns the removed Type.
125   /// @returns the Type that was erased from the symbol table.
126   Type* remove(iterator TI);
127
128 /// @}
129 /// @name AbstractTypeUser Methods
130 /// @{
131 private:
132   /// This function is called when one of the types in the type plane
133   /// is refined.
134   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
135
136   /// This function marks a type as being concrete (defined).
137   virtual void typeBecameConcrete(const DerivedType *AbsTy);
138
139 /// @}
140 /// @name Internal Data
141 /// @{
142 private:
143   TypeMap tmap; ///< This is the mapping of names to types.
144   mutable uint32_t LastUnique; ///< Counter for tracking unique names
145
146 /// @}
147
148 };
149
150 } // End llvm namespace
151
152 #endif