[PDB] General improvements to Stream library.

This adds various new functionality and cleanup surrounding the
use of the Stream library.  Major changes include:

* Renaming of all classes for more consistency / meaningfulness
* Addition of some new methods for reading multiple values at once.
* Full suite of unit tests for reader / writer functionality.
* Full set of doxygen comments for all classes.
* Streams now store their own endianness.
* Fixed some bugs in a few of the classes that were discovered
  by the unit tests.

llvm-svn: 296215
diff --git a/llvm/lib/DebugInfo/MSF/BinaryStreamReader.cpp b/llvm/lib/DebugInfo/MSF/BinaryStreamReader.cpp
index 567e6b1..ba5fd21 100644
--- a/llvm/lib/DebugInfo/MSF/BinaryStreamReader.cpp
+++ b/llvm/lib/DebugInfo/MSF/BinaryStreamReader.cpp
@@ -1,4 +1,4 @@
-//===- StreamReader.cpp - Reads bytes and objects from a stream -----------===//
+//===- BinaryStreamReader.cpp - Reads objects from a binary stream --------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -10,53 +10,79 @@
 #include "llvm/DebugInfo/MSF/BinaryStreamReader.h"
 
 #include "llvm/DebugInfo/MSF/BinaryStreamRef.h"
-#include "llvm/DebugInfo/MSF/MSFError.h"
 
 using namespace llvm;
-using namespace llvm::msf;
 
-StreamReader::StreamReader(ReadableStreamRef S) : Stream(S), Offset(0) {}
+BinaryStreamReader::BinaryStreamReader(BinaryStreamRef S)
+    : Stream(S), Offset(0) {}
 
-Error StreamReader::readLongestContiguousChunk(ArrayRef<uint8_t> &Buffer) {
+Error BinaryStreamReader::readLongestContiguousChunk(
+    ArrayRef<uint8_t> &Buffer) {
   if (auto EC = Stream.readLongestContiguousChunk(Offset, Buffer))
     return EC;
   Offset += Buffer.size();
   return Error::success();
 }
 
-Error StreamReader::readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size) {
+Error BinaryStreamReader::readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size) {
   if (auto EC = Stream.readBytes(Offset, Size, Buffer))
     return EC;
   Offset += Size;
   return Error::success();
 }
 
-Error StreamReader::readZeroString(StringRef &Dest) {
+Error BinaryStreamReader::readInteger(uint64_t &Dest, uint32_t ByteSize) {
+  assert(ByteSize == 1 || ByteSize == 2 || ByteSize == 4 || ByteSize == 8);
+  ArrayRef<uint8_t> Bytes;
+
+  if (auto EC = readBytes(Bytes, ByteSize))
+    return EC;
+  switch (ByteSize) {
+  case 1:
+    Dest = Bytes[0];
+    return Error::success();
+  case 2:
+    Dest = llvm::support::endian::read16(Bytes.data(), Stream.getEndian());
+    return Error::success();
+  case 4:
+    Dest = llvm::support::endian::read32(Bytes.data(), Stream.getEndian());
+    return Error::success();
+  case 8:
+    Dest = llvm::support::endian::read64(Bytes.data(), Stream.getEndian());
+    return Error::success();
+  }
+  llvm_unreachable("Unreachable!");
+  return Error::success();
+}
+
+Error BinaryStreamReader::readCString(StringRef &Dest) {
+  // TODO: This could be made more efficient by using readLongestContiguousChunk
+  // and searching for null terminators in the resulting buffer.
+
   uint32_t Length = 0;
   // First compute the length of the string by reading 1 byte at a time.
   uint32_t OriginalOffset = getOffset();
   const char *C;
-  do {
+  while (true) {
     if (auto EC = readObject(C))
       return EC;
-    if (*C != '\0')
-      ++Length;
-  } while (*C != '\0');
+    if (*C == '\0')
+      break;
+    ++Length;
+  }
   // Now go back and request a reference for that many bytes.
   uint32_t NewOffset = getOffset();
   setOffset(OriginalOffset);
 
-  ArrayRef<uint8_t> Data;
-  if (auto EC = readBytes(Data, Length))
+  if (auto EC = readFixedString(Dest, Length))
     return EC;
-  Dest = StringRef(reinterpret_cast<const char *>(Data.begin()), Data.size());
 
   // Now set the offset back to where it was after we calculated the length.
   setOffset(NewOffset);
   return Error::success();
 }
 
-Error StreamReader::readFixedString(StringRef &Dest, uint32_t Length) {
+Error BinaryStreamReader::readFixedString(StringRef &Dest, uint32_t Length) {
   ArrayRef<uint8_t> Bytes;
   if (auto EC = readBytes(Bytes, Length))
     return EC;
@@ -64,26 +90,26 @@
   return Error::success();
 }
 
-Error StreamReader::readStreamRef(ReadableStreamRef &Ref) {
+Error BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref) {
   return readStreamRef(Ref, bytesRemaining());
 }
 
-Error StreamReader::readStreamRef(ReadableStreamRef &Ref, uint32_t Length) {
+Error BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref, uint32_t Length) {
   if (bytesRemaining() < Length)
-    return make_error<MSFError>(msf_error_code::insufficient_buffer);
+    return errorCodeToError(make_error_code(std::errc::no_buffer_space));
   Ref = Stream.slice(Offset, Length);
   Offset += Length;
   return Error::success();
 }
 
-Error StreamReader::skip(uint32_t Amount) {
+Error BinaryStreamReader::skip(uint32_t Amount) {
   if (Amount > bytesRemaining())
-    return make_error<MSFError>(msf_error_code::insufficient_buffer);
+    return errorCodeToError(make_error_code(std::errc::no_buffer_space));
   Offset += Amount;
   return Error::success();
 }
 
-uint8_t StreamReader::peek() const {
+uint8_t BinaryStreamReader::peek() const {
   ArrayRef<uint8_t> Buffer;
   auto EC = Stream.readBytes(Offset, 1, Buffer);
   assert(!EC && "Cannot peek an empty buffer!");