From: Ondrej Zajicek (work) Date: Mon, 21 Oct 2019 14:28:15 +0000 (+0200) Subject: Filter: Use explicit function structure X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d7939561b7b872db2529b4070d3f22fe325147f;p=thirdparty%2Fbird.git Filter: Use explicit function structure --- diff --git a/conf/conf.h b/conf/conf.h index 21dc3fa1f..ff1a89072 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -116,7 +116,7 @@ struct symbol { union { struct proto_config *proto; /* For SYM_PROTO and SYM_TEMPLATE */ - const struct f_line *function; /* For SYM_FUNCTION */ + const struct function *function; /* For SYM_FUNCTION */ const struct filter *filter; /* For SYM_FILTER */ struct rtable_config *table; /* For SYM_TABLE */ struct f_dynamic_attr *attribute; /* For SYM_ATTRIBUTE */ diff --git a/filter/config.Y b/filter/config.Y index ff1d3cb3a..08c861ce8 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -492,7 +492,7 @@ bt_test_suite: BT_TEST_SUITE '(' CF_SYM_KNOWN ',' text ')' { cf_assert_symbol($3, SYM_FUNCTION); struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite)); - t->fn = $3->function; + t->fn = $3->function->body; t->fn_name = $3->name; t->dsc = $5; @@ -506,8 +506,8 @@ bt_test_same: cf_assert_symbol($3, SYM_FUNCTION); cf_assert_symbol($5, SYM_FUNCTION); struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite)); - t->fn = $3->function; - t->cmp = $5->function; + t->fn = $3->function->body; + t->cmp = $5->function->body; t->result = $7; t->fn_name = $3->name; t->dsc = $5->name; @@ -612,8 +612,10 @@ function_def: cf_push_scope($2); } function_args function_body { DBG("Definition of function %s with %u args and %u local vars.\n", $2->name, $4, $5->vars); + struct function *fn = cfg_alloc(sizeof(struct function)); + *fn = (struct function) { .sym = $2, .body = $5 }; + $2->function = fn; $5->args = $4; - $2->function = $5; cf_pop_scope(); } ; diff --git a/filter/f-inst.c b/filter/f-inst.c index ad3ef3f6a..c21d48df6 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -899,9 +899,9 @@ SYMBOL; FID_NEW_BODY() - if (whati->varcount != sym->function->args) + if (whati->varcount != sym->function->body->args) cf_error("Function call '%s' got %u arguments, needs %u arguments", - sym->name, whati->varcount, sym->function->args); + sym->name, whati->varcount, sym->function->body->args); /* Add void slot for return value (requires [[NEVER_CONSTANT]]) */ struct f_inst *rv = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_VOID }); @@ -916,7 +916,7 @@ FID_INTERPRET_BODY() /* Push the body on stack */ - LINEX(sym->function); + LINEX(sym->function->body); curline.emask |= FE_RETURN; /* Set new base for local variables */ @@ -926,8 +926,9 @@ fstk->vcnt += whati->varcount; /* Storage for local variables */ - memset(&(fstk->vstk[fstk->vcnt]), 0, sizeof(struct f_val) * sym->function->vars); - fstk->vcnt += sym->function->vars; + uint vars = sym->function->body->vars; + memset(&(fstk->vstk[fstk->vcnt]), 0, sizeof(struct f_val) * vars); + fstk->vcnt += vars; } INST(FI_DROP_RESULT, 1, 0) { diff --git a/filter/filter.c b/filter/filter.c index 60e351f9c..f97a16a53 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -457,7 +457,7 @@ filter_commit(struct config *new, struct config *old) case SYM_FUNCTION: if ((osym = cf_find_symbol(old, sym->name)) && (osym->class == SYM_FUNCTION) && - f_same(sym->function, osym->function)) + f_same(sym->function->body, osym->function->body)) sym->flags |= SYM_FLAG_SAME; else sym->flags &= ~SYM_FLAG_SAME; @@ -485,7 +485,7 @@ void filters_dump_all(void) break; case SYM_FUNCTION: debug("Function %s:\n", sym->name); - f_dump_line(sym->function, 1); + f_dump_line(sym->function->body, 1); break; case SYM_PROTO: { diff --git a/filter/filter.h b/filter/filter.h index 9d997efbf..8b790e370 100644 --- a/filter/filter.h +++ b/filter/filter.h @@ -43,14 +43,19 @@ static inline const char *filter_return_str(const enum filter_return fret) { } struct f_val; +struct f_line; /* The filter encapsulating structure to be pointed-to from outside */ -struct f_line; struct filter { struct symbol *sym; const struct f_line *root; }; +struct function { + struct symbol *sym; + const struct f_line *body; +}; + struct rte; enum filter_return f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, int flags);