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