summaryrefslogtreecommitdiff
path: root/lib/Core/Reader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Core/Reader.cpp')
-rw-r--r--lib/Core/Reader.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/Core/Reader.cpp b/lib/Core/Reader.cpp
index 6f8b8cbd1bf8d..6069093d211ef 100644
--- a/lib/Core/Reader.cpp
+++ b/lib/Core/Reader.cpp
@@ -13,7 +13,6 @@
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Path.h"
#include <memory>
#include <system_error>
@@ -29,22 +28,17 @@ void Registry::add(std::unique_ptr<YamlIOTaggedDocumentHandler> handler) {
_yamlHandlers.push_back(std::move(handler));
}
-std::error_code
-Registry::loadFile(std::unique_ptr<MemoryBuffer> mb,
- std::vector<std::unique_ptr<File>> &result) const {
- // Get file type.
+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);
- // Get file extension.
- StringRef extension = llvm::sys::path::extension(mb->getBufferIdentifier());
// Ask each registered reader if it can handle this file type or extension.
for (const std::unique_ptr<Reader> &reader : _readers) {
- if (!reader->canParse(fileType, extension, *mb))
+ if (!reader->canParse(fileType, mb->getMemBufferRef()))
continue;
- if (std::error_code ec = reader->loadFile(std::move(mb), *this, result))
- return ec;
- return std::error_code();
+ return reader->loadFile(std::move(mb), *this);
}
// No Reader could parse this file.