llvm.org GIT mirror llvm / 5c1c055
Object: Add range iterators for Archive children No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218471 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 5 years ago
2 changed file(s) with 12 addition(s) and 9 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/iterator_range.h"
1617 #include "llvm/ADT/StringRef.h"
1718 #include "llvm/Object/Binary.h"
1819 #include "llvm/Support/ErrorHandling.h"
9697
9798 class child_iterator {
9899 Child child;
100
99101 public:
100102 child_iterator() : child(Child(nullptr, nullptr)) {}
101103 child_iterator(const Child &c) : child(c) {}
102 const Child* operator->() const {
103 return &child;
104 }
104 const Child *operator->() const { return &child; }
105 const Child &operator*() const { return child; }
105106
106107 bool operator==(const child_iterator &other) const {
107108 return child == other.child;
111112 return !(*this == other);
112113 }
113114
114 bool operator <(const child_iterator &other) const {
115 bool operator<(const child_iterator &other) const {
115116 return child < other.child;
116117 }
117118
118 child_iterator& operator++() { // Preincrement
119 child_iterator &operator++() { // Preincrement
119120 child = child.getNext();
120121 return *this;
121122 }
177178
178179 child_iterator child_begin(bool SkipInternal = true) const;
179180 child_iterator child_end() const;
181 iterator_range children(bool SkipInternal = true) const {
182 return iterator_range(child_begin(SkipInternal),
183 child_end());
184 }
180185
181186 symbol_iterator symbol_begin() const;
182187 symbol_iterator symbol_end() const;
136136 }
137137
138138 static void dumpArchive(const Archive *Arc) {
139 for (Archive::child_iterator ArcI = Arc->child_begin(),
140 ArcE = Arc->child_end();
141 ArcI != ArcE; ++ArcI) {
142 ErrorOr> ChildOrErr = ArcI->getAsBinary();
139 for (const Archive::Child &ArcC : Arc->children()) {
140 ErrorOr> ChildOrErr = ArcC.getAsBinary();
143141 if (std::error_code EC = ChildOrErr.getError()) {
144142 // Ignore non-object files.
145143 if (EC != object_error::invalid_file_type)