diff options
Diffstat (limited to 'include/llvm/Object/Archive.h')
-rw-r--r-- | include/llvm/Object/Archive.h | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/include/llvm/Object/Archive.h b/include/llvm/Object/Archive.h index 8dd042a2533fe..cfba2567371ac 100644 --- a/include/llvm/Object/Archive.h +++ b/include/llvm/Object/Archive.h @@ -14,6 +14,7 @@ #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" @@ -42,7 +43,7 @@ struct ArchiveMemberHeader { sys::fs::perms getAccessMode() const; sys::TimeValue getLastModified() const; llvm::StringRef getRawLastModified() const { - return StringRef(LastModified, sizeof(LastModified)).rtrim(" "); + return StringRef(LastModified, sizeof(LastModified)).rtrim(' '); } unsigned getUID() const; unsigned getGID() const; @@ -78,6 +79,7 @@ public: ErrorOr<Child> getNext() const; ErrorOr<StringRef> getName() const; + ErrorOr<std::string> getFullName() const; StringRef getRawName() const { return getHeader()->getName(); } sys::TimeValue getLastModified() const { return getHeader()->getLastModified(); @@ -100,26 +102,25 @@ public: ErrorOr<MemoryBufferRef> getMemoryBufferRef() const; - ErrorOr<std::unique_ptr<Binary>> + Expected<std::unique_ptr<Binary>> getAsBinary(LLVMContext *Context = nullptr) const; }; class child_iterator { - ErrorOr<Child> child; + Child C; + Error *E; public: - child_iterator() : child(Child(nullptr, nullptr, nullptr)) {} - child_iterator(const Child &c) : child(c) {} - child_iterator(std::error_code EC) : child(EC) {} - const ErrorOr<Child> *operator->() const { return &child; } - const ErrorOr<Child> &operator*() const { return child; } + child_iterator() : C(Child(nullptr, nullptr, nullptr)), E(nullptr) {} + child_iterator(const Child &C, Error *E) : C(C), E(E) {} + const Child *operator->() const { return &C; } + const Child &operator*() const { return C; } bool operator==(const child_iterator &other) const { - // We ignore error states so that comparisions with end() work, which - // allows range loops. - if (child.getError() || other.child.getError()) - return false; - return *child == *other.child; + // Ignore errors here: If an error occurred during increment then getNext + // will have been set to child_end(), and the following comparison should + // do the right thing. + return C == other.C; } bool operator!=(const child_iterator &other) const { @@ -129,8 +130,15 @@ public: // Code in loops with child_iterators must check for errors on each loop // iteration. And if there is an error break out of the loop. child_iterator &operator++() { // Preincrement - assert(child && "Can't increment iterator with error"); - child = child->getNext(); + assert(E && "Can't increment iterator with no Error attached"); + if (auto ChildOrErr = C.getNext()) + C = *ChildOrErr; + else { + ErrorAsOutParameter ErrAsOutParam(*E); + C = C.getParent()->child_end().C; + *E = errorCodeToError(ChildOrErr.getError()); + E = nullptr; + } return *this; } }; @@ -175,23 +183,25 @@ public: } }; - Archive(MemoryBufferRef Source, std::error_code &EC); - static ErrorOr<std::unique_ptr<Archive>> create(MemoryBufferRef Source); + Archive(MemoryBufferRef Source, Error &Err); + static Expected<std::unique_ptr<Archive>> create(MemoryBufferRef Source); enum Kind { K_GNU, K_MIPS64, K_BSD, + K_DARWIN64, K_COFF }; Kind kind() const { return (Kind)Format; } bool isThin() const { return IsThin; } - child_iterator child_begin(bool SkipInternal = true) const; + child_iterator child_begin(Error &Err, bool SkipInternal = true) const; child_iterator child_end() const; - iterator_range<child_iterator> children(bool SkipInternal = true) const { - return make_range(child_begin(SkipInternal), child_end()); + iterator_range<child_iterator> children(Error &Err, + bool SkipInternal = true) const { + return make_range(child_begin(Err, SkipInternal), child_end()); } symbol_iterator symbol_begin() const; @@ -206,12 +216,16 @@ public: } // check if a symbol is in the archive - child_iterator findSym(StringRef name) const; + Expected<Optional<Child>> findSym(StringRef name) const; bool hasSymbolTable() const; StringRef getSymbolTable() const { return SymbolTable; } uint32_t getNumberOfSymbols() const; + std::vector<std::unique_ptr<MemoryBuffer>> takeThinBuffers() { + return std::move(ThinBuffers); + } + private: StringRef SymbolTable; StringRef StringTable; @@ -220,7 +234,7 @@ private: uint16_t FirstRegularStartOfFile = -1; void setFirstRegular(const Child &C); - unsigned Format : 2; + unsigned Format : 3; unsigned IsThin : 1; mutable std::vector<std::unique_ptr<MemoryBuffer>> ThinBuffers; }; |