comparison lib/DebugInfo/PDB/Native/RawError.cpp @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
comparison
equal deleted inserted replaced
146:3fc4d5c3e21e 148:63bd29f05246
10 // will be removed once this transition is complete. Clients should prefer to 10 // will be removed once this transition is complete. Clients should prefer to
11 // deal with the Error value directly, rather than converting to error_code. 11 // deal with the Error value directly, rather than converting to error_code.
12 class RawErrorCategory : public std::error_category { 12 class RawErrorCategory : public std::error_category {
13 public: 13 public:
14 const char *name() const noexcept override { return "llvm.pdb.raw"; } 14 const char *name() const noexcept override { return "llvm.pdb.raw"; }
15
16 std::string message(int Condition) const override { 15 std::string message(int Condition) const override {
17 switch (static_cast<raw_error_code>(Condition)) { 16 switch (static_cast<raw_error_code>(Condition)) {
18 case raw_error_code::unspecified: 17 case raw_error_code::unspecified:
19 return "An unknown error has occurred."; 18 return "An unknown error has occurred.";
20 case raw_error_code::feature_unsupported: 19 case raw_error_code::feature_unsupported:
44 return "The Type record has an invalid hash value."; 43 return "The Type record has an invalid hash value.";
45 } 44 }
46 llvm_unreachable("Unrecognized raw_error_code"); 45 llvm_unreachable("Unrecognized raw_error_code");
47 } 46 }
48 }; 47 };
49 } // end anonymous namespace 48 } // namespace
50 49
51 static ManagedStatic<RawErrorCategory> Category; 50 static llvm::ManagedStatic<RawErrorCategory> RawCategory;
51 const std::error_category &llvm::pdb::RawErrCategory() { return *RawCategory; }
52 52
53 char RawError::ID = 0; 53 char RawError::ID;
54
55 RawError::RawError(raw_error_code C) : RawError(C, "") {}
56
57 RawError::RawError(const std::string &Context)
58 : RawError(raw_error_code::unspecified, Context) {}
59
60 RawError::RawError(raw_error_code C, const std::string &Context) : Code(C) {
61 ErrMsg = "Native PDB Error: ";
62 std::error_code EC = convertToErrorCode();
63 if (Code != raw_error_code::unspecified)
64 ErrMsg += EC.message() + " ";
65 if (!Context.empty())
66 ErrMsg += Context;
67 }
68
69 void RawError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
70
71 const std::string &RawError::getErrorMessage() const { return ErrMsg; }
72
73 std::error_code RawError::convertToErrorCode() const {
74 return std::error_code(static_cast<int>(Code), *Category);
75 }