mirror of
https://github.com/intel/llvm.git
synced 2026-01-31 07:27:33 +08:00
Remove a parameter for file extension from canParse.
canParse took three parameters -- file magic, filename extension and memory buffer. All but YAMLReader ignored the second parameter. This patch removes the parameter. llvm-svn: 234080
This commit is contained in:
@@ -45,10 +45,8 @@ public:
|
||||
/// Sniffs the file to determine if this Reader can parse it.
|
||||
/// The method is called with:
|
||||
/// 1) the file_magic enumeration returned by identify_magic()
|
||||
/// 2) the file extension (e.g. ".obj")
|
||||
/// 3) the whole file content buffer if the above is not enough.
|
||||
virtual bool canParse(file_magic magic, StringRef fileExtension,
|
||||
const MemoryBuffer &mb) const = 0;
|
||||
/// 2) the whole file content buffer if the above is not enough.
|
||||
virtual bool canParse(file_magic magic, const MemoryBuffer &mb) const = 0;
|
||||
|
||||
/// \brief Parse a supplied buffer (already filled with the contents of a
|
||||
/// file) and create a File object.
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -32,15 +31,13 @@ void Registry::add(std::unique_ptr<YamlIOTaggedDocumentHandler> handler) {
|
||||
std::error_code
|
||||
Registry::loadFile(std::unique_ptr<MemoryBuffer> mb,
|
||||
std::vector<std::unique_ptr<File>> &result) const {
|
||||
// Get file type.
|
||||
// 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))
|
||||
continue;
|
||||
if (std::error_code ec = reader->loadFile(std::move(mb), *this, result))
|
||||
return ec;
|
||||
|
||||
@@ -25,10 +25,9 @@ public:
|
||||
|
||||
ELFReader(ContextT &ctx) : _ctx(ctx) {}
|
||||
|
||||
bool canParse(file_magic magic, StringRef,
|
||||
const MemoryBuffer &buf) const override {
|
||||
bool canParse(file_magic magic, const MemoryBuffer &mb) const override {
|
||||
return (FileT<ELFT>::canParse(magic) &&
|
||||
elfHeader(buf)->e_machine == ContextT::machine);
|
||||
elfHeader(mb)->e_machine == ContextT::machine);
|
||||
}
|
||||
|
||||
std::error_code
|
||||
|
||||
@@ -265,9 +265,8 @@ class ArchiveReader : public Reader {
|
||||
public:
|
||||
ArchiveReader(bool logLoading) : _logLoading(logLoading) {}
|
||||
|
||||
bool canParse(file_magic magic, StringRef,
|
||||
const MemoryBuffer &) const override {
|
||||
return (magic == llvm::sys::fs::file_magic::archive);
|
||||
bool canParse(file_magic magic, const MemoryBuffer &) const override {
|
||||
return magic == llvm::sys::fs::file_magic::archive;
|
||||
}
|
||||
|
||||
std::error_code
|
||||
|
||||
@@ -516,14 +516,9 @@ class MachOObjectReader : public Reader {
|
||||
public:
|
||||
MachOObjectReader(MachOLinkingContext &ctx) : _ctx(ctx) {}
|
||||
|
||||
bool canParse(file_magic magic, StringRef ext,
|
||||
const MemoryBuffer &mb) const override {
|
||||
switch (magic) {
|
||||
case llvm::sys::fs::file_magic::macho_object:
|
||||
return (mb.getBufferSize() > 32);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
bool canParse(file_magic magic, const MemoryBuffer &mb) const override {
|
||||
return (magic == llvm::sys::fs::file_magic::macho_object &&
|
||||
mb.getBufferSize() > 32);
|
||||
}
|
||||
|
||||
std::error_code
|
||||
@@ -542,12 +537,11 @@ class MachODylibReader : public Reader {
|
||||
public:
|
||||
MachODylibReader(MachOLinkingContext &ctx) : _ctx(ctx) {}
|
||||
|
||||
bool canParse(file_magic magic, StringRef ext,
|
||||
const MemoryBuffer &mb) const override {
|
||||
bool canParse(file_magic magic, const MemoryBuffer &mb) const override {
|
||||
switch (magic) {
|
||||
case llvm::sys::fs::file_magic::macho_dynamically_linked_shared_lib:
|
||||
case llvm::sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
|
||||
return (mb.getBufferSize() > 32);
|
||||
return mb.getBufferSize() > 32;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -988,8 +988,7 @@ namespace {
|
||||
|
||||
class NativeReader : public Reader {
|
||||
public:
|
||||
virtual bool canParse(file_magic magic, StringRef,
|
||||
const MemoryBuffer &mb) const override {
|
||||
bool canParse(file_magic magic, const MemoryBuffer &mb) const override {
|
||||
const NativeFileHeader *const header =
|
||||
reinterpret_cast<const NativeFileHeader *>(mb.getBufferStart());
|
||||
return (memcmp(header->magic, NATIVE_FILE_HEADER_MAGIC,
|
||||
|
||||
@@ -1049,8 +1049,7 @@ class COFFObjectReader : public Reader {
|
||||
public:
|
||||
COFFObjectReader(PECOFFLinkingContext &ctx) : _ctx(ctx) {}
|
||||
|
||||
bool canParse(file_magic magic, StringRef ext,
|
||||
const MemoryBuffer &) const override {
|
||||
bool canParse(file_magic magic, const MemoryBuffer &) const override {
|
||||
return magic == llvm::sys::fs::file_magic::coff_object;
|
||||
}
|
||||
|
||||
|
||||
@@ -361,11 +361,10 @@ class COFFImportLibraryReader : public Reader {
|
||||
public:
|
||||
COFFImportLibraryReader(PECOFFLinkingContext &ctx) : _ctx(ctx) {}
|
||||
|
||||
bool canParse(file_magic magic, StringRef,
|
||||
const MemoryBuffer &mb) const override {
|
||||
bool canParse(file_magic magic, const MemoryBuffer &mb) const override {
|
||||
if (mb.getBufferSize() < sizeof(COFF::ImportHeader))
|
||||
return false;
|
||||
return (magic == llvm::sys::fs::file_magic::coff_import_library);
|
||||
return magic == llvm::sys::fs::file_magic::coff_import_library;
|
||||
}
|
||||
|
||||
std::error_code
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/YAMLTraits.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <memory>
|
||||
@@ -1304,8 +1305,9 @@ class YAMLReader : public Reader {
|
||||
public:
|
||||
YAMLReader(const Registry ®istry) : _registry(registry) {}
|
||||
|
||||
bool canParse(file_magic, StringRef ext, const MemoryBuffer &) const override {
|
||||
return (ext.equals(".objtxt") || ext.equals(".yaml"));
|
||||
bool canParse(file_magic magic, const MemoryBuffer &mb) const override {
|
||||
StringRef ext = llvm::sys::path::extension(mb.getBufferIdentifier());
|
||||
return ext.equals(".objtxt") || ext.equals(".yaml");
|
||||
}
|
||||
|
||||
std::error_code
|
||||
|
||||
Reference in New Issue
Block a user