]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Make the IF instruction three-args
authorJan Maria Matejka <mq@ucw.cz>
Wed, 30 May 2018 15:18:56 +0000 (17:18 +0200)
committerJan Maria Matejka <mq@ucw.cz>
Wed, 30 May 2018 15:18:56 +0000 (17:18 +0200)
Dropping another old quirk.

filter/config.Y
filter/filter.c

index cf499b66adbe26008e28038b93c0066fde7a3bfd..182bfa3c021238c3972ab5d9cf9153fb1a6d31b4 100644 (file)
@@ -996,12 +996,10 @@ cmd:
      $$->a2.p = $4;
    }
  | IF term THEN block ELSE block {
-     struct f_inst *i = f_new_inst(FI_CONDITION);
-     i->a1.p = $2;
-     i->a2.p = $4;
      $$ = f_new_inst(FI_CONDITION);
-     $$->a1.p = i;
-     $$->a2.p = $6;
+     $$->a1.p = $2;
+     $$->a2.p = $4;
+     $$->a3.p = $6;
    }
  | SYM '=' term ';' {
      DBG( "Ook, we'll set value\n" );
index 6290e74a8b1255e28d8c42eeecf6d931f2490429..47fb81e8d64e3b4bcc9bd01171b54e1763ea5ad8 100644 (file)
@@ -898,14 +898,13 @@ interpret(struct f_inst *what)
     ARG_ANY(1);
     val_format(v1, &f_buf);
     break;
-  case FI_CONDITION:   /* ? has really strange error value, so we can implement if ... else nicely :-) */
+  case FI_CONDITION:
     ARG(1, T_BOOL);
     if (v1.val.i) {
       ARG_ANY(2);
-      res.val.i = 0;
-    } else
-      res.val.i = 1;
-    res.type = T_BOOL;
+    } else {
+      ARG_ANY(3);
+    }
     break;
   case FI_NOP:
     debug( "No operation\n" );
@@ -1670,7 +1669,7 @@ i_same(struct f_inst *f1, struct f_inst *f2)
       return 0;
     break;
   case FI_PRINT: case FI_LENGTH: ONEARG; break;
-  case FI_CONDITION: TWOARGS; break;
+  case FI_CONDITION: THREEARGS; break;
   case FI_NOP: case FI_EMPTY: break;
   case FI_PRINT_AND_DIE: ONEARG; A2_SAME; break;
   case FI_PREF_GET: