#ifndef LLVM_OBJECT_ARCHIVE_H
#define LLVM_OBJECT_ARCHIVE_H
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Object/Binary.h"
}
// check if a symbol is in the archive
- child_iterator findSym(Error &Err, StringRef name) const;
+ Expected<Optional<Child>> findSym(StringRef name) const;
bool hasSymbolTable() const;
StringRef getSymbolTable() const { return SymbolTable; }
for (object::OwningBinary<object::Archive> &OB : Archives) {
object::Archive *A = OB.getBinary();
// Look for our symbols in each Archive
- Error Err;
- object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
- if (Err)
- report_fatal_error(std::move(Err));
- if (ChildIt != A->child_end()) {
+ auto OptionalChildOrErr = A->findSym(Name);
+ if (!OptionalChildOrErr)
+ report_fatal_error(OptionalChildOrErr.takeError());
+ auto &OptionalChild = *OptionalChildOrErr;
+ if (OptionalChild) {
// FIXME: Support nested archives?
Expected<std::unique_ptr<object::Binary>> ChildBinOrErr =
- ChildIt->getAsBinary();
+ OptionalChild->getAsBinary();
if (!ChildBinOrErr) {
// TODO: Actually report errors helpfully.
consumeError(ChildBinOrErr.takeError());
for (object::OwningBinary<object::Archive> &OB : Archives) {
object::Archive *A = OB.getBinary();
// Look for our symbols in each Archive
- Error Err;
- object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
- if (Err)
- report_fatal_error(std::move(Err));
- if (ChildIt != A->child_end()) {
+ auto OptionalChildOrErr = A->findSym(Name);
+ if (!OptionalChildOrErr)
+ report_fatal_error(OptionalChildOrErr.takeError());
+ auto &OptionalChild = *OptionalChildOrErr;
+ if (OptionalChild) {
// FIXME: Support nested archives?
Expected<std::unique_ptr<object::Binary>> ChildBinOrErr =
- ChildIt->getAsBinary();
+ OptionalChild->getAsBinary();
if (!ChildBinOrErr) {
// TODO: Actually report errors helpfully.
consumeError(ChildBinOrErr.takeError());
return read32le(buf);
}
-Archive::child_iterator Archive::findSym(Error &Err, StringRef name) const {
+Expected<Optional<Archive::Child>> Archive::findSym(StringRef name) const {
Archive::symbol_iterator bs = symbol_begin();
Archive::symbol_iterator es = symbol_end();
for (; bs != es; ++bs) {
StringRef SymName = bs->getName();
if (SymName == name) {
- if (auto MemberOrErr = bs->getMember()) {
- return child_iterator(*MemberOrErr, &Err);
- } else {
- ErrorAsOutParameter ErrAsOutParam(Err);
- Err = errorCodeToError(MemberOrErr.getError());
- return child_end();
- }
+ if (auto MemberOrErr = bs->getMember())
+ return Child(*MemberOrErr);
+ else
+ return errorCodeToError(MemberOrErr.getError());
}
}
- return child_end();
+ return Optional<Child>();
}
bool Archive::hasSymbolTable() const { return !SymbolTable.empty(); }