llvm.org GIT mirror llvm / 36105c0
[Object] Change Archive::findSym to return an Expected<Optional<Child>>. As suggested by Rafael in review of D22079 - this was accidentally left out of the final commit (r275316). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275469 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
4 changed file(s) with 22 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_OBJECT_ARCHIVE_H
1414 #define LLVM_OBJECT_ARCHIVE_H
1515
16 #include "llvm/ADT/Optional.h"
1617 #include "llvm/ADT/StringRef.h"
1718 #include "llvm/ADT/iterator_range.h"
1819 #include "llvm/Object/Binary.h"
214215 }
215216
216217 // check if a symbol is in the archive
217 child_iterator findSym(Error &Err, StringRef name) const;
218 Expected> findSym(StringRef name) const;
218219
219220 bool hasSymbolTable() const;
220221 StringRef getSymbolTable() const { return SymbolTable; }
326326 for (object::OwningBinary &OB : Archives) {
327327 object::Archive *A = OB.getBinary();
328328 // Look for our symbols in each Archive
329 Error Err;
330 object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
331 if (Err)
332 report_fatal_error(std::move(Err));
333 if (ChildIt != A->child_end()) {
329 auto OptionalChildOrErr = A->findSym(Name);
330 if (!OptionalChildOrErr)
331 report_fatal_error(OptionalChildOrErr.takeError());
332 auto &OptionalChild = *OptionalChildOrErr;
333 if (OptionalChild) {
334334 // FIXME: Support nested archives?
335335 Expected> ChildBinOrErr =
336 ChildIt->getAsBinary();
336 OptionalChild->getAsBinary();
337337 if (!ChildBinOrErr) {
338338 // TODO: Actually report errors helpfully.
339339 consumeError(ChildBinOrErr.takeError());
257257 for (object::OwningBinary &OB : Archives) {
258258 object::Archive *A = OB.getBinary();
259259 // Look for our symbols in each Archive
260 Error Err;
261 object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
262 if (Err)
263 report_fatal_error(std::move(Err));
264 if (ChildIt != A->child_end()) {
260 auto OptionalChildOrErr = A->findSym(Name);
261 if (!OptionalChildOrErr)
262 report_fatal_error(OptionalChildOrErr.takeError());
263 auto &OptionalChild = *OptionalChildOrErr;
264 if (OptionalChild) {
265265 // FIXME: Support nested archives?
266266 Expected> ChildBinOrErr =
267 ChildIt->getAsBinary();
267 OptionalChild->getAsBinary();
268268 if (!ChildBinOrErr) {
269269 // TODO: Actually report errors helpfully.
270270 consumeError(ChildBinOrErr.takeError());
666666 return read32le(buf);
667667 }
668668
669 Archive::child_iterator Archive::findSym(Error &Err, StringRef name) const {
669 Expected> Archive::findSym(StringRef name) const {
670670 Archive::symbol_iterator bs = symbol_begin();
671671 Archive::symbol_iterator es = symbol_end();
672672
673673 for (; bs != es; ++bs) {
674674 StringRef SymName = bs->getName();
675675 if (SymName == name) {
676 if (auto MemberOrErr = bs->getMember()) {
677 return child_iterator(*MemberOrErr, &Err);
678 } else {
679 ErrorAsOutParameter ErrAsOutParam(Err);
680 Err = errorCodeToError(MemberOrErr.getError());
681 return child_end();
682 }
683 }
684 }
685 return child_end();
676 if (auto MemberOrErr = bs->getMember())
677 return Child(*MemberOrErr);
678 else
679 return errorCodeToError(MemberOrErr.getError());
680 }
681 }
682 return Optional();
686683 }
687684
688685 bool Archive::hasSymbolTable() const { return !SymbolTable.empty(); }