mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 07:38:19 +00:00
GH-213: change type of vector for-loop index to a count
This commit is contained in:
parent
89da20339d
commit
ed1a50ec5b
4 changed files with 11 additions and 7 deletions
5
NEWS
5
NEWS
|
@ -30,6 +30,11 @@ New Functionality
|
||||||
Changed Functionality
|
Changed Functionality
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
- The for-loop index variable for vectors has been changed from
|
||||||
|
'int' to 'count' type. It's unlikely this would alter/break any
|
||||||
|
script behavior unless they were explicitly inspecting the variable's
|
||||||
|
type (and there's typically no reason to do that).
|
||||||
|
|
||||||
Removed Functionality
|
Removed Functionality
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -559,9 +559,8 @@ Here is a more detailed description of each type:
|
||||||
|
|
||||||
.. bro:type:: vector
|
.. bro:type:: vector
|
||||||
|
|
||||||
A vector is like a :bro:type:`table`, except it's always indexed by a
|
A vector is like a :bro:type:`table`, except its indices are non-negative
|
||||||
:bro:type:`count` (and vector indexing is always zero-based). A vector
|
integers, starting from zero. A vector is declared like:
|
||||||
is declared like:
|
|
||||||
|
|
||||||
.. sourcecode:: bro
|
.. sourcecode:: bro
|
||||||
|
|
||||||
|
|
|
@ -1387,7 +1387,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, Expr* loop_expr)
|
||||||
|
|
||||||
BroType* t = (*loop_vars)[0]->Type();
|
BroType* t = (*loop_vars)[0]->Type();
|
||||||
if ( ! t )
|
if ( ! t )
|
||||||
delete add_local((*loop_vars)[0], base_type(TYPE_INT),
|
delete add_local((*loop_vars)[0], base_type(TYPE_COUNT),
|
||||||
INIT_NONE, 0, 0, VAR_REGULAR);
|
INIT_NONE, 0, 0, VAR_REGULAR);
|
||||||
|
|
||||||
else if ( ! IsIntegral(t->Tag()) )
|
else if ( ! IsIntegral(t->Tag()) )
|
||||||
|
@ -1470,7 +1470,7 @@ Val* ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
|
||||||
{
|
{
|
||||||
VectorVal* vv = v->AsVectorVal();
|
VectorVal* vv = v->AsVectorVal();
|
||||||
|
|
||||||
for ( int i = 0; i <= int(vv->Size()); ++i )
|
for ( auto i = 0u; i <= vv->Size(); ++i )
|
||||||
{
|
{
|
||||||
// Skip unassigned vector indices.
|
// Skip unassigned vector indices.
|
||||||
if ( ! vv->Lookup(i) )
|
if ( ! vv->Lookup(i) )
|
||||||
|
@ -1479,7 +1479,7 @@ Val* ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
|
||||||
// Set the loop variable to the current index, and make
|
// Set the loop variable to the current index, and make
|
||||||
// another pass over the loop body.
|
// another pass over the loop body.
|
||||||
f->SetElement((*loop_vars)[0]->Offset(),
|
f->SetElement((*loop_vars)[0]->Offset(),
|
||||||
new Val(i, TYPE_INT));
|
new Val(i, TYPE_COUNT));
|
||||||
flow = FLOW_NEXT;
|
flow = FLOW_NEXT;
|
||||||
ret = body->Exec(f, flow);
|
ret = body->Exec(f, flow);
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ event bro_init()
|
||||||
ct = 0;
|
ct = 0;
|
||||||
for ( c in v1 )
|
for ( c in v1 )
|
||||||
{
|
{
|
||||||
if ( type_name(c) != "int" )
|
if ( type_name(c) != "count" )
|
||||||
print "Error: wrong index type";
|
print "Error: wrong index type";
|
||||||
if ( type_name(v1[c]) != "string" )
|
if ( type_name(v1[c]) != "string" )
|
||||||
print "Error: wrong vector type";
|
print "Error: wrong vector type";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue