mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
Merge remote-tracking branch 'origin/topic/bernhard/ticket-1144'
* origin/topic/bernhard/ticket-1144: Allow iterating over bif functions with result type vector of any. BIT-1144 #merged
This commit is contained in:
commit
7774af7518
13 changed files with 74 additions and 7 deletions
7
CHANGES
7
CHANGES
|
@ -1,4 +1,11 @@
|
|||
|
||||
2.2-199 | 2014-03-03 16:34:20 -0800
|
||||
|
||||
* Allow iterating over bif functions with result type vector of any.
|
||||
This changes the internal type that is used to signal that a
|
||||
vector is unspecified from any to void. Addresses BIT-1144
|
||||
(Bernhard Amann)
|
||||
|
||||
2.2-197 | 2014-02-28 15:36:58 -0800
|
||||
|
||||
* Remove test code. (Robin Sommer)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
2.2-197
|
||||
2.2-199
|
||||
|
|
|
@ -39,6 +39,14 @@ type count_set: set[count];
|
|||
## directly and then remove this alias.
|
||||
type index_vec: vector of count;
|
||||
|
||||
## A vector of any, used by some builtin functions to store a list of varying
|
||||
## types.
|
||||
##
|
||||
## .. todo:: We need this type definition only for declaring builtin functions
|
||||
## via ``bifcl``. We should extend ``bifcl`` to understand composite types
|
||||
## directly and then remove this alias.
|
||||
type any_vec: vector of any;
|
||||
|
||||
## A vector of strings.
|
||||
##
|
||||
## .. todo:: We need this type definition only for declaring builtin functions
|
||||
|
|
|
@ -3819,7 +3819,9 @@ VectorConstructorExpr::VectorConstructorExpr(ListExpr* constructor_list,
|
|||
if ( constructor_list->Exprs().length() == 0 )
|
||||
{
|
||||
// vector().
|
||||
SetType(new ::VectorType(base_type(TYPE_ANY)));
|
||||
// By default, assign VOID type here. A vector with
|
||||
// void type set is seen as an unspecified vector.
|
||||
SetType(new ::VectorType(base_type(TYPE_VOID)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
19
src/Type.cc
19
src/Type.cc
|
@ -1626,6 +1626,23 @@ VectorType::~VectorType()
|
|||
Unref(yield_type);
|
||||
}
|
||||
|
||||
BroType* VectorType::YieldType()
|
||||
{
|
||||
// Work around the fact that we use void internally to mark a vector
|
||||
// as being unspecified. When looking at its yield type, we need to
|
||||
// return any as that's what other code historically expects for type
|
||||
// comparisions.
|
||||
if ( IsUnspecifiedVector() )
|
||||
{
|
||||
BroType* ret = ::base_type(TYPE_ANY);
|
||||
Unref(ret); // unref, because this won't be held by anyone.
|
||||
assert(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return yield_type;
|
||||
}
|
||||
|
||||
int VectorType::MatchesIndex(ListExpr*& index) const
|
||||
{
|
||||
expr_list& el = index->Exprs();
|
||||
|
@ -1645,7 +1662,7 @@ int VectorType::MatchesIndex(ListExpr*& index) const
|
|||
|
||||
bool VectorType::IsUnspecifiedVector() const
|
||||
{
|
||||
return yield_type->Tag() == TYPE_ANY;
|
||||
return yield_type->Tag() == TYPE_VOID;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(VectorType, SER_VECTOR_TYPE);
|
||||
|
|
|
@ -572,7 +572,7 @@ class VectorType : public BroType {
|
|||
public:
|
||||
VectorType(BroType* t);
|
||||
virtual ~VectorType();
|
||||
BroType* YieldType() { return yield_type; }
|
||||
BroType* YieldType();
|
||||
|
||||
int MatchesIndex(ListExpr*& index) const;
|
||||
|
||||
|
|
|
@ -3122,7 +3122,7 @@ bool VectorVal::DoUnserialize(UnserialInfo* info)
|
|||
for ( int i = 0; i < len; ++i )
|
||||
{
|
||||
Val* v;
|
||||
UNSERIALIZE_OPTIONAL(v, Val::Unserialize(info, TYPE_ANY));
|
||||
UNSERIALIZE_OPTIONAL(v, Val::Unserialize(info, TYPE_ANY)); // accept any type
|
||||
Assign(i, v);
|
||||
}
|
||||
|
||||
|
|
|
@ -656,6 +656,8 @@ protected:
|
|||
DECLARE_SERIAL(PatternVal);
|
||||
};
|
||||
|
||||
// ListVals are mainly used to index tables that have more than one
|
||||
// element in their index.
|
||||
class ListVal : public Val {
|
||||
public:
|
||||
ListVal(TypeTag t);
|
||||
|
|
|
@ -49,7 +49,7 @@ function topk_add%(handle: opaque of topk, value: any%): any
|
|||
##
|
||||
## .. bro:see:: topk_init topk_add topk_count topk_epsilon
|
||||
## topk_size topk_sum topk_merge topk_merge_prune
|
||||
function topk_get_top%(handle: opaque of topk, k: count%): any
|
||||
function topk_get_top%(handle: opaque of topk, k: count%): any_vec
|
||||
%{
|
||||
assert(handle);
|
||||
probabilistic::TopkVal* h = (probabilistic::TopkVal*) handle;
|
||||
|
|
|
@ -79,3 +79,12 @@
|
|||
0
|
||||
8
|
||||
0
|
||||
0, c
|
||||
1, e
|
||||
2, d
|
||||
0, c
|
||||
1, e
|
||||
2, d
|
||||
0, c
|
||||
1, e
|
||||
2, d
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
[5, Hi, 127.0.0.1]
|
|
@ -148,7 +148,17 @@ event bro_init()
|
|||
print topk_count(k3, "d");
|
||||
print topk_epsilon(k3, "d");
|
||||
|
||||
local styped: vector of count;
|
||||
styped = topk_get_top(k3, 3);
|
||||
for ( i in styped )
|
||||
print i, styped[i];
|
||||
|
||||
local anytyped: vector of any;
|
||||
anytyped = topk_get_top(k3, 3);
|
||||
for ( i in anytyped )
|
||||
print i, anytyped[i];
|
||||
|
||||
|
||||
local suntyped = topk_get_top(k3, 3);
|
||||
for ( i in suntyped )
|
||||
print i, suntyped[i];
|
||||
}
|
||||
|
|
11
testing/btest/language/vector-unspecified.bro
Normal file
11
testing/btest/language/vector-unspecified.bro
Normal file
|
@ -0,0 +1,11 @@
|
|||
# @TEST-EXEC: bro -b %INPUT >output 2>&1
|
||||
# @TEST-EXEC: btest-diff output
|
||||
|
||||
# Test assignment behavior of unspecified vectors
|
||||
local a = vector();
|
||||
|
||||
a[0] = 5;
|
||||
a[1] = "Hi";
|
||||
a[2] = 127.0.0.1;
|
||||
|
||||
print a;
|
Loading…
Add table
Add a link
Reference in a new issue