diff --git a/NEWS b/NEWS index 4f23388cea..ff7b02f657 100644 --- a/NEWS +++ b/NEWS @@ -151,6 +151,8 @@ Deprecated Functionality - ``BroType::HasField()`` and ``BroType::FieldType()`` are deprecated, use the methods of ``RecordType`` directly. +- ``BroType::YieldType()`` is deprecated, use ``BroType::Yield()``. + Zeek 3.1.0 ========== diff --git a/src/Attr.cc b/src/Attr.cc index 6480f19ce6..747994a396 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -273,7 +273,7 @@ void Attributes::CheckAttr(Attr* a) } FuncType* aft = at->AsFuncType(); - if ( ! same_type(aft->YieldType(), type.get()) ) + if ( ! same_type(aft->Yield().get(), type.get()) ) { a->AttrExpr()->Error( is_add ? @@ -328,7 +328,7 @@ void Attributes::CheckAttr(Attr* a) } TableType* tt = type->AsTableType(); - BroType* ytype = tt->YieldType(); + BroType* ytype = tt->Yield().get(); if ( ! in_record ) { @@ -340,7 +340,7 @@ void Attributes::CheckAttr(Attr* a) { FuncType* f = atype->AsFuncType(); if ( ! f->CheckArgs(tt->IndexTypes()) || - ! same_type(f->YieldType(), ytype) ) + ! same_type(f->Yield().get(), ytype) ) Error("&default function type clash"); // Ok. @@ -453,7 +453,7 @@ void Attributes::CheckAttr(Attr* a) const FuncType* e_ft = expire_func->Type()->AsFuncType(); - if ( e_ft->YieldType()->Tag() != TYPE_INTERVAL ) + if ( e_ft->Yield()->Tag() != TYPE_INTERVAL ) { Error("&expire_func must yield a value of type interval"); break; @@ -500,7 +500,7 @@ void Attributes::CheckAttr(Attr* a) const FuncType* c_ft = change_func->Type()->AsFuncType(); - if ( c_ft->YieldType()->Tag() != TYPE_VOID ) + if ( c_ft->Yield()->Tag() != TYPE_VOID ) { Error("&on_change must not return a value"); break; @@ -542,7 +542,7 @@ void Attributes::CheckAttr(Attr* a) } if ( ! type->IsSet() ) - if ( ! same_type(args[2+t_indexes.size()].get(), the_table->YieldType()) ) + if ( ! same_type(args[2+t_indexes.size()].get(), the_table->Yield().get()) ) { Error("&on_change: value type does not match table"); break; diff --git a/src/CompHash.cc b/src/CompHash.cc index 416ae38208..ea98690e69 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -277,7 +277,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, if ( val ) { if ( ! (kp1 = SingleValHash(type_check, kp1, - vt->YieldType(), val, false)) ) + vt->Yield().get(), val, false)) ) return nullptr; } } @@ -570,7 +570,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, sz = SizeAlign(sz, sizeof(unsigned int)); sz = SizeAlign(sz, sizeof(unsigned int)); if ( val ) - sz = SingleTypeKeySize(bt->AsVectorType()->YieldType(), + sz = SingleTypeKeySize(bt->AsVectorType()->Yield().get(), val, type_check, sz, false, calc_static_size); if ( ! sz ) return 0; @@ -956,7 +956,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, else { IntrusivePtr value; - kp1 = RecoverOneVal(k, kp1, k_end, tt->YieldType(), &value, + kp1 = RecoverOneVal(k, kp1, k_end, tt->Yield().get(), &value, false); tv->Assign(key.get(), std::move(value)); } @@ -986,7 +986,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, IntrusivePtr value; if ( have_val ) - kp1 = RecoverOneVal(k, kp1, k_end, vt->YieldType(), &value, + kp1 = RecoverOneVal(k, kp1, k_end, vt->Yield().get(), &value, false); vv->Assign(index, std::move(value)); diff --git a/src/Expr.cc b/src/Expr.cc index 0929de3888..cff9cd0d08 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -676,7 +676,7 @@ IntrusivePtr BinaryExpr::Fold(Val* v1, Val* v2) const BroType* ret_type = Type(); if ( IsVector(ret_type->Tag()) ) - ret_type = ret_type->YieldType(); + ret_type = ret_type->Yield().get(); if ( ret_type->Tag() == TYPE_INTERVAL ) return make_intrusive(d3, 1.0); @@ -863,9 +863,9 @@ void BinaryExpr::PromoteOps(TypeTag t) bool is_vec2 = IsVector(bt2); if ( is_vec1 ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); if ( is_vec2 ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( (is_vec1 || is_vec2) && ! (is_vec1 && is_vec2) ) reporter->Warning("mixing vector and scalar operands is deprecated"); @@ -922,7 +922,7 @@ IncrExpr::IncrExpr(BroExprTag arg_tag, IntrusivePtr arg_op) if ( IsVector(t->Tag()) ) { - if ( ! IsIntegral(t->AsVectorType()->YieldType()->Tag()) ) + if ( ! IsIntegral(t->AsVectorType()->Yield()->Tag()) ) ExprError("vector elements must be integral for increment operator"); else { @@ -956,7 +956,7 @@ IntrusivePtr IncrExpr::DoSingleEval(Frame* f, Val* v) const BroType* ret_type = Type(); if ( IsVector(ret_type->Tag()) ) - ret_type = Type()->YieldType(); + ret_type = Type()->Yield().get(); if ( ret_type->Tag() == TYPE_INT ) return val_mgr->Int(k); @@ -1050,7 +1050,7 @@ PosExpr::PosExpr(IntrusivePtr arg_op) BroType* t = op->Type(); if ( IsVector(t->Tag()) ) - t = t->AsVectorType()->YieldType(); + t = t->AsVectorType()->Yield().get(); TypeTag bt = t->Tag(); IntrusivePtr base_result_type; @@ -1088,7 +1088,7 @@ NegExpr::NegExpr(IntrusivePtr arg_op) BroType* t = op->Type(); if ( IsVector(t->Tag()) ) - t = t->AsVectorType()->YieldType(); + t = t->AsVectorType()->Yield().get(); TypeTag bt = t->Tag(); IntrusivePtr base_result_type; @@ -1153,12 +1153,12 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); IntrusivePtr base_result_type; @@ -1209,7 +1209,7 @@ AddToExpr::AddToExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) else if ( IsVector(bt1) ) { - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); if ( IsArithmetic(bt1) ) { @@ -1279,11 +1279,11 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) - bt1 = t1->AsVectorType()->YieldType()->Tag(); + bt1 = t1->AsVectorType()->Yield()->Tag(); TypeTag bt2 = t2->Tag(); if ( IsVector(bt2) ) - bt2 = t2->AsVectorType()->YieldType()->Tag(); + bt2 = t2->AsVectorType()->Yield()->Tag(); IntrusivePtr base_result_type; @@ -1366,12 +1366,12 @@ TimesExpr::TimesExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) { @@ -1403,12 +1403,12 @@ DivideExpr::DivideExpr(IntrusivePtr arg_op1, TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) { @@ -1470,12 +1470,12 @@ ModExpr::ModExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( BothIntegral(bt1, bt2) ) PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); @@ -1493,12 +1493,12 @@ BoolExpr::BoolExpr(BroExprTag arg_tag, TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( BothBool(bt1, bt2) ) { @@ -1643,12 +1643,12 @@ BitExpr::BitExpr(BroExprTag arg_tag, TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) - bt1 = t1->AsVectorType()->YieldType()->Tag(); + bt1 = t1->AsVectorType()->Yield()->Tag(); TypeTag bt2 = t2->Tag(); if ( IsVector(bt2) ) - bt2 = t2->AsVectorType()->YieldType()->Tag(); + bt2 = t2->AsVectorType()->Yield()->Tag(); if ( (bt1 == TYPE_COUNT || bt1 == TYPE_COUNTER) && (bt2 == TYPE_COUNT || bt2 == TYPE_COUNTER) ) @@ -1697,11 +1697,11 @@ EqExpr::EqExpr(BroExprTag arg_tag, TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) - bt1 = t1->AsVectorType()->YieldType()->Tag(); + bt1 = t1->AsVectorType()->Yield()->Tag(); TypeTag bt2 = t2->Tag(); if ( IsVector(bt2) ) - bt2 = t2->AsVectorType()->YieldType()->Tag(); + bt2 = t2->AsVectorType()->Yield()->Tag(); if ( is_vector(op1.get()) || is_vector(op2.get()) ) SetType(make_intrusive(base_type(TYPE_BOOL))); @@ -1799,11 +1799,11 @@ RelExpr::RelExpr(BroExprTag arg_tag, TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) - bt1 = t1->AsVectorType()->YieldType()->Tag(); + bt1 = t1->AsVectorType()->Yield()->Tag(); TypeTag bt2 = t2->Tag(); if ( IsVector(bt2) ) - bt2 = t2->AsVectorType()->YieldType()->Tag(); + bt2 = t2->AsVectorType()->Yield()->Tag(); if ( is_vector(op1.get()) || is_vector(op2.get()) ) SetType(make_intrusive(base_type(TYPE_BOOL))); @@ -1851,7 +1851,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); if ( op1->IsError() || op2->IsError() || op3->IsError() ) SetError(); @@ -1864,12 +1864,12 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, TypeTag bt2 = op2->Type()->Tag(); if ( is_vector(op2.get()) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt3 = op3->Type()->Tag(); if ( IsVector(bt3) ) - bt3 = op3->Type()->AsVectorType()->YieldType()->Tag(); + bt3 = op3->Type()->AsVectorType()->Yield()->Tag(); if ( is_vector(op1.get()) && ! (is_vector(op2.get()) && is_vector(op3.get())) ) { @@ -2329,7 +2329,7 @@ void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const TableVal* tv = aggr->AsTableVal(); auto index = op1->Eval(f); - auto v = check_and_promote(op2->Eval(f), t->YieldType(), true); + auto v = check_and_promote(op2->Eval(f), t->Yield().get(), true); if ( ! index || ! v ) return; @@ -2395,10 +2395,10 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) auto tv = cast_intrusive(std::move(aggr)); const TableType* tt = tv->Type()->AsTableType(); - const BroType* yt = tv->Type()->YieldType(); + const auto& yt = tv->Type()->Yield(); auto index = op1->InitVal(tt->Indices(), nullptr); - auto v = op2->InitVal(yt, nullptr); + auto v = op2->InitVal(yt.get(), nullptr); if ( ! index || ! v ) return nullptr; @@ -2491,7 +2491,7 @@ IndexExpr::IndexExpr(IntrusivePtr arg_op1, SetError(error_msg.data()); } - else if ( ! op1->Type()->YieldType() ) + else if ( ! op1->Type()->Yield() ) { if ( IsString(op1->Type()->Tag()) && match_type == MATCHES_INDEX_SCALAR ) SetType(base_type(TYPE_STRING)); @@ -2504,10 +2504,10 @@ IndexExpr::IndexExpr(IntrusivePtr arg_op1, } else if ( match_type == MATCHES_INDEX_SCALAR ) - SetType({NewRef{}, op1->Type()->YieldType()}); + SetType(op1->Type()->Yield()); else if ( match_type == MATCHES_INDEX_VECTOR ) - SetType(make_intrusive(IntrusivePtr{NewRef{}, op1->Type()->YieldType()})); + SetType(make_intrusive(op1->Type()->Yield())); else ExprError("Unknown MatchesIndex() return value"); @@ -2595,7 +2595,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const auto v_result = make_intrusive(Type()->AsVectorType()); // Booleans select each element (or not). - if ( IsBool(v_v2->Type()->YieldType()->Tag()) ) + if ( IsBool(v_v2->Type()->Yield()->Tag()) ) { if ( v_v1->Size() != v_v2->Size() ) { @@ -3343,7 +3343,7 @@ VectorConstructorExpr::VectorConstructorExpr(IntrusivePtr constructor_ } if ( ! check_and_promote_exprs_to_type(op->AsListExpr(), - type->AsVectorType()->YieldType()) ) + type->AsVectorType()->Yield().get()) ) ExprError("inconsistent types in vector constructor"); } @@ -3383,7 +3383,7 @@ IntrusivePtr VectorConstructorExpr::InitVal(const BroType* t, IntrusivePtr< loop_over_list(exprs, i) { Expr* e = exprs[i]; - auto v = check_and_promote(e->Eval(nullptr), t->YieldType(), true); + auto v = check_and_promote(e->Eval(nullptr), t->Yield().get(), true); if ( ! v || ! vec->Assign(i, std::move(v)) ) { @@ -3461,7 +3461,7 @@ ArithCoerceExpr::ArithCoerceExpr(IntrusivePtr arg_op, TypeTag t) if ( IsVector(bt) ) { SetType(make_intrusive(base_type(t))); - vbt = op->Type()->AsVectorType()->YieldType()->Tag(); + vbt = op->Type()->AsVectorType()->Yield()->Tag(); } else SetType(base_type(t)); @@ -3506,12 +3506,12 @@ IntrusivePtr ArithCoerceExpr::Fold(Val* v) const // invocation is being done per-element rather than on // the whole vector. Correct the type tag if necessary. if ( type->Tag() == TYPE_VECTOR ) - t = Type()->AsVectorType()->YieldType()->InternalType(); + t = Type()->AsVectorType()->Yield()->InternalType(); return FoldSingleVal(v, t); } - t = Type()->AsVectorType()->YieldType()->InternalType(); + t = Type()->AsVectorType()->Yield()->InternalType(); VectorVal* vv = v->AsVectorVal(); auto result = make_intrusive(Type()->AsVectorType()); @@ -4082,7 +4082,7 @@ CallExpr::CallExpr(IntrusivePtr arg_func, SetError("argument type mismatch in function call"); else { - BroType* yield = func_type->YieldType(); + const auto& yield = func_type->Yield(); if ( ! yield ) { @@ -4110,7 +4110,7 @@ CallExpr::CallExpr(IntrusivePtr arg_func, } } else - SetType({NewRef{}, yield}); + SetType(yield); // Check for call to built-ins that can be statically analyzed. IntrusivePtr func_val; @@ -4385,7 +4385,7 @@ EventExpr::EventExpr(const char* arg_name, IntrusivePtr arg_args) SetError("argument type mismatch in event invocation"); else { - if ( func_type->YieldType() ) + if ( func_type->Yield() ) { Error("function invoked as an event"); SetError(); @@ -4633,7 +4633,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co loop_over_list(exprs, i) { Expr* e = exprs[i]; - auto promoted_e = check_and_promote_expr(e, vec->Type()->AsVectorType()->YieldType()); + auto promoted_e = check_and_promote_expr(e, vec->Type()->AsVectorType()->Yield().get()); if ( promoted_e ) e = promoted_e.get(); diff --git a/src/Func.cc b/src/Func.cc index cc8e0b92f3..984e7991ce 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -245,7 +245,7 @@ std::pair Func::HandlePluginResult(std::pair plugin_resu case FUNC_FLAVOR_FUNCTION: { - BroType* yt = FType()->YieldType(); + const auto& yt = FType()->Yield(); if ( (! yt) || yt->Tag() == TYPE_VOID ) { @@ -423,7 +423,7 @@ IntrusivePtr BroFunc::Call(const zeek::Args& args, Frame* parent) const // Warn if the function returns something, but we returned from // the function without an explicit return, or without a value. - else if ( FType()->YieldType() && FType()->YieldType()->Tag() != TYPE_VOID && + else if ( FType()->Yield() && FType()->Yield()->Tag() != TYPE_VOID && (flow != FLOW_RETURN /* we fell off the end */ || ! result /* explicit return with no result */) && ! f->HasDelayed() ) diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index e561d28e0f..00b673253a 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -141,7 +141,7 @@ RuleConditionEval::RuleConditionEval(const char* func) // Validate argument quantity and type. FuncType* f = id->Type()->AsFuncType(); - if ( f->YieldType()->Tag() != TYPE_BOOL ) + if ( f->Yield()->Tag() != TYPE_BOOL ) rules_error("eval function type must yield a 'bool'", func); TypeList tl; diff --git a/src/Scope.cc b/src/Scope.cc index f8a6f6d8bf..be702afedd 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -34,7 +34,7 @@ Scope::Scope(IntrusivePtr id, attr_list* al) reporter->InternalError("bad scope id"); FuncType* ft = id->Type()->AsFuncType(); - return_type = {NewRef{}, ft->YieldType()}; + return_type = ft->Yield(); } } diff --git a/src/Stmt.cc b/src/Stmt.cc index b778e93ab1..420e27fe3e 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1148,18 +1148,17 @@ ForStmt::ForStmt(id_list* arg_loop_vars, if ( e->Type()->IsTable() ) { - BroType* yield_type = e->Type()->AsTableType()->YieldType(); + const auto& yield_type = e->Type()->AsTableType()->Yield(); // Verify value_vars type if its already been defined if ( value_var->Type() ) { - if ( ! same_type(value_var->Type(), yield_type) ) - value_var->Type()->Error("type clash in iteration", yield_type); + if ( ! same_type(value_var->Type(), yield_type.get()) ) + value_var->Type()->Error("type clash in iteration", yield_type.get()); } else { - add_local(value_var, {NewRef{}, yield_type}, INIT_NONE, - nullptr, nullptr, VAR_REGULAR); + add_local(value_var, yield_type, INIT_NONE, nullptr, nullptr, VAR_REGULAR); } } else @@ -1424,7 +1423,7 @@ ReturnStmt::ReturnStmt(IntrusivePtr arg_e) } FuncType* ft = s->ScopeID()->Type()->AsFuncType(); - BroType* yt = ft->YieldType(); + const auto& yt = ft->Yield(); if ( s->ScopeID()->DoInferReturnType() ) { @@ -1449,7 +1448,7 @@ ReturnStmt::ReturnStmt(IntrusivePtr arg_e) else { - auto promoted_e = check_and_promote_expr(e.get(), yt); + auto promoted_e = check_and_promote_expr(e.get(), yt.get()); if ( promoted_e ) e = std::move(promoted_e); diff --git a/src/Type.cc b/src/Type.cc index d4cbfd0f15..0fcbd5bf58 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -109,9 +109,10 @@ int BroType::MatchesIndex(ListExpr* const index) const return DOES_NOT_MATCH_INDEX; } -BroType* BroType::YieldType() +const IntrusivePtr& BroType::Yield() const { - return nullptr; + static IntrusivePtr nil; + return nil; } bool BroType::HasField(const char* /* field */) const @@ -234,16 +235,6 @@ int IndexType::MatchesIndex(ListExpr* const index) const MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX; } -BroType* IndexType::YieldType() - { - return yield_type.get(); - } - -const BroType* IndexType::YieldType() const - { - return yield_type.get(); - } - void IndexType::Describe(ODesc* d) const { BroType::Describe(d); @@ -481,16 +472,6 @@ string FuncType::FlavorString() const FuncType::~FuncType() = default; -BroType* FuncType::YieldType() - { - return yield.get(); - } - -const BroType* FuncType::YieldType() const - { - return yield.get(); - } - int FuncType::MatchesIndex(ListExpr* const index) const { return check_and_promote_args(index, args.get()) ? @@ -785,7 +766,7 @@ static string container_type_name(const BroType* ft) if ( ft->Tag() == TYPE_RECORD ) s = "record " + ft->GetName(); else if ( ft->Tag() == TYPE_VECTOR ) - s = "vector of " + container_type_name(ft->YieldType()); + s = "vector of " + container_type_name(ft->Yield().get()); else if ( ft->Tag() == TYPE_TABLE ) { if ( ft->IsSet() ) @@ -802,10 +783,10 @@ static string container_type_name(const BroType* ft) s += container_type_name(tl[i].get()); } s += "]"; - if ( ft->YieldType() ) + if ( ft->Yield() ) { s += " of "; - s += container_type_name(ft->YieldType()); + s += container_type_name(ft->Yield().get()); } } else @@ -1070,11 +1051,6 @@ FileType::FileType(IntrusivePtr yield_type) FileType::~FileType() = default; -BroType* FileType::YieldType() - { - return yield.get(); - } - void FileType::Describe(ODesc* d) const { if ( d->IsReadable() ) @@ -1358,33 +1334,16 @@ IntrusivePtr VectorType::ShallowClone() VectorType::~VectorType() = default; -BroType* VectorType::YieldType() +const IntrusivePtr& VectorType::Yield() const { // Work around the fact that we use void internally to mark a vector // as being unspecified. When looking at its yield type, we need to // return any as that's what other code historically expects for type // comparisions. if ( IsUnspecifiedVector() ) - return ::base_type(TYPE_ANY).get(); + return ::base_type(TYPE_ANY); - return yield_type.get(); - } - -const BroType* VectorType::YieldType() const - { - // Work around the fact that we use void internally to mark a vector - // as being unspecified. When looking at its yield type, we need to - // return any as that's what other code historically expects for type - // comparisions. - if ( IsUnspecifiedVector() ) - { - auto ret = ::base_type(TYPE_ANY); - assert(ret); - // release, because this won't be held by anyone. - return ret.release(); - } - - return yield_type.get(); + return yield_type; } int VectorType::MatchesIndex(ListExpr* const index) const @@ -1397,8 +1356,8 @@ int VectorType::MatchesIndex(ListExpr* const index) const if ( el.length() == 2 ) return MATCHES_INDEX_VECTOR; else if ( el[0]->Type()->Tag() == TYPE_VECTOR ) - return (IsIntegral(el[0]->Type()->YieldType()->Tag()) || - IsBool(el[0]->Type()->YieldType()->Tag())) ? + return (IsIntegral(el[0]->Type()->Yield()->Tag()) || + IsBool(el[0]->Type()->Yield()->Tag())) ? MATCHES_INDEX_VECTOR : DOES_NOT_MATCH_INDEX; else return (IsIntegral(el[0]->Type()->Tag()) || @@ -1528,8 +1487,8 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re return false; } - const BroType* y1 = t1->YieldType(); - const BroType* y2 = t2->YieldType(); + const BroType* y1 = t1->Yield().get(); + const BroType* y2 = t2->Yield().get(); if ( y1 || y2 ) { @@ -1548,10 +1507,10 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re if ( ft1->Flavor() != ft2->Flavor() ) return false; - if ( t1->YieldType() || t2->YieldType() ) + if ( t1->Yield() || t2->Yield() ) { - if ( ! t1->YieldType() || ! t2->YieldType() || - ! same_type(t1->YieldType(), t2->YieldType(), is_init, match_record_field_names) ) + if ( ! t1->Yield() || ! t2->Yield() || + ! same_type(t1->Yield().get(), t2->Yield().get(), is_init, match_record_field_names) ) return false; } @@ -1596,7 +1555,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re case TYPE_VECTOR: case TYPE_FILE: - return same_type(t1->YieldType(), t2->YieldType(), is_init, match_record_field_names); + return same_type(t1->Yield().get(), t2->Yield().get(), is_init, match_record_field_names); case TYPE_OPAQUE: { @@ -1848,8 +1807,8 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) tl3->Append(std::move(tl3_i)); } - const BroType* y1 = t1->YieldType(); - const BroType* y2 = t2->YieldType(); + const BroType* y1 = t1->Yield().get(); + const BroType* y2 = t2->Yield().get(); IntrusivePtr y3; if ( y1 || y2 ) @@ -1882,8 +1841,8 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) const FuncType* ft1 = (const FuncType*) t1; const FuncType* ft2 = (const FuncType*) t1; auto args = cast_intrusive(merge_types(ft1->Args(), ft2->Args())); - auto yield = t1->YieldType() ? - merge_types(t1->YieldType(), t2->YieldType()) : nullptr; + auto yield = t1->Yield() ? + merge_types(t1->Yield().get(), t2->Yield().get()) : nullptr; return make_intrusive(std::move(args), std::move(yield), ft1->Flavor()); @@ -1967,22 +1926,22 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) } case TYPE_VECTOR: - if ( ! same_type(t1->YieldType(), t2->YieldType()) ) + if ( ! same_type(t1->Yield().get(), t2->Yield().get()) ) { t1->Error("incompatible types", t2); return nullptr; } - return make_intrusive(merge_types(t1->YieldType(), t2->YieldType())); + return make_intrusive(merge_types(t1->Yield().get(), t2->Yield().get())); case TYPE_FILE: - if ( ! same_type(t1->YieldType(), t2->YieldType()) ) + if ( ! same_type(t1->Yield().get(), t2->Yield().get()) ) { t1->Error("incompatible types", t2); return nullptr; } - return make_intrusive(merge_types(t1->YieldType(), t2->YieldType())); + return make_intrusive(merge_types(t1->Yield().get(), t2->Yield().get())); case TYPE_UNION: reporter->InternalError("union type in merge_types()"); diff --git a/src/Type.h b/src/Type.h index d8c24e365a..c215603c82 100644 --- a/src/Type.h +++ b/src/Type.h @@ -171,9 +171,14 @@ public: // Returns the type yielded by this type. For example, if // this type is a table[string] of port, then returns the "port" // type. Returns nil if this is not an index type. - virtual BroType* YieldType(); + virtual const IntrusivePtr& Yield() const; + + [[deprecated("Remove in v4.1. Use Yield() instead.")]] + virtual BroType* YieldType() + { return Yield().get(); } + [[deprecated("Remove in v4.1. Use Yield() instead.")]] virtual const BroType* YieldType() const - { return ((BroType*) this)->YieldType(); } + { return Yield().get(); } // Returns true if this type is a record and contains the // given field, false otherwise. @@ -307,12 +312,12 @@ public: bool IsSet() const { - return tag == TYPE_TABLE && (YieldType() == nullptr); + return tag == TYPE_TABLE && ! Yield(); } bool IsTable() const { - return tag == TYPE_TABLE && (YieldType() != nullptr); + return tag == TYPE_TABLE && Yield(); } BroType* Ref() { ::Ref(this); return this; } @@ -398,8 +403,8 @@ public: const std::vector>& IndexTypes() const { return indices->Types(); } - BroType* YieldType() override; - const BroType* YieldType() const override; + const IntrusivePtr& Yield() const override + { return yield_type; } void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool roles_only = false) const override; @@ -469,8 +474,10 @@ public: ~FuncType() override; RecordType* Args() const { return args.get(); } - BroType* YieldType() override; - const BroType* YieldType() const override; + + const IntrusivePtr& Yield() const override + { return yield; } + void SetYieldType(IntrusivePtr arg_yield) { yield = std::move(arg_yield); } function_flavor Flavor() const { return flavor; } std::string FlavorString() const; @@ -646,7 +653,8 @@ public: IntrusivePtr ShallowClone() override { return make_intrusive(yield); } ~FileType() override; - BroType* YieldType() override; + const IntrusivePtr& Yield() const override + { return yield; } void Describe(ODesc* d) const override; @@ -729,8 +737,8 @@ public: explicit VectorType(IntrusivePtr t); IntrusivePtr ShallowClone() override; ~VectorType() override; - BroType* YieldType() override; - const BroType* YieldType() const override; + + const IntrusivePtr& Yield() const override; int MatchesIndex(ListExpr* index) const override; diff --git a/src/Val.cc b/src/Val.cc index 8d1a1707e7..cf76a1771f 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1348,7 +1348,7 @@ static void find_nested_record_types(BroType* t, std::set* found) return; case TYPE_TABLE: find_nested_record_types(t->AsTableType()->Indices(), found); - find_nested_record_types(t->AsTableType()->YieldType(), found); + find_nested_record_types(t->AsTableType()->Yield().get(), found); return; case TYPE_LIST: { @@ -1358,10 +1358,10 @@ static void find_nested_record_types(BroType* t, std::set* found) return; case TYPE_FUNC: find_nested_record_types(t->AsFuncType()->Args(), found); - find_nested_record_types(t->AsFuncType()->YieldType(), found); + find_nested_record_types(t->AsFuncType()->Yield().get(), found); return; case TYPE_VECTOR: - find_nested_record_types(t->AsVectorType()->YieldType(), found); + find_nested_record_types(t->AsVectorType()->Yield().get(), found); return; case TYPE_TYPE: find_nested_record_types(t->AsTypeType()->Type(), found); @@ -1439,7 +1439,7 @@ int TableVal::RecursiveSize() const int n = AsTable()->Length(); if ( Type()->IsSet() || - const_cast(Type()->AsTableType())->YieldType()->Tag() + const_cast(Type()->AsTableType())->Yield()->Tag() != TYPE_TABLE ) return n; @@ -1809,11 +1809,11 @@ IntrusivePtr TableVal::Default(Val* index) if ( ! def_val ) { - BroType* ytype = Type()->YieldType(); + const auto& ytype = Type()->Yield(); BroType* dtype = def_attr->AttrExpr()->Type(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype, ytype) && + ! same_type(dtype, ytype.get()) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) { @@ -1834,7 +1834,7 @@ IntrusivePtr TableVal::Default(Val* index) } if ( def_val->Type()->Tag() != TYPE_FUNC || - same_type(def_val->Type(), Type()->YieldType()) ) + same_type(def_val->Type(), Type()->Yield().get()) ) { if ( def_attr->AttrExpr()->IsConst() ) return def_val; @@ -2305,11 +2305,11 @@ void TableVal::InitDefaultFunc(Frame* f) if ( ! def_attr ) return; - BroType* ytype = Type()->YieldType(); + const auto& ytype = Type()->Yield(); BroType* dtype = def_attr->AttrExpr()->Type(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype, ytype) && + ! same_type(dtype, ytype.get()) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) return; // TableVal::Default will handle this. @@ -3001,7 +3001,7 @@ IntrusivePtr VectorVal::SizeVal() const bool VectorVal::Assign(unsigned int index, IntrusivePtr element) { if ( element && - ! same_type(element->Type(), vector_type->YieldType(), false) ) + ! same_type(element->Type(), vector_type->Yield().get(), false) ) return false; Val* val_at_index = nullptr; @@ -3042,7 +3042,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, bool VectorVal::Insert(unsigned int index, Val* element) { if ( element && - ! same_type(element->Type(), vector_type->YieldType(), false) ) + ! same_type(element->Type(), vector_type->Yield().get(), false) ) { Unref(element); return false; diff --git a/src/Var.cc b/src/Var.cc index 33cbc7916e..a9881b6c3b 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -459,7 +459,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, { if ( flavor == FUNC_FLAVOR_EVENT ) { - const BroType* yt = t->YieldType(); + const auto& yt = t->Yield(); if ( yt && yt->Tag() != TYPE_VOID ) id->Error("event cannot yield a value", t.get()); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 2e405e1f1e..cbed055db3 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -314,7 +314,7 @@ struct val_converter { } auto value_val = bro_broker::data_to_val(move(item.second), - tt->YieldType()); + tt->Yield().get()); if ( ! value_val ) return nullptr; @@ -334,7 +334,7 @@ struct val_converter { for ( auto& item : a ) { - auto item_val = bro_broker::data_to_val(move(item), vt->YieldType()); + auto item_val = bro_broker::data_to_val(move(item), vt->Yield().get()); if ( ! item_val ) return nullptr; @@ -667,7 +667,7 @@ struct type_checker { return false; } - if ( ! data_type_check(item.second, tt->YieldType()) ) + if ( ! data_type_check(item.second, tt->Yield().get()) ) return false; } @@ -682,7 +682,7 @@ struct type_checker { for ( auto& item : a ) { - if ( ! data_type_check(item, vt->YieldType()) ) + if ( ! data_type_check(item, vt->Yield().get()) ) return false; } diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 766a0c559a..a72f7a5894 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -522,13 +522,13 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( val ) { - const BroType* table_yield = dst->Type()->AsTableType()->YieldType(); + const auto& table_yield = dst->Type()->AsTableType()->Yield(); const BroType* compare_type = val.get(); if ( want_record->InternalInt() == 0 ) compare_type = val->GetFieldType(0).get(); - if ( ! same_type(table_yield, compare_type) ) + if ( ! same_type(table_yield.get(), compare_type) ) { ODesc desc1; ODesc desc2; @@ -821,7 +821,7 @@ bool Manager::IsCompatibleType(BroType* t, bool atomic_only) if ( atomic_only ) return false; - return IsCompatibleType(t->AsVectorType()->YieldType(), true); + return IsCompatibleType(t->AsVectorType()->Yield().get(), true); } default: @@ -945,7 +945,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, st = rec->GetFieldType(i)->AsSetType()->Indices()->GetPureType()->Tag(); else if ( ty == TYPE_VECTOR ) - st = rec->GetFieldType(i)->AsVectorType()->YieldType()->Tag(); + st = rec->GetFieldType(i)->AsVectorType()->Yield()->Tag(); else if ( ty == TYPE_PORT && rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN) ) @@ -2354,16 +2354,14 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ case TYPE_VECTOR: { // all entries have to have the same type... - BroType* type = request_type->AsVectorType()->YieldType(); - VectorType* vt = new VectorType({NewRef{}, type}); - VectorVal* v = new VectorVal(vt); - for ( int j = 0; j < val->val.vector_val.size; j++ ) - { - v->Assign(j, ValueToVal(i, val->val.vector_val.vals[j], type, have_error)); - } + const auto& type = request_type->AsVectorType()->Yield(); + auto vt = make_intrusive(type); + auto v = make_intrusive(vt.get()); - Unref(vt); - return v; + for ( int j = 0; j < val->val.vector_val.size; j++ ) + v->Assign(j, ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error)); + + return v.release(); } case TYPE_ENUM: { diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 22433453fe..cc2866f63d 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -47,7 +47,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) if ( primary == TYPE_TABLE ) secondary = id->Type()->AsSetType()->Indices()->GetPureType()->Tag(); else if ( primary == TYPE_VECTOR ) - secondary = id->Type()->AsVectorType()->YieldType()->Tag(); + secondary = id->Type()->AsVectorType()->Yield()->Tag(); option_types[id->Name()] = std::make_tuple(primary, secondary); } diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 44327ee43e..2a190ba53a 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -401,7 +401,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, if ( j < num_ext_fields ) { i = j; - rtype = filter->ext_func->FType()->YieldType()->AsRecordType(); + rtype = filter->ext_func->FType()->Yield()->AsRecordType(); } else { @@ -520,7 +520,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, st = t->AsSetType()->Indices()->GetPureType()->Tag(); else if ( t->Tag() == TYPE_VECTOR ) - st = t->AsVectorType()->YieldType()->Tag(); + st = t->AsVectorType()->Yield()->Tag(); bool optional = rtype->FieldDecl(i)->FindAttr(ATTR_OPTIONAL); @@ -587,18 +587,18 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) filter->num_ext_fields = 0; if ( filter->ext_func ) { - if ( filter->ext_func->FType()->YieldType()->Tag() == TYPE_RECORD ) + if ( filter->ext_func->FType()->Yield()->Tag() == TYPE_RECORD ) { - filter->num_ext_fields = filter->ext_func->FType()->YieldType()->AsRecordType()->NumFields(); + filter->num_ext_fields = filter->ext_func->FType()->Yield()->AsRecordType()->NumFields(); } - else if ( filter->ext_func->FType()->YieldType()->Tag() == TYPE_VOID ) + else if ( filter->ext_func->FType()->Yield()->Tag() == TYPE_VOID ) { // This is a special marker for the default no-implementation // of the ext_func and we'll allow it to slide. } else { - reporter->Error("Return value of log_ext is not a record (got %s)", type_name(filter->ext_func->FType()->YieldType()->Tag())); + reporter->Error("Return value of log_ext is not a record (got %s)", type_name(filter->ext_func->FType()->Yield()->Tag())); delete filter; return false; } @@ -1038,7 +1038,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) { lval->val.vector_val.vals[i] = ValToLogVal(vec->Lookup(i), - vec->Type()->YieldType()); + vec->Type()->Yield().get()); } break; diff --git a/src/option.bif b/src/option.bif index dd534811a8..2105054cfc 100644 --- a/src/option.bif +++ b/src/option.bif @@ -199,10 +199,10 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( ! same_type(on_change->Type()->AsFuncType()->YieldType(), i->Type()) ) + if ( ! same_type(on_change->Type()->AsFuncType()->Yield().get(), i->Type()) ) { builtin_error(fmt("Passed function needs to return type '%s' for ID '%s'; got '%s'", - type_name(i->Type()->Tag()), ID->CheckString(), type_name(on_change->Type()->AsFuncType()->YieldType()->Tag()))); + type_name(i->Type()->Tag()), ID->CheckString(), type_name(on_change->Type()->AsFuncType()->Yield()->Tag()))); return val_mgr->False(); } diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index 2d39fecf51..189b40798a 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -154,7 +154,7 @@ bool Value::IsCompatibleType(BroType* t, bool atomic_only) if ( atomic_only ) return false; - return IsCompatibleType(t->AsVectorType()->YieldType(), true); + return IsCompatibleType(t->AsVectorType()->Yield().get(), true); } default: diff --git a/src/zeek.bif b/src/zeek.bif index bea7c94761..fc14bbb892 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -804,7 +804,7 @@ function sha256_hash_finish%(handle: opaque of sha256%): string function paraglob_init%(v: any%) : opaque of paraglob %{ if ( v->Type()->Tag() != TYPE_VECTOR || - v->Type()->YieldType()->Tag() != TYPE_STRING ) + v->Type()->Yield()->Tag() != TYPE_STRING ) { // reporter->Error will throw an exception. reporter->Error("paraglob requires a vector of strings for initialization."); @@ -1281,7 +1281,7 @@ function resize%(aggr: any, newsize: count%) : count function any_set%(v: any%) : bool %{ if ( v->Type()->Tag() != TYPE_VECTOR || - v->Type()->YieldType()->Tag() != TYPE_BOOL ) + v->Type()->Yield()->Tag() != TYPE_BOOL ) { builtin_error("any_set() requires vector of bool"); return val_mgr->False(); @@ -1310,7 +1310,7 @@ function any_set%(v: any%) : bool function all_set%(v: any%) : bool %{ if ( v->Type()->Tag() != TYPE_VECTOR || - v->Type()->YieldType()->Tag() != TYPE_BOOL ) + v->Type()->Yield()->Tag() != TYPE_BOOL ) { builtin_error("all_set() requires vector of bool"); return val_mgr->False(); @@ -1408,7 +1408,7 @@ function sort%(v: any, ...%) : any return rval; } - BroType* elt_type = v->Type()->YieldType(); + const auto& elt_type = v->Type()->Yield(); Func* comp = 0; if ( @ARG@.size() > 2 ) @@ -1434,7 +1434,7 @@ function sort%(v: any, ...%) : any if ( comp ) { FuncType* comp_type = comp->FType()->AsFuncType(); - if ( comp_type->YieldType()->Tag() != TYPE_INT || + if ( comp_type->Yield()->Tag() != TYPE_INT || ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) { builtin_error("invalid comparison function in call to sort()"); @@ -1478,7 +1478,7 @@ function order%(v: any, ...%) : index_vec return result_v; } - BroType* elt_type = v->Type()->YieldType(); + const auto& elt_type = v->Type()->Yield(); Func* comp = 0; if ( @ARG@.size() > 2 ) @@ -1516,7 +1516,7 @@ function order%(v: any, ...%) : index_vec if ( comp ) { FuncType* comp_type = comp->FType()->AsFuncType(); - if ( comp_type->YieldType()->Tag() != TYPE_INT || + if ( comp_type->Yield()->Tag() != TYPE_INT || ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) { builtin_error("invalid comparison function in call to order()");