[TextAPI] update interface file for filtered iter

Summary:
This is a simple change that allows easy iterator semantics for symbols held in interface file.
Not being used, so harmless change right now, but will be once TBD-v4 is submitted.

Reviewers: ributzka, steven_wu

Reviewed By: ributzka

Subscribers: javed.absar, kristof.beyls, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67204

llvm-svn: 371097
This commit is contained in:
Cyndy Ishida 2019-09-05 17:33:44 +00:00
parent e3e6624ca2
commit 541ab7130e
1 changed files with 22 additions and 71 deletions

View File

@ -320,84 +320,35 @@ public:
reference operator*() const { return I->second; }
pointer operator->() const { return I->second; }
};
using const_symbol_range = iterator_range<const_symbol_iterator>;
// Custom iterator to return only exported symbols.
struct const_export_iterator
: public iterator_adaptor_base<
const_export_iterator, const_symbol_iterator,
std::forward_iterator_tag, const Symbol *> {
const_symbol_iterator _end;
void skipToNextSymbol() {
while (I != _end && I->isUndefined())
++I;
}
const_export_iterator() = default;
template <typename U>
const_export_iterator(U &&it, U &&end)
: iterator_adaptor_base(std::forward<U &&>(it)),
_end(std::forward<U &&>(end)) {
skipToNextSymbol();
}
const_export_iterator &operator++() {
++I;
skipToNextSymbol();
return *this;
}
const_export_iterator operator++(int) {
const_export_iterator tmp(*this);
++(*this);
return tmp;
}
};
using const_export_range = llvm::iterator_range<const_export_iterator>;
// Custom iterator to return only undefined symbols.
struct const_undefined_iterator
: public iterator_adaptor_base<
const_undefined_iterator, const_symbol_iterator,
std::forward_iterator_tag, const Symbol *> {
const_symbol_iterator _end;
void skipToNextSymbol() {
while (I != _end && !I->isUndefined())
++I;
}
const_undefined_iterator() = default;
template <typename U>
const_undefined_iterator(U &&it, U &&end)
: iterator_adaptor_base(std::forward<U &&>(it)),
_end(std::forward<U &&>(end)) {
skipToNextSymbol();
}
const_undefined_iterator &operator++() {
++I;
skipToNextSymbol();
return *this;
}
const_undefined_iterator operator++(int) {
const_undefined_iterator tmp(*this);
++(*this);
return tmp;
}
};
using const_undefined_range = llvm::iterator_range<const_undefined_iterator>;
using const_filtered_symbol_iterator =
filter_iterator<const_symbol_iterator,
std::function<bool(const Symbol *)>>;
using const_filtered_symbol_range =
iterator_range<const_filtered_symbol_iterator>;
const_symbol_range symbols() const {
return {Symbols.begin(), Symbols.end()};
}
const_export_range exports() const {
return {{Symbols.begin(), Symbols.end()}, {Symbols.end(), Symbols.end()}};
const_filtered_symbol_range exports() const {
std::function<bool(const Symbol *)> fn = [](const Symbol *Symbol) {
return !Symbol->isUndefined();
};
return make_filter_range(
make_range<const_symbol_iterator>({Symbols.begin()}, {Symbols.end()}),
fn);
}
const_undefined_range undefineds() const {
return {{Symbols.begin(), Symbols.end()}, {Symbols.end(), Symbols.end()}};
const_filtered_symbol_range undefineds() const {
std::function<bool(const Symbol *)> fn = [](const Symbol *Symbol) {
return Symbol->isUndefined();
};
return make_filter_range(
make_range<const_symbol_iterator>({Symbols.begin()}, {Symbols.end()}),
fn);
}
private: