update to use the new BitcodeCursor readRecord that takes a StringRef blob parameter,
and adopt "advance" in more places.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172951 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CXLoadedDiagnostic.cpp b/tools/libclang/CXLoadedDiagnostic.cpp
index f819224..65b816c 100644
--- a/tools/libclang/CXLoadedDiagnostic.cpp
+++ b/tools/libclang/CXLoadedDiagnostic.cpp
@@ -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;
       }
     }