Merge topic/actor-system throug a squashed commit.

This commit is contained in:
Robin Sommer 2018-05-16 23:48:07 +00:00
parent 7a6f5020f6
commit fe7e1ee7f0
466 changed files with 12559 additions and 9655 deletions

View file

@ -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;
}