1 //===-- llvm/TypeSymbolTable.h - Implement a Type Symtab --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the name/type symbol table for LLVM.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TYPE_SYMBOL_TABLE_H
15 #define LLVM_TYPE_SYMBOL_TABLE_H
17 #include "llvm/Type.h"
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
{
34 /// @brief A mapping of names to types.
35 typedef std::map
<const std::string
, const Type
*> TypeMap
;
37 /// @brief An iterator over the TypeMap.
38 typedef TypeMap::iterator iterator
;
40 /// @brief A const_iterator over the TypeMap.
41 typedef TypeMap::const_iterator const_iterator
;
44 /// @name Constructors
48 TypeSymbolTable():LastUnique(0) {}
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(const StringRef
&BaseName
) const;
62 /// This method finds the type with the given \p name in the type map
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(const StringRef
&name
) const;
69 /// Lookup the type associated with name.
70 /// @returns end() if the name is not found, or an iterator at the entry for
72 iterator
find(const StringRef
&name
);
74 /// Lookup the type associated with name.
75 /// @returns end() if the name is not found, or an iterator at the entry for
77 const_iterator
find(const StringRef
&name
) const;
79 /// @returns true iff the symbol table is empty.
80 /// @brief Determine if the symbol table is empty
81 inline bool empty() const { return tmap
.empty(); }
83 /// @returns the size of the symbol table
84 /// @brief The number of name/type pairs is returned.
85 inline unsigned size() const { return unsigned(tmap
.size()); }
87 /// This function can be used from the debugger to display the
88 /// content of the symbol table while debugging.
89 /// @brief Print out symbol table on stderr
96 /// Get an iterator to the start of the symbol table
97 inline iterator
begin() { return tmap
.begin(); }
99 /// @brief Get a const_iterator to the start of the symbol table
100 inline const_iterator
begin() const { return tmap
.begin(); }
102 /// Get an iterator to the end of the symbol table.
103 inline iterator
end() { return tmap
.end(); }
105 /// Get a const_iterator to the end of the symbol table.
106 inline const_iterator
end() const { return tmap
.end(); }
113 /// Inserts a type into the symbol table with the specified name. There can be
114 /// a many-to-one mapping between names and types. This method allows a type
115 /// with an existing entry in the symbol table to get a new name.
116 /// @brief Insert a type under a new name.
117 void insert(const StringRef
&Name
, const Type
*Typ
);
119 /// Remove a type at the specified position in the symbol table.
120 /// @returns the removed Type.
121 /// @returns the Type that was erased from the symbol table.
122 Type
* remove(iterator TI
);
125 /// @name AbstractTypeUser Methods
128 /// This function is called when one of the types in the type plane
130 virtual void refineAbstractType(const DerivedType
*OldTy
, const Type
*NewTy
);
132 /// This function markes a type as being concrete (defined).
133 virtual void typeBecameConcrete(const DerivedType
*AbsTy
);
136 /// @name Internal Data
139 TypeMap tmap
; ///< This is the mapping of names to types.
140 mutable uint32_t LastUnique
; ///< Counter for tracking unique names
146 } // End llvm namespace