mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Allow Zeek function equality comparisons
Equality between two functions acts like a pointer comparison.
This commit is contained in:
parent
11949ce37a
commit
6e67a40d24
3 changed files with 28 additions and 0 deletions
|
@ -1762,6 +1762,7 @@ EqExpr::EqExpr(BroExprTag arg_tag, ExprPtr arg_op1, ExprPtr arg_op2)
|
|||
case zeek::TYPE_ADDR:
|
||||
case zeek::TYPE_SUBNET:
|
||||
case zeek::TYPE_ERROR:
|
||||
case zeek::TYPE_FUNC:
|
||||
break;
|
||||
|
||||
case zeek::TYPE_ENUM:
|
||||
|
@ -1814,6 +1815,11 @@ ValPtr EqExpr::Fold(Val* v1, Val* v2) const
|
|||
else
|
||||
return zeek::val_mgr->Bool(! re->MatchExactly(s));
|
||||
}
|
||||
else if ( op1->GetType()->Tag() == zeek::TYPE_FUNC )
|
||||
{
|
||||
auto res = v1->AsFunc() == v2->AsFunc();
|
||||
return val_mgr->Bool(tag == EXPR_EQ ? res : ! res);
|
||||
}
|
||||
|
||||
else
|
||||
return BinaryExpr::Fold(v1, v2);
|
||||
|
|
4
testing/btest/Baseline/language.func-equality/out
Normal file
4
testing/btest/Baseline/language.func-equality/out
Normal file
|
@ -0,0 +1,4 @@
|
|||
F
|
||||
T
|
||||
T
|
||||
F
|
18
testing/btest/language/func-equality.zeek
Normal file
18
testing/btest/language/func-equality.zeek
Normal file
|
@ -0,0 +1,18 @@
|
|||
# @TEST-EXEC: zeek -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
function foo()
|
||||
{ print "foo"; }
|
||||
|
||||
function bar()
|
||||
{ print "bar"; }
|
||||
|
||||
global baz = bar;
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
print foo == bar;
|
||||
print foo != bar;
|
||||
print bar == baz;
|
||||
print bar != baz;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue