[lld] r235744 - Return ErrorOr<std::unique_ptr<File>>. NFC.
Rafael Espindola
rafael.espindola at gmail.com
Fri Apr 24 11:51:30 PDT 2015
Author: rafael
Date: Fri Apr 24 13:51:30 2015
New Revision: 235744
URL: http://llvm.org/viewvc/llvm-project?rev=235744&view=rev
Log:
Return ErrorOr<std::unique_ptr<File>>. NFC.
Modified:
lld/trunk/include/lld/Core/Reader.h
lld/trunk/lib/Core/Reader.cpp
lld/trunk/lib/Driver/DarwinLdDriver.cpp
lld/trunk/lib/Driver/Driver.cpp
lld/trunk/lib/ReaderWriter/FileArchive.cpp
lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
Modified: lld/trunk/include/lld/Core/Reader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Reader.h?rev=235744&r1=235743&r2=235744&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Reader.h (original)
+++ lld/trunk/include/lld/Core/Reader.h Fri Apr 24 13:51:30 2015
@@ -89,8 +89,8 @@ public:
/// Walk the list of registered Readers and find one that can parse the
/// supplied file and parse it.
- std::error_code loadFile(std::unique_ptr<MemoryBuffer> mb,
- std::unique_ptr<File> &result) const;
+ ErrorOr<std::unique_ptr<File>>
+ loadFile(std::unique_ptr<MemoryBuffer> mb) const;
/// Walk the list of registered kind tables to convert a Reference Kind
/// name to a value.
Modified: lld/trunk/lib/Core/Reader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Reader.cpp?rev=235744&r1=235743&r2=235744&view=diff
==============================================================================
--- lld/trunk/lib/Core/Reader.cpp (original)
+++ lld/trunk/lib/Core/Reader.cpp Fri Apr 24 13:51:30 2015
@@ -28,8 +28,8 @@ void Registry::add(std::unique_ptr<YamlI
_yamlHandlers.push_back(std::move(handler));
}
-std::error_code Registry::loadFile(std::unique_ptr<MemoryBuffer> mb,
- std::unique_ptr<File> &result) const {
+ErrorOr<std::unique_ptr<File>>
+Registry::loadFile(std::unique_ptr<MemoryBuffer> mb) const {
// Get file magic.
StringRef content(mb->getBufferStart(), mb->getBufferSize());
llvm::sys::fs::file_magic fileType = llvm::sys::fs::identify_magic(content);
@@ -38,12 +38,7 @@ std::error_code Registry::loadFile(std::
for (const std::unique_ptr<Reader> &reader : _readers) {
if (!reader->canParse(fileType, *mb))
continue;
- ErrorOr<std::unique_ptr<File>> 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();
+ return reader->loadFile(std::move(mb), *this);
}
// No Reader could parse this file.
Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=235744&r1=235743&r2=235744&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Fri Apr 24 13:51:30 2015
@@ -80,12 +80,12 @@ loadFile(MachOLinkingContext &ctx, Strin
ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = ctx.getMemoryBuffer(path);
if (std::error_code ec = mbOrErr.getError())
return makeErrorFile(path, ec);
- std::unique_ptr<File> file;
- if (std::error_code ec =
- ctx.registry().loadFile(std::move(mbOrErr.get()), file))
+ ErrorOr<std::unique_ptr<File>> fileOrErr =
+ ctx.registry().loadFile(std::move(mbOrErr.get()));
+ if (std::error_code ec = fileOrErr.getError())
return makeErrorFile(path, ec);
std::vector<std::unique_ptr<File>> files;
- files.push_back(std::move(file));
+ files.push_back(std::move(fileOrErr.get()));
for (std::unique_ptr<File> &pf : files) {
// If file is a dylib, inform LinkingContext about it.
if (SharedLibraryFile *shl = dyn_cast<SharedLibraryFile>(pf.get())) {
Modified: lld/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=235744&r1=235743&r2=235744&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Driver.cpp (original)
+++ lld/trunk/lib/Driver/Driver.cpp Fri Apr 24 13:51:30 2015
@@ -54,11 +54,12 @@ FileVector loadFile(LinkingContext &ctx,
= MemoryBuffer::getFileOrSTDIN(path);
if (std::error_code ec = mb.getError())
return makeErrorFile(path, ec);
- std::unique_ptr<File> file;
- if (std::error_code ec = ctx.registry().loadFile(std::move(mb.get()), file))
+ ErrorOr<std::unique_ptr<File>> fileOrErr =
+ ctx.registry().loadFile(std::move(mb.get()));
+ if (std::error_code ec = fileOrErr.getError())
return makeErrorFile(path, ec);
std::vector<std::unique_ptr<File>> files;
- files.push_back(std::move(file));
+ files.push_back(std::move(fileOrErr.get()));
if (wholeArchive)
return parseMemberFiles(files);
return files;
Modified: lld/trunk/lib/ReaderWriter/FileArchive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/FileArchive.cpp?rev=235744&r1=235743&r2=235744&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/FileArchive.cpp (original)
+++ lld/trunk/lib/ReaderWriter/FileArchive.cpp Fri Apr 24 13:51:30 2015
@@ -173,11 +173,12 @@ private:
std::unique_ptr<MemoryBuffer> memberMB(MemoryBuffer::getMemBuffer(
mb.getBuffer(), mb.getBufferIdentifier(), false));
- std::unique_ptr<File> file;
- if (std::error_code ec = _registry.loadFile(std::move(memberMB), file))
+ ErrorOr<std::unique_ptr<File>> fileOrErr =
+ _registry.loadFile(std::move(memberMB));
+ if (std::error_code ec = fileOrErr.getError())
return ec;
std::vector<std::unique_ptr<File>> files;
- files.push_back(std::move(file));
+ files.push_back(std::move(fileOrErr.get()));
assert(files.size() == 1);
result = std::move(files[0]);
if (std::error_code ec = result->parse())
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=235744&r1=235743&r2=235744&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Fri Apr 24 13:51:30 2015
@@ -623,11 +623,12 @@ MachODylibFile* MachOLinkingContext::loa
if (mbOrErr.getError())
return nullptr;
- std::unique_ptr<File> file;
- if (registry().loadFile(std::move(mbOrErr.get()), file))
+ ErrorOr<std::unique_ptr<File>> fileOrErr =
+ registry().loadFile(std::move(mbOrErr.get()));
+ if (!fileOrErr)
return nullptr;
std::vector<std::unique_ptr<File>> files;
- files.push_back(std::move(file));
+ files.push_back(std::move(fileOrErr.get()));
assert(files.size() == 1 && "expected one file in dylib");
files[0]->parse();
MachODylibFile* result = reinterpret_cast<MachODylibFile*>(files[0].get());
More information about the llvm-commits
mailing list