BinaryStreamError.h 1.5 KB

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