From: Rafael Espindola Date: Fri, 24 Apr 2015 18:33:50 +0000 (+0000) Subject: Return an ErrorOr>. NFC. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dedab912c3435f19b65191ff35825330077318bd;p=platform%2Fupstream%2Fllvm.git Return an ErrorOr>. NFC. llvm-svn: 235741 --- diff --git a/lld/include/lld/Core/Reader.h b/lld/include/lld/Core/Reader.h index 0b6cf65..0c9d67b 100644 --- a/lld/include/lld/Core/Reader.h +++ b/lld/include/lld/Core/Reader.h @@ -51,9 +51,8 @@ public: /// \brief Parse a supplied buffer (already filled with the contents of a /// file) and create a File object. /// The resulting File object takes ownership of the MemoryBuffer. - virtual std::error_code loadFile(std::unique_ptr mb, - const class Registry &, - std::unique_ptr &result) const = 0; + virtual ErrorOr> + loadFile(std::unique_ptr mb, const class Registry &) const = 0; }; diff --git a/lld/lib/Core/Reader.cpp b/lld/lib/Core/Reader.cpp index c97193d..d27cc73 100644 --- a/lld/lib/Core/Reader.cpp +++ b/lld/lib/Core/Reader.cpp @@ -38,8 +38,11 @@ std::error_code Registry::loadFile(std::unique_ptr mb, for (const std::unique_ptr &reader : _readers) { if (!reader->canParse(fileType, *mb)) continue; - if (std::error_code ec = reader->loadFile(std::move(mb), *this, result)) + ErrorOr> fileOrErr = + reader->loadFile(std::move(mb), *this); + if (std::error_code ec = fileOrErr.getError()) return ec; + result = std::move(fileOrErr.get()); return std::error_code(); } diff --git a/lld/lib/ReaderWriter/ELF/ELFReader.h b/lld/lib/ReaderWriter/ELF/ELFReader.h index 76f3823..ef337f5 100644 --- a/lld/lib/ReaderWriter/ELF/ELFReader.h +++ b/lld/lib/ReaderWriter/ELF/ELFReader.h @@ -28,13 +28,13 @@ public: return FileT::canParse(magic); } - std::error_code loadFile(std::unique_ptr mb, - const class Registry &, - std::unique_ptr &result) const override { + ErrorOr> + loadFile(std::unique_ptr mb, + const class Registry &) const override { if (std::error_code ec = FileT::isCompatible(*mb, _ctx)) return ec; - result = llvm::make_unique(std::move(mb), _ctx); - return std::error_code(); + std::unique_ptr ret = llvm::make_unique(std::move(mb), _ctx); + return std::move(ret); } private: diff --git a/lld/lib/ReaderWriter/FileArchive.cpp b/lld/lib/ReaderWriter/FileArchive.cpp index 23a2cb5..4f7863d 100644 --- a/lld/lib/ReaderWriter/FileArchive.cpp +++ b/lld/lib/ReaderWriter/FileArchive.cpp @@ -267,13 +267,12 @@ public: return magic == llvm::sys::fs::file_magic::archive; } - std::error_code loadFile(std::unique_ptr mb, - const Registry ®, - std::unique_ptr &result) const override { + ErrorOr> loadFile(std::unique_ptr mb, + const Registry ®) const override { StringRef path = mb->getBufferIdentifier(); - result = + std::unique_ptr ret = llvm::make_unique(std::move(mb), reg, path, _logLoading); - return std::error_code(); + return std::move(ret); } private: diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp index 45757ee..c0d8500 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp @@ -522,11 +522,12 @@ public: mb.getBufferSize() > 32); } - std::error_code loadFile(std::unique_ptr mb, - const Registry ®istry, - std::unique_ptr &result) const override { - result = llvm::make_unique(std::move(mb), &_ctx); - return std::error_code(); + ErrorOr> + loadFile(std::unique_ptr mb, + const Registry ®istry) const override { + std::unique_ptr ret = + llvm::make_unique(std::move(mb), &_ctx); + return std::move(ret); } private: @@ -547,11 +548,12 @@ public: } } - std::error_code loadFile(std::unique_ptr mb, - const Registry ®istry, - std::unique_ptr &result) const override { - result = llvm::make_unique(std::move(mb), &_ctx); - return std::error_code(); + ErrorOr> + loadFile(std::unique_ptr mb, + const Registry ®istry) const override { + std::unique_ptr ret = + llvm::make_unique(std::move(mb), &_ctx); + return std::move(ret); } private: diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index aa053bc..14f36d5 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -1052,11 +1052,12 @@ public: return magic == llvm::sys::fs::file_magic::coff_object; } - std::error_code loadFile(std::unique_ptr mb, const Registry &, - std::unique_ptr &result) const override { + ErrorOr> loadFile(std::unique_ptr mb, + const Registry &) const override { // Parse the memory buffer as PECOFF file. - result = llvm::make_unique(std::move(mb), _ctx); - return std::error_code(); + std::unique_ptr ret = + llvm::make_unique(std::move(mb), _ctx); + return std::move(ret); } private: diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp index 75d5807..a750e99 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp @@ -367,12 +367,12 @@ public: return magic == llvm::sys::fs::file_magic::coff_import_library; } - std::error_code loadFile(std::unique_ptr mb, - const class Registry &, - std::unique_ptr &result) const override { - result = llvm::make_unique(std::move(mb), - _ctx.getMachineType()); - return std::error_code(); + ErrorOr> + loadFile(std::unique_ptr mb, + const class Registry &) const override { + std::unique_ptr ret = llvm::make_unique( + std::move(mb), _ctx.getMachineType()); + return std::move(ret); } private: diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index d6863f3..4144349 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -1294,9 +1294,9 @@ public: return ext.equals(".objtxt") || ext.equals(".yaml"); } - std::error_code loadFile(std::unique_ptr mb, - const class Registry &, - std::unique_ptr &result) const override { + ErrorOr> + loadFile(std::unique_ptr mb, + const class Registry &) const override { // Create YAML Input Reader. YamlContext yamlContext; yamlContext._registry = &_registry; @@ -1318,8 +1318,7 @@ public: File *f = const_cast(file); f->setLastError(std::error_code()); f->setSharedMemoryBuffer(smb); - result = std::unique_ptr(f); - return make_error_code(lld::YamlReaderError::success); + return std::unique_ptr(f); } private: