LLVM  6.0.0svn
MSFError.cpp
Go to the documentation of this file.
1 //===- MSFError.cpp - Error extensions for MSF files ------------*- 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 
13 
14 using namespace llvm;
15 using namespace llvm::msf;
16 
17 namespace {
18 // FIXME: This class is only here to support the transition to llvm::Error. It
19 // will be removed once this transition is complete. Clients should prefer to
20 // deal with the Error value directly, rather than converting to error_code.
21 class MSFErrorCategory : public std::error_category {
22 public:
23  const char *name() const noexcept override { return "llvm.msf"; }
24 
25  std::string message(int Condition) const override {
26  switch (static_cast<msf_error_code>(Condition)) {
28  return "An unknown error has occurred.";
30  return "The buffer is not large enough to read the requested number of "
31  "bytes.";
33  return "The specified stream is not writable.";
35  return "The specified stream does not exist.";
37  return "The data is in an unexpected format.";
39  return "The block is already in use.";
40  }
41  llvm_unreachable("Unrecognized msf_error_code");
42  }
43 };
44 } // end anonymous namespace
45 
47 
48 char MSFError::ID = 0;
49 
51 
52 MSFError::MSFError(const std::string &Context)
53  : MSFError(msf_error_code::unspecified, Context) {}
54 
55 MSFError::MSFError(msf_error_code C, const std::string &Context) : Code(C) {
56  ErrMsg = "MSF Error: ";
57  std::error_code EC = convertToErrorCode();
58  if (Code != msf_error_code::unspecified)
59  ErrMsg += EC.message() + " ";
60  if (!Context.empty())
61  ErrMsg += Context;
62 }
63 
64 void MSFError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
65 
66 const std::string &MSFError::getErrorMessage() const { return ErrMsg; }
67 
68 std::error_code MSFError::convertToErrorCode() const {
69  return std::error_code(static_cast<int>(Code), *Category);
70 }
uint64_t CallInst * C
Base class for errors originating when parsing raw PDB files.
Definition: MSFError.h:29
LLVMContext & Context
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MSFError(msf_error_code C)
Definition: MSFError.cpp:50
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: MSFError.cpp:68
static char ID
Definition: MSFError.h:31
const std::string & getErrorMessage() const
Definition: MSFError.cpp:66
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:74
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
msf_error_code
Definition: MSFError.h:19
static ManagedStatic< MSFErrorCategory > Category
Definition: MSFError.cpp:46
aarch64 promote const
static const char * name
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:61
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: MSFError.cpp:64