[augeas-devel] [PATCH 2/8] * src/pathx.c (check_app): allow overloaded functions
lutter at redhat.com
lutter at redhat.com
Sat May 7 01:12:50 UTC 2011
From: David Lutterkort <lutter at redhat.com>
Make it possible to have multiple functions with the same name, but
different signatures. All variants of a function must have the same arity,
they can only differ in their return type and the types of the arguments.
---
src/pathx.c | 28 ++++++++++++++++++++++++----
1 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/pathx.c b/src/pathx.c
index acd4eb0..a73a83d 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -1168,15 +1168,35 @@ static void check_filter(struct expr *expr, struct state *state) {
static void check_app(struct expr *expr, struct state *state) {
assert(expr->tag == E_APP);
+
for (int i=0; i < expr->func->arity; i++) {
check_expr(expr->args[i], state);
CHECK_ERROR;
- if (expr->args[i]->type != expr->func->arg_types[i]) {
- STATE_ERROR(state, PATHX_ETYPE);
- return;
+ }
+
+ int f;
+ for (f=0; f < ARRAY_CARDINALITY(builtin_funcs); f++) {
+ const struct func *fn = builtin_funcs + f;
+ if (STRNEQ(expr->func->name, fn->name))
+ continue;
+
+ int match = 1;
+ for (int i=0; i < expr->func->arity; i++) {
+ if (expr->args[i]->type != fn->arg_types[i]) {
+ match = 0;
+ break;
+ }
}
+ if (match)
+ break;
+ }
+
+ if (f < ARRAY_CARDINALITY(builtin_funcs)) {
+ expr->func = builtin_funcs + f;
+ expr->type = expr->func->type;
+ } else {
+ STATE_ERROR(state, PATHX_ETYPE);
}
- expr->type = expr->func->type;
}
/* Check the binary operators. Type rules:
--
1.7.4.4
More information about the augeas-devel
mailing list