LLVM API Documentation

TypeSymbolTable.h

Go to the documentation of this file.
00001 //===-- llvm/TypeSymbolTable.h - Implement a Type Symtab --------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the name/type symbol table for LLVM.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_TYPE_SYMBOL_TABLE_H
00015 #define LLVM_TYPE_SYMBOL_TABLE_H
00016 
00017 #include "llvm/Type.h"
00018 #include <map>
00019 
00020 namespace llvm {
00021 
00022 class StringRef;
00023 
00024 /// This class provides a symbol table of name/type pairs with operations to
00025 /// support constructing, searching and iterating over the symbol table. The
00026 /// class derives from AbstractTypeUser so that the contents of the symbol
00027 /// table can be updated when abstract types become concrete.
00028 class TypeSymbolTable : public AbstractTypeUser {
00029 
00030 /// @name Types
00031 /// @{
00032 public:
00033 
00034   /// @brief A mapping of names to types.
00035   typedef std::map<const std::string, const Type*> TypeMap;
00036 
00037   /// @brief An iterator over the TypeMap.
00038   typedef TypeMap::iterator iterator;
00039 
00040   /// @brief A const_iterator over the TypeMap.
00041   typedef TypeMap::const_iterator const_iterator;
00042 
00043 /// @}
00044 /// @name Constructors
00045 /// @{
00046 public:
00047 
00048   TypeSymbolTable():LastUnique(0) {}
00049   ~TypeSymbolTable();
00050 
00051 /// @}
00052 /// @name Accessors
00053 /// @{
00054 public:
00055 
00056   /// Generates a unique name for a type based on the \p BaseName by
00057   /// incrementing an integer and appending it to the name, if necessary
00058   /// @returns the unique name
00059   /// @brief Get a unique name for a type
00060   std::string getUniqueName(const StringRef &BaseName) const;
00061 
00062   /// This method finds the type with the given \p name in the type map
00063   /// and returns it.
00064   /// @returns null if the name is not found, otherwise the Type
00065   /// associated with the \p name.
00066   /// @brief Lookup a type by name.
00067   Type *lookup(const StringRef &name) const;
00068 
00069   /// Lookup the type associated with name.
00070   /// @returns end() if the name is not found, or an iterator at the entry for
00071   /// Type.
00072   iterator find(const StringRef &name);
00073 
00074   /// Lookup the type associated with name.
00075   /// @returns end() if the name is not found, or an iterator at the entry for
00076   /// Type.
00077   const_iterator find(const StringRef &name) const;
00078 
00079   /// @returns true iff the symbol table is empty.
00080   /// @brief Determine if the symbol table is empty
00081   inline bool empty() const { return tmap.empty(); }
00082 
00083   /// @returns the size of the symbol table
00084   /// @brief The number of name/type pairs is returned.
00085   inline unsigned size() const { return unsigned(tmap.size()); }
00086 
00087   /// This function can be used from the debugger to display the
00088   /// content of the symbol table while debugging.
00089   /// @brief Print out symbol table on stderr
00090   void dump() const;
00091 
00092 /// @}
00093 /// @name Iteration
00094 /// @{
00095 public:
00096   /// Get an iterator to the start of the symbol table
00097   inline iterator begin() { return tmap.begin(); }
00098 
00099   /// @brief Get a const_iterator to the start of the symbol table
00100   inline const_iterator begin() const { return tmap.begin(); }
00101 
00102   /// Get an iterator to the end of the symbol table.
00103   inline iterator end() { return tmap.end(); }
00104 
00105   /// Get a const_iterator to the end of the symbol table.
00106   inline const_iterator end() const { return tmap.end(); }
00107 
00108 /// @}
00109 /// @name Mutators
00110 /// @{
00111 public:
00112 
00113   /// Inserts a type into the symbol table with the specified name. There can be
00114   /// a many-to-one mapping between names and types. This method allows a type
00115   /// with an existing entry in the symbol table to get a new name.
00116   /// @brief Insert a type under a new name.
00117   void insert(const StringRef &Name, const Type *Typ);
00118 
00119   /// Remove a type at the specified position in the symbol table.
00120   /// @returns the removed Type.
00121   /// @returns the Type that was erased from the symbol table.
00122   Type* remove(iterator TI);
00123 
00124 /// @}
00125 /// @name AbstractTypeUser Methods
00126 /// @{
00127 private:
00128   /// This function is called when one of the types in the type plane
00129   /// is refined.
00130   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
00131 
00132   /// This function markes a type as being concrete (defined).
00133   virtual void typeBecameConcrete(const DerivedType *AbsTy);
00134 
00135 /// @}
00136 /// @name Internal Data
00137 /// @{
00138 private:
00139   TypeMap tmap; ///< This is the mapping of names to types.
00140   mutable uint32_t LastUnique; ///< Counter for tracking unique names
00141 
00142 /// @}
00143 
00144 };
00145 
00146 } // End llvm namespace
00147 
00148 #endif