mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-09 12:48:43 +00:00
Filter: Use explicit function structure
This commit is contained in:
parent
b3fdba0bf8
commit
3d7939561b
@ -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 */
|
||||
|
@ -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();
|
||||
}
|
||||
;
|
||||
|
@ -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) {
|
||||
|
@ -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:
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user