]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Use explicit function structure
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 21 Oct 2019 14:28:15 +0000 (16:28 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 21 Oct 2019 17:48:02 +0000 (19:48 +0200)
conf/conf.h
filter/config.Y
filter/f-inst.c
filter/filter.c
filter/filter.h

index 21dc3fa1fbecef0e4f9086c172e8e5c6905ff3cc..ff1a890723ffe8793b2377cb973be2dbb72a55c3 100644 (file)
@@ -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 */
index ff1d3cb3a1495500c1a48cbfd257e8309d758305..08c861ce885ddbadad05bc5d49d05440bab2c9d7 100644 (file)
@@ -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();
    }
  ;
index ad3ef3f6a047740f03d37f4e99ee78098eb780dc..c21d48df64b42d735d08c828e23c5293f202b915 100644 (file)
     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 });
     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 */
     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) {
index 60e351f9cad65a9249f75ecb36772c803b61ea9a..f97a16a5362db5c7bfd3e0ff4d5578dafcce53f7 100644 (file)
@@ -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:
        {
index 9d997efbf9b9c755256d11b2a024dbe4dc39527d..8b790e370faed04d02fd2728dcc2af98684b3d99 100644 (file)
@@ -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);