LLVM  6.0.0svn
CodeViewError.cpp
Go to the documentation of this file.
1 //===- CodeViewError.cpp - Error extensions for CodeView --------*- 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::codeview;
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 CodeViewErrorCategory : public std::error_category {
22 public:
23  const char *name() const noexcept override { return "llvm.codeview"; }
24 
25  std::string message(int Condition) const override {
26  switch (static_cast<cv_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 CodeView record is corrupted.";
35  return "There are no records";
37  return "The requested operation is not supported.";
39  return "The member record is of an unknown type.";
40  }
41  llvm_unreachable("Unrecognized cv_error_code");
42  }
43 };
44 } // end anonymous namespace
45 
47 
48 char CodeViewError::ID = 0;
49 
51 
54 
56  : Code(C) {
57  ErrMsg = "CodeView Error: ";
58  std::error_code EC = convertToErrorCode();
59  if (Code != cv_error_code::unspecified)
60  ErrMsg += EC.message() + " ";
61  if (!Context.empty())
62  ErrMsg += Context;
63 }
64 
65 void CodeViewError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
66 
67 const std::string &CodeViewError::getErrorMessage() const { return ErrMsg; }
68 
69 std::error_code CodeViewError::convertToErrorCode() const {
70  return std::error_code(static_cast<int>(Code), *Category);
71 }
LLVMContext & Context
const std::string & getErrorMessage() const
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Base class for errors originating when parsing raw PDB files.
Definition: CodeViewError.h:29
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.
static ManagedStatic< CodeViewErrorCategory > Category
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
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