Home | History | Annotate | Download | only in Support
      1 //===- BinaryStreamError.h - Error extensions for Binary Streams *- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef LLVM_SUPPORT_BINARYSTREAMERROR_H
     11 #define LLVM_SUPPORT_BINARYSTREAMERROR_H
     12 
     13 #include "llvm/ADT/StringRef.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 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 
     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