LLVM  8.0.1
Error.cpp
Go to the documentation of this file.
1 //===- Error.cpp - system_error extensions for Object -----------*- 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 // This defines a new error_category for the Object library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/Object/Error.h"
17 
18 using namespace llvm;
19 using namespace object;
20 
21 namespace {
22 // FIXME: This class is only here to support the transition to llvm::Error. It
23 // will be removed once this transition is complete. Clients should prefer to
24 // deal with the Error value directly, rather than converting to error_code.
25 class _object_error_category : public std::error_category {
26 public:
27  const char* name() const noexcept override;
28  std::string message(int ev) const override;
29 };
30 }
31 
32 const char *_object_error_category::name() const noexcept {
33  return "llvm.object";
34 }
35 
36 std::string _object_error_category::message(int EV) const {
37  object_error E = static_cast<object_error>(EV);
38  switch (E) {
40  return "No object file for requested architecture";
42  return "The file was not recognized as a valid object file";
44  return "Invalid data was encountered while parsing the file";
46  return "The end of the file was unexpectedly encountered";
48  return "String table must end with a null terminator";
50  return "Invalid section index";
52  return "Bitcode section not found in object file";
54  return "Invalid symbol index";
55  }
56  llvm_unreachable("An enumerator of object_error does not have a message "
57  "defined.");
58 }
59 
60 void BinaryError::anchor() {}
61 char BinaryError::ID = 0;
62 char GenericBinaryError::ID = 0;
63 
65 
67  : Msg(Msg.str()) {
68  setErrorCode(make_error_code(ECOverride));
69 }
70 
72  OS << Msg;
73 }
74 
76 
78  return *error_category;
79 }
80 
82  if (auto Err2 =
83  handleErrors(std::move(Err), [](std::unique_ptr<ECError> M) -> Error {
84  // Try to handle 'M'. If successful, return a success value from
85  // the handler.
86  if (M->convertToErrorCode() == object_error::invalid_file_type)
87  return Error::success();
88 
89  // We failed to handle 'M' - return it from the handler.
90  // This value will be passed back from catchErrors and
91  // wind up in Err2, where it will be returned from this function.
92  return Error(std::move(M));
93  }))
94  return Err2;
95  return Err;
96 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
std::error_code make_error_code(object_error e)
Definition: Error.h:40
void log(raw_ostream &OS) const override
Definition: Error.cpp:71
const std::error_category & object_category()
Definition: Error.cpp:77
Definition: BitVector.h:938
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Error isNotObjectErrorInvalidFileType(llvm::Error Err)
isNotObjectErrorInvalidFileType() is used when looping through the children of an archive after calli...
Definition: Error.cpp:81
static char ID
Definition: Error.h:55
object_error
Definition: Error.h:28
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static ErrorSuccess success()
Create a success value.
Definition: Error.h:327
aarch64 promote const
static const char * name
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Definition: Error.h:882
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:61