BinaryStreamError.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //===- BinaryStreamError.h - Error extensions for Binary Streams *- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_SUPPORT_BINARYSTREAMERROR_H
  9. #define LLVM_SUPPORT_BINARYSTREAMERROR_H
  10. #include "llvm/ADT/StringRef.h"
  11. #include "llvm/Support/Error.h"
  12. #include <string>
  13. namespace llvm {
  14. enum class stream_error_code {
  15. unspecified,
  16. stream_too_short,
  17. invalid_array_size,
  18. invalid_offset,
  19. filesystem_error
  20. };
  21. /// Base class for errors originating when parsing raw PDB files
  22. class BinaryStreamError : public ErrorInfo<BinaryStreamError> {
  23. public:
  24. static char ID;
  25. explicit BinaryStreamError(stream_error_code C);
  26. explicit BinaryStreamError(StringRef Context);
  27. BinaryStreamError(stream_error_code C, StringRef Context);
  28. void log(raw_ostream &OS) const override;
  29. std::error_code convertToErrorCode() const override;
  30. StringRef getErrorMessage() const;
  31. stream_error_code getErrorCode() const { return Code; }
  32. private:
  33. std::string ErrMsg;
  34. stream_error_code Code;
  35. };
  36. } // namespace llvm
  37. #endif // LLVM_SUPPORT_BINARYSTREAMERROR_H