diff --git a/NEWS b/NEWS index ff7b02f657..f3fd5eb603 100644 --- a/NEWS +++ b/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 ========== diff --git a/src/Expr.cc b/src/Expr.cc index cff9cd0d08..fbd033d3da 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -218,8 +218,8 @@ NameExpr::NameExpr(IntrusivePtr arg_id, bool const_init) { in_const_init = const_init; - if ( id->AsType() ) - SetType(make_intrusive(IntrusivePtr{NewRef{}, id->AsType()})); + if ( id->IsType() ) + SetType(make_intrusive(IntrusivePtr{NewRef{}, id->Type()})); else SetType({NewRef{}, id->Type()}); @@ -232,8 +232,8 @@ IntrusivePtr NameExpr::Eval(Frame* f) const { IntrusivePtr v; - if ( id->AsType() ) - return make_intrusive(id->AsType(), true); + if ( id->IsType() ) + return make_intrusive(id->Type(), true); if ( id->IsGlobal() ) v = {NewRef{}, id->ID_Val()}; @@ -256,7 +256,7 @@ IntrusivePtr NameExpr::Eval(Frame* f) const IntrusivePtr NameExpr::MakeLvalue() { - if ( id->AsType() ) + if ( id->IsType() ) ExprError("Type name is not an lvalue"); if ( id->IsConst() && ! in_const_init ) diff --git a/src/ID.h b/src/ID.h index 3735e7a843..94b876dbd4 100644 --- a/src/ID.h +++ b/src/ID.h @@ -37,13 +37,23 @@ public: std::string ModuleName() const; void SetType(IntrusivePtr t); + BroType* Type() { return type.get(); } const BroType* Type() const { return type.get(); } - void MakeType() { is_type = true; } + const IntrusivePtr& 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. // diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 2ae0b06455..392b3ed9c1 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -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(&(*v)[1]); diff --git a/src/Type.cc b/src/Type.cc index 0fcbd5bf58..877fa24340 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1766,12 +1766,12 @@ IntrusivePtr 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)", diff --git a/src/parse.y b/src/parse.y index 00f2e65874..fc556041ca 100644 --- a/src/parse.y +++ b/src/parse.y @@ -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 ) diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 6ae8038fcd..269b6576ea 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1171,7 +1171,7 @@ IntrusivePtr Supervisor::Node::ToRecord() const static IntrusivePtr 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(); diff --git a/src/zeek.bif b/src/zeek.bif index fc14bbb892..6ab3f39820 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -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 tt{NewRef{}, internal_type("record_field_table")->AsTableType()}; return make_intrusive(std::move(tt)); } - return id->AsType()->AsRecordType()->GetRecordFieldsVal(); + return id->Type()->AsRecordType()->GetRecordFieldsVal(); } return rec->GetRecordFields(); diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index 6636447516..47192cfd27 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -274,7 +274,7 @@ void Manager::StartType(IntrusivePtr 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) diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index 532a6667ff..5b75415613 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -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",