diff options
author | Chris Lattner <sabre@nondot.org> | 2013-01-20 02:38:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2013-01-20 02:38:54 +0000 |
commit | b3ce35764adcc5749e8729709b1f3737227d90ec (patch) | |
tree | 102917f508a20547da57cb3bbd0e12483cfb1201 /tools/libclang/CXLoadedDiagnostic.cpp | |
parent | d47afb96a3f988e6d21a92fe4dfe875ab227c7c0 (diff) |
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
Diffstat (limited to 'tools/libclang/CXLoadedDiagnostic.cpp')
-rw-r--r-- | tools/libclang/CXLoadedDiagnostic.cpp | 64 |
1 files changed, 26 insertions, 38 deletions
diff --git a/tools/libclang/CXLoadedDiagnostic.cpp b/tools/libclang/CXLoadedDiagnostic.cpp index f81922416d..65b816c397 100644 --- a/tools/libclang/CXLoadedDiagnostic.cpp +++ b/tools/libclang/CXLoadedDiagnostic.cpp @@ -38,8 +38,6 @@ public: 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 @@ public: 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 @@ class DiagLoader { 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 @@ LoadResult DiagLoader::readMetaBlock(llvm::BitstreamCursor &Stream) { } 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 @@ LoadResult DiagLoader::readString(CXLoadedDiagnosticSetImpl &TopDiags, 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 @@ LoadResult DiagLoader::readString(CXLoadedDiagnosticSetImpl &TopDiags, 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 @@ LoadResult DiagLoader::readDiagnosticBlock(llvm::BitstreamCursor &Stream, // 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 @@ LoadResult DiagLoader::readDiagnosticBlock(llvm::BitstreamCursor &Stream, 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 @@ LoadResult DiagLoader::readDiagnosticBlock(llvm::BitstreamCursor &Stream, 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 @@ LoadResult DiagLoader::readDiagnosticBlock(llvm::BitstreamCursor &Stream, 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; } } |