mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 01:58:20 +00:00
test suite for bitwise operators
brief NEWS blurb allow for "counter" operands (does anyone still use these?) for one (but not both) of the bitwise operands
This commit is contained in:
parent
1658931af1
commit
58ffd61dcc
4 changed files with 33 additions and 4 deletions
4
NEWS
4
NEWS
|
@ -146,6 +146,10 @@ New Functionality
|
|||
- Added new SMB events: smb1_transaction_secondary_request,
|
||||
smb1_transaction2_secondary_request, smb1_transaction_response
|
||||
|
||||
- Added support for bitwise operations on "count" values. '&', '|' and
|
||||
'^' are binary "and", "or" and "xor" operators, and '~' is a unary
|
||||
ones-complement operator.
|
||||
|
||||
Changed Functionality
|
||||
---------------------
|
||||
|
||||
|
|
11
src/Expr.cc
11
src/Expr.cc
|
@ -1874,12 +1874,15 @@ BitExpr::BitExpr(BroExprTag arg_tag, Expr* arg_op1, Expr* arg_op2)
|
|||
if ( IsVector(bt2) )
|
||||
bt2 = op2->Type()->AsVectorType()->YieldType()->Tag();
|
||||
|
||||
if ( bt1 == TYPE_COUNT && bt2 == bt1 )
|
||||
if ( (bt1 == TYPE_COUNT || bt1 == TYPE_COUNTER) &&
|
||||
(bt2 == TYPE_COUNT || bt2 == TYPE_COUNTER) )
|
||||
{
|
||||
if ( is_vector(op1) || is_vector(op2) )
|
||||
SetType(new VectorType(base_type(bt1)));
|
||||
if ( bt1 == TYPE_COUNTER && bt2 == TYPE_COUNTER )
|
||||
ExprError("cannot apply a bitwise operator to two \"counter\" operands");
|
||||
else if ( is_vector(op1) || is_vector(op2) )
|
||||
SetType(new VectorType(base_type(TYPE_COUNT)));
|
||||
else
|
||||
SetType(base_type(bt1));
|
||||
SetType(base_type(TYPE_COUNT));
|
||||
}
|
||||
|
||||
else
|
||||
|
|
|
@ -14,5 +14,16 @@ modulus operator (PASS)
|
|||
division operator (PASS)
|
||||
assignment operator (PASS)
|
||||
assignment operator (PASS)
|
||||
bitwise and (PASS)
|
||||
bitwise and (PASS)
|
||||
bitwise and (PASS)
|
||||
bitwise or (PASS)
|
||||
bitwise or (PASS)
|
||||
bitwise or (PASS)
|
||||
bitwise xor (PASS)
|
||||
bitwise xor (PASS)
|
||||
bitwise xor (PASS)
|
||||
bitwise complement (PASS)
|
||||
bitwise complement (PASS)
|
||||
max count value = 18446744073709551615 (PASS)
|
||||
max count value = 18446744073709551615 (PASS)
|
||||
|
|
|
@ -47,6 +47,17 @@ event bro_init()
|
|||
test_case( "assignment operator", c2 == 8 );
|
||||
c2 -= 2;
|
||||
test_case( "assignment operator", c2 == 6 );
|
||||
test_case( "bitwise and", c2 & 0x4 == 0x4 );
|
||||
test_case( "bitwise and", c4 & 0x4 == 0x4 );
|
||||
test_case( "bitwise and", c8 & 0x4 == 0x0 );
|
||||
test_case( "bitwise or", c2 | 0x4 == c2 );
|
||||
test_case( "bitwise or", c4 | 0x4 == c4 );
|
||||
test_case( "bitwise or", c8 | 0x4 == c7 );
|
||||
test_case( "bitwise xor", c7 ^ 0x4 == c8 );
|
||||
test_case( "bitwise xor", c4 ^ 0x4 == 251 );
|
||||
test_case( "bitwise xor", c8 ^ 0x4 == c7 );
|
||||
test_case( "bitwise complement", ~c6 == 0 );
|
||||
test_case( "bitwise complement", ~~c4 == c4 );
|
||||
|
||||
# Max. value tests
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue