[cfe-commits] r145695 - in /cfe/trunk: include/clang/Serialization/ASTBitCodes.h include/clang/Serialization/ASTReader.h lib/Basic/Module.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp

Douglas Gregor dgregor at apple.com
Fri Dec 2 10:58:38 PST 2011


Author: dgregor
Date: Fri Dec  2 12:58:38 2011
New Revision: 145695

URL: http://llvm.org/viewvc/llvm-project?rev=145695&view=rev
Log:
Implement (de-)serialization of the set of exported modules in a
module map. 

Modified:
    cfe/trunk/include/clang/Serialization/ASTBitCodes.h
    cfe/trunk/include/clang/Serialization/ASTReader.h
    cfe/trunk/lib/Basic/Module.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=145695&r1=145694&r2=145695&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Fri Dec  2 12:58:38 2011
@@ -512,7 +512,10 @@
       /// \brief Specifies a header that falls into this (sub)module.
       SUBMODULE_HEADER = 2,
       /// \brief Metadata for submodules as a whole.
-      SUBMODULE_METADATA = 3
+      SUBMODULE_METADATA = 3,
+      /// \brief Specifies the submodules that are re-exported from this 
+      /// submodule.
+      SUBMODULE_EXPORTS = 4
     };
     
     /// \defgroup ASTAST AST file AST constants

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=145695&r1=145694&r2=145695&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri Dec  2 12:58:38 2011
@@ -393,6 +393,22 @@
   /// declarations in that submodule that could be made visible.
   HiddenNamesMapType HiddenNamesMap;
   
+  /// \brief A module export that hasn't yet been resolved.
+  struct UnresolvedModuleExport {
+    /// \brief The file in which this module resides.
+    ModuleFile *File;
+    
+    /// \brief The module that is exporting, along with a bit that specifies
+    /// whether this is a wildcard export.
+    llvm::PointerIntPair<Module *, 1, bool> ModuleAndWildcard;
+    
+    /// \brief The local ID of the module that is being exported.
+    unsigned ExportedID;
+  };
+  
+  /// \brief The set of module exports that still need to be resolved.
+  llvm::SmallVector<UnresolvedModuleExport, 2> UnresolvedModuleExports;
+  
   /// \brief A vector containing selectors that have already been loaded.
   ///
   /// This vector is indexed by the Selector ID (-1). NULL selector

Modified: cfe/trunk/lib/Basic/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Module.cpp?rev=145695&r1=145694&r2=145695&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Module.cpp (original)
+++ cfe/trunk/lib/Basic/Module.cpp Fri Dec  2 12:58:38 2011
@@ -53,6 +53,14 @@
   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)
+      OS << ".";
+    OS << Id[I].first;
+  }
+}
+
 void Module::print(llvm::raw_ostream &OS, unsigned Indent) const {
   OS.indent(Indent);
   if (IsFramework)
@@ -80,6 +88,23 @@
        MI != MIEnd; ++MI)
     MI->getValue()->print(OS, Indent + 2);
   
+  for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
+    OS.indent(Indent + 2);
+    OS << "export " << Exports[I].getPointer()->getFullModuleName();
+    if (Exports[I].getInt())
+      OS << ".*";
+    OS << "\n";
+  }
+
+  for (unsigned I = 0, N = UnresolvedExports.size(); I != N; ++I) {
+    OS.indent(Indent + 2);
+    OS << "export ";
+    printModuleId(OS, UnresolvedExports[I].Id);
+    if (UnresolvedExports[I].Wildcard)
+      OS << ".*";
+    OS << "\n";
+  }
+
   OS.indent(Indent);
   OS << "}\n";
 }

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=145695&r1=145694&r2=145695&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Dec  2 12:58:38 2011
@@ -2533,6 +2533,19 @@
        Id != IdEnd; ++Id)
     Id->second->setOutOfDate(true);
 
+  // Resolve any unresolved module exports.
+  for (unsigned I = 0, N = UnresolvedModuleExports.size(); I != N; ++I) {
+    UnresolvedModuleExport &Unresolved = UnresolvedModuleExports[I];
+    SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,
+                                                Unresolved.ExportedID);
+    if (Module *Exported = getSubmodule(GlobalID)) {
+      Module *Exportee = Unresolved.ModuleAndWildcard.getPointer();
+      bool Wildcard = Unresolved.ModuleAndWildcard.getInt();
+      Exportee->Exports.push_back(Module::ExportDecl(Exported, Wildcard));
+    }
+  }
+  UnresolvedModuleExports.clear();
+  
   InitializeContext();
 
   if (DeserializationListener)
@@ -3050,6 +3063,30 @@
       }      
       break;
     }
+        
+    case SUBMODULE_EXPORTS: {
+      if (First) {
+        Error("missing submodule metadata record at beginning of block");
+        return Failure;
+      }
+      
+      if (!CurrentModule)
+        break;
+      
+      for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) {
+        UnresolvedModuleExport Unresolved;
+        Unresolved.File = &F;
+        Unresolved.ModuleAndWildcard.setPointer(CurrentModule);
+        Unresolved.ModuleAndWildcard.setInt(Record[Idx + 1]);
+        Unresolved.ExportedID = Record[Idx];
+        UnresolvedModuleExports.push_back(Unresolved);
+      }
+      
+      // Once we've loaded the set of exports, there's no reason to keep 
+      // the parsed, unresolved exports around.
+      CurrentModule->UnresolvedExports.clear();
+      break;
+    }
     }
   }
 

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=145695&r1=145694&r2=145695&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Dec  2 12:58:38 2011
@@ -1893,6 +1893,7 @@
   while (!Q.empty()) {
     Module *Mod = Q.front();
     Q.pop();
+    assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end());
     SubmoduleIDs[Mod] = NextSubmoduleID++;
     
     // Emit the definition of the block.
@@ -1924,6 +1925,18 @@
                                 Mod->Headers[I]->getName());
     }
     
+    // Emit the exports. 
+    if (!Mod->Exports.empty()) {
+      Record.clear();
+      for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) {
+        unsigned ExportedID = SubmoduleIDs[Mod->Exports[I].getPointer()];
+        assert(ExportedID && "Unknown submodule!");                                           
+        Record.push_back(ExportedID);
+        Record.push_back(Mod->Exports[I].getInt());
+      }
+      Stream.EmitRecord(SUBMODULE_EXPORTS, Record);
+    }
+    
     // Queue up the submodules of this module.
     llvm::SmallVector<StringRef, 2> SubModules;
     
@@ -3214,7 +3227,7 @@
     {
       llvm::raw_svector_ostream Out(Buffer);
       for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(),
-           MEnd = Chain->ModuleMgr.end();
+                                           MEnd = Chain->ModuleMgr.end();
            M != MEnd; ++M) {
         StringRef FileName = (*M)->FileName;
         io::Emit16(Out, FileName.size());





More information about the cfe-commits mailing list