[PATCH] Add methods to get archive file name from member file
Rui Ueyama
ruiu at google.com
Thu Feb 5 14:02:57 PST 2015
Hi shankarke,
Previously we only have File::path() to get the path name of a file.
If a file was a member of an archive file, path() returns a concatenated
string of the file name in the archive and the archive file name.
If we wanted to get a file name or an archive file name, we had to
parse that string. That's of course not good.
This patch adds new member functions, archivePath and memberPath, to File.
http://reviews.llvm.org/D7447
Files:
include/lld/Core/File.h
lib/ReaderWriter/FileArchive.cpp
Index: include/lld/Core/File.h
===================================================================
--- include/lld/Core/File.h
+++ include/lld/Core/File.h
@@ -55,12 +55,24 @@
return _kind;
}
- /// \brief For error messages and debugging, this returns the path to the file
- /// which was used to create this object (e.g. "/tmp/foo.o").
- StringRef path() const {
- return _path;
+ /// This returns the path to the file which was used to create this object
+ /// (e.g. "/tmp/foo.o"). If the file is a member of an archive file, the
+ /// returned string includes the archive file name.
+ StringRef path() const {
+ if (_archivePath.empty())
+ return _path;
+ return *new (_allocator) std::string(
+ (_archivePath + "(" + _path + ")").str());
}
+ /// Returns the path of the archive file name if this file is instantiated
+ /// from an archive file. Otehrwise returns the empty string.
+ StringRef archivePath() const { return _archivePath; }
+ void setArchivePath(StringRef path) { _archivePath = path; }
+
+ /// Returns the path name of this file. It doesn't include archive file name.
+ StringRef memberPath() const { return _path; }
+
/// Returns the command line order of the file.
uint64_t ordinal() const {
assert(_ordinal != UINT64_MAX);
@@ -248,6 +260,7 @@
private:
StringRef _path;
+ std::string _archivePath;
Kind _kind;
mutable uint64_t _ordinal;
std::shared_ptr<MemoryBuffer> _sharedMemoryBuffer;
Index: lib/ReaderWriter/FileArchive.cpp
===================================================================
--- lib/ReaderWriter/FileArchive.cpp
+++ lib/ReaderWriter/FileArchive.cpp
@@ -196,15 +196,16 @@
llvm::errs() << memberPath << "\n";
std::unique_ptr<MemoryBuffer> memberMB(MemoryBuffer::getMemBuffer(
- mb.getBuffer(), memberPath, false));
+ mb.getBuffer(), mb.getBufferIdentifier(), false));
std::vector<std::unique_ptr<File>> files;
if (std::error_code ec = _registry.loadFile(std::move(memberMB), files))
return ec;
assert(files.size() == 1);
result = std::move(files[0]);
if (std::error_code ec = result->parse())
return ec;
+ result->setArchivePath(_archive->getFileName());
// The memory buffer is co-owned by the archive file and the children,
// so that the bufffer is deallocated when all the members are destructed.
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7447.19431.patch
Type: text/x-patch
Size: 2413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150205/5212177e/attachment.bin>
More information about the llvm-commits
mailing list