#include "llvm/Object/Archive.h"
#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Endian.h"
+ sizeof(ArchiveMemberHeader)
+ offset;
// Verify it.
- if (Parent->StringTable == Parent->end_children()
+ if (Parent->StringTable == Parent->child_end()
|| addr < (Parent->StringTable->Data.begin()
+ sizeof(ArchiveMemberHeader))
|| addr > (Parent->StringTable->Data.begin()
return object_error::success;
}
-error_code Archive::Child::getMemoryBuffer(OwningPtr<MemoryBuffer> &Result,
+error_code Archive::Child::getMemoryBuffer(std::unique_ptr<MemoryBuffer> &Result,
bool FullPath) const {
StringRef Name;
if (error_code ec = getName(Name))
return error_code::success();
}
-error_code Archive::Child::getAsBinary(OwningPtr<Binary> &Result) const {
- OwningPtr<Binary> ret;
- OwningPtr<MemoryBuffer> Buff;
+error_code Archive::Child::getMemoryBuffer(OwningPtr<MemoryBuffer> &Result,
+ bool FullPath) const {
+ std::unique_ptr<MemoryBuffer> MB;
+ error_code ec = getMemoryBuffer(MB, FullPath);
+ Result = std::move(MB);
+ return ec;
+}
+
+error_code Archive::Child::getAsBinary(std::unique_ptr<Binary> &Result,
+ LLVMContext *Context) const {
+ std::unique_ptr<Binary> ret;
+ std::unique_ptr<MemoryBuffer> Buff;
if (error_code ec = getMemoryBuffer(Buff))
return ec;
- if (error_code ec = createBinary(Buff.take(), ret))
- return ec;
- Result.swap(ret);
+ ErrorOr<Binary *> BinaryOrErr = createBinary(Buff.release(), Context);
+ if (error_code EC = BinaryOrErr.getError())
+ return EC;
+ Result.reset(BinaryOrErr.get());
return object_error::success;
}
+error_code Archive::Child::getAsBinary(OwningPtr<Binary> &Result,
+ LLVMContext *Context) const {
+ std::unique_ptr<Binary> B;
+ error_code ec = getAsBinary(B, Context);
+ Result = std::move(B);
+ return ec;
+}
+
+ErrorOr<Archive*> Archive::create(MemoryBuffer *Source) {
+ error_code EC;
+ std::unique_ptr<Archive> Ret(new Archive(Source, EC));
+ if (EC)
+ return EC;
+ return Ret.release();
+}
+
Archive::Archive(MemoryBuffer *source, error_code &ec)
- : Binary(Binary::ID_Archive, source), SymbolTable(end_children()) {
+ : Binary(Binary::ID_Archive, source), SymbolTable(child_end()) {
// Check for sufficient magic.
assert(source);
if (source->getBufferSize() < 8 ||
}
// Get the special members.
- child_iterator i = begin_children(false);
- child_iterator e = end_children();
+ child_iterator i = child_begin(false);
+ child_iterator e = child_end();
if (i == e) {
ec = object_error::success;
ec = object_error::success;
}
-Archive::child_iterator Archive::begin_children(bool SkipInternal) const {
+Archive::child_iterator Archive::child_begin(bool SkipInternal) const {
if (Data->getBufferSize() == 8) // empty archive.
- return end_children();
+ return child_end();
if (SkipInternal)
return FirstRegular;
return c;
}
-Archive::child_iterator Archive::end_children() const {
+Archive::child_iterator Archive::child_end() const {
return Child(this, NULL);
}
return t;
}
-Archive::symbol_iterator Archive::begin_symbols() const {
+Archive::symbol_iterator Archive::symbol_begin() const {
if (!hasSymbolTable())
return symbol_iterator(Symbol(this, 0, 0));
return symbol_iterator(Symbol(this, 0, string_start_offset));
}
-Archive::symbol_iterator Archive::end_symbols() const {
+Archive::symbol_iterator Archive::symbol_end() const {
if (!hasSymbolTable())
return symbol_iterator(Symbol(this, 0, 0));
}
Archive::child_iterator Archive::findSym(StringRef name) const {
- Archive::symbol_iterator bs = begin_symbols();
- Archive::symbol_iterator es = end_symbols();
+ Archive::symbol_iterator bs = symbol_begin();
+ Archive::symbol_iterator es = symbol_end();
Archive::child_iterator result;
StringRef symname;
for (; bs != es; ++bs) {
if (bs->getName(symname))
- return end_children();
+ return child_end();
if (symname == name) {
if (bs->getMember(result))
- return end_children();
+ return child_end();
return result;
}
}
- return end_children();
+ return child_end();
}
bool Archive::hasSymbolTable() const {
- return SymbolTable != end_children();
+ return SymbolTable != child_end();
}