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