]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter refactoring: Expanded the short instructions with common code.
authorMaria Matejka <mq@ucw.cz>
Thu, 20 Dec 2018 13:05:32 +0000 (14:05 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 20 Feb 2019 21:30:54 +0000 (22:30 +0100)
This will make the further changes more straightforward.

filter/f-inst.c

index 41cace61049c19c175ad8985f0b848e3fba77e16..4041a8047c3ab1971ab3c3f3af379d876887c892 100644 (file)
     res.val.i = v1.val.i / v2.val.i;
     break;
   case FI_AND:
+    ARG(1,T_BOOL);
+    if (!v1.val.i) {
+      res = v1;
+    } else {
+      ARG(2,T_BOOL);
+      res = v2;
+    }
+    break;
   case FI_OR:
     ARG(1,T_BOOL);
-    if (v1.val.i == (what->fi_code == FI_OR)) {
-      res.type = T_BOOL;
-      res.val.i = v1.val.i;
+    if (v1.val.i) {
+      res = v1;
     } else {
       ARG(2,T_BOOL);
       res = v2;
 
 /* Relational operators */
 
-#define COMPARE(x) \
-    ARG_ANY(1); \
-    ARG_ANY(2); \
-    i = val_compare(v1, v2); \
-    if (i==CMP_ERROR) \
-      runtime( "Can't compare values of incompatible types" ); \
-    res.type = T_BOOL; \
-    res.val.i = (x); \
+  case FI_NEQ:
+    ARG_ANY(1);
+    ARG_ANY(2);
+    res.type = T_BOOL;
+    res.val.i = !val_same(v1, v2);
+    break;
+
+  case FI_EQ:
+    ARG_ANY(1);
+    ARG_ANY(2);
+    res.type = T_BOOL;
+    res.val.i = val_same(v1, v2);
     break;
 
-#define SAME(x) \
-    ARG_ANY(1); \
-    ARG_ANY(2); \
-    i = val_same(v1, v2); \
-    res.type = T_BOOL; \
-    res.val.i = (x); \
+  case FI_LT:
+    ARG_ANY(1);
+    ARG_ANY(2);
+    i = val_compare(v1, v2);
+    if (i==CMP_ERROR)
+      runtime( "Can't compare values of incompatible types" );
+    res.type = T_BOOL;
+    res.val.i = (i == -1);
     break;
 
-  case FI_NEQ: SAME(!i);
-  case FI_EQ: SAME(i);
-  case FI_LT: COMPARE(i==-1);
-  case FI_LTE: COMPARE(i!=1);
+  case FI_LTE:
+    ARG_ANY(1);
+    ARG_ANY(2);
+    i = val_compare(v1, v2);
+    if (i==CMP_ERROR)
+      runtime( "Can't compare values of incompatible types" );
+    res.type = T_BOOL;
+    res.val.i = (i != 1);
+    break;
 
   case FI_NOT:
     ARG(1,T_BOOL);