diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/expr/node.h | 22 | ||||
-rw-r--r-- | src/expr/node_value.h | 8 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/expr/node.h b/src/expr/node.h index 1fc583118..91c5bb21b 100644 --- a/src/expr/node.h +++ b/src/expr/node.h @@ -456,7 +456,7 @@ public: /** * Returns the iterator pointing to the end of the children (one beyond the - * last one. + * last one). * @return the end of the children iterator. */ inline iterator end() { @@ -468,7 +468,13 @@ public: } /** - * Returns the iterator pointing to the first child. + * Returns the iterator pointing to the first child, if the node's + * kind is the same as the template parameter, otherwise returns the + * iterator pointing to the node itself. This is useful if you want + * to pretend to iterate over a "unary" PLUS, for instance, since + * unary PLUSes don't exist---begin<PLUS>() will give an iterator + * over the children if the node's a PLUS node, otherwise give an + * iterator over the node itself, as if it were a unary PLUS. * @return the iterator */ template <Kind kind> @@ -481,9 +487,15 @@ public: } /** - * Returns the iterator pointing to the end of the children (one beyond the - * last one. - * @return the end of the children iterator. + * Returns the iterator pointing to the end of the children (one + * beyond the last one), if the node's kind is the same as the + * template parameter, otherwise returns the iterator pointing to + * the one-of-the-node-itself. This is useful if you want to + * pretend to iterate over a "unary" PLUS, for instance, since unary + * PLUSes don't exist---begin<PLUS>() will give an iterator over the + * children if the node's a PLUS node, otherwise give an iterator + * over the node itself, as if it were a unary PLUS. @return the + * end of the children iterator. */ template <Kind kind> inline iterator end() { diff --git a/src/expr/node_value.h b/src/expr/node_value.h index 63121b981..2b26b273d 100644 --- a/src/expr/node_value.h +++ b/src/expr/node_value.h @@ -364,7 +364,9 @@ inline NodeValue::iterator<T> NodeValue::end() const { template <typename T, Kind kind> inline NodeValue::iterator<T> NodeValue::begin() const { - if (d_kind != kind) return iterator<T>(this); + if(d_kind != kind) { + return iterator<T>(this); + } NodeValue* const* firstChild = d_children; if(getMetaKind() == kind::metakind::PARAMETERIZED) { ++firstChild; @@ -374,7 +376,9 @@ inline NodeValue::iterator<T> NodeValue::begin() const { template <typename T, Kind kind> inline NodeValue::iterator<T> NodeValue::end() const { - if (d_kind != kind) return iterator<T>(this + 1); + if(d_kind != kind) { + return iterator<T>(this + 1); + } return iterator<T>(d_children + d_nchildren); } |