mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 05:28:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/local-container-init'
Closes #952. * origin/topic/jsiwek/local-container-init: Fix init of local sets/vectors via curly brace initializer lists.
This commit is contained in:
commit
9f99a4a942
5 changed files with 105 additions and 6 deletions
5
CHANGES
5
CHANGES
|
@ -1,4 +1,9 @@
|
|||
|
||||
2.1-338 | 2013-03-06 15:10:43 -0800
|
||||
|
||||
* Fix init of local sets/vectors via curly brace initializer lists.
|
||||
(Jon Siwek)
|
||||
|
||||
2.1-336 | 2013-03-06 15:08:06 -0800
|
||||
|
||||
* Fix memory leaks resulting from 'when' and 'return when'
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
2.1-336
|
||||
2.1-338
|
||||
|
|
22
src/Expr.cc
22
src/Expr.cc
|
@ -2507,15 +2507,27 @@ bool AssignExpr::TypeCheck(attr_list* attrs)
|
|||
attr_copy->append((*attrs)[i]);
|
||||
}
|
||||
|
||||
op2 = new TableConstructorExpr(op2->AsListExpr(), attr_copy);
|
||||
if ( op1->Type()->IsSet() )
|
||||
op2 = new SetConstructorExpr(op2->AsListExpr(), attr_copy);
|
||||
else
|
||||
op2 = new TableConstructorExpr(op2->AsListExpr(), attr_copy);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( bt1 == TYPE_VECTOR && bt2 == bt1 &&
|
||||
op2->Type()->AsVectorType()->IsUnspecifiedVector() )
|
||||
if ( bt1 == TYPE_VECTOR )
|
||||
{
|
||||
op2 = new VectorCoerceExpr(op2, op1->Type()->AsVectorType());
|
||||
return true;
|
||||
if ( bt2 == bt1 && op2->Type()->AsVectorType()->IsUnspecifiedVector() )
|
||||
{
|
||||
op2 = new VectorCoerceExpr(op2, op1->Type()->AsVectorType());
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( op2->Tag() == EXPR_LIST )
|
||||
{
|
||||
op2 = new VectorConstructorExpr(op2->AsListExpr());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( op1->Type()->Tag() == TYPE_RECORD &&
|
||||
|
|
44
testing/btest/Baseline/language.container-ctor-scope/out
Normal file
44
testing/btest/Baseline/language.container-ctor-scope/out
Normal file
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
[2/tcp] = 2,
|
||||
[1/tcp] = 1,
|
||||
[3/tcp] = 3
|
||||
}
|
||||
{
|
||||
[2/tcp] = 2,
|
||||
[1/tcp] = 1,
|
||||
[3/tcp] = 3
|
||||
}
|
||||
{
|
||||
2/tcp,
|
||||
1/tcp,
|
||||
3/tcp
|
||||
}
|
||||
{
|
||||
2/tcp,
|
||||
1/tcp,
|
||||
3/tcp
|
||||
}
|
||||
[1/tcp, 2/tcp, 3/tcp, 1/tcp]
|
||||
[1/tcp, 2/tcp, 3/tcp, 1/tcp]
|
||||
{
|
||||
[2/tcp] = 2,
|
||||
[1/tcp] = 1,
|
||||
[3/tcp] = 3
|
||||
}
|
||||
{
|
||||
[2/tcp] = 2,
|
||||
[1/tcp] = 1,
|
||||
[3/tcp] = 3
|
||||
}
|
||||
{
|
||||
2/tcp,
|
||||
1/tcp,
|
||||
3/tcp
|
||||
}
|
||||
{
|
||||
2/tcp,
|
||||
1/tcp,
|
||||
3/tcp
|
||||
}
|
||||
[1/tcp, 2/tcp, 3/tcp, 1/tcp]
|
||||
[1/tcp, 2/tcp, 3/tcp, 1/tcp]
|
38
testing/btest/language/container-ctor-scope.bro
Normal file
38
testing/btest/language/container-ctor-scope.bro
Normal file
|
@ -0,0 +1,38 @@
|
|||
# @TEST-EXEC: bro -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
# All various container contructors should work at both global and local scope.
|
||||
|
||||
global gt1: table[port] of count = table( [1/tcp] = 1, [2/tcp] = 2, [3/tcp] = 3 );
|
||||
global gs1: set[port] = set( 1/tcp, 2/tcp, 3/tcp );
|
||||
global gv1: vector of port = vector( 1/tcp, 2/tcp, 3/tcp, 1/tcp );
|
||||
|
||||
global gt2: table[port] of count = { [1/tcp] = 1, [2/tcp] = 2, [3/tcp] = 3 };
|
||||
global gs2: set[port] = { 1/tcp, 2/tcp, 3/tcp };
|
||||
global gv2: vector of port = { 1/tcp, 2/tcp, 3/tcp, 1/tcp };
|
||||
|
||||
local t1: table[port] of count = table( [1/tcp] = 1, [2/tcp] = 2, [3/tcp] = 3 );
|
||||
local s1: set[port] = set( 1/tcp, 2/tcp, 3/tcp );
|
||||
local v1: vector of port = vector( 1/tcp, 2/tcp, 3/tcp, 1/tcp );
|
||||
|
||||
local t2: table[port] of count = { [1/tcp] = 1, [2/tcp] = 2, [3/tcp] = 3 };
|
||||
local s2: set[port] = { 1/tcp, 2/tcp, 3/tcp };
|
||||
local v2: vector of port = { 1/tcp, 2/tcp, 3/tcp, 1/tcp };
|
||||
|
||||
print gt1;
|
||||
print gt2;
|
||||
|
||||
print gs1;
|
||||
print gs2;
|
||||
|
||||
print gv1;
|
||||
print gv2;
|
||||
|
||||
print t1;
|
||||
print t2;
|
||||
|
||||
print s1;
|
||||
print s2;
|
||||
|
||||
print v1;
|
||||
print v2;
|
Loading…
Add table
Add a link
Reference in a new issue