From 9fc0cd638744aa07675e337bb5db66322c4c3946 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 17 Jul 2013 16:03:10 +0200 Subject: [PATCH] add pet_expr_foreach_access_expr Signed-off-by: Sven Verdoolaege --- scop.c | 23 +++++++++++++++++++++++ scop.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/scop.c b/scop.c index 1a3b957..4e281b6 100644 --- a/scop.c +++ b/scop.c @@ -546,6 +546,29 @@ struct pet_expr *pet_expr_map_access(struct pet_expr *expr, return expr; } +/* Call "fn" on each of the subexpressions of "expr" of type pet_expr_access. + * + * Return -1 on error (where fn return a negative value is treated as an error). + * Otherwise return 0. + */ +int pet_expr_foreach_access_expr(struct pet_expr *expr, + int (*fn)(struct pet_expr *expr, void *user), void *user) +{ + int i; + + if (!expr) + return -1; + + for (i = 0; i < expr->n_arg; ++i) + if (pet_expr_foreach_access_expr(expr->args[i], fn, user) < 0) + return -1; + + if (expr->type == pet_expr_access) + return fn(expr, user); + + return 0; +} + /* Modify the access relation of the given access expression * based on the given iteration space transformation. * If the access has any arguments then the domain of the access relation diff --git a/scop.h b/scop.h index 45091c2..3e29856 100644 --- a/scop.h +++ b/scop.h @@ -82,6 +82,8 @@ struct pet_scop *pet_scop_gist(struct pet_scop *scop, struct pet_scop *pet_scop_anonymize(struct pet_scop *scop); +int pet_expr_foreach_access_expr(struct pet_expr *expr, + int (*fn)(struct pet_expr *expr, void *user), void *user); struct pet_expr *pet_expr_map_access(struct pet_expr *expr, struct pet_expr *(*fn)(struct pet_expr *expr, void *user), void *user); -- 2.11.4.GIT