]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Minor updates to methods
authorOndrej Zajicek <santiago@crfreenet.org>
Tue, 12 Sep 2023 16:44:20 +0000 (18:44 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Tue, 12 Sep 2023 16:44:20 +0000 (18:44 +0200)
Remove warning when function-like syntax is used for calling
add/remove/... methods.

Fix argument offset in error messages for function-like syntax.

filter/config.Y
filter/f-inst.h
filter/f-util.c

index da96d9e862cc11615060b8494cefd5f82aaebc22..dc4d75eded9fe9868870a119e331a8e816eabb4a 100644 (file)
@@ -876,12 +876,12 @@ static_attr:
 term_dot_method: term '.' { f_method_call_start($1); } method_name_cont { f_method_call_end(); $$ = $4; };
 method_name_cont:
    CF_SYM_METHOD_BARE {
-     $$ = f_dispatch_method($1, FM.object, NULL);
+     $$ = f_dispatch_method($1, FM.object, NULL, 1);
    }
  | CF_SYM_METHOD_ARGS {
      f_method_call_args();
    } '(' var_list ')' {
-     $$ = f_dispatch_method($1, FM.object, $4);
+     $$ = f_dispatch_method($1, FM.object, $4, 1);
    }
  ;
 
@@ -918,19 +918,10 @@ term:
  | '-' EMPTY '-' { $$ = f_const_empty(T_CLIST); }
  | '-' '-' EMPTY '-' '-' { $$ = f_const_empty(T_ECLIST); }
  | '-' '-' '-' EMPTY '-' '-' '-' { $$ = f_const_empty(T_LCLIST); }
- | PREPEND '(' term ',' term ')' { $$ = f_new_inst(FI_PATH_PREPEND, $3, $5); }
- | ADD '(' term ',' term ')' {
-     $$ = f_dispatch_method_x("add", $3->type, $3, $5);
-     cf_warn("add(x,y) function is deprecated, please use x.add(y)");
-   }
- | DELETE '(' term ',' term ')' {
-     $$ = f_dispatch_method_x("delete", $3->type, $3, $5);
-     cf_warn("delete(x,y) function is deprecated, please use x.delete(y)");
-   }
- | FILTER '(' term ',' term ')' {
-     $$ = f_dispatch_method_x("filter", $3->type, $3, $5);
-     cf_warn("filter(x,y) function is deprecated, please use x.filter(y)");
-   }
+ | PREPEND '(' term ',' term ')' { $$ = f_dispatch_method_x("prepend", $3->type, $3, $5); }
+ | ADD '(' term ',' term ')' { $$ = f_dispatch_method_x("add", $3->type, $3, $5); }
+ | DELETE '(' term ',' term ')' { $$ = f_dispatch_method_x("delete", $3->type, $3, $5); }
+ | FILTER '(' term ',' term ')' { $$ = f_dispatch_method_x("filter", $3->type, $3, $5); }
 
  | ROA_CHECK '(' rtable ')' { $$ = f_new_inst(FI_ROA_CHECK_IMPLICIT, $3); }
  | ROA_CHECK '(' rtable ',' term ',' term ')' { $$ = f_new_inst(FI_ROA_CHECK_EXPLICIT, $5, $7, $3); }
index e8147e2683634a0697318d0a73d5198bd4b9f7eb..2bde6378c30043c587e779a475cbe1f5e7aad569 100644 (file)
@@ -106,7 +106,7 @@ void f_add_lines(const struct f_line_item *what, struct filter_iterator *fit);
 
 
 struct filter *f_new_where(struct f_inst *);
-struct f_inst *f_dispatch_method(struct symbol *sym, struct f_inst *obj, struct f_inst *args);
+struct f_inst *f_dispatch_method(struct symbol *sym, struct f_inst *obj, struct f_inst *args, int skip);
 struct f_inst *f_dispatch_method_x(const char *name, enum f_type t, struct f_inst *obj, struct f_inst *args);
 struct f_inst *f_for_cycle(struct symbol *var, struct f_inst *term, struct f_inst *block);
 struct f_inst *f_print(struct f_inst *vars, int flush, enum filter_return fret);
index 768ee83b4fda271bacaefa67d99fe5cce4db89b2..d589927a191553e4af577722ac9c3777db34e678 100644 (file)
@@ -72,7 +72,7 @@ f_match_signature_err(const struct f_method *dsc, struct f_inst *args, int *pos,
 }
 
 struct f_inst *
-f_dispatch_method(struct symbol *sym, struct f_inst *obj, struct f_inst *args)
+f_dispatch_method(struct symbol *sym, struct f_inst *obj, struct f_inst *args, int skip)
 {
   /* Find match */
   for (const struct f_method *dsc = sym->method; dsc; dsc = dsc->next)
@@ -123,7 +123,8 @@ f_dispatch_method(struct symbol *sym, struct f_inst *obj, struct f_inst *args)
   /* There is at least one method */
   ASSERT(best_pos >= 0 && best_count > 0);
 
-  /* TODO: Here fix best_pos */
+  /* Update best_pos for printing */
+  best_pos = best_pos - skip + 1;
 
   if (!best_got)
     cf_error("Cannot infer type of argument %d of '%s', please assign it to a variable", best_pos, sym->name);
@@ -149,7 +150,7 @@ f_dispatch_method_x(const char *name, enum f_type t, struct f_inst *obj, struct
   if (!sym)
     cf_error("Cannot dispatch method '%s'", name);
 
-  return f_dispatch_method(sym, obj, args);
+  return f_dispatch_method(sym, obj, args, 0);
 }