diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-01-21 11:09:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-21 11:09:34 -0800 |
commit | 02ef6b11d740f5a3aa2071b53b35c306d6ddfa7a (patch) | |
tree | 00466c409634df147d52d9400a263f563bd642b4 /src/wasm | |
parent | 060442225165d0423d06ea33ab865e850b54f61b (diff) | |
download | binaryen-02ef6b11d740f5a3aa2071b53b35c306d6ddfa7a.tar.gz binaryen-02ef6b11d740f5a3aa2071b53b35c306d6ddfa7a.tar.bz2 binaryen-02ef6b11d740f5a3aa2071b53b35c306d6ddfa7a.zip |
Create `ParentIndexIterator` to reduce iterator boilerplate (#4469)
Add a utility class for defining all the common operations like pre- and post-
increment and decrement, addition and subtraction, and assigning addition and
subtraction for iterators that are comprised of a parent object and an index
into that parent object. Use the new utility to reduce the boilerplate in
wasm-type.h. Add a new test of the iterator behavior.
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-type.cpp | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index af382da23..7801cc289 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -1082,13 +1082,13 @@ Type Type::getLeastUpperBound(Type a, Type b) { return TypeBounder().getLeastUpperBound(a, b); } -Type::Iterator Type::end() const { +size_t Type::size() const { if (isTuple()) { - return Iterator(this, getTypeInfo(*this)->tuple.types.size()); + return getTypeInfo(*this)->tuple.types.size(); } else { // TODO: unreachable is special and expands to {unreachable} currently. // see also: https://github.com/WebAssembly/binaryen/issues/3062 - return Iterator(this, size_t(id != Type::none)); + return size_t(id != Type::none); } } @@ -1096,21 +1096,12 @@ const Type& Type::Iterator::operator*() const { if (parent->isTuple()) { return getTypeInfo(*parent)->tuple.types[index]; } else { - // TODO: see comment in Type::end() + // TODO: see comment in Type::size() assert(index == 0 && parent->id != Type::none && "Index out of bounds"); return *parent; } } -const Type& Type::operator[](size_t index) const { - if (isTuple()) { - return getTypeInfo(*this)->tuple.types[index]; - } else { - assert(index == 0 && "Index out of bounds"); - return *begin(); - } -} - HeapType::HeapType(Signature sig) { assert(!isTemp(sig.params) && "Leaking temporary type!"); assert(!isTemp(sig.results) && "Leaking temporary type!"); |