Parse inferred submodules in module maps, track their contents in
Module, and (de-)serialize this information. Semantics of inferred
submodules to follow.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145864 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/Module.cpp b/lib/Basic/Module.cpp
index c3a8a37..97bddfa 100644
--- a/lib/Basic/Module.cpp
+++ b/lib/Basic/Module.cpp
@@ -37,6 +37,14 @@
   return false;
 }
 
+const Module *Module::getTopLevelModule() const {
+  const Module *Result = this;
+  while (Result->Parent)
+    Result = Result->Parent;
+  
+  return Result;
+}
+
 std::string Module::getFullModuleName() const {
   llvm::SmallVector<StringRef, 2> Names;
   
@@ -57,14 +65,6 @@
   return Result;
 }
 
-StringRef Module::getTopLevelModuleName() const {
-  const Module *Top = this;
-  while (Top->Parent)
-    Top = Top->Parent;
-  
-  return Top->Name;
-}
-
 static void printModuleId(llvm::raw_ostream &OS, const ModuleId &Id) {
   for (unsigned I = 0, N = Id.size(); I != N; ++I) {
     if (I)
@@ -96,7 +96,7 @@
   }
   
   for (llvm::StringMap<Module *>::const_iterator MI = SubModules.begin(), 
-       MIEnd = SubModules.end();
+                                              MIEnd = SubModules.end();
        MI != MIEnd; ++MI)
     MI->getValue()->print(OS, Indent + 2);
   
@@ -126,6 +126,19 @@
     OS << "\n";
   }
 
+  if (InferSubmodules) {
+    OS.indent(Indent + 2);
+    if (InferExplicitSubmodules)
+      OS << "explicit ";
+    OS << "module * {\n";
+    if (InferExportWildcard) {
+      OS.indent(Indent + 4);
+      OS << "export *\n";
+    }
+    OS.indent(Indent + 2);
+    OS << "}\n";
+  }
+  
   OS.indent(Indent);
   OS << "}\n";
 }