mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 02:58:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/bit-1288'
* origin/topic/jsiwek/bit-1288: BIT-1288: Improve coercion of &default expressions. BIT-1288 #merged
This commit is contained in:
commit
bf35ed699c
7 changed files with 56 additions and 2 deletions
5
CHANGES
5
CHANGES
|
@ -1,4 +1,9 @@
|
|||
|
||||
2.3-305 | 2014-11-18 11:09:04 -0800
|
||||
|
||||
* Improve coercion of &default expressions. Addresses BIT-1288. (Jon
|
||||
Siwek)
|
||||
|
||||
2.3-303 | 2014-11-18 10:53:04 -0800
|
||||
|
||||
* For DH key exchanges, use p as the parameter for weak key
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
2.3-303
|
||||
2.3-305
|
||||
|
|
11
src/Attr.cc
11
src/Attr.cc
|
@ -265,6 +265,14 @@ void Attributes::CheckAttr(Attr* a)
|
|||
// Ok.
|
||||
break;
|
||||
|
||||
Expr* e = a->AttrExpr();
|
||||
if ( check_and_promote_expr(e, type) )
|
||||
{
|
||||
a->SetAttrExpr(e);
|
||||
// Ok.
|
||||
break;
|
||||
}
|
||||
|
||||
a->AttrExpr()->Error("&default value has inconsistent type", type);
|
||||
}
|
||||
|
||||
|
@ -297,8 +305,11 @@ void Attributes::CheckAttr(Attr* a)
|
|||
|
||||
Expr* e = a->AttrExpr();
|
||||
if ( check_and_promote_expr(e, ytype) )
|
||||
{
|
||||
a->SetAttrExpr(e);
|
||||
// Ok.
|
||||
break;
|
||||
}
|
||||
|
||||
Error("&default value has inconsistent type 2");
|
||||
}
|
||||
|
|
|
@ -45,6 +45,13 @@ public:
|
|||
attr_tag Tag() const { return tag; }
|
||||
Expr* AttrExpr() const { return expr; }
|
||||
|
||||
// Up to the caller to decide if previous expr can be unref'd since it may
|
||||
// not always be safe; e.g. expressions (at time of writing) don't always
|
||||
// keep careful track of referencing their operands, so doing something
|
||||
// like SetAttrExpr(coerce(AttrExpr())) must not completely unref the
|
||||
// previous expr as the new expr depends on it.
|
||||
void SetAttrExpr(Expr* e) { expr = e; }
|
||||
|
||||
int RedundantAttrOkay() const
|
||||
{ return tag == ATTR_REDEF || tag == ATTR_OPTIONAL; }
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
7.0
|
||||
[i=1, d=3.0]
|
||||
237, 101.0
|
||||
-5, 101.0
|
||||
-37, -8.1
|
|
@ -16,7 +16,7 @@
|
|||
[one] = 1.0,
|
||||
[three] = 3.0
|
||||
}
|
||||
0
|
||||
0.0
|
||||
{
|
||||
[42] = forty-two,
|
||||
[37] = thirty-seven
|
||||
|
|
26
testing/btest/language/attr-default-coercion.bro
Normal file
26
testing/btest/language/attr-default-coercion.bro
Normal file
|
@ -0,0 +1,26 @@
|
|||
# @TEST-EXEC: bro -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
type my_table: table[string] of double;
|
||||
|
||||
type my_record: record {
|
||||
i: int &default = 1;
|
||||
d: double &default = 3;
|
||||
};
|
||||
|
||||
global t: my_table &default = 7;
|
||||
global r = my_record();
|
||||
|
||||
function foo(i: int &default = 237, d: double &default = 101)
|
||||
{
|
||||
print i, d;
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
print t["nope"];
|
||||
print r;
|
||||
foo();
|
||||
foo(-5);
|
||||
foo(-37, -8.1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue