xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DebugInfo/MSF/MSFError.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- MSFError.h - Error extensions for MSF Files --------------*- 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_DEBUGINFO_MSF_MSFERROR_H
10 #define LLVM_DEBUGINFO_MSF_MSFERROR_H
11 
12 #include "llvm/Support/Compiler.h"
13 #include "llvm/Support/Error.h"
14 
15 namespace llvm {
16 namespace msf {
17 enum class msf_error_code {
18   unspecified = 1,
19   insufficient_buffer,
20   not_writable,
21   no_stream,
22   invalid_format,
23   block_in_use,
24   size_overflow_4096,
25   size_overflow_8192,
26   size_overflow_16384,
27   size_overflow_32768,
28   stream_directory_overflow,
29 };
30 } // namespace msf
31 } // namespace llvm
32 
33 namespace std {
34 template <>
35 struct is_error_code_enum<llvm::msf::msf_error_code> : std::true_type {};
36 } // namespace std
37 
38 namespace llvm {
39 namespace msf {
40 LLVM_ABI const std::error_category &MSFErrCategory();
41 
42 inline std::error_code make_error_code(msf_error_code E) {
43   return std::error_code(static_cast<int>(E), MSFErrCategory());
44 }
45 
46 /// Base class for errors originating when parsing raw PDB files
47 class MSFError : public ErrorInfo<MSFError, StringError> {
48 public:
49   using ErrorInfo<MSFError, StringError>::ErrorInfo; // inherit constructors
50   MSFError(const Twine &S) : ErrorInfo(S, msf_error_code::unspecified) {}
51 
52   bool isPageOverflow() const {
53     switch (static_cast<msf_error_code>(convertToErrorCode().value())) {
54     case msf_error_code::unspecified:
55     case msf_error_code::insufficient_buffer:
56     case msf_error_code::not_writable:
57     case msf_error_code::no_stream:
58     case msf_error_code::invalid_format:
59     case msf_error_code::block_in_use:
60       return false;
61     case msf_error_code::size_overflow_4096:
62     case msf_error_code::size_overflow_8192:
63     case msf_error_code::size_overflow_16384:
64     case msf_error_code::size_overflow_32768:
65     case msf_error_code::stream_directory_overflow:
66       return true;
67     }
68     llvm_unreachable("msf error code not implemented");
69   }
70 
71   LLVM_ABI static char ID;
72 };
73 } // namespace msf
74 } // namespace llvm
75 
76 #endif // LLVM_DEBUGINFO_MSF_MSFERROR_H
77