xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Support/BinaryStreamError.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
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 
9 #ifndef LLVM_SUPPORT_BINARYSTREAMERROR_H
10 #define LLVM_SUPPORT_BINARYSTREAMERROR_H
11 
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Support/Compiler.h"
14 #include "llvm/Support/Error.h"
15 
16 #include <string>
17 
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 
27 /// Base class for errors originating when parsing raw PDB files
28 class LLVM_ABI BinaryStreamError : public ErrorInfo<BinaryStreamError> {
29 public:
30   static char ID;
31   explicit BinaryStreamError(stream_error_code C);
32   explicit BinaryStreamError(StringRef Context);
33   BinaryStreamError(stream_error_code C, StringRef Context);
34 
35   void log(raw_ostream &OS) const override;
36   std::error_code convertToErrorCode() const override;
37 
38   StringRef getErrorMessage() const;
39 
getErrorCode()40   stream_error_code getErrorCode() const { return Code; }
41 
42 private:
43   std::string ErrMsg;
44   stream_error_code Code;
45 };
46 } // namespace llvm
47 
48 #endif // LLVM_SUPPORT_BINARYSTREAMERROR_H
49