diff options
author | Patrick Palka <ppalka@redhat.com> | 2022-05-11 16:14:59 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2022-05-11 16:14:59 -0400 |
commit | 25addf8352e590fab926e9d16c2cd4a7ea0963b9 (patch) | |
tree | c7bfc1219fe51540c69b99c3ed97bcf9c4673e19 /gcc/tree.h | |
parent | 88459c3965e2a2f62ab4d4c8b2ac8460b1a15c33 (diff) | |
download | gcc-25addf8352e590fab926e9d16c2cd4a7ea0963b9.zip gcc-25addf8352e590fab926e9d16c2cd4a7ea0963b9.tar.gz gcc-25addf8352e590fab926e9d16c2cd4a7ea0963b9.tar.bz2 |
tree: introduce range adaptor for TREE_VEC
This patch implements a simple tree wrapper, named tree_vec_range, which
lets us idiomatically loop over all the elements of a TREE_VEC using a
C++11 range-based for loop:
// v is a TREE_VEC
for (tree e : tree_vec_range (v))
...
This is similar to the existing tree-based range adaptors ovl_range and
lkp_range added to the C++ FE in r12-340-g3307b9a07a3c51.
This patch also converts some existing loops over TREE_VEC within the
C++ FE to use tree_vec_range / range-for.
gcc/cp/ChangeLog:
* constraint.cc (tsubst_parameter_mapping): Convert loop over
TREE_VEC into a range-based for loop using tree_vec_range.
* pt.cc (iterative_hash_template_arg): Likewise.
(template_parms_level_to_args): Likewise.
(deducible_template_args): Likewise.
(check_undeduced_parms): Likewise.
(dependent_type_p_r): Likewise.
(value_dependent_expression_p) <case NONTYPE_ARGUMENT_PACK>:
Likewise.
(dependent_template_arg_p): Likewise.
* tree.cc (cp_walk_subtrees) <case NONTYPE_ARGUMENT_PACK>:
Likewise.
gcc/ChangeLog:
* tree.h (TREE_VEC_BEGIN): Define.
(TREE_VEC_END): Correct 'length' member access.
(class tree_vec_range): Define.
Diffstat (limited to 'gcc/tree.h')
-rw-r--r-- | gcc/tree.h | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -1107,8 +1107,9 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, /* In a TREE_VEC node. */ #define TREE_VEC_LENGTH(NODE) (TREE_VEC_CHECK (NODE)->base.u.length) +#define TREE_VEC_BEGIN(NODE) (&TREE_VEC_CHECK (NODE)->vec.a[0]) #define TREE_VEC_END(NODE) \ - ((void) TREE_VEC_CHECK (NODE), &((NODE)->vec.a[(NODE)->vec.base.u.length])) + ((void) TREE_VEC_CHECK (NODE), &((NODE)->vec.a[(NODE)->base.u.length])) #define TREE_VEC_ELT(NODE,I) TREE_VEC_ELT_CHECK (NODE, I) @@ -4481,6 +4482,18 @@ extern tree make_tree_vec (int CXX_MEM_STAT_INFO); extern tree grow_tree_vec (tree v, int CXX_MEM_STAT_INFO); +/* Treat a TREE_VEC as a range of trees, e.g. + for (tree e : tree_vec_range (v)) { ... } */ + +class tree_vec_range +{ + tree v; +public: + tree_vec_range(tree v) : v(v) { } + tree *begin() { return TREE_VEC_BEGIN (v); } + tree *end() { return TREE_VEC_END (v); } +}; + /* Construct various types of nodes. */ extern tree build_nt (enum tree_code, ...); |