]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
update operator precedence (and tests)
authorAlan T. DeKok <aland@freeradius.org>
Thu, 22 Sep 2022 12:42:53 +0000 (08:42 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 22 Sep 2022 12:53:53 +0000 (08:53 -0400)
src/lib/unlang/xlat_expr.c
src/tests/unit/xlat/expr.txt

index 987263ee73d296435ef57041847dea1cdcf25e45..59250361c13743b412bd8d03ab1d32c00849f40f 100644 (file)
@@ -1775,6 +1775,8 @@ static const bool logical_ops[T_TOKEN_LAST] = {
 /*
  *     Allow for BEDMAS ordering.  Gross ordering is first number,
  *     fine ordering is second number.  Unused operators are assigned as zero.
+ *
+ *     Larger numbers are higher precedence.
  */
 #define P(_x, _y) (((_x) << 4) | (_y))
 
@@ -1782,7 +1784,7 @@ static const int precedence[T_TOKEN_LAST] = {
        [T_INVALID]     = 0,
 
        /*
-        *      Assignment operators go here:
+        *      Assignment operators go here as P(1,n)
         *
         *      += -= *= /= %= <<= >>= &= ^= |=
         *
@@ -1805,8 +1807,11 @@ static const int precedence[T_TOKEN_LAST] = {
        [T_XOR]         = P(3,1),
        [T_AND]         = P(3,2),
 
-       [T_OP_CMP_EQ]   = P(4,0),
-       [T_OP_NE]       = P(4,0),
+       [T_OP_REG_EQ]   = P(4,0),
+       [T_OP_REG_NE]   = P(4,0),
+
+       [T_OP_CMP_EQ]   = P(4,1),
+       [T_OP_NE]       = P(4,1),
 
        [T_OP_LT]       = P(5,0),
        [T_OP_LE]       = P(5,0),
@@ -1816,15 +1821,12 @@ static const int precedence[T_TOKEN_LAST] = {
        [T_RSHIFT]      = P(6,0),
        [T_LSHIFT]      = P(6,0),
 
-       [T_ADD]         = P(7,0),
-       [T_SUB]         = P(7,1),
-
-       [T_MUL]         = P(8,0),
-       [T_DIV]         = P(8,1),
-       [T_MOD]         = P(8,2),
+       [T_SUB]         = P(7,0),
+       [T_ADD]         = P(7,1),
 
-       [T_OP_REG_EQ]   = P(9,0),
-       [T_OP_REG_NE]   = P(9,0),
+       [T_MOD]         = P(8,0),
+       [T_MUL]         = P(8,1),
+       [T_DIV]         = P(8,2),
 
        [T_LBRACE]      = P(10,0),
 };
index bc233eab0b9b7f6ec0277b6355cc6079ac6ef2ff..d3127b2371e6d79f84f37d7e1c25bcce2b02e1ac 100644 (file)
@@ -132,5 +132,8 @@ match &reply
 xlat_expr &reply && (1 < 2)
 match (&reply && (1 < 2))
 
+xlat_expr 5 + 5 - 10
+match ((5 + 5) - 10)
+
 count
-match 63
+match 65