From 71d2ffe69319fa9f577e0597e2d7bff2c4a1cbcd Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Wed, 9 Feb 2022 19:41:03 -0500 Subject: [PATCH] allow << and >> --- src/lib/unlang/xlat_expr.c | 6 ++++++ src/tests/xlat/expr.txt | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index b33aaed8b14..a18ec8e6552 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -346,6 +346,8 @@ XLAT_BINARY_FUNC(op_div, T_DIV) XLAT_BINARY_FUNC(op_and, T_AND) XLAT_BINARY_FUNC(op_or, T_OR) XLAT_BINARY_FUNC(op_xor, T_XOR) +XLAT_BINARY_FUNC(op_rshift, T_RSHIFT) +XLAT_BINARY_FUNC(op_lshift, T_LSHIFT) XLAT_BINARY_FUNC(cmp_eq, T_OP_CMP_EQ) XLAT_BINARY_FUNC(cmp_ne, T_OP_NE) @@ -640,6 +642,8 @@ int xlat_register_expressions(void) XLAT_REGISTER_BINARY_OP(T_AND, and); XLAT_REGISTER_BINARY_OP(T_OR, or); XLAT_REGISTER_BINARY_OP(T_XOR, xor); + XLAT_REGISTER_BINARY_OP(T_RSHIFT, rshift); + XLAT_REGISTER_BINARY_OP(T_LSHIFT, lshift); XLAT_REGISTER_BINARY_CMP(T_OP_CMP_EQ, eq); XLAT_REGISTER_BINARY_CMP(T_OP_NE, ne); @@ -684,6 +688,8 @@ static const fr_sbuff_term_elem_t binary_ops[T_TOKEN_LAST] = { [ T_AND ] = L("op_and"), [ T_OR ] = L("op_or"), [ T_XOR ] = L("op_xor"), + [ T_RSHIFT ] = L("op_rshift"), + [ T_LSHIFT ] = L("op_lshift"), [ T_LAND ] = L("logical_and"), [ T_LOR ] = L("logical_or"), diff --git a/src/tests/xlat/expr.txt b/src/tests/xlat/expr.txt index b0360272685..6f18ba6d5af 100644 --- a/src/tests/xlat/expr.txt +++ b/src/tests/xlat/expr.txt @@ -30,3 +30,25 @@ match 0xabcdef1234 xlat_expr 2 ^ 4 match 6 + +xlat_expr (uint32) 8 >> 2 +match 2 + +xlat_expr (uint32) 1 << 31 +match 2147483648 + +# +# The errors actually go out RPEDEBUG(), and aren't visible to unit_test_module :( +# +xlat_expr (uint32) 1 << 32 +match ERROR expanding xlat: + +# +# This shifts it 8, and then tries to cast it to uint8? +# +xlat_expr (uint8) 1 << 8 +match ERROR expanding xlat: + +# Cannot perform any operations for destination type ether +xlat_expr 00:01:02:03:04:05 ^ 11:22:33:44:55:66 +match ERROR expanding xlat: -- 2.47.3