Rename ASTReader::PerFileData to serialization::Module, pulling it out
of ASTReader so it can become its own full-fledged class
(eventually). No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135767 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index e6d16fe..929db51 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -483,7 +483,7 @@
 namespace {
 class ASTSelectorLookupTrait {
   ASTReader &Reader;
-  ASTReader::PerFileData &F;
+  Module &F;
   
 public:
   struct data_type {
@@ -494,7 +494,7 @@
   typedef Selector external_key_type;
   typedef external_key_type internal_key_type;
 
-  ASTSelectorLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F) 
+  ASTSelectorLookupTrait(ASTReader &Reader, Module &F) 
     : Reader(Reader), F(F) { }
 
   static bool EqualKey(const internal_key_type& a,
@@ -595,7 +595,7 @@
 namespace clang {
 class ASTIdentifierLookupTrait {
   ASTReader &Reader;
-  ASTReader::PerFileData &F;
+  Module &F;
 
   // If we know the IdentifierInfo in advance, it is here and we will
   // not build a new one. Used when deserializing information about an
@@ -609,7 +609,7 @@
 
   typedef external_key_type internal_key_type;
 
-  ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F,
+  ASTIdentifierLookupTrait(ASTReader &Reader, Module &F,
                            IdentifierInfo *II = 0)
     : Reader(Reader), F(F), KnownII(II) { }
 
@@ -738,7 +738,7 @@
 namespace {
 class ASTDeclContextNameLookupTrait {
   ASTReader &Reader;
-  ASTReader::PerFileData &F;
+  Module &F;
   
 public:
   /// \brief Pair of begin/end iterators for DeclIDs.
@@ -757,7 +757,7 @@
   typedef DeclNameKey internal_key_type;
 
   explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, 
-                                         ASTReader::PerFileData &F) 
+                                         Module &F) 
     : Reader(Reader), F(F) { }
 
   static bool EqualKey(const internal_key_type& a,
@@ -996,7 +996,7 @@
 
 /// \brief Read the line table in the source manager block.
 /// \returns true if there was an error.
-bool ASTReader::ParseLineTable(PerFileData &F,
+bool ASTReader::ParseLineTable(Module &F,
                                llvm::SmallVectorImpl<uint64_t> &Record) {
   unsigned Idx = 0;
   LineTableInfo &LineTable = SourceMgr.getLineTable();
@@ -1140,7 +1140,7 @@
 
 
 /// \brief Read a source manager block
-ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) {
+ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(Module &F) {
   using namespace SrcMgr;
 
   llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor;
@@ -1249,7 +1249,7 @@
     return Failure;
   }
 
-  PerFileData *F = GlobalSLocEntryMap.find(-ID)->second;
+  Module *F = GlobalSLocEntryMap.find(-ID)->second;
   F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]);
   llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
   unsigned BaseOffset = F->SLocEntryBaseOffset;
@@ -1313,7 +1313,7 @@
     }
 
     SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]);
-    if (IncludeLoc.isInvalid() && F->Type != MainFile) {
+    if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) {
       // This is the module's main file.
       IncludeLoc = getImportLocation(F);
     }
@@ -1373,7 +1373,7 @@
 }
 
 /// \brief Find the location where the module F is imported.
-SourceLocation ASTReader::getImportLocation(PerFileData *F) {
+SourceLocation ASTReader::getImportLocation(Module *F) {
   if (F->ImportLoc.isValid())
     return F->ImportLoc;
   // Otherwise we have a PCH. It's considered to be "imported" at the first
@@ -1412,7 +1412,7 @@
   }
 }
 
-PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) {
+PreprocessedEntity *ASTReader::ReadMacroRecord(Module &F, uint64_t Offset) {
   assert(PP && "Forgot to set Preprocessor ?");
   llvm::BitstreamCursor &Stream = F.MacroCursor;
 
@@ -1532,7 +1532,7 @@
   return 0;
 }
 
-PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) {
+PreprocessedEntity *ASTReader::LoadPreprocessedEntity(Module &F) {
   assert(PP && "Forgot to set Preprocessor ?");
   unsigned Code = F.PreprocessorDetailCursor.ReadCode();
   switch (Code) {
@@ -1730,7 +1730,7 @@
 typedef OnDiskChainedHashTable<HeaderFileInfoTrait>
   HeaderFileInfoLookupTable;
 
-void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F,
+void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, Module &F,
                                      uint64_t Offset) {
   // Note that this identifier has a macro definition.
   II->setHasMacroDefinition(true);
@@ -1741,7 +1741,7 @@
 
 void ASTReader::ReadDefinedMacros() {
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
-    PerFileData &F = *Chain[N - I - 1];
+    Module &F = *Chain[N - I - 1];
     llvm::BitstreamCursor &MacroCursor = F.MacroCursor;
 
     // If there was no preprocessor block, skip this file.
@@ -1821,7 +1821,7 @@
     GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID);
     assert(I != GlobalMacroDefinitionMap.end() && 
            "Corrupted global macro definition map");
-    PerFileData &F = *I->second.first;
+    Module &F = *I->second.first;
     unsigned Index = ID - 1 + I->second.second;
     SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor);  
     F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]);
@@ -1872,7 +1872,7 @@
 }
 
 ASTReader::ASTReadResult
-ASTReader::ReadASTBlock(PerFileData &F) {
+ASTReader::ReadASTBlock(Module &F) {
   llvm::BitstreamCursor &Stream = F.Stream;
 
   if (Stream.EnterSubBlock(AST_BLOCK_ID)) {
@@ -2002,7 +2002,8 @@
       }
 
       // Load the chained file, which is always a PCH file.
-      switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) {
+      // FIXME: This could end up being a module.
+      switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), MK_PCH)) {
       case Failure: return Failure;
         // If we have to ignore the dependency, we'll have to ignore this too.
       case IgnorePCH: return IgnorePCH;
@@ -2222,7 +2223,7 @@
         uint32_t Offset = io::ReadUnalignedLE32(Data);
         uint16_t Len = io::ReadUnalignedLE16(Data);
         llvm::StringRef Name = llvm::StringRef((const char*)Data, Len);
-        PerFileData *OM = Modules.lookup(Name);
+        Module *OM = Modules.lookup(Name);
         if (!OM) {
           Error("SourceLocation remap refers to unknown module");
           return Failure;
@@ -2465,7 +2466,7 @@
 
 ASTReader::ASTReadResult ASTReader::validateFileEntries() {
   for (unsigned CI = 0, CN = Chain.size(); CI != CN; ++CI) {
-    PerFileData *F = Chain[CI];
+    Module *F = Chain[CI];
     llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
 
     for (unsigned i = 0, e = F->LocalNumSLocFileEntries; i != e; ++i) {
@@ -2533,7 +2534,7 @@
 }
 
 ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
-                                            ASTFileType Type) {
+                                            ModuleKind Type) {
   switch(ReadASTCore(FileName, Type)) {
   case Failure: return Failure;
   case IgnorePCH: return IgnorePCH;
@@ -2613,7 +2614,7 @@
   // If this AST file is a precompiled preamble, then set the main file ID of 
   // the source manager to the file source file from which the preamble was
   // built. This is the only valid way to use a precompiled preamble.
-  if (Type == Preamble) {
+  if (Type == MK_Preamble) {
     if (OriginalFileID.isInvalid()) {
       SourceLocation Loc
         = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1);
@@ -2633,10 +2634,10 @@
 }
 
 ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName,
-                                                ASTFileType Type) {
-  PerFileData *Prev = Chain.empty() ? 0 : Chain.back();
-  Chain.push_back(new PerFileData(Type));
-  PerFileData &F = *Chain.back();
+                                                ModuleKind Type) {
+  Module *Prev = Chain.empty() ? 0 : Chain.back();
+  Chain.push_back(new Module(Type));
+  Module &F = *Chain.back();
   if (Prev)
     Prev->NextInSource = &F;
   else
@@ -2741,7 +2742,7 @@
     }
   }
   
-  // Once read, set the PerFileData bit base offset and update the size in 
+  // Once read, set the Module bit base offset and update the size in 
   // bits of all files we've seen.
   F.GlobalBitOffset = TotalModulesSizeInBits;
   TotalModulesSizeInBits += F.SizeInBits;
@@ -3060,7 +3061,7 @@
 
 void ASTReader::ReadPreprocessedEntities() {
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
-    PerFileData &F = *Chain[I];
+    Module &F = *Chain[I];
     if (!F.PreprocessorDetailCursor.getBitStreamReader())
       continue;
 
@@ -3083,7 +3084,7 @@
 HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) {
   HeaderFileInfoTrait Trait(FE->getName());
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
-    PerFileData &F = *Chain[I];
+    Module &F = *Chain[I];
     HeaderFileInfoLookupTable *Table
       = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable);
     if (!Table)
@@ -3107,7 +3108,7 @@
 
 void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) {
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
-    PerFileData &F = *Chain[I];
+    Module &F = *Chain[I];
     unsigned Idx = 0;
     while (Idx < F.PragmaDiagMappings.size()) {
       SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]);
@@ -3565,7 +3566,7 @@
 
 class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> {
   ASTReader &Reader;
-  ASTReader::PerFileData &F;
+  Module &F;
   llvm::BitstreamCursor &DeclsCursor;
   const ASTReader::RecordData &Record;
   unsigned &Idx;
@@ -3581,7 +3582,7 @@
   }
   
 public:
-  TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F,
+  TypeLocReader(ASTReader &Reader, Module &F,
                 const ASTReader::RecordData &Record, unsigned &Idx)
     : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx)
   { }
@@ -3793,7 +3794,7 @@
   TL.setStarLoc(ReadSourceLocation(Record, Idx));
 }
 
-TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F,
+TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F,
                                              const RecordData &Record,
                                              unsigned &Idx) {
   QualType InfoTy = readType(F, Record, Idx);
@@ -3873,12 +3874,12 @@
   return TypesLoaded[Index].withFastQualifiers(FastQuals);
 }
 
-QualType ASTReader::getLocalType(PerFileData &F, unsigned LocalID) {
+QualType ASTReader::getLocalType(Module &F, unsigned LocalID) {
   return GetType(getGlobalTypeID(F, LocalID));
 }
 
 serialization::TypeID 
-ASTReader::getGlobalTypeID(PerFileData &F, unsigned LocalID) const {
+ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const {
   // FIXME: Map from local type ID to global type ID.
   return LocalID;
 }
@@ -3905,7 +3906,7 @@
 }
 
 TemplateArgumentLocInfo
-ASTReader::GetTemplateArgumentLocInfo(PerFileData &F,
+ASTReader::GetTemplateArgumentLocInfo(Module &F,
                                       TemplateArgument::ArgKind Kind,
                                       const RecordData &Record,
                                       unsigned &Index) {
@@ -3940,7 +3941,7 @@
 }
 
 TemplateArgumentLoc
-ASTReader::ReadTemplateArgumentLoc(PerFileData &F,
+ASTReader::ReadTemplateArgumentLoc(Module &F,
                                    const RecordData &Record, unsigned &Index) {
   TemplateArgument Arg = ReadTemplateArgument(F, Record, Index);
 
@@ -4007,7 +4008,7 @@
 }
 
 serialization::DeclID 
-ASTReader::getGlobalDeclID(PerFileData &F, unsigned LocalID) const {
+ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const {
   // FIXME: Perform local -> global remapping for declarations.
   return LocalID;
 }
@@ -4031,7 +4032,7 @@
   return DeclsLoaded[Index];
 }
 
-serialization::DeclID ASTReader::ReadDeclID(PerFileData &F, 
+serialization::DeclID ASTReader::ReadDeclID(Module &F, 
                                             const RecordData &Record,
                                             unsigned &Idx) {
   if (Idx >= Record.size()) {
@@ -4247,15 +4248,15 @@
   std::fprintf(stderr, "\n");
 }
 
-template<typename Key, typename PerFileData, unsigned InitialCapacity>
+template<typename Key, typename Module, unsigned InitialCapacity>
 static void 
 dumpModuleIDMap(llvm::StringRef Name,
-                const ContinuousRangeMap<Key, PerFileData *, 
+                const ContinuousRangeMap<Key, Module *, 
                                          InitialCapacity> &Map) {
   if (Map.begin() == Map.end())
     return;
   
-  typedef ContinuousRangeMap<Key, PerFileData *, InitialCapacity> MapType;
+  typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType;
   llvm::errs() << Name << ":\n";
   for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); 
        I != IEnd; ++I) {
@@ -4264,18 +4265,18 @@
   }
 }
 
-template<typename Key, typename PerFileData, typename Adjustment, 
+template<typename Key, typename Module, typename Adjustment, 
          unsigned InitialCapacity>
 static void 
 dumpModuleIDOffsetMap(llvm::StringRef Name,
                       const ContinuousRangeMap<Key, 
-                                               std::pair<PerFileData *, 
+                                               std::pair<Module *, 
                                                          Adjustment>, 
                                                InitialCapacity> &Map) {
   if (Map.begin() == Map.end())
     return;
   
-  typedef ContinuousRangeMap<Key, std::pair<PerFileData *, Adjustment>, 
+  typedef ContinuousRangeMap<Key, std::pair<Module *, Adjustment>, 
                              InitialCapacity> MapType;
   llvm::errs() << Name << ":\n";
   for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); 
@@ -4383,7 +4384,7 @@
     SemaObj->StdBadAlloc = SemaDeclRefs[1];
   }
 
-  for (PerFileData *F = FirstInSource; F; F = F->NextInSource) {
+  for (Module *F = FirstInSource; F; F = F->NextInSource) {
 
     // If there are @selector references added them to its pool. This is for
     // implementation of -Wselector.
@@ -4401,7 +4402,7 @@
 
   // The special data sets below always come from the most recent PCH,
   // which is at the front of the chain.
-  PerFileData &F = *Chain.front();
+  Module &F = *Chain.front();
 
   // If there were any pending implicit instantiations, deserialize them
   // and add them to Sema's queue of such instantiations.
@@ -4538,7 +4539,7 @@
 ASTReader::ReadMethodPool(Selector Sel) {
   // Find this selector in a hash table. We want to find the most recent entry.
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
-    PerFileData &F = *Chain[I];
+    Module &F = *Chain[I];
     if (!F.SelectorLookupTable)
       continue;
 
@@ -4685,7 +4686,7 @@
     // Load this selector from the selector table.
     GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID);
     assert(I != GlobalSelectorMap.end() && "Corrupted global selector map");
-    PerFileData &F = *I->second.first;
+    Module &F = *I->second.first;
     ASTSelectorLookupTrait Trait(*this, F);
     unsigned Idx = ID - 1 + I->second.second;
     SelectorsLoaded[ID - 1] =
@@ -4707,7 +4708,7 @@
 }
 
 DeclarationName
-ASTReader::ReadDeclarationName(PerFileData &F, 
+ASTReader::ReadDeclarationName(Module &F, 
                                const RecordData &Record, unsigned &Idx) {
   DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++];
   switch (Kind) {
@@ -4747,7 +4748,7 @@
   return DeclarationName();
 }
 
-void ASTReader::ReadDeclarationNameLoc(PerFileData &F,
+void ASTReader::ReadDeclarationNameLoc(Module &F,
                                        DeclarationNameLoc &DNLoc,
                                        DeclarationName Name,
                                       const RecordData &Record, unsigned &Idx) {
@@ -4779,7 +4780,7 @@
   }
 }
 
-void ASTReader::ReadDeclarationNameInfo(PerFileData &F,
+void ASTReader::ReadDeclarationNameInfo(Module &F,
                                         DeclarationNameInfo &NameInfo,
                                       const RecordData &Record, unsigned &Idx) {
   NameInfo.setName(ReadDeclarationName(F, Record, Idx));
@@ -4789,7 +4790,7 @@
   NameInfo.setInfo(DNLoc);
 }
 
-void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info,
+void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info,
                                   const RecordData &Record, unsigned &Idx) {
   Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx);
   unsigned NumTPLists = Record[Idx++];
@@ -4802,7 +4803,7 @@
 }
 
 TemplateName
-ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, 
+ASTReader::ReadTemplateName(Module &F, const RecordData &Record, 
                             unsigned &Idx) {
   TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++];
   switch (Kind) {
@@ -4861,7 +4862,7 @@
 }
 
 TemplateArgument
-ASTReader::ReadTemplateArgument(PerFileData &F,
+ASTReader::ReadTemplateArgument(Module &F,
                                 const RecordData &Record, unsigned &Idx) {
   TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++];
   switch (Kind) {
@@ -4901,7 +4902,7 @@
 }
 
 TemplateParameterList *
-ASTReader::ReadTemplateParameterList(PerFileData &F,
+ASTReader::ReadTemplateParameterList(Module &F,
                                      const RecordData &Record, unsigned &Idx) {
   SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx);
   SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx);
@@ -4922,7 +4923,7 @@
 void
 ASTReader::
 ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs,
-                         PerFileData &F, const RecordData &Record,
+                         Module &F, const RecordData &Record,
                          unsigned &Idx) {
   unsigned NumTemplateArgs = Record[Idx++];
   TemplArgs.reserve(NumTemplateArgs);
@@ -4931,7 +4932,7 @@
 }
 
 /// \brief Read a UnresolvedSet structure.
-void ASTReader::ReadUnresolvedSet(PerFileData &F, UnresolvedSetImpl &Set,
+void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set,
                                   const RecordData &Record, unsigned &Idx) {
   unsigned NumDecls = Record[Idx++];
   while (NumDecls--) {
@@ -4942,7 +4943,7 @@
 }
 
 CXXBaseSpecifier
-ASTReader::ReadCXXBaseSpecifier(PerFileData &F,
+ASTReader::ReadCXXBaseSpecifier(Module &F,
                                 const RecordData &Record, unsigned &Idx) {
   bool isVirtual = static_cast<bool>(Record[Idx++]);
   bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
@@ -4958,7 +4959,7 @@
 }
 
 std::pair<CXXCtorInitializer **, unsigned>
-ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record,
+ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record,
                                    unsigned &Idx) {
   CXXCtorInitializer **CtorInitializers = 0;
   unsigned NumInitializers = Record[Idx++];
@@ -5042,7 +5043,7 @@
 }
 
 NestedNameSpecifier *
-ASTReader::ReadNestedNameSpecifier(PerFileData &F,
+ASTReader::ReadNestedNameSpecifier(Module &F,
                                    const RecordData &Record, unsigned &Idx) {
   unsigned N = Record[Idx++];
   NestedNameSpecifier *NNS = 0, *Prev = 0;
@@ -5091,7 +5092,7 @@
 }
 
 NestedNameSpecifierLoc
-ASTReader::ReadNestedNameSpecifierLoc(PerFileData &F, const RecordData &Record, 
+ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, 
                                       unsigned &Idx) {
   unsigned N = Record[Idx++];
   NestedNameSpecifierLocBuilder Builder;
@@ -5147,7 +5148,7 @@
 }
 
 SourceRange
-ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record,
+ASTReader::ReadSourceRange(Module &F, const RecordData &Record,
                            unsigned &Idx) {
   SourceLocation beg = ReadSourceLocation(F, Record, Idx);
   SourceLocation end = ReadSourceLocation(F, Record, Idx);
@@ -5194,7 +5195,7 @@
   return VersionTuple(Major, Minor - 1, Subminor - 1);
 }
 
-CXXTemporary *ASTReader::ReadCXXTemporary(PerFileData &F, 
+CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, 
                                           const RecordData &Record,
                                           unsigned &Idx) {
   CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx);
@@ -5328,8 +5329,8 @@
   }
 }
 
-ASTReader::PerFileData::PerFileData(ASTFileType Ty)
-  : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocEntryBaseID(0),
+Module::Module(ModuleKind Kind)
+  : Kind(Kind), SizeInBits(0), LocalNumSLocEntries(0), SLocEntryBaseID(0),
     SLocEntryBaseOffset(0), SLocEntryOffsets(0),
     SLocFileOffsets(0), LocalNumIdentifiers(0), 
     IdentifierOffsets(0), IdentifierTableData(0),
@@ -5343,7 +5344,7 @@
     NumPreallocatedPreprocessingEntities(0), NextInSource(0)
 {}
 
-ASTReader::PerFileData::~PerFileData() {
+Module::~Module() {
   delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
   delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
   delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index 841c4d7..30800fb 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -31,7 +31,7 @@
 namespace clang {
   class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
     ASTReader &Reader;
-    ASTReader::PerFileData &F;
+    Module &F;
     llvm::BitstreamCursor &Cursor;
     const DeclID ThisDeclID;
     typedef ASTReader::RecordData RecordData;
@@ -91,7 +91,7 @@
                                      CXXRecordDecl *DefinitionDecl,
                                      const RecordData &Record, unsigned &Idx);
   public:
-    ASTDeclReader(ASTReader &Reader, ASTReader::PerFileData &F,
+    ASTDeclReader(ASTReader &Reader, Module &F,
                   llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
                   const RecordData &Record, unsigned &Idx)
       : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
@@ -101,7 +101,7 @@
 
     void Visit(Decl *D);
 
-    void UpdateDecl(Decl *D, ASTReader::PerFileData &Module,
+    void UpdateDecl(Decl *D, Module &Module,
                     const RecordData &Record);
 
     void VisitDecl(Decl *D);
@@ -239,7 +239,7 @@
   D->setUsed(Record[Idx++]);
   D->setReferenced(Record[Idx++]);
   D->setAccess((AccessSpecifier)Record[Idx++]);
-  D->setPCHLevel(Record[Idx++] + (F.Type <= ASTReader::PCH));
+  D->setPCHLevel(Record[Idx++] + (F.Kind <= MK_PCH));
 }
 
 void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
@@ -1349,7 +1349,7 @@
 //===----------------------------------------------------------------------===//
 
 /// \brief Reads attributes from the current stream position.
-void ASTReader::ReadAttributes(PerFileData &F, AttrVec &Attrs,
+void ASTReader::ReadAttributes(Module &F, AttrVec &Attrs,
                                const RecordData &Record, unsigned &Idx) {
   for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
     Attr *New = 0;
@@ -1411,7 +1411,7 @@
 }
 
 ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
-  ContinuousRangeMap<uint64_t, PerFileData*, 4>::iterator I
+  ContinuousRangeMap<uint64_t, Module*, 4>::iterator I
     = GlobalBitOffsetsMap.find(GlobalOffset);
 
   assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
@@ -1728,7 +1728,7 @@
     FileOffsetsTy &UpdateOffsets = UpdI->second;
     for (FileOffsetsTy::iterator
            I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
-      PerFileData *F = I->first;
+      Module *F = I->first;
       uint64_t Offset = I->second;
       llvm::BitstreamCursor &Cursor = F->DeclsCursor;
       SavedStreamPosition SavedPosition(Cursor);
@@ -1752,7 +1752,7 @@
   return D;
 }
 
-void ASTDeclReader::UpdateDecl(Decl *D, ASTReader::PerFileData &Module,
+void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
                                const RecordData &Record) {
   unsigned Idx = 0;
   while (Idx < Record.size()) {
diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp
index 03ffaf4..f6c91b4 100644
--- a/lib/Serialization/ASTReaderStmt.cpp
+++ b/lib/Serialization/ASTReaderStmt.cpp
@@ -25,7 +25,7 @@
     typedef ASTReader::RecordData RecordData;
     
     ASTReader &Reader;
-    ASTReader::PerFileData &F;
+    Module &F;
     llvm::BitstreamCursor &DeclsCursor;
     const ASTReader::RecordData &Record;
     unsigned &Idx;
@@ -66,7 +66,7 @@
     }
 
   public:
-    ASTStmtReader(ASTReader &Reader, ASTReader::PerFileData &F,
+    ASTStmtReader(ASTReader &Reader, Module &F,
                   llvm::BitstreamCursor &Cursor,
                   const ASTReader::RecordData &Record, unsigned &Idx)
       : Reader(Reader), F(F), DeclsCursor(Cursor), Record(Record), Idx(Idx) { }
@@ -1382,7 +1382,7 @@
 // ASTReader Implementation
 //===----------------------------------------------------------------------===//
 
-Stmt *ASTReader::ReadStmt(PerFileData &F) {
+Stmt *ASTReader::ReadStmt(Module &F) {
   switch (ReadingKind) {
   case Read_Decl:
   case Read_Type:
@@ -1395,7 +1395,7 @@
   return 0;
 }
 
-Expr *ASTReader::ReadExpr(PerFileData &F) {
+Expr *ASTReader::ReadExpr(Module &F) {
   return cast_or_null<Expr>(ReadStmt(F));
 }
 
@@ -1410,7 +1410,7 @@
 // the stack, with expressions having operands removing those operands from the
 // stack. Evaluation terminates when we see a STMT_STOP record, and
 // the single remaining expression on the stack is our result.
-Stmt *ASTReader::ReadStmtFromStream(PerFileData &F) {
+Stmt *ASTReader::ReadStmtFromStream(Module &F) {
 
   ReadingKindTracker ReadingKind(Read_Stmt, *this);
   llvm::BitstreamCursor &Cursor = F.DeclsCursor;
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index e6e88f8..65e0380 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -1549,7 +1549,7 @@
     typedef std::pair<uint32_t, llvm::StringRef> ModuleOffset;
     llvm::SmallVector<ModuleOffset, 16> Modules;
     Modules.reserve(Chain->Modules.size());
-    for (llvm::StringMap<ASTReader::PerFileData*>::const_iterator
+    for (llvm::StringMap<Module*>::const_iterator
              I = Chain->Modules.begin(), E = Chain->Modules.end();
          I != E; ++I) {
       Modules.push_back(ModuleOffset(I->getValue()->SLocEntryBaseOffset,
diff --git a/lib/Serialization/ChainedIncludesSource.cpp b/lib/Serialization/ChainedIncludesSource.cpp
index 3b7cd23..8337c70 100644
--- a/lib/Serialization/ChainedIncludesSource.cpp
+++ b/lib/Serialization/ChainedIncludesSource.cpp
@@ -36,7 +36,7 @@
                              /*DisableValidation=*/true));
   Reader->setASTMemoryBuffers(memBufs, numBufs);
   Reader->setDeserializationListener(deserialListener);
-  switch (Reader->ReadAST(pchFile, ASTReader::PCH)) {
+  switch (Reader->ReadAST(pchFile, serialization::MK_PCH)) {
   case ASTReader::Success:
     // Set the predefines buffer as suggested by the PCH reader.
     PP.setPredefines(Reader->getSuggestedPredefines());