* Make Module::getTypeName const
authorChris Lattner <sabre@nondot.org>
Wed, 31 Dec 2003 07:09:33 +0000 (07:09 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 31 Dec 2003 07:09:33 +0000 (07:09 +0000)
* Add new Module::getTypeByName method
* Group methods in Module.cpp better

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10668 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Module.h
lib/VMCore/Module.cpp

index b38269dde027d4aad751012fb5f6eaa3b0bf3df5..2e448e604591df41b24de47bc41e4286d31c237c 100644 (file)
@@ -132,7 +132,11 @@ public:
   /// getTypeName - If there is at least one entry in the symbol table for the
   /// specified type, return it.
   ///
-  std::string getTypeName(const Type *Ty);
+  std::string getTypeName(const Type *Ty) const;
+
+  /// getTypeByName - Return the type with the specified name in this module, or
+  /// null if there is none by that name.
+  const Type *getTypeByName(const std::string &Name) const;
 
   /// Get the underlying elements of the Module...
   inline const GlobalListType &getGlobalList() const  { return GlobalList; }
index b4b0925926f0c6cb51d8f5e2829651496d88856c..83e0a6e1ff5a2e6efe956c7713b8569861130b0d 100644 (file)
@@ -137,21 +137,6 @@ Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) {
   return cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name));
 }
 
-// addTypeName - Insert an entry in the symbol table mapping Str to Type.  If
-// there is already an entry for this name, true is returned and the symbol
-// table is not modified.
-//
-bool Module::addTypeName(const std::string &Name, const Type *Ty) {
-  SymbolTable &ST = getSymbolTable();
-
-  if (ST.lookup(Type::TypeTy, Name)) return true;  // Already in symtab...
-  
-  // Not in symbol table?  Set the name with the Symtab as an argument so the
-  // type knows what to update...
-  ((Value*)Ty)->setName(Name, &ST);
-
-  return false;
-}
 
 /// getMainFunction - This function looks up main efficiently.  This is such a
 /// common case, that it is a method in Module.  If main cannot be found, a
@@ -217,11 +202,33 @@ Function *Module::getNamedFunction(const std::string &Name) {
 }
 
 
+// addTypeName - Insert an entry in the symbol table mapping Str to Type.  If
+// there is already an entry for this name, true is returned and the symbol
+// table is not modified.
+//
+bool Module::addTypeName(const std::string &Name, const Type *Ty) {
+  SymbolTable &ST = getSymbolTable();
+
+  if (ST.lookup(Type::TypeTy, Name)) return true;  // Already in symtab...
+  
+  // Not in symbol table?  Set the name with the Symtab as an argument so the
+  // type knows what to update...
+  ((Value*)Ty)->setName(Name, &ST);
+
+  return false;
+}
+
+/// getTypeByName - Return the type with the specified name in this module, or
+/// null if there is none by that name.
+const Type *Module::getTypeByName(const std::string &Name) const {
+  const SymbolTable &ST = getSymbolTable();
+  return cast_or_null<Type>(ST.lookup(Type::TypeTy, Name));
+}
 
 // getTypeName - If there is at least one entry in the symbol table for the
 // specified type, return it.
 //
-std::string Module::getTypeName(const Type *Ty) {
+std::string Module::getTypeName(const Type *Ty) const {
   const SymbolTable &ST = getSymbolTable();
   if (ST.find(Type::TypeTy) == ST.end())
     return ""; // No names for types...