mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 03:28:19 +00:00
Merge topic/actor-system throug a squashed commit.
This commit is contained in:
parent
7a6f5020f6
commit
fe7e1ee7f0
466 changed files with 12559 additions and 9655 deletions
64
src/Val.cc
64
src/Val.cc
|
@ -3526,3 +3526,67 @@ void delete_vals(val_list* vals)
|
|||
delete vals;
|
||||
}
|
||||
}
|
||||
|
||||
Val* cast_value_to_type(Val* v, BroType* t)
|
||||
{
|
||||
// Note: when changing this function, adapt all three of
|
||||
// cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type().
|
||||
|
||||
if ( ! v )
|
||||
return 0;
|
||||
|
||||
// Always allow casting to same type. This also covers casting 'any'
|
||||
// to the actual type.
|
||||
if ( same_type(v->Type(), t) )
|
||||
return v->Ref();
|
||||
|
||||
if ( same_type(v->Type(), bro_broker::DataVal::ScriptDataType()) )
|
||||
{
|
||||
auto dv = v->AsRecordVal()->Lookup(0);
|
||||
return static_cast<bro_broker::DataVal *>(dv)->castTo(t);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool can_cast_value_to_type(const Val* v, BroType* t)
|
||||
{
|
||||
// Note: when changing this function, adapt all three of
|
||||
// cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type().
|
||||
|
||||
if ( ! v )
|
||||
return false;
|
||||
|
||||
// Always allow casting to same type. This also covers casting 'any'
|
||||
// to the actual type.
|
||||
if ( same_type(v->Type(), t) )
|
||||
return true;
|
||||
|
||||
if ( same_type(v->Type(), bro_broker::DataVal::ScriptDataType()) )
|
||||
{
|
||||
auto dv = v->AsRecordVal()->Lookup(0);
|
||||
return static_cast<const bro_broker::DataVal *>(dv)->canCastTo(t);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool can_cast_value_to_type(const BroType* s, BroType* t)
|
||||
{
|
||||
// Note: when changing this function, adapt all three of
|
||||
// cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type().
|
||||
|
||||
// Always allow casting to same type. This also covers casting 'any'
|
||||
// to the actual type.
|
||||
if ( same_type(s, t) )
|
||||
return true;
|
||||
|
||||
if ( same_type(s, bro_broker::DataVal::ScriptDataType()) )
|
||||
// As Broker is dynamically typed, we don't know if we will be able
|
||||
// to convert the type as intended. We optimistically assume that we
|
||||
// will.
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue