mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Deprecate ID::AsType(), add ID::IsType() and ID::GetType()
This commit is contained in:
parent
f26904e031
commit
6e647416d5
10 changed files with 32 additions and 22 deletions
2
NEWS
2
NEWS
|
@ -153,6 +153,8 @@ Deprecated Functionality
|
|||
|
||||
- ``BroType::YieldType()`` is deprecated, use ``BroType::Yield()``.
|
||||
|
||||
- ``ID::AsType()`` is deprecated, use ``ID::IsType()`` and ``ID::GetType()``.
|
||||
|
||||
Zeek 3.1.0
|
||||
==========
|
||||
|
||||
|
|
10
src/Expr.cc
10
src/Expr.cc
|
@ -218,8 +218,8 @@ NameExpr::NameExpr(IntrusivePtr<ID> arg_id, bool const_init)
|
|||
{
|
||||
in_const_init = const_init;
|
||||
|
||||
if ( id->AsType() )
|
||||
SetType(make_intrusive<TypeType>(IntrusivePtr{NewRef{}, id->AsType()}));
|
||||
if ( id->IsType() )
|
||||
SetType(make_intrusive<TypeType>(IntrusivePtr{NewRef{}, id->Type()}));
|
||||
else
|
||||
SetType({NewRef{}, id->Type()});
|
||||
|
||||
|
@ -232,8 +232,8 @@ IntrusivePtr<Val> NameExpr::Eval(Frame* f) const
|
|||
{
|
||||
IntrusivePtr<Val> v;
|
||||
|
||||
if ( id->AsType() )
|
||||
return make_intrusive<Val>(id->AsType(), true);
|
||||
if ( id->IsType() )
|
||||
return make_intrusive<Val>(id->Type(), true);
|
||||
|
||||
if ( id->IsGlobal() )
|
||||
v = {NewRef{}, id->ID_Val()};
|
||||
|
@ -256,7 +256,7 @@ IntrusivePtr<Val> NameExpr::Eval(Frame* f) const
|
|||
|
||||
IntrusivePtr<Expr> NameExpr::MakeLvalue()
|
||||
{
|
||||
if ( id->AsType() )
|
||||
if ( id->IsType() )
|
||||
ExprError("Type name is not an lvalue");
|
||||
|
||||
if ( id->IsConst() && ! in_const_init )
|
||||
|
|
12
src/ID.h
12
src/ID.h
|
@ -37,13 +37,23 @@ public:
|
|||
std::string ModuleName() const;
|
||||
|
||||
void SetType(IntrusivePtr<BroType> t);
|
||||
|
||||
BroType* Type() { return type.get(); }
|
||||
const BroType* Type() const { return type.get(); }
|
||||
|
||||
void MakeType() { is_type = true; }
|
||||
const IntrusivePtr<BroType>& GetType() const
|
||||
{ return type; }
|
||||
|
||||
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
|
||||
BroType* AsType() { return is_type ? Type() : nullptr; }
|
||||
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
|
||||
const BroType* AsType() const { return is_type ? Type() : nullptr; }
|
||||
|
||||
bool IsType() const
|
||||
{ return is_type; }
|
||||
|
||||
void MakeType() { is_type = true; }
|
||||
|
||||
// If weak_ref is false, the Val is assumed to be already ref'ed
|
||||
// and will be deref'ed when the ID is deleted.
|
||||
//
|
||||
|
|
|
@ -130,11 +130,10 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data)
|
|||
if ( ! id )
|
||||
return nullptr;
|
||||
|
||||
BroType* t = id->AsType();
|
||||
if ( ! t )
|
||||
if ( ! id->IsType() )
|
||||
return nullptr;
|
||||
|
||||
return t->Ref();
|
||||
return id->Type()->Ref();
|
||||
}
|
||||
|
||||
auto tag = caf::get_if<uint64_t>(&(*v)[1]);
|
||||
|
|
|
@ -1766,12 +1766,12 @@ IntrusivePtr<BroType> merge_types(const BroType* t1, const BroType* t2)
|
|||
// (potentially) avoiding a pitfall mentioned earlier about clones.
|
||||
auto id = global_scope()->Lookup(t1->GetName());
|
||||
|
||||
if ( id && id->AsType() && id->AsType()->Tag() == TYPE_ENUM )
|
||||
if ( id && id->IsType() && id->Type()->Tag() == TYPE_ENUM )
|
||||
// It should make most sense to return the real type here rather
|
||||
// than a copy since it may be redef'd later in parsing. If we
|
||||
// return a copy, then whoever is using this return value won't
|
||||
// actually see those changes from the redef.
|
||||
return {NewRef{}, id->AsType()};
|
||||
return {NewRef{}, id->Type()};
|
||||
|
||||
std::string msg = fmt("incompatible enum types: '%s' and '%s'"
|
||||
" ('%s' enum type ID is invalid)",
|
||||
|
|
|
@ -606,11 +606,10 @@ expr:
|
|||
{
|
||||
set_location(@1, @6);
|
||||
|
||||
BroType* ctor_type = 0;
|
||||
|
||||
if ( $1->Tag() == EXPR_NAME &&
|
||||
(ctor_type = $1->AsNameExpr()->Id()->AsType()) )
|
||||
if ( $1->Tag() == EXPR_NAME && $1->AsNameExpr()->Id()->IsType() )
|
||||
{
|
||||
auto ctor_type = $1->AsNameExpr()->Id()->Type();
|
||||
|
||||
switch ( ctor_type->Tag() ) {
|
||||
case TYPE_RECORD:
|
||||
{
|
||||
|
@ -1007,7 +1006,7 @@ type:
|
|||
|
||||
| resolve_id
|
||||
{
|
||||
if ( ! $1 || ! ($$ = $1->AsType()) )
|
||||
if ( ! $1 || ! ($$ = $1->IsType() ? $1->Type() : nullptr) )
|
||||
{
|
||||
NullStmt here;
|
||||
if ( $1 )
|
||||
|
|
|
@ -1171,7 +1171,7 @@ IntrusivePtr<RecordVal> Supervisor::Node::ToRecord() const
|
|||
|
||||
static IntrusivePtr<Val> supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role)
|
||||
{
|
||||
static auto node_type = global_scope()->Lookup("Cluster::NodeType")->AsType()->AsEnumType();
|
||||
static auto node_type = global_scope()->Lookup("Cluster::NodeType")->Type()->AsEnumType();
|
||||
|
||||
switch ( role ) {
|
||||
case BifEnum::Supervisor::LOGGER:
|
||||
|
@ -1192,7 +1192,7 @@ bool Supervisor::SupervisedNode::InitCluster() const
|
|||
if ( config.cluster.empty() )
|
||||
return false;
|
||||
|
||||
auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->AsType()->AsRecordType();
|
||||
auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->Type()->AsRecordType();
|
||||
auto cluster_nodes_id = global_scope()->Lookup("Cluster::nodes");
|
||||
auto cluster_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger");
|
||||
auto cluster_nodes = cluster_nodes_id->ID_Val()->AsTableVal();
|
||||
|
|
|
@ -2003,14 +2003,14 @@ function record_fields%(rec: any%): record_field_table
|
|||
{
|
||||
auto id = global_scope()->Lookup(rec->AsStringVal()->ToStdString());
|
||||
|
||||
if ( ! id || ! id->AsType() || id->AsType()->Tag() != TYPE_RECORD )
|
||||
if ( ! id || ! id->IsType() || id->Type()->Tag() != TYPE_RECORD )
|
||||
{
|
||||
reporter->Error("record_fields string argument does not name a record type");
|
||||
IntrusivePtr<TableType> tt{NewRef{}, internal_type("record_field_table")->AsTableType()};
|
||||
return make_intrusive<TableVal>(std::move(tt));
|
||||
}
|
||||
|
||||
return id->AsType()->AsRecordType()->GetRecordFieldsVal();
|
||||
return id->Type()->AsRecordType()->GetRecordFieldsVal();
|
||||
}
|
||||
|
||||
return rec->GetRecordFields();
|
||||
|
|
|
@ -274,7 +274,7 @@ void Manager::StartType(IntrusivePtr<ID> id)
|
|||
|
||||
static bool IsEnumType(ID* id)
|
||||
{
|
||||
return id->AsType() ? id->AsType()->Tag() == TYPE_ENUM : false;
|
||||
return id->IsType() ? id->Type()->Tag() == TYPE_ENUM : false;
|
||||
}
|
||||
|
||||
void Manager::Identifier(IntrusivePtr<ID> id)
|
||||
|
|
|
@ -183,7 +183,7 @@ void ScriptInfo::DoInitPostScript()
|
|||
if ( ! zeekygen::is_public_api(id) )
|
||||
continue;
|
||||
|
||||
if ( id->AsType() )
|
||||
if ( id->IsType() )
|
||||
{
|
||||
types.push_back(info);
|
||||
DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a type",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue