Small refactoring of FileError. NFC.
Differential revision: https://reviews.llvm.org/D57945 llvm-svn: 353679
This commit is contained in:
parent
150ccb889e
commit
317f9e7ae7
|
@ -1176,7 +1176,7 @@ Error createStringError(std::error_code EC, char const *Msg);
|
|||
/// show more detailed information to the user.
|
||||
class FileError final : public ErrorInfo<FileError> {
|
||||
|
||||
friend Error createFileError(std::string, Error);
|
||||
friend Error createFileError(const Twine &, Error);
|
||||
|
||||
public:
|
||||
void log(raw_ostream &OS) const override {
|
||||
|
@ -1193,15 +1193,15 @@ public:
|
|||
static char ID;
|
||||
|
||||
private:
|
||||
FileError(std::string F, std::unique_ptr<ErrorInfoBase> E) {
|
||||
FileError(const Twine &F, std::unique_ptr<ErrorInfoBase> E) {
|
||||
assert(E && "Cannot create FileError from Error success value.");
|
||||
assert(!F.empty() &&
|
||||
"The file name provided to FileError must not be empty.");
|
||||
FileName = F;
|
||||
FileName = F.str();
|
||||
Err = std::move(E);
|
||||
}
|
||||
|
||||
static Error build(std::string F, Error E) {
|
||||
static Error build(const Twine &F, Error E) {
|
||||
return Error(std::unique_ptr<FileError>(new FileError(F, E.takePayload())));
|
||||
}
|
||||
|
||||
|
@ -1211,11 +1211,17 @@ private:
|
|||
|
||||
/// Concatenate a source file path and/or name with an Error. The resulting
|
||||
/// Error is unchecked.
|
||||
inline Error createFileError(std::string F, Error E) {
|
||||
inline Error createFileError(const Twine &F, Error E) {
|
||||
return FileError::build(F, std::move(E));
|
||||
}
|
||||
|
||||
Error createFileError(std::string F, ErrorSuccess) = delete;
|
||||
/// Concatenate a source file path and/or name with a std::error_code
|
||||
/// to form an Error object.
|
||||
inline Error createFileError(const Twine &F, std::error_code EC) {
|
||||
return createFileError(F, errorCodeToError(EC));
|
||||
}
|
||||
|
||||
Error createFileError(const Twine &F, ErrorSuccess) = delete;
|
||||
|
||||
/// Helper for check-and-exit error handling.
|
||||
///
|
||||
|
|
|
@ -263,7 +263,7 @@ static Error addSymbolsToRenameFromFile(StringMap<StringRef> &SymbolsToRename,
|
|||
SmallVector<StringRef, 16> Lines;
|
||||
auto BufOrErr = MemoryBuffer::getFile(Filename);
|
||||
if (!BufOrErr)
|
||||
return createError(Filename, BufOrErr.getError());
|
||||
return createFileError(Filename, BufOrErr.getError());
|
||||
|
||||
BufOrErr.get()->getBuffer().split(Lines, '\n');
|
||||
size_t NumLines = Lines.size();
|
||||
|
|
|
@ -52,11 +52,6 @@ namespace objcopy {
|
|||
// The name this program was invoked as.
|
||||
StringRef ToolName;
|
||||
|
||||
Error createError(StringRef File, std::error_code EC) {
|
||||
assert(EC);
|
||||
return createFileError(File, make_error<StringError>(EC));
|
||||
}
|
||||
|
||||
LLVM_ATTRIBUTE_NORETURN void error(Twine Message) {
|
||||
WithColor::error(errs(), ToolName) << Message << ".\n";
|
||||
errs().flush();
|
||||
|
@ -74,7 +69,8 @@ LLVM_ATTRIBUTE_NORETURN void error(Error E) {
|
|||
}
|
||||
|
||||
LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, std::error_code EC) {
|
||||
error(createError(File, EC));
|
||||
assert(EC);
|
||||
error(createFileError(File, EC));
|
||||
}
|
||||
|
||||
LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Error E) {
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
namespace llvm {
|
||||
namespace objcopy {
|
||||
|
||||
Error createError(StringRef File, std::error_code EC);
|
||||
|
||||
LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message);
|
||||
LLVM_ATTRIBUTE_NORETURN extern void error(Error E);
|
||||
LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File, Error E);
|
||||
|
|
Loading…
Reference in New Issue