Promote ModuleMap::Module to a namespace-scope class in the Basic
library, since modules cut across all of the libraries. Rename
serialization::Module to serialization::ModuleFile to side-step the
annoying naming conflict. Prune a bunch of ModuleMap.h includes that
are no longer needed (most files only needed the Module type).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145538 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp
index c1c3a2f..1d560fc 100644
--- a/lib/Lex/HeaderSearch.cpp
+++ b/lib/Lex/HeaderSearch.cpp
@@ -102,7 +102,7 @@
 }
 
 const FileEntry *HeaderSearch::lookupModule(StringRef ModuleName,
-                                            ModuleMap::Module *&Module,
+                                            Module *&Module,
                                             std::string *ModuleFileName) {
   Module = 0;
   
@@ -198,7 +198,7 @@
     SmallVectorImpl<char> *SearchPath,
     SmallVectorImpl<char> *RelativePath,
     StringRef BuildingModule,
-    ModuleMap::Module **SuggestedModule) const {
+    Module **SuggestedModule) const {
   llvm::SmallString<1024> TmpDir;
   if (isNormalDir()) {
     // Concatenate the requested file onto the directory.
@@ -224,7 +224,7 @@
       
       // If there is a module that corresponds to this header, 
       // suggest it.
-      ModuleMap::Module *Module = HS.findModuleForHeader(File);
+      Module *Module = HS.findModuleForHeader(File);
       if (Module && Module->getTopLevelModuleName() != BuildingModule)
         *SuggestedModule = Module;
       
@@ -264,7 +264,7 @@
     SmallVectorImpl<char> *SearchPath,
     SmallVectorImpl<char> *RelativePath,
     StringRef BuildingModule,
-    ModuleMap::Module **SuggestedModule) const 
+    Module **SuggestedModule) const 
 {
   FileManager &FileMgr = HS.getFileMgr();
 
@@ -319,7 +319,7 @@
 
   // If we're allowed to look for modules, try to load or create the module
   // corresponding to this framework.
-  ModuleMap::Module *Module = 0;
+  Module *Module = 0;
   if (SuggestedModule) {
     if (const DirectoryEntry *FrameworkDir
                                     = FileMgr.getDirectory(FrameworkName)) {
@@ -387,7 +387,7 @@
     const FileEntry *CurFileEnt,
     SmallVectorImpl<char> *SearchPath,
     SmallVectorImpl<char> *RelativePath,
-    ModuleMap::Module **SuggestedModule,
+    Module **SuggestedModule,
     bool SkipCache)
 {
   if (SuggestedModule)
@@ -786,8 +786,8 @@
   return false;
 }
 
-ModuleMap::Module *HeaderSearch::findModuleForHeader(const FileEntry *File) {
-  if (ModuleMap::Module *Module = ModMap.findModuleForHeader(File))
+Module *HeaderSearch::findModuleForHeader(const FileEntry *File) {
+  if (Module *Module = ModMap.findModuleForHeader(File))
     return Module;
   
   return 0;
@@ -806,8 +806,8 @@
   return Result;
 }
 
-ModuleMap::Module *HeaderSearch::getModule(StringRef Name, bool AllowSearch) {
-  if (ModuleMap::Module *Module = ModMap.findModule(Name))
+Module *HeaderSearch::getModule(StringRef Name, bool AllowSearch) {
+  if (Module *Module = ModMap.findModule(Name))
     return Module;
   
   if (!AllowSearch)
@@ -824,7 +824,7 @@
       break;
         
     case LMM_NewlyLoaded:
-      if (ModuleMap::Module *Module = ModMap.findModule(Name))
+      if (Module *Module = ModMap.findModule(Name))
         return Module;
       break;
     }
@@ -833,9 +833,9 @@
   return 0;
 }
   
-ModuleMap::Module *HeaderSearch::getFrameworkModule(StringRef Name, 
+Module *HeaderSearch::getFrameworkModule(StringRef Name, 
                                                     const DirectoryEntry *Dir) {
-  if (ModuleMap::Module *Module = ModMap.findModule(Name))
+  if (Module *Module = ModMap.findModule(Name))
     return Module;
   
   // Try to load a module map file.
diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp
index 11a20e0..77f6351 100644
--- a/lib/Lex/ModuleMap.cpp
+++ b/lib/Lex/ModuleMap.cpp
@@ -27,86 +27,6 @@
 #include "llvm/ADT/StringSwitch.h"
 using namespace clang;
 
-//----------------------------------------------------------------------------//
-// Module
-//----------------------------------------------------------------------------//
-
-ModuleMap::Module::~Module() {
-  for (llvm::StringMap<Module *>::iterator I = SubModules.begin(), 
-                                        IEnd = SubModules.end();
-       I != IEnd; ++I) {
-    delete I->getValue();
-  }
-
-}
-
-std::string ModuleMap::Module::getFullModuleName() const {
-  llvm::SmallVector<StringRef, 2> Names;
-  
-  // Build up the set of module names (from innermost to outermost).
-  for (const Module *M = this; M; M = M->Parent)
-    Names.push_back(M->Name);
-  
-  std::string Result;
-  for (llvm::SmallVector<StringRef, 2>::reverse_iterator I = Names.rbegin(),
-                                                      IEnd = Names.rend(); 
-       I != IEnd; ++I) {
-    if (!Result.empty())
-      Result += '.';
-    
-    Result += *I;
-  }
-  
-  return Result;
-}
-
-StringRef ModuleMap::Module::getTopLevelModuleName() const {
-  const Module *Top = this;
-  while (Top->Parent)
-    Top = Top->Parent;
-  
-  return Top->Name;
-}
-
-void ModuleMap::Module::print(llvm::raw_ostream &OS, unsigned Indent) const {
-  OS.indent(Indent);
-  if (IsFramework)
-    OS << "framework ";
-  if (IsExplicit)
-    OS << "explicit ";
-  OS << "module " << Name << " {\n";
-  
-  if (UmbrellaHeader) {
-    OS.indent(Indent + 2);
-    OS << "umbrella \"";
-    OS.write_escaped(UmbrellaHeader->getName());
-    OS << "\"\n";
-  }
-  
-  for (unsigned I = 0, N = Headers.size(); I != N; ++I) {
-    OS.indent(Indent + 2);
-    OS << "header \"";
-    OS.write_escaped(Headers[I]->getName());
-    OS << "\"\n";
-  }
-  
-  for (llvm::StringMap<Module *>::const_iterator MI = SubModules.begin(), 
-                                              MIEnd = SubModules.end();
-       MI != MIEnd; ++MI)
-    MI->getValue()->print(OS, Indent + 2);
-  
-  OS.indent(Indent);
-  OS << "}\n";
-}
-
-void ModuleMap::Module::dump() const {
-  print(llvm::errs());
-}
-
-//----------------------------------------------------------------------------//
-// Module map
-//----------------------------------------------------------------------------//
-
 ModuleMap::ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC) {
   llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(new DiagnosticIDs);
   Diags = llvm::IntrusiveRefCntPtr<DiagnosticsEngine>(
@@ -125,7 +45,7 @@
   delete SourceMgr;
 }
 
-ModuleMap::Module *ModuleMap::findModuleForHeader(const FileEntry *File) {
+Module *ModuleMap::findModuleForHeader(const FileEntry *File) {
   llvm::DenseMap<const FileEntry *, Module *>::iterator Known
     = Headers.find(File);
   if (Known != Headers.end())
@@ -169,7 +89,7 @@
   return 0;
 }
 
-ModuleMap::Module *ModuleMap::findModule(StringRef Name) {
+Module *ModuleMap::findModule(StringRef Name) {
   llvm::StringMap<Module *>::iterator Known = Modules.find(Name);
   if (Known != Modules.end())
     return Known->getValue();
@@ -177,7 +97,7 @@
   return 0;
 }
 
-std::pair<ModuleMap::Module *, bool> 
+std::pair<Module *, bool> 
 ModuleMap::findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
                               bool IsExplicit) {
   // Try to find an existing module with this name.
@@ -194,7 +114,7 @@
   return std::make_pair(Result, true);
 }
 
-ModuleMap::Module *
+Module *
 ModuleMap::inferFrameworkModule(StringRef ModuleName, 
                                 const DirectoryEntry *FrameworkDir) {
   // Check whether we've already found this module.
@@ -224,7 +144,7 @@
 }
 
 const FileEntry *
-ModuleMap::getContainingModuleMapFile(ModuleMap::Module *Module) {
+ModuleMap::getContainingModuleMapFile(Module *Module) {
   if (Module->DefinitionLoc.isInvalid() || !SourceMgr)
     return 0;
 
@@ -315,7 +235,7 @@
     MMToken Tok;
     
     /// \brief The active module.
-    ModuleMap::Module *ActiveModule;
+    Module *ActiveModule;
     
     /// \brief Consume the current token and return its location.
     SourceLocation consumeToken();
@@ -329,7 +249,7 @@
     void parseHeaderDecl();
     
   public:
-    typedef ModuleMap::Module Module;
+    typedef Module Module;
     
     explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr, 
                              DiagnosticsEngine &Diags,
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index e86680e..81cb526 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -487,7 +487,7 @@
     const DirectoryLookup *&CurDir,
     SmallVectorImpl<char> *SearchPath,
     SmallVectorImpl<char> *RelativePath,
-    ModuleMap::Module **SuggestedModule,
+    Module **SuggestedModule,
     bool SkipCache) {
   // If the header lookup mechanism may be relative to the current file, pass in
   // info about where the current file is.
@@ -1274,7 +1274,7 @@
   llvm::SmallString<1024> RelativePath;
   // We get the raw path only if we have 'Callbacks' to which we later pass
   // the path.
-  ModuleMap::Module *SuggestedModule = 0;
+  Module *SuggestedModule = 0;
   const FileEntry *File = LookupFile(
       Filename, isAngled, LookupFrom, CurDir,
       Callbacks ? &SearchPath : NULL, Callbacks ? &RelativePath : NULL,
@@ -1316,7 +1316,7 @@
     // FIXME: Should we have a second loadModule() overload to avoid this
     // extra lookup step?
     llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
-    for (ModuleMap::Module *Mod = SuggestedModule; Mod; Mod = Mod->Parent)
+    for (Module *Mod = SuggestedModule; Mod; Mod = Mod->Parent)
       Path.push_back(std::make_pair(getIdentifierInfo(Mod->Name),
                                     FilenameTok.getLocation()));
     std::reverse(Path.begin(), Path.end());