comparison lib/Object/Error.cpp @ 120:1172e4bd9c6f

update 4.0.0
author mir3636
date Fri, 25 Nov 2016 19:14:25 +0900
parents afa8332a0e37
children c2174574ed3a
comparison
equal deleted inserted replaced
101:34baf5011add 120:1172e4bd9c6f
17 17
18 using namespace llvm; 18 using namespace llvm;
19 using namespace object; 19 using namespace object;
20 20
21 namespace { 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.
22 class _object_error_category : public std::error_category { 25 class _object_error_category : public std::error_category {
23 public: 26 public:
24 const char* name() const LLVM_NOEXCEPT override; 27 const char* name() const noexcept override;
25 std::string message(int ev) const override; 28 std::string message(int ev) const override;
26 }; 29 };
27 } 30 }
28 31
29 const char *_object_error_category::name() const LLVM_NOEXCEPT { 32 const char *_object_error_category::name() const noexcept {
30 return "llvm.object"; 33 return "llvm.object";
31 } 34 }
32 35
33 std::string _object_error_category::message(int EV) const { 36 std::string _object_error_category::message(int EV) const {
34 object_error E = static_cast<object_error>(EV); 37 object_error E = static_cast<object_error>(EV);
45 return "String table must end with a null terminator"; 48 return "String table must end with a null terminator";
46 case object_error::invalid_section_index: 49 case object_error::invalid_section_index:
47 return "Invalid section index"; 50 return "Invalid section index";
48 case object_error::bitcode_section_not_found: 51 case object_error::bitcode_section_not_found:
49 return "Bitcode section not found in object file"; 52 return "Bitcode section not found in object file";
50 case object_error::elf_invalid_dynamic_table_size: 53 case object_error::invalid_symbol_index:
51 return "Invalid dynamic table size"; 54 return "Invalid symbol index";
52 case object_error::macho_small_load_command:
53 return "Mach-O load command with size < 8 bytes";
54 case object_error::macho_load_segment_too_many_sections:
55 return "Mach-O segment load command contains too many sections";
56 case object_error::macho_load_segment_too_small:
57 return "Mach-O segment load command size is too small";
58 } 55 }
59 llvm_unreachable("An enumerator of object_error does not have a message " 56 llvm_unreachable("An enumerator of object_error does not have a message "
60 "defined."); 57 "defined.");
58 }
59
60 char BinaryError::ID = 0;
61 char GenericBinaryError::ID = 0;
62
63 GenericBinaryError::GenericBinaryError(Twine Msg) : Msg(Msg.str()) {}
64
65 GenericBinaryError::GenericBinaryError(Twine Msg, object_error ECOverride)
66 : Msg(Msg.str()) {
67 setErrorCode(make_error_code(ECOverride));
68 }
69
70 void GenericBinaryError::log(raw_ostream &OS) const {
71 OS << Msg;
61 } 72 }
62 73
63 static ManagedStatic<_object_error_category> error_category; 74 static ManagedStatic<_object_error_category> error_category;
64 75
65 const std::error_category &object::object_category() { 76 const std::error_category &object::object_category() {
66 return *error_category; 77 return *error_category;
67 } 78 }
79
80 llvm::Error llvm::object::isNotObjectErrorInvalidFileType(llvm::Error Err) {
81 if (auto Err2 =
82 handleErrors(std::move(Err), [](std::unique_ptr<ECError> M) -> Error {
83 // Try to handle 'M'. If successful, return a success value from
84 // the handler.
85 if (M->convertToErrorCode() == object_error::invalid_file_type)
86 return Error::success();
87
88 // We failed to handle 'M' - return it from the handler.
89 // This value will be passed back from catchErrors and
90 // wind up in Err2, where it will be returned from this function.
91 return Error(std::move(M));
92 }))
93 return Err2;
94 return Err;
95 }