[cfe-commits] r172951 - in /cfe/trunk: lib/Serialization/ASTReader.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTReaderStmt.cpp tools/libclang/CXLoadedDiagnostic.cpp

Chris Lattner sabre at nondot.org
Sat Jan 19 18:38:55 PST 2013


Author: lattner
Date: Sat Jan 19 20:38:54 2013
New Revision: 172951

URL: http://llvm.org/viewvc/llvm-project?rev=172951&view=rev
Log:
update to use the new BitcodeCursor readRecord that takes a StringRef blob parameter,
and adopt "advance" in more places.

Modified:
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
    cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=172951&r1=172950&r2=172951&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sat Jan 19 20:38:54 2013
@@ -671,17 +671,16 @@
     Cursor.JumpToBit(Offsets.first);
 
     RecordData Record;
-    const char *Blob;
-    unsigned BlobLen;
+    StringRef Blob;
     unsigned Code = Cursor.ReadCode();
-    unsigned RecCode = Cursor.ReadRecord(Code, Record, Blob, BlobLen);
+    unsigned RecCode = Cursor.readRecord(Code, Record, &Blob);
     if (RecCode != DECL_CONTEXT_LEXICAL) {
       Error("Expected lexical block");
       return true;
     }
 
-    Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob);
-    Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair);
+    Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob.data());
+    Info.NumLexicalDecls = Blob.size() / sizeof(KindDeclIDPair);
   }
 
   // Now the lookup table.
@@ -689,18 +688,17 @@
     Cursor.JumpToBit(Offsets.second);
 
     RecordData Record;
-    const char *Blob;
-    unsigned BlobLen;
+    StringRef Blob;
     unsigned Code = Cursor.ReadCode();
-    unsigned RecCode = Cursor.ReadRecord(Code, Record, Blob, BlobLen);
+    unsigned RecCode = Cursor.readRecord(Code, Record, &Blob);
     if (RecCode != DECL_CONTEXT_VISIBLE) {
       Error("Expected visible lookup table block");
       return true;
     }
     Info.NameLookupTableData
       = ASTDeclContextNameLookupTable::Create(
-                    (const unsigned char *)Blob + Record[0],
-                    (const unsigned char *)Blob,
+                    (const unsigned char *)Blob.data() + Record[0],
+                    (const unsigned char *)Blob.data(),
                     ASTDeclContextNameLookupTrait(*this, M));
   }
 
@@ -811,10 +809,8 @@
     }
     
     // Read a record.
-    const char *BlobStart;
-    unsigned BlobLen;
     Record.clear();
-    switch (SLocEntryCursor.ReadRecord(E.ID, Record, BlobStart, BlobLen)) {
+    switch (SLocEntryCursor.readRecord(E.ID, Record)) {
     default:  // Default behavior: ignore.
       break;
 
@@ -882,9 +878,8 @@
   }
   
   RecordData Record;
-  const char *BlobStart;
-  unsigned BlobLen;
-  switch (SLocEntryCursor.ReadRecord(Entry.ID, Record, BlobStart, BlobLen)) {
+  StringRef Blob;
+  switch (SLocEntryCursor.readRecord(Entry.ID, Record, &Blob)) {
   default:
     Error("incorrectly-formatted source location entry in AST file");
     return true;
@@ -930,8 +925,7 @@
         ContentCache->ContentsEntry == ContentCache->OrigEntry) {
       unsigned Code = SLocEntryCursor.ReadCode();
       Record.clear();
-      unsigned RecCode
-        = SLocEntryCursor.ReadRecord(Code, Record, BlobStart, BlobLen);
+      unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob);
       
       if (RecCode != SM_SLOC_BUFFER_BLOB) {
         Error("AST record has invalid code");
@@ -939,8 +933,7 @@
       }
       
       llvm::MemoryBuffer *Buffer
-        = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1),
-                                           File->getName());
+        = llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), File->getName());
       SourceMgr.overrideFileContents(File, Buffer);
     }
 
@@ -948,7 +941,7 @@
   }
 
   case SM_SLOC_BUFFER_ENTRY: {
-    const char *Name = BlobStart;
+    const char *Name = Blob.data();
     unsigned Offset = Record[0];
     SrcMgr::CharacteristicKind
       FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
@@ -959,7 +952,7 @@
     unsigned Code = SLocEntryCursor.ReadCode();
     Record.clear();
     unsigned RecCode
-      = SLocEntryCursor.ReadRecord(Code, Record, BlobStart, BlobLen);
+      = SLocEntryCursor.readRecord(Code, Record, &Blob);
 
     if (RecCode != SM_SLOC_BUFFER_BLOB) {
       Error("AST record has invalid code");
@@ -967,8 +960,7 @@
     }
 
     llvm::MemoryBuffer *Buffer
-      = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1),
-                                         Name);
+      = llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name);
     SourceMgr.createFileIDForMemBuffer(Buffer, FileCharacter, ID,
                                        BaseOffset + Offset, IncludeLoc);
     break;
@@ -1100,12 +1092,9 @@
     }
 
     // Read a record.
-    const char *BlobStart = 0;
-    unsigned BlobLen = 0;
     Record.clear();
     PreprocessorRecordTypes RecType =
-      (PreprocessorRecordTypes)Stream.ReadRecord(Entry.ID, Record, BlobStart,
-                                                 BlobLen);
+      (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record);
     switch (RecType) {
     case PP_MACRO_OBJECT_LIKE:
     case PP_MACRO_FUNCTION_LIKE: {
@@ -1361,10 +1350,8 @@
         goto NextCursor;
         
       case llvm::BitstreamEntry::Record:
-        const char *BlobStart;
-        unsigned BlobLen;
         Record.clear();
-        switch (Cursor.ReadRecord(E.ID, Record, BlobStart, BlobLen)) {
+        switch (Cursor.readRecord(E.ID, Record)) {
         default:  // Default behavior: ignore.
           break;
           
@@ -1470,10 +1457,8 @@
   
   unsigned Code = Cursor.ReadCode();
   RecordData Record;
-  const char *BlobStart = 0;
-  unsigned BlobLen = 0;
-  switch ((InputFileRecordTypes)Cursor.ReadRecord(Code, Record,
-                                                  BlobStart, BlobLen)) {
+  StringRef Blob;
+  switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) {
   case INPUT_FILE: {
     unsigned StoredID = Record[0];
     assert(ID == StoredID && "Bogus stored ID or offset");
@@ -1483,7 +1468,7 @@
     bool Overridden = (bool)Record[3];
     
     // Get the file entry for this input file.
-    StringRef OrigFilename(BlobStart, BlobLen);
+    StringRef OrigFilename = Blob;
     std::string Filename = OrigFilename;
     MaybeAddSystemRootToFilename(F, Filename);
     const FileEntry *File 
@@ -1661,10 +1646,8 @@
 
     // Read and process a record.
     Record.clear();
-    const char *BlobStart = 0;
-    unsigned BlobLen = 0;
-    switch ((ControlRecordTypes)Stream.ReadRecord(Entry.ID, Record,
-                                                  BlobStart, BlobLen)) {
+    StringRef Blob;
+    switch ((ControlRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) {
     case METADATA: {
       if (Record[0] != VERSION_MAJOR && !DisableValidation) {
         if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
@@ -1682,7 +1665,7 @@
       F.RelocatablePCH = Record[4];
 
       const std::string &CurBranch = getClangFullRepositoryVersion();
-      StringRef ASTBranch(BlobStart, BlobLen);
+      StringRef ASTBranch = Blob;
       if (StringRef(CurBranch) != ASTBranch && !DisableValidation) {
         if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0)
           Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch;
@@ -1779,7 +1762,7 @@
 
     case ORIGINAL_FILE:
       F.OriginalSourceFileID = FileID::get(Record[0]);
-      F.ActualOriginalSourceFileName.assign(BlobStart, BlobLen);
+      F.ActualOriginalSourceFileName = Blob;
       F.OriginalSourceFileName = F.ActualOriginalSourceFileName;
       MaybeAddSystemRootToFilename(F, F.OriginalSourceFileName);
       break;
@@ -1789,11 +1772,11 @@
       break;
 
     case ORIGINAL_PCH_DIR:
-      F.OriginalDir.assign(BlobStart, BlobLen);
+      F.OriginalDir = Blob;
       break;
 
     case INPUT_FILE_OFFSETS:
-      F.InputFileOffsets = (const uint32_t *)BlobStart;
+      F.InputFileOffsets = (const uint32_t *)Blob.data();
       F.InputFilesLoaded.resize(Record[0]);
       break;
     }
@@ -1914,10 +1897,8 @@
 
     // Read and process a record.
     Record.clear();
-    const char *BlobStart = 0;
-    unsigned BlobLen = 0;
-    switch ((ASTRecordTypes)Stream.ReadRecord(Entry.ID, Record,
-                                              BlobStart, BlobLen)) {
+    StringRef Blob;
+    switch ((ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) {
     default:  // Default behavior: ignore.
       break;
 
@@ -1926,7 +1907,7 @@
         Error("duplicate TYPE_OFFSET record in AST file");
         return true;
       }
-      F.TypeOffsets = (const uint32_t *)BlobStart;
+      F.TypeOffsets = (const uint32_t *)Blob.data();
       F.LocalNumTypes = Record[0];
       unsigned LocalBaseTypeIndex = Record[1];
       F.BaseTypeIndex = getTotalNumTypes();
@@ -1950,7 +1931,7 @@
         Error("duplicate DECL_OFFSET record in AST file");
         return true;
       }
-      F.DeclOffsets = (const DeclOffset *)BlobStart;
+      F.DeclOffsets = (const DeclOffset *)Blob.data();
       F.LocalNumDecls = Record[0];
       unsigned LocalBaseDeclID = Record[1];
       F.BaseDeclID = getTotalNumDecls();
@@ -1978,9 +1959,9 @@
     case TU_UPDATE_LEXICAL: {
       DeclContext *TU = Context.getTranslationUnitDecl();
       DeclContextInfo &Info = F.DeclContextInfos[TU];
-      Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart);
+      Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(Blob.data());
       Info.NumLexicalDecls 
-        = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair));
+        = static_cast<unsigned int>(Blob.size() / sizeof(KindDeclIDPair));
       TU->setHasExternalLexicalStorage(true);
       break;
     }
@@ -1990,8 +1971,8 @@
       serialization::DeclID ID = ReadDeclID(F, Record, Idx);
       ASTDeclContextNameLookupTable *Table =
         ASTDeclContextNameLookupTable::Create(
-                        (const unsigned char *)BlobStart + Record[Idx++],
-                        (const unsigned char *)BlobStart,
+                        (const unsigned char *)Blob.data() + Record[Idx++],
+                        (const unsigned char *)Blob.data(),
                         ASTDeclContextNameLookupTrait(*this, F));
       if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU?
         DeclContext *TU = Context.getTranslationUnitDecl();
@@ -2003,7 +1984,7 @@
     }
 
     case IDENTIFIER_TABLE:
-      F.IdentifierTableData = BlobStart;
+      F.IdentifierTableData = Blob.data();
       if (Record[0]) {
         F.IdentifierLookupTable
           = ASTIdentifierLookupTable::Create(
@@ -2020,7 +2001,7 @@
         Error("duplicate IDENTIFIER_OFFSET record in AST file");
         return true;
       }
-      F.IdentifierOffsets = (const uint32_t *)BlobStart;
+      F.IdentifierOffsets = (const uint32_t *)Blob.data();
       F.LocalNumIdentifiers = Record[0];
       unsigned LocalBaseIdentifierID = Record[1];
       F.BaseIdentifierID = getTotalNumIdentifiers();
@@ -2098,7 +2079,7 @@
       break;
 
     case SELECTOR_OFFSETS: {
-      F.SelectorOffsets = (const uint32_t *)BlobStart;
+      F.SelectorOffsets = (const uint32_t *)Blob.data();
       F.LocalNumSelectors = Record[0];
       unsigned LocalBaseSelectorID = Record[1];
       F.BaseSelectorID = getTotalNumSelectors();
@@ -2120,7 +2101,7 @@
     }
         
     case METHOD_POOL:
-      F.SelectorLookupTableData = (const unsigned char *)BlobStart;
+      F.SelectorLookupTableData = (const unsigned char *)Blob.data();
       if (Record[0])
         F.SelectorLookupTable
           = ASTSelectorLookupTable::Create(
@@ -2147,12 +2128,12 @@
       break;
       
     case FILE_SORTED_DECLS:
-      F.FileSortedDecls = (const DeclID *)BlobStart;
+      F.FileSortedDecls = (const DeclID *)Blob.data();
       F.NumFileSortedDecls = Record[0];
       break;
 
     case SOURCE_LOCATION_OFFSETS: {
-      F.SLocEntryOffsets = (const uint32_t *)BlobStart;
+      F.SLocEntryOffsets = (const uint32_t *)Blob.data();
       F.LocalNumSLocEntries = Record[0];
       unsigned SLocSpaceSize = Record[1];
       llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) =
@@ -2185,8 +2166,8 @@
 
     case MODULE_OFFSET_MAP: {
       // Additional remapping information.
-      const unsigned char *Data = (const unsigned char*)BlobStart;
-      const unsigned char *DataEnd = Data + BlobLen;
+      const unsigned char *Data = (const unsigned char*)Blob.data();
+      const unsigned char *DataEnd = Data + Blob.size();
       
       // Continuous range maps we may be updating in our module.
       ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap);
@@ -2322,9 +2303,9 @@
       break;
 
     case PPD_ENTITIES_OFFSETS: {
-      F.PreprocessedEntityOffsets = (const PPEntityOffset *)BlobStart;
-      assert(BlobLen % sizeof(PPEntityOffset) == 0);
-      F.NumPreprocessedEntities = BlobLen / sizeof(PPEntityOffset);
+      F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data();
+      assert(Blob.size() % sizeof(PPEntityOffset) == 0);
+      F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset);
 
       unsigned LocalBasePreprocessedEntityID = Record[0];
       
@@ -2382,7 +2363,7 @@
       }
       
       F.LocalNumObjCCategoriesInMap = Record[0];
-      F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)BlobStart;
+      F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data();
       break;
     }
         
@@ -2397,7 +2378,7 @@
       }
       
       F.LocalNumCXXBaseSpecifiers = Record[0];
-      F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart;
+      F.CXXBaseSpecifiersOffsets = (const uint32_t *)Blob.data();
       NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers;
       break;
     }
@@ -2419,9 +2400,9 @@
       break;
 
     case HEADER_SEARCH_TABLE: {
-      F.HeaderFileInfoTableData = BlobStart;
+      F.HeaderFileInfoTableData = Blob.data();
       F.LocalNumHeaderFileInfos = Record[1];
-      F.HeaderFileFrameworkStrings = BlobStart + Record[2];
+      F.HeaderFileFrameworkStrings = Blob.data() + Record[2];
       if (Record[0]) {
         F.HeaderFileInfoTable
           = HeaderFileInfoLookupTable::Create(
@@ -2429,7 +2410,7 @@
                    (const unsigned char *)F.HeaderFileInfoTableData,
                    HeaderFileInfoTrait(*this, F, 
                                        &PP.getHeaderSearchInfo(),
-                                       BlobStart + Record[2]));
+                                       Blob.data() + Record[2]));
         
         PP.getHeaderSearchInfo().SetExternalSource(this);
         if (!PP.getHeaderSearchInfo().getExternalLookup())
@@ -2483,7 +2464,7 @@
       }
       
       F.LocalNumRedeclarationsInMap = Record[0];
-      F.RedeclarationsMap = (const LocalRedeclarationsInfo *)BlobStart;
+      F.RedeclarationsMap = (const LocalRedeclarationsInfo *)Blob.data();
       break;
     }
         
@@ -2502,7 +2483,7 @@
         Error("duplicate MACRO_OFFSET record in AST file");
         return true;
       }
-      F.MacroOffsets = (const uint32_t *)BlobStart;
+      F.MacroOffsets = (const uint32_t *)Blob.data();
       F.LocalNumMacros = Record[0];
       unsigned LocalBaseMacroID = Record[1];
       F.BaseMacroID = getTotalNumMacros();
@@ -3123,11 +3104,9 @@
     }
     
     Record.clear();
-    const char *BlobStart = 0;
-    unsigned BlobLen = 0;
-    if (Stream.ReadRecord(Entry.ID, Record, BlobStart, BlobLen)
-          == ORIGINAL_FILE)
-      return std::string(BlobStart, BlobLen);
+    StringRef Blob;
+    if (Stream.readRecord(Entry.ID, Record, &Blob) == ORIGINAL_FILE)
+      return Blob.str();
   }
 }
 
@@ -3208,17 +3187,15 @@
       return true;
     
     Record.clear();
-    const char *BlobStart = 0;
-    unsigned BlobLen = 0;
-    unsigned RecCode = Stream.ReadRecord(Entry.ID, Record, BlobStart, BlobLen);
+    StringRef Blob;
+    unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob);
     switch ((ControlRecordTypes)RecCode) {
     case METADATA: {
       if (Record[0] != VERSION_MAJOR)
         return true;
 
       const std::string &CurBranch = getClangFullRepositoryVersion();
-      StringRef ASTBranch(BlobStart, BlobLen);
-      if (StringRef(CurBranch) != ASTBranch)
+      if (StringRef(CurBranch) != Blob)
         return true;
 
       break;
@@ -3300,10 +3277,9 @@
     }
 
     // Read a record.
-    const char *BlobStart;
-    unsigned BlobLen;
+    StringRef Blob;
     Record.clear();
-    switch (F.Stream.ReadRecord(Entry.ID, Record, BlobStart, BlobLen)) {
+    switch (F.Stream.readRecord(Entry.ID, Record, &Blob)) {
     default:  // Default behavior: ignore.
       break;
       
@@ -3318,7 +3294,7 @@
         return true;
       }
       
-      StringRef Name(BlobStart, BlobLen);
+      StringRef Name = Blob;
       SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[0]);
       SubmoduleID Parent = getGlobalSubmoduleID(F, Record[1]);
       bool IsFramework = Record[2];
@@ -3369,8 +3345,7 @@
       if (!CurrentModule)
         break;
       
-      StringRef FileName(BlobStart, BlobLen);
-      if (const FileEntry *Umbrella = PP.getFileManager().getFile(FileName)) {
+      if (const FileEntry *Umbrella = PP.getFileManager().getFile(Blob)) {
         if (!CurrentModule->getUmbrellaHeader())
           ModMap.setUmbrellaHeader(CurrentModule, Umbrella);
         else if (CurrentModule->getUmbrellaHeader() != Umbrella) {
@@ -3391,8 +3366,7 @@
         break;
       
       // FIXME: Be more lazy about this!
-      StringRef FileName(BlobStart, BlobLen);
-      if (const FileEntry *File = PP.getFileManager().getFile(FileName)) {
+      if (const FileEntry *File = PP.getFileManager().getFile(Blob)) {
         if (std::find(CurrentModule->Headers.begin(), 
                       CurrentModule->Headers.end(), 
                       File) == CurrentModule->Headers.end())
@@ -3411,8 +3385,7 @@
         break;
       
       // FIXME: Be more lazy about this!
-      StringRef FileName(BlobStart, BlobLen);
-      if (const FileEntry *File = PP.getFileManager().getFile(FileName)) {
+      if (const FileEntry *File = PP.getFileManager().getFile(Blob)) {
         if (std::find(CurrentModule->Headers.begin(), 
                       CurrentModule->Headers.end(), 
                       File) == CurrentModule->Headers.end())
@@ -3431,8 +3404,7 @@
         break;
 
       // FIXME: Be more lazy about this!
-      StringRef FileName(BlobStart, BlobLen);
-      if (const FileEntry *File = PP.getFileManager().getFile(FileName))
+      if (const FileEntry *File = PP.getFileManager().getFile(Blob))
         CurrentModule->TopHeaders.insert(File);
       break;
     }
@@ -3446,9 +3418,8 @@
       if (!CurrentModule)
         break;
       
-      StringRef DirName(BlobStart, BlobLen);
       if (const DirectoryEntry *Umbrella
-                                  = PP.getFileManager().getDirectory(DirName)) {
+                                  = PP.getFileManager().getDirectory(Blob)) {
         if (!CurrentModule->getUmbrellaDir())
           ModMap.setUmbrellaDir(CurrentModule, Umbrella);
         else if (CurrentModule->getUmbrellaDir() != Umbrella) {
@@ -3539,8 +3510,7 @@
       if (!CurrentModule)
         break;
 
-      CurrentModule->addRequirement(StringRef(BlobStart, BlobLen), 
-                                    Context.getLangOpts(),
+      CurrentModule->addRequirement(Blob, Context.getLangOpts(),
                                     Context.getTargetInfo());
       break;
     }
@@ -3555,8 +3525,7 @@
         break;
 
       CurrentModule->LinkLibraries.push_back(
-         Module::LinkLibrary(StringRef(BlobStart, BlobLen),
-         Record[0]));
+                                         Module::LinkLibrary(Blob, Record[0]));
       break;
     }
   }
@@ -3763,12 +3732,11 @@
   SourceRange Range(ReadSourceLocation(M, PPOffs.Begin),
                     ReadSourceLocation(M, PPOffs.End));
   PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
-  const char *BlobStart = 0;
-  unsigned BlobLen = 0;
+  StringRef Blob;
   RecordData Record;
   PreprocessorDetailRecordTypes RecType =
-    (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord(
-                                          Entry.ID, Record, BlobStart, BlobLen);
+    (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.readRecord(
+                                          Entry.ID, Record, &Blob);
   switch (RecType) {
   case PPD_MACRO_EXPANSION: {
     bool isBuiltin = Record[0];
@@ -3805,8 +3773,8 @@
   }
       
   case PPD_INCLUSION_DIRECTIVE: {
-    const char *FullFileNameStart = BlobStart + Record[0];
-    StringRef FullFileName(FullFileNameStart, BlobLen - Record[0]);
+    const char *FullFileNameStart = Blob.data() + Record[0];
+    StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]);
     const FileEntry *File = 0;
     if (!FullFileName.empty())
       File = PP.getFileManager().getFile(FullFileName);
@@ -3816,7 +3784,7 @@
       = static_cast<InclusionDirective::InclusionKind>(Record[2]);
     InclusionDirective *ID
       = new (PPRec) InclusionDirective(PPRec, Kind,
-                                       StringRef(BlobStart, Record[0]),
+                                       StringRef(Blob.data(), Record[0]),
                                        Record[1], Record[3],
                                        File,
                                        Range);
@@ -4117,7 +4085,7 @@
   DeclsCursor.JumpToBit(Loc.Offset);
   RecordData Record;
   unsigned Code = DeclsCursor.ReadCode();
-  switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) {
+  switch ((TypeCode)DeclsCursor.readRecord(Code, Record)) {
   case TYPE_EXT_QUAL: {
     if (Record.size() != 2) {
       Error("Incorrect encoding of extended qualifier type");
@@ -4968,7 +4936,7 @@
   ReadingKindTracker ReadingKind(Read_Decl, *this);
   RecordData Record;
   unsigned Code = Cursor.ReadCode();
-  unsigned RecCode = Cursor.ReadRecord(Code, Record);
+  unsigned RecCode = Cursor.readRecord(Code, Record);
   if (RecCode != DECL_CXX_BASE_SPECIFIERS) {
     Error("Malformed AST file: missing C++ base specifiers");
     return 0;
@@ -6762,7 +6730,7 @@
 
       // Read a record.
       Record.clear();
-      switch ((CommentRecordTypes)Cursor.ReadRecord(Entry.ID, Record)) {
+      switch ((CommentRecordTypes)Cursor.readRecord(Entry.ID, Record)) {
       case COMMENTS_RAW_COMMENT: {
         unsigned Idx = 0;
         SourceRange SR = ReadSourceRange(F, Record, Idx);

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=172951&r1=172950&r2=172951&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sat Jan 19 20:38:54 2013
@@ -1937,7 +1937,7 @@
   ASTDeclReader Reader(*this, *Loc.F, ID, RawLocation, Record,Idx);
 
   Decl *D = 0;
-  switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
+  switch ((DeclCode)DeclsCursor.readRecord(Code, Record)) {
   case DECL_CONTEXT_LEXICAL:
   case DECL_CONTEXT_VISIBLE:
     llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
@@ -2189,7 +2189,7 @@
       Cursor.JumpToBit(Offset);
       RecordData Record;
       unsigned Code = Cursor.ReadCode();
-      unsigned RecCode = Cursor.ReadRecord(Code, Record);
+      unsigned RecCode = Cursor.readRecord(Code, Record);
       (void)RecCode;
       assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
       

Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=172951&r1=172950&r2=172951&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Sat Jan 19 20:38:54 2013
@@ -1595,36 +1595,27 @@
   Stmt::EmptyShell Empty;
 
   while (true) {
-    unsigned Code = Cursor.ReadCode();
-    if (Code == llvm::bitc::END_BLOCK) {
-      if (Cursor.ReadBlockEnd()) {
-        Error("error at end of block in AST file");
-        return 0;
-      }
+    llvm::BitstreamEntry Entry = Cursor.advanceSkippingSubblocks();
+    
+    switch (Entry.Kind) {
+    case llvm::BitstreamEntry::SubBlock: // Handled for us already.
+    case llvm::BitstreamEntry::Error:
+      Error("malformed block record in AST file");
+      return 0;
+    case llvm::BitstreamEntry::EndBlock:
+      goto Done;
+    case llvm::BitstreamEntry::Record:
+      // The interesting case.
       break;
     }
 
-    if (Code == llvm::bitc::ENTER_SUBBLOCK) {
-      // No known subblocks, always skip them.
-      Cursor.ReadSubBlockID();
-      if (Cursor.SkipBlock()) {
-        Error("malformed block record in AST file");
-        return 0;
-      }
-      continue;
-    }
-
-    if (Code == llvm::bitc::DEFINE_ABBREV) {
-      Cursor.ReadAbbrevRecord();
-      continue;
-    }
 
     Stmt *S = 0;
     Idx = 0;
     Record.clear();
     bool Finished = false;
     bool IsStmtReference = false;
-    switch ((StmtCode)Cursor.ReadRecord(Code, Record)) {
+    switch ((StmtCode)Cursor.readRecord(Entry.ID, Record)) {
     case STMT_STOP:
       Finished = true;
       break;
@@ -2249,11 +2240,8 @@
     assert(Idx == Record.size() && "Invalid deserialization of statement");
     StmtStack.push_back(S);
   }
-
-#ifndef NDEBUG
+Done:
   assert(StmtStack.size() > PrevNumStmts && "Read too many sub stmts!");
   assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
-#endif
-
   return StmtStack.pop_back_val();
 }

Modified: cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp?rev=172951&r1=172950&r2=172951&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp Sat Jan 19 20:38:54 2013
@@ -38,8 +38,6 @@
   CXLoadedDiagnosticSetImpl() : CXDiagnosticSetImpl(true), FakeFiles(FO) {}
   virtual ~CXLoadedDiagnosticSetImpl() {}  
 
-  llvm::StringRef makeString(const char *blob, unsigned blobLen);
-  
   llvm::BumpPtrAllocator Alloc;
   Strings Categories;
   Strings WarningFlags;
@@ -48,19 +46,18 @@
   FileSystemOptions FO;
   FileManager FakeFiles;
   llvm::DenseMap<unsigned, const FileEntry *> Files;
+  
+  llvm::StringRef makeString(StringRef Blob) {
+    char *mem = Alloc.Allocate<char>(Blob.size() + 1);
+    memcpy(mem, Blob.data(), Blob.size());
+    // Add a null terminator for those clients accessing the buffer
+    // like a c-string.
+    mem[Blob.size()] = '\0';
+    return llvm::StringRef(mem, Blob.size());
+  }
 };
 }
 
-llvm::StringRef CXLoadedDiagnosticSetImpl::makeString(const char *blob,
-                                                      unsigned bloblen) {
-  char *mem = Alloc.Allocate<char>(bloblen + 1);
-  memcpy(mem, blob, bloblen);
-  // Add a null terminator for those clients accessing the buffer
-  // like a c-string.
-  mem[bloblen] = '\0';
-  return llvm::StringRef(mem, bloblen);
-}
-
 //===----------------------------------------------------------------------===//
 // Cleanup.
 //===----------------------------------------------------------------------===//
@@ -220,16 +217,14 @@
   LoadResult readString(CXLoadedDiagnosticSetImpl &TopDiags,
                         Strings &strings, llvm::StringRef errorContext,
                         RecordData &Record,
-                        const char *BlobStart,
-                        unsigned BlobLen,
+                        StringRef Blob,
                         bool allowEmptyString = false);
 
   LoadResult readString(CXLoadedDiagnosticSetImpl &TopDiags,
                         llvm::StringRef &RetStr,
                         llvm::StringRef errorContext,
                         RecordData &Record,
-                        const char *BlobStart,
-                        unsigned BlobLen,
+                        StringRef Blob,
                         bool allowEmptyString = false);
 
   LoadResult readRange(CXLoadedDiagnosticSetImpl &TopDiags,
@@ -422,9 +417,7 @@
     }
     
     RecordData Record;
-    const char *Blob;
-    unsigned BlobLen;
-    unsigned recordID = Stream.ReadRecord(blockOrCode, Record, &Blob, &BlobLen);
+    unsigned recordID = Stream.readRecord(blockOrCode, Record);
     
     if (recordID == serialized_diags::RECORD_VERSION) {
       if (Record.size() < 1) {
@@ -445,29 +438,28 @@
                                   llvm::StringRef &RetStr,
                                   llvm::StringRef errorContext,
                                   RecordData &Record,
-                                  const char *BlobStart,
-                                  unsigned BlobLen,
+                                  StringRef Blob,
                                   bool allowEmptyString) {
   
   // Basic buffer overflow check.
-  if (BlobLen > 65536) {
+  if (Blob.size() > 65536) {
     reportInvalidFile(std::string("Out-of-bounds string in ") +
                       std::string(errorContext));
     return Failure;
   }
 
-  if (allowEmptyString && Record.size() >= 1 && BlobLen == 0) {
+  if (allowEmptyString && Record.size() >= 1 && Blob.size() == 0) {
     RetStr = "";
     return Success;
   }
   
-  if (Record.size() < 1 || BlobLen == 0) {
+  if (Record.size() < 1 || Blob.size() == 0) {
     reportInvalidFile(std::string("Corrupted ") + std::string(errorContext)
                       + std::string(" entry"));
     return Failure;
   }
   
-  RetStr = TopDiags.makeString(BlobStart, BlobLen);
+  RetStr = TopDiags.makeString(Blob);
   return Success;
 }
 
@@ -475,11 +467,10 @@
                                   Strings &strings,
                                   llvm::StringRef errorContext,
                                   RecordData &Record,
-                                  const char *BlobStart,
-                                  unsigned BlobLen,
+                                  StringRef Blob,
                                   bool allowEmptyString) {
   llvm::StringRef RetStr;
-  if (readString(TopDiags, RetStr, errorContext, Record, BlobStart, BlobLen,
+  if (readString(TopDiags, RetStr, errorContext, Record, Blob,
                  allowEmptyString))
     return Failure;
   strings[Record[0]] = RetStr;
@@ -579,10 +570,8 @@
     
     // Read the record.
     Record.clear();
-    const char *BlobStart = 0;
-    unsigned BlobLen = 0;
-    unsigned recID = Stream.ReadRecord(blockOrCode, Record,
-                                       BlobStart, BlobLen);
+    StringRef Blob;
+    unsigned recID = Stream.readRecord(blockOrCode, Record, &Blob);
     
     if (recID < serialized_diags::RECORD_FIRST ||
         recID > serialized_diags::RECORD_LAST)
@@ -593,20 +582,19 @@
         continue;
       case serialized_diags::RECORD_CATEGORY:
         if (readString(TopDiags, TopDiags.Categories, "category", Record,
-                       BlobStart, BlobLen,
-                       /* allowEmptyString */ true))
+                       Blob, /* allowEmptyString */ true))
           return Failure;
         continue;
       
       case serialized_diags::RECORD_DIAG_FLAG:
         if (readString(TopDiags, TopDiags.WarningFlags, "warning flag", Record,
-                       BlobStart, BlobLen))
+                       Blob))
           return Failure;
         continue;
         
       case serialized_diags::RECORD_FILENAME: {
         if (readString(TopDiags, TopDiags.FileNames, "filename", Record,
-                       BlobStart, BlobLen))
+                       Blob))
           return Failure;
 
         if (Record.size() < 3) {
@@ -636,7 +624,7 @@
         if (readRange(TopDiags, Record, 0, SR))
           return Failure;
         llvm::StringRef RetStr;
-        if (readString(TopDiags, RetStr, "FIXIT", Record, BlobStart, BlobLen,
+        if (readString(TopDiags, RetStr, "FIXIT", Record, Blob,
                        /* allowEmptyString */ true))
           return Failure;
         D->FixIts.push_back(std::make_pair(SR, createCXString(RetStr, false)));
@@ -652,7 +640,7 @@
         unsigned diagFlag = Record[offset++];
         D->DiagOption = diagFlag ? TopDiags.WarningFlags[diagFlag] : "";
         D->CategoryText = D->category ? TopDiags.Categories[D->category] : "";
-        D->Spelling = TopDiags.makeString(BlobStart, BlobLen);
+        D->Spelling = TopDiags.makeString(Blob);
         continue;
       }
     }





More information about the cfe-commits mailing list