1 //===-- llvm/TypeSymbolTable.h - Implement a Type Symtab --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer. It is distributed under the
6 // University of Illinois Open Source 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"
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 {
32 /// @brief A mapping of names to types.
33 typedef std::map<const std::string, const Type*> TypeMap;
35 /// @brief An iterator over the TypeMap.
36 typedef TypeMap::iterator iterator;
38 /// @brief A const_iterator over the TypeMap.
39 typedef TypeMap::const_iterator const_iterator;
42 /// @name Constructors
46 TypeSymbolTable():LastUnique(0) {}
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;
60 /// This method finds the type with the given \p name in the type map
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;
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(); }
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()); }
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
84 /// Get an iterator to the start of the symbol table
85 inline iterator begin() { return tmap.begin(); }
87 /// @brief Get a const_iterator to the start of the symbol table
88 inline const_iterator begin() const { return tmap.begin(); }
90 /// Get an iterator to the end of the symbol talbe.
91 inline iterator end() { return tmap.end(); }
93 /// Get a const_iterator to the end of the symbol table.
94 inline const_iterator end() const { return tmap.end(); }
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);
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);
113 /// @name AbstractTypeUser Methods
116 /// This function is called when one of the types in the type plane
118 virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
120 /// This function markes a type as being concrete (defined).
121 virtual void typeBecameConcrete(const DerivedType *AbsTy);
124 /// @name Internal Data
127 TypeMap tmap; ///< This is the mapping of names to types.
128 mutable uint32_t LastUnique; ///< Counter for tracking unique names
134 } // End llvm namespace