diff --git a/src/Attr.cc b/src/Attr.cc index 251b1c595c..093e2d7f28 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->Yield().get(), type.get()) ) + if ( ! same_type(aft->Yield(), type) ) { a->AttrExpr()->Error( is_add ? @@ -294,11 +294,11 @@ void Attributes::CheckAttr(Attr* a) break; } - BroType* atype = a->AttrExpr()->GetType().get(); + const auto& atype = a->AttrExpr()->GetType(); if ( type->Tag() != TYPE_TABLE || (type->IsSet() && ! in_record) ) { - if ( same_type(atype, type.get()) ) + if ( same_type(atype, type) ) // Ok. break; @@ -328,7 +328,7 @@ void Attributes::CheckAttr(Attr* a) } TableType* tt = type->AsTableType(); - BroType* ytype = tt->Yield().get(); + const auto& ytype = tt->Yield(); if ( ! in_record ) { @@ -340,7 +340,7 @@ void Attributes::CheckAttr(Attr* a) { FuncType* f = atype->AsFuncType(); if ( ! f->CheckArgs(tt->IndexTypes()) || - ! same_type(f->Yield().get(), ytype) ) + ! same_type(f->Yield(), ytype) ) Error("&default function type clash"); // Ok. @@ -354,7 +354,7 @@ void Attributes::CheckAttr(Attr* a) // Ok. break; - auto e = check_and_promote_expr(a->AttrExpr(), ytype); + auto e = check_and_promote_expr(a->AttrExpr(), ytype.get()); if ( e ) { @@ -374,7 +374,7 @@ void Attributes::CheckAttr(Attr* a) { // &default applies to record field. - if ( same_type(atype, type.get()) ) + if ( same_type(atype, type) ) // Ok. break; @@ -519,7 +519,7 @@ void Attributes::CheckAttr(Attr* a) break; } - if ( ! same_type(args[0].get(), the_table->AsTableType()) ) + if ( ! same_type(args[0], the_table->AsTableType()) ) { Error("&on_change: first argument must be of same type as table"); break; @@ -534,7 +534,7 @@ void Attributes::CheckAttr(Attr* a) for ( size_t i = 0; i < t_indexes.size(); i++ ) { - if ( ! same_type(args[2+i].get(), t_indexes[i].get()) ) + if ( ! same_type(args[2+i], t_indexes[i]) ) { Error("&on_change: index types do not match table"); break; @@ -542,7 +542,7 @@ void Attributes::CheckAttr(Attr* a) } if ( ! type->IsSet() ) - if ( ! same_type(args[2+t_indexes.size()].get(), the_table->Yield().get()) ) + if ( ! same_type(args[2+t_indexes.size()], the_table->Yield()) ) { Error("&on_change: value type does not match table"); break; diff --git a/src/CompHash.cc b/src/CompHash.cc index a826df8fbf..1804f24900 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -855,7 +855,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, if ( ! pvt ) reporter->InternalError("bad aggregate Val in CompositeHash::RecoverOneVal()"); - else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt.get(), t) ) + else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt, t) ) // ### Maybe fix later, but may be fundamentally // un-checkable --US reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); diff --git a/src/Expr.cc b/src/Expr.cc index 04bf4d640a..e652a3d09a 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -1282,7 +1282,7 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) else if ( t1->IsSet() && t2->IsSet() ) { - if ( same_type(t1.get(), t2.get()) ) + if ( same_type(t1, t2) ) SetType(op1->GetType()); else ExprError("incompatible \"set\" operands"); @@ -1660,7 +1660,7 @@ BitExpr::BitExpr(BroExprTag arg_tag, else if ( t1->IsSet() && t2->IsSet() ) { - if ( same_type(t1.get(), t2.get()) ) + if ( same_type(t1, t2) ) SetType(op1->GetType()); else ExprError("incompatible \"set\" operands"); @@ -1718,14 +1718,14 @@ EqExpr::EqExpr(BroExprTag arg_tag, break; case TYPE_ENUM: - if ( ! same_type(t1.get(), t2.get()) ) + if ( ! same_type(t1, t2) ) ExprError("illegal enum comparison"); break; case TYPE_TABLE: if ( t1->IsSet() && t2->IsSet() ) { - if ( ! same_type(t1.get(), t2.get()) ) + if ( ! same_type(t1, t2) ) ExprError("incompatible sets in comparison"); break; } @@ -1802,7 +1802,7 @@ RelExpr::RelExpr(BroExprTag arg_tag, else if ( t1->IsSet() && t2->IsSet() ) { - if ( ! same_type(t1.get(), t2.get()) ) + if ( ! same_type(t1, t2) ) ExprError("incompatible sets in comparison"); } @@ -1884,7 +1884,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, else { if ( IsRecord(bt2) && IsRecord(bt3) && - ! same_type(op2->GetType().get(), op3->GetType().get()) ) + ! same_type(op2->GetType(), op3->GetType()) ) ExprError("operands must be of the same type"); else SetType(op2->GetType()); @@ -2086,7 +2086,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs) op2 = make_intrusive( IntrusivePtr{NewRef{}, op2->AsListExpr()}, attr_copy); - if ( ! empty_list_assignment && ! same_type(op1->GetType().get(), op2->GetType().get()) ) + if ( ! empty_list_assignment && ! same_type(op1->GetType(), op2->GetType()) ) { if ( op1->GetType()->IsSet() ) ExprError("set type mismatch in assignment"); @@ -2119,7 +2119,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs) if ( op1->GetType()->Tag() == TYPE_RECORD && op2->GetType()->Tag() == TYPE_RECORD ) { - if ( same_type(op1->GetType().get(), op2->GetType().get()) ) + if ( same_type(op1->GetType(), op2->GetType()) ) { RecordType* rt1 = op1->GetType()->AsRecordType(); RecordType* rt2 = op2->GetType()->AsRecordType(); @@ -2141,7 +2141,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs) return true; } - if ( ! same_type(op1->GetType().get(), op2->GetType().get()) ) + if ( ! same_type(op1->GetType(), op2->GetType()) ) { if ( bt1 == TYPE_TABLE && bt2 == TYPE_TABLE ) { @@ -3547,8 +3547,8 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, break; } - BroType* sub_t_i = sub_r->GetFieldType(i).get(); - BroType* sup_t_i = t_r->GetFieldType(t_i).get(); + const auto& sub_t_i = sub_r->GetFieldType(i); + const auto& sup_t_i = t_r->GetFieldType(t_i); if ( ! same_type(sup_t_i, sub_t_i) ) { @@ -3581,12 +3581,12 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, sub->AsRecordType()); }; - if ( ! is_arithmetic_promotable(sup_t_i, sub_t_i) && - ! is_record_promotable(sup_t_i, sub_t_i) ) + if ( ! is_arithmetic_promotable(sup_t_i.get(), sub_t_i.get()) && + ! is_record_promotable(sup_t_i.get(), sub_t_i.get()) ) { std::string error_msg = fmt( "type clash for field \"%s\"", sub_r->FieldName(i)); - Error(error_msg.c_str(), sub_t_i); + Error(error_msg.c_str(), sub_t_i.get()); SetError(); break; } @@ -3670,18 +3670,18 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const continue; } - BroType* rhs_type = rhs->GetType().get(); + const auto& rhs_type = rhs->GetType(); const auto& field_type = val_type->GetFieldType(i); if ( rhs_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && - ! same_type(rhs_type, field_type.get()) ) + ! same_type(rhs_type, field_type) ) { if ( auto new_val = rhs->AsRecordVal()->CoerceTo(cast_intrusive(field_type)) ) rhs = std::move(new_val); } else if ( BothArithmetic(rhs_type->Tag(), field_type->Tag()) && - ! same_type(rhs_type, field_type.get()) ) + ! same_type(rhs_type, field_type) ) { if ( auto new_val = check_and_promote(rhs, field_type.get(), false, op->GetLocationInfo()) ) rhs = std::move(new_val); @@ -3701,7 +3701,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const if ( def_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && - ! same_type(def_type.get(), field_type.get()) ) + ! same_type(def_type, field_type) ) { auto tmp = def_val->AsRecordVal()->CoerceTo( cast_intrusive(field_type)); @@ -3908,7 +3908,7 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) const auto& t1 = op1->GetType(); const auto& it = op2->GetType()->AsTableType()->GetIndices(); - if ( ! same_type(t1.get(), it.get()) ) + if ( ! same_type(t1, it) ) { t1->Error("indexing mismatch", op2->GetType().get()); SetError(); @@ -4608,7 +4608,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co auto v = e->Eval(nullptr); - if ( ! same_type(v->GetType().get(), t) ) + if ( ! same_type(v->GetType(), t) ) { v->GetType()->Error("type clash in table initializer", t); return nullptr; @@ -4648,7 +4648,7 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) if ( element->GetType()->IsSet() ) { - if ( ! same_type(element->GetType().get(), t) ) + if ( ! same_type(element->GetType(), t) ) { element->Error("type clash in set initializer", t); return nullptr; @@ -4747,7 +4747,7 @@ RecordAssignExpr::RecordAssignExpr(const IntrusivePtr& record, int field = lhs->FieldOffset(field_name); if ( field >= 0 && - same_type(lhs->GetFieldType(field).get(), t->GetFieldType(j).get()) ) + same_type(lhs->GetFieldType(field), t->GetFieldType(j)) ) { auto fe_lhs = make_intrusive(record, field_name); auto fe_rhs = make_intrusive(IntrusivePtr{NewRef{}, init}, field_name); @@ -4818,7 +4818,7 @@ IntrusivePtr CastExpr::Eval(Frame* f) const GetType()->Describe(&d); d.Add("'"); - if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) && + if ( same_type(v->GetType(), bro_broker::DataVal::ScriptDataType()) && ! v->AsRecordVal()->GetField(0) ) d.Add(" (nil $data field)"); @@ -4906,7 +4906,7 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) RecordType* t_r = t->AsRecordType(); RecordType* et_r = et->AsRecordType(); - if ( same_type(t, et.get()) ) + if ( same_type(t, et) ) { // Make sure the attributes match as well. for ( int i = 0; i < t_r->NumFields(); ++i ) @@ -4929,7 +4929,7 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) } - if ( ! same_type(t, et.get()) ) + if ( ! same_type(t, et) ) { if ( t->Tag() == TYPE_TABLE && et->Tag() == TYPE_TABLE && et->AsTableType()->IsUnspecifiedTable() ) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 80d8462949..351d00fa19 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -770,7 +770,7 @@ IntrusivePtr BloomFilterVal::Merge(const BloomFilterVal* x, { if ( x->Type() && // any one 0 is ok here y->Type() && - ! same_type(x->Type().get(), y->Type().get()) ) + ! same_type(x->Type(), y->Type()) ) { reporter->Error("cannot merge Bloom filters with different types"); return nullptr; diff --git a/src/Stmt.cc b/src/Stmt.cc index ba0a95968f..f2de940c12 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -741,7 +741,7 @@ bool SwitchStmt::AddCaseLabelTypeMapping(ID* t, int idx) { for ( auto i : case_label_type_list ) { - if ( same_type(i.first->GetType().get(), t->GetType().get()) ) + if ( same_type(i.first->GetType(), t->GetType()) ) return false; } @@ -1080,7 +1080,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) if ( lvt ) { - if ( ! same_type(lvt.get(), ind_type.get()) ) + if ( ! same_type(lvt, ind_type) ) lvt->Error("type clash in iteration", ind_type.get()); } @@ -1151,7 +1151,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, // Verify value_vars type if its already been defined if ( value_var->GetType() ) { - if ( ! same_type(value_var->GetType().get(), yield_type.get()) ) + if ( ! same_type(value_var->GetType(), yield_type) ) value_var->GetType()->Error("type clash in iteration", yield_type.get()); } else diff --git a/src/Type.cc b/src/Type.cc index d29ecc05b0..3ab5bfee3e 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -156,14 +156,14 @@ unsigned int BroType::MemoryAllocation() const bool TypeList::AllMatch(const BroType* t, bool is_init) const { for ( const auto& type : types ) - if ( ! same_type(type.get(), t, is_init) ) + if ( ! same_type(type, t, is_init) ) return false; return true; } void TypeList::Append(IntrusivePtr t) { - if ( pure_type && ! same_type(t.get(), pure_type.get()) ) + if ( pure_type && ! same_type(t, pure_type) ) reporter->InternalError("pure type-list violation"); types.emplace_back(std::move(t)); @@ -171,7 +171,7 @@ void TypeList::Append(IntrusivePtr t) void TypeList::AppendEvenIfNotPure(IntrusivePtr t) { - if ( pure_type && ! same_type(t.get(), pure_type.get()) ) + if ( pure_type && ! same_type(t, pure_type) ) pure_type = nullptr; types.emplace_back(std::move(t)); @@ -503,7 +503,7 @@ bool FuncType::CheckArgs(const std::vector>& args, bool success = true; for ( size_t i = 0; i < my_args.size(); ++i ) - if ( ! same_type(args[i].get(), my_args[i].get(), is_init) ) + if ( ! same_type(args[i], my_args[i], is_init) ) { Warn(fmt("Type mismatch in function argument #%zu. Expected %s, got %s.", i, type_name(args[i]->Tag()), type_name(my_args[i]->Tag()))); @@ -592,7 +592,7 @@ std::optional FuncType::FindPrototype(const RecordType& arg const auto& ptype = p.args->GetFieldType(i); const auto& desired_type = args.GetFieldType(i); - if ( ! same_type(ptype.get(), desired_type.get()) || + if ( ! same_type(ptype, desired_type) || ! streq(args.FieldName(i), p.args->FieldName(i)) ) { matched = false; @@ -1405,38 +1405,40 @@ const IntrusivePtr& base_type(TypeTag tag) // false otherwise. Assumes that t1's tag is different from t2's. Note // that the test is in only one direction - we don't check whether t2 is // initialization-compatible with t1. -static bool is_init_compat(const BroType* t1, const BroType* t2) +static bool is_init_compat(const BroType& t1, const BroType& t2) { - if ( t1->Tag() == TYPE_LIST ) + if ( t1.Tag() == TYPE_LIST ) { - if ( t2->Tag() == TYPE_RECORD ) + if ( t2.Tag() == TYPE_RECORD ) return true; else - return t1->AsTypeList()->AllMatch(t2, true); + return t1.AsTypeList()->AllMatch(&t2, true); } - if ( t1->IsSet() ) - return same_type(t1->AsSetType()->GetIndices().get(), t2, true); + if ( t1.IsSet() ) + return same_type(*t1.AsSetType()->GetIndices(), t2, true); return false; } -bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_record_field_names) +bool same_type(const BroType& arg_t1, const BroType& arg_t2, + bool is_init, bool match_record_field_names) { - if ( t1 == t2 || - t1->Tag() == TYPE_ANY || - t2->Tag() == TYPE_ANY ) + if ( &arg_t1 == &arg_t2 || + arg_t1.Tag() == TYPE_ANY || + arg_t2.Tag() == TYPE_ANY ) return true; - t1 = flatten_type(t1); - t2 = flatten_type(t2); + auto t1 = flatten_type(&arg_t1); + auto t2 = flatten_type(&arg_t2); + if ( t1 == t2 ) return true; if ( t1->Tag() != t2->Tag() ) { if ( is_init ) - return is_init_compat(t1, t2) || is_init_compat(t2, t1); + return is_init_compat(*t1, *t2) || is_init_compat(*t2, *t1); return false; } @@ -1477,12 +1479,12 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re if ( tl1 || tl2 ) { - if ( ! tl1 || ! tl2 || ! same_type(tl1.get(), tl2.get(), is_init, match_record_field_names) ) + if ( ! tl1 || ! tl2 || ! same_type(tl1, tl2, is_init, match_record_field_names) ) return false; } - const BroType* y1 = t1->Yield().get(); - const BroType* y2 = t2->Yield().get(); + const auto& y1 = t1->Yield(); + const auto& y2 = t2->Yield(); if ( y1 || y2 ) { @@ -1504,7 +1506,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re if ( t1->Yield() || t2->Yield() ) { if ( ! t1->Yield() || ! t2->Yield() || - ! same_type(t1->Yield().get(), t2->Yield().get(), is_init, match_record_field_names) ) + ! same_type(t1->Yield(), t2->Yield(), is_init, match_record_field_names) ) return false; } @@ -1525,7 +1527,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re const TypeDecl* td2 = rt2->FieldDecl(i); if ( (match_record_field_names && ! streq(td1->id, td2->id)) || - ! same_type(td1->type.get(), td2->type.get(), is_init, match_record_field_names) ) + ! same_type(td1->type, td2->type, is_init, match_record_field_names) ) return false; } @@ -1541,7 +1543,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re return false; for ( auto i = 0u; i < tl1.size(); ++i ) - if ( ! same_type(tl1[i].get(), tl2[i].get(), is_init, match_record_field_names) ) + if ( ! same_type(tl1[i], tl2[i], is_init, match_record_field_names) ) return false; return true; @@ -1549,7 +1551,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->Yield().get(), t2->Yield().get(), is_init, match_record_field_names); + return same_type(t1->Yield(), t2->Yield(), is_init, match_record_field_names); case TYPE_OPAQUE: { @@ -1562,7 +1564,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re { auto tt1 = t1->AsTypeType(); auto tt2 = t2->AsTypeType(); - return same_type(tt1->Type(), tt1->Type(), + return same_type(tt1->GetType(), tt1->GetType(), is_init, match_record_field_names); } @@ -1597,7 +1599,7 @@ bool record_promotion_compatible(const RecordType* super_rec, const auto& sub_field_type = sub_rec->GetFieldType(i); const auto& super_field_type = super_rec->GetFieldType(o); - if ( same_type(sub_field_type.get(), super_field_type.get()) ) + if ( same_type(sub_field_type, super_field_type) ) continue; if ( sub_field_type->Tag() != TYPE_RECORD ) @@ -1924,7 +1926,7 @@ IntrusivePtr merge_types(const IntrusivePtr& arg_t1, } case TYPE_VECTOR: - if ( ! same_type(t1->Yield().get(), t2->Yield().get()) ) + if ( ! same_type(t1->Yield(), t2->Yield()) ) { t1->Error("incompatible types", t2); return nullptr; @@ -1933,7 +1935,7 @@ IntrusivePtr merge_types(const IntrusivePtr& arg_t1, return make_intrusive(merge_types(t1->Yield(), t2->Yield())); case TYPE_FILE: - if ( ! same_type(t1->Yield().get(), t2->Yield().get()) ) + if ( ! same_type(t1->Yield(), t2->Yield()) ) { t1->Error("incompatible types", t2); return nullptr; @@ -2051,7 +2053,7 @@ IntrusivePtr init_type(Expr* init) if ( ! ti ) return nullptr; - if ( same_type(t.get(), ti.get()) ) + if ( same_type(t, ti) ) continue; t = merge_types(t, ti); diff --git a/src/Type.h b/src/Type.h index 38be9b8c31..efda5f6e17 100644 --- a/src/Type.h +++ b/src/Type.h @@ -544,6 +544,9 @@ public: explicit TypeType(IntrusivePtr t) : BroType(TYPE_TYPE), type(std::move(t)) {} IntrusivePtr ShallowClone() override { return make_intrusive(type); } + const IntrusivePtr& GetType() const + { return type; } + BroType* Type() { return type.get(); } const BroType* Type() const { return type.get(); } @@ -811,7 +814,20 @@ inline const IntrusivePtr& error_type() { return base_type(TYPE_ERROR); // True if the two types are equivalent. If is_init is true then the test is // done in the context of an initialization. If match_record_field_names is // true then for record types the field names have to match, too. -extern bool same_type(const BroType* t1, const BroType* t2, bool is_init=false, bool match_record_field_names=true); +extern bool same_type(const BroType& t1, const BroType& t2, + bool is_init=false, bool match_record_field_names=true); +inline bool same_type(const IntrusivePtr& t1, const IntrusivePtr& t2, + bool is_init=false, bool match_record_field_names=true) + { return same_type(*t1, *t2, is_init, match_record_field_names); } +inline bool same_type(const BroType* t1, const BroType* t2, + bool is_init=false, bool match_record_field_names=true) + { return same_type(*t1, *t2, is_init, match_record_field_names); } +inline bool same_type(const IntrusivePtr& t1, const BroType* t2, + bool is_init=false, bool match_record_field_names=true) + { return same_type(*t1, *t2, is_init, match_record_field_names); } +inline bool same_type(const BroType* t1, const IntrusivePtr& t2, + bool is_init=false, bool match_record_field_names=true) + { return same_type(*t1, *t2, is_init, match_record_field_names); } // True if the two attribute lists are equivalent. extern bool same_attrs(const Attributes* a1, const Attributes* a2); diff --git a/src/Val.cc b/src/Val.cc index b609436cb2..ce5f0d06bd 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1602,7 +1602,7 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const TableVal* t = val->AsTableVal(); - if ( ! same_type(type.get(), t->GetType().get()) ) + if ( ! same_type(type, t->GetType()) ) { type->Error("table type clash", t->GetType().get()); return false; @@ -1650,7 +1650,7 @@ bool TableVal::RemoveFrom(Val* val) const TableVal* t = val->AsTableVal(); - if ( ! same_type(type.get(), t->GetType().get()) ) + if ( ! same_type(type, t->GetType()) ) { type->Error("table type clash", t->GetType().get()); return false; @@ -1824,7 +1824,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) const auto& dtype = def_attr->AttrExpr()->GetType(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype.get(), ytype.get()) && + ! same_type(dtype, ytype) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) { @@ -1845,7 +1845,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) } if ( def_val->GetType()->Tag() != TYPE_FUNC || - same_type(def_val->GetType().get(), GetType()->Yield().get()) ) + same_type(def_val->GetType(), GetType()->Yield()) ) { if ( def_attr->AttrExpr()->IsConst() ) return def_val; @@ -2348,7 +2348,7 @@ void TableVal::InitDefaultFunc(Frame* f) const auto& dtype = def_attr->AttrExpr()->GetType(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype.get(), ytype.get()) && + ! same_type(dtype, ytype) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) return; // TableVal::Default will handle this. @@ -2720,7 +2720,7 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo if ( def && type->Tag() == TYPE_RECORD && def->GetType()->Tag() == TYPE_RECORD && - ! same_type(def->GetType().get(), type.get()) ) + ! same_type(def->GetType(), type) ) { auto tmp = def->AsRecordVal()->CoerceTo(cast_intrusive(type)); @@ -2867,7 +2867,7 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, const auto& ft = ar_t->GetFieldType(t_i); - if ( ft->Tag() == TYPE_RECORD && ! same_type(ft.get(), v->GetType().get()) ) + if ( ft->Tag() == TYPE_RECORD && ! same_type(ft, v->GetType()) ) { auto rhs = make_intrusive(v); auto e = make_intrusive(std::move(rhs), @@ -2895,7 +2895,7 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, bool allow_orphaning) { - if ( same_type(GetType().get(), t.get()) ) + if ( same_type(GetType(), t) ) return {NewRef{}, this}; return CoerceTo(std::move(t), nullptr, allow_orphaning); @@ -3051,7 +3051,7 @@ IntrusivePtr VectorVal::SizeVal() const bool VectorVal::Assign(unsigned int index, IntrusivePtr element) { if ( element && - ! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) ) + ! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) ) return false; if ( index >= val.vector_val->size() ) @@ -3078,7 +3078,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, bool VectorVal::Insert(unsigned int index, IntrusivePtr element) { if ( element && - ! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) ) + ! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) ) { return false; } @@ -3118,7 +3118,7 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const VectorVal* v = val->AsVectorVal(); - if ( ! same_type(type.get(), v->GetType().get()) ) + if ( ! same_type(type, v->GetType()) ) { type->Error("vector type clash", v->GetType().get()); return false; @@ -3198,9 +3198,7 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, if ( ! v ) return nullptr; - BroType* vt = v->GetType().get(); - - vt = flatten_type(vt); + BroType* vt = flatten_type(v->GetType().get()); t = flatten_type(t); TypeTag t_tag = t->Tag(); @@ -3394,10 +3392,10 @@ IntrusivePtr cast_value_to_type(Val* v, BroType* t) // Always allow casting to same type. This also covers casting 'any' // to the actual type. - if ( same_type(v->GetType().get(), t) ) + if ( same_type(v->GetType(), t) ) return {NewRef{}, v}; - if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(v->GetType(), bro_broker::DataVal::ScriptDataType()) ) { const auto& dv = v->AsRecordVal()->GetField(0); @@ -3420,10 +3418,10 @@ bool can_cast_value_to_type(const Val* v, BroType* t) // Always allow casting to same type. This also covers casting 'any' // to the actual type. - if ( same_type(v->GetType().get(), t) ) + if ( same_type(v->GetType(), t) ) return true; - if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(v->GetType(), bro_broker::DataVal::ScriptDataType()) ) { const auto& dv = v->AsRecordVal()->GetField(0); diff --git a/src/Var.cc b/src/Var.cc index 33895f5def..590823587e 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -153,7 +153,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, } // Allow redeclaration in order to initialize. - if ( ! same_type(t.get(), id->GetType().get()) ) + if ( ! same_type(t, id->GetType()) ) { id->Error("redefinition changes type", init.get()); return; @@ -449,7 +449,7 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl return false; for ( auto i = 0; i < canon_args->NumFields(); ++i ) - if ( ! same_type(canon_args->GetFieldType(i).get(), impl_args->GetFieldType(i).get()) ) + if ( ! same_type(canon_args->GetFieldType(i), impl_args->GetFieldType(i)) ) return false; return true; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 74e572ff76..98f9651d41 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -743,7 +743,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) const auto& got_type = (*args)[i]->GetType(); const auto& expected_type = func->GetType()->ParamList()->Types()[i - 1]; - if ( ! same_type(got_type.get(), expected_type.get()) ) + if ( ! same_type(got_type, expected_type) ) { rval->Assign(0, nullptr); Error("event parameter #%d type mismatch, got %s, expect %s", i, @@ -754,7 +754,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) IntrusivePtr data_val; - if ( same_type(got_type.get(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(got_type, bro_broker::DataVal::ScriptDataType()) ) data_val = {NewRef{}, (*args)[i]->AsRecordVal()}; else data_val = make_data_val((*args)[i]); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 8d9d82fb42..06931636c8 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -217,9 +217,9 @@ ReaderBackend* Manager::CreateBackend(ReaderFrontend* frontend, EnumVal* tag) bool Manager::CreateStream(Stream* info, RecordVal* description) { RecordType* rtype = description->GetType()->AsRecordType(); - if ( ! ( same_type(rtype, zeek::BifType::Record::Input::TableDescription.get(), false) - || same_type(rtype, zeek::BifType::Record::Input::EventDescription.get(), false) - || same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription.get(), false) ) ) + if ( ! ( same_type(rtype, zeek::BifType::Record::Input::TableDescription, false) + || same_type(rtype, zeek::BifType::Record::Input::EventDescription, false) + || same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription, false) ) ) { reporter->Error("Stream description argument not of right type for new input stream"); return false; @@ -305,7 +305,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) bool Manager::CreateEventStream(RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, zeek::BifType::Record::Input::EventDescription.get(), false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Input::EventDescription, false) ) { reporter->Error("EventDescription argument not of right type"); return false; @@ -339,13 +339,13 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - if ( ! same_type(args[1].get(), zeek::BifType::Enum::Input::Event.get(), false) ) + if ( ! same_type(args[1], zeek::BifType::Enum::Input::Event, false) ) { reporter->Error("Input stream %s: Event's second attribute must be of type Input::Event", stream_name.c_str()); return false; } - if ( ! same_type(args[0].get(), zeek::BifType::Record::Input::EventDescription.get(), false) ) + if ( ! same_type(args[0], zeek::BifType::Record::Input::EventDescription, false) ) { reporter->Error("Input stream %s: Event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; @@ -361,7 +361,7 @@ bool Manager::CreateEventStream(RecordVal* fval) for ( int i = 0; i < fields->NumFields(); i++ ) { - if ( ! same_type(args[i + 2].get(), fields->GetFieldType(i).get() ) ) + if ( ! same_type(args[i + 2], fields->GetFieldType(i) ) ) { ODesc desc1; ODesc desc2; @@ -387,7 +387,7 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - if ( ! same_type(args[2].get(), fields ) ) + if ( ! same_type(args[2], fields ) ) { ODesc desc1; ODesc desc2; @@ -459,7 +459,7 @@ bool Manager::CreateEventStream(RecordVal* fval) bool Manager::CreateTableStream(RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, zeek::BifType::Record::Input::TableDescription.get(), false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Input::TableDescription, false) ) { reporter->Error("TableDescription argument not of right type"); return false; @@ -492,7 +492,7 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( ! same_type(idx->GetFieldType(j).get(), tl[j].get()) ) + if ( ! same_type(idx->GetFieldType(j), tl[j]) ) { ODesc desc1; ODesc desc2; @@ -518,12 +518,9 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( val ) { const auto& table_yield = dst->GetType()->AsTableType()->Yield(); - const BroType* compare_type = val.get(); + const auto& compare_type = want_record->InternalInt() == 0 ? val->GetFieldType(0) : val; - if ( want_record->InternalInt() == 0 ) - compare_type = val->GetFieldType(0).get(); - - if ( ! same_type(table_yield.get(), compare_type) ) + if ( ! same_type(table_yield, compare_type) ) { ODesc desc1; ODesc desc2; @@ -567,19 +564,19 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( ! same_type(args[0].get(), zeek::BifType::Record::Input::TableDescription.get(), false) ) + if ( ! same_type(args[0], zeek::BifType::Record::Input::TableDescription, false) ) { reporter->Error("Input stream %s: Table event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! same_type(args[1].get(), zeek::BifType::Enum::Input::Event.get(), false) ) + if ( ! same_type(args[1], zeek::BifType::Enum::Input::Event, false) ) { reporter->Error("Input stream %s: Table event's second attribute must be of type Input::Event", stream_name.c_str()); return false; } - if ( ! same_type(args[2].get(), idx) ) + if ( ! same_type(args[2], idx) ) { ODesc desc1; ODesc desc2; @@ -590,7 +587,7 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( want_record->InternalInt() == 1 && val && ! same_type(args[3].get(), val.get()) ) + if ( want_record->InternalInt() == 1 && val && ! same_type(args[3], val) ) { ODesc desc1; ODesc desc2; @@ -601,7 +598,7 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } else if ( want_record->InternalInt() == 0 - && val && !same_type(args[3].get(), val->GetFieldType(0).get() ) ) + && val && !same_type(args[3], val->GetFieldType(0) ) ) { ODesc desc1; ODesc desc2; @@ -714,13 +711,13 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - if ( table && ! same_type(args[0].get(), zeek::BifType::Record::Input::TableDescription.get(), false) ) + if ( table && ! same_type(args[0], zeek::BifType::Record::Input::TableDescription, false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! table && ! same_type(args[0].get(), zeek::BifType::Record::Input::EventDescription.get(), false) ) + if ( ! table && ! same_type(args[0], zeek::BifType::Record::Input::EventDescription, false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; @@ -732,7 +729,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - if ( ! same_type(args[2].get(), zeek::BifType::Enum::Reporter::Level.get(), false) ) + if ( ! same_type(args[2], zeek::BifType::Enum::Reporter::Level, false) ) { reporter->Error("Input stream %s: Error event's third attribute must be of type Reporter::Level", stream_name.c_str()); return false; @@ -745,7 +742,7 @@ bool Manager::CreateAnalysisStream(RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription.get(), false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription, false) ) { reporter->Error("AnalysisDescription argument not of right type"); return false; diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 3499382b88..fa86027ed2 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -229,9 +229,7 @@ void Manager::RemoveDisabledWriters(Stream* stream) bool Manager::CreateStream(EnumVal* id, RecordVal* sval) { - RecordType* rtype = sval->GetType()->AsRecordType(); - - if ( ! same_type(rtype, zeek::BifType::Record::Log::Stream.get(), false) ) + if ( ! same_type(sval->GetType(), zeek::BifType::Record::Log::Stream, false) ) { reporter->Error("sval argument not of right type"); return false; @@ -286,7 +284,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) return false; } - if ( ! same_type(args[0].get(), columns) ) + if ( ! same_type(args[0], columns) ) { reporter->Error("stream event's argument type does not match column record type"); return false; @@ -528,9 +526,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, bool Manager::AddFilter(EnumVal* id, RecordVal* fval) { - RecordType* rtype = fval->GetType()->AsRecordType(); - - if ( ! same_type(rtype, zeek::BifType::Record::Log::Filter.get(), false) ) + if ( ! same_type(fval->GetType(), zeek::BifType::Record::Log::Filter, false) ) { reporter->Error("filter argument not of right type"); return false; diff --git a/src/option.bif b/src/option.bif index fd118ca5cc..14c65c1d50 100644 --- a/src/option.bif +++ b/src/option.bif @@ -79,7 +79,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool return val_mgr->False(); } - if ( same_type(val->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(val->GetType(), bro_broker::DataVal::ScriptDataType()) ) { auto dv = static_cast(val->AsRecordVal()->GetField(0).get()); auto val_from_data = dv->castTo(i->GetType().get()); @@ -95,7 +95,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool return val_mgr->Bool(rval); } - if ( ! same_type(i->GetType().get(), val->GetType().get()) ) + if ( ! same_type(i->GetType(), val->GetType()) ) { if ( i->GetType()->Tag() == TYPE_TABLE && val->GetType()->Tag() == TYPE_TABLE && @@ -185,7 +185,7 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( ! same_type(args[1].get(), i->GetType().get()) ) + if ( ! same_type(args[1], i->GetType()) ) { builtin_error(fmt("Second argument of passed function has to be %s in Option::on_change for ID '%s'; got '%s'", type_name(i->GetType()->Tag()), ID->CheckString(), type_name(args[1]->Tag()))); @@ -199,7 +199,7 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( ! same_type(on_change->GetType()->AsFuncType()->Yield().get(), i->GetType().get()) ) + if ( ! same_type(on_change->GetType()->AsFuncType()->Yield(), i->GetType()) ) { builtin_error(fmt("Passed function needs to return type '%s' for ID '%s'; got '%s'", type_name(i->GetType()->Tag()), ID->CheckString(), type_name(on_change->GetType()->AsFuncType()->Yield()->Tag()))); diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index a6942ddbca..f870619e87 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -86,7 +86,7 @@ void TopkVal::Merge(const TopkVal* value, bool doPrune) else { - if ( ! same_type(type.get(), value->type.get()) ) + if ( ! same_type(type, value->type) ) { reporter->Error("Cannot merge top-k elements of differing types."); return; @@ -278,7 +278,7 @@ void TopkVal::Encountered(IntrusivePtr encountered) if ( numElements == 0 ) Typify(encountered->GetType()); else - if ( ! same_type(type.get(), encountered->GetType().get()) ) + if ( ! same_type(type, encountered->GetType()) ) { reporter->Error("Trying to add element to topk with differing type from other elements"); return; diff --git a/src/probabilistic/bloom-filter.bif b/src/probabilistic/bloom-filter.bif index 21425cd10d..b8c4592c8d 100644 --- a/src/probabilistic/bloom-filter.bif +++ b/src/probabilistic/bloom-filter.bif @@ -149,7 +149,7 @@ function bloomfilter_add%(bf: opaque of bloomfilter, x: any%): any if ( ! bfv->Type() && ! bfv->Typify(x->GetType()) ) reporter->Error("failed to set Bloom filter type"); - else if ( ! same_type(bfv->Type().get(), x->GetType().get()) ) + else if ( ! same_type(bfv->Type(), x->GetType()) ) reporter->Error("incompatible Bloom filter types"); else @@ -176,7 +176,7 @@ function bloomfilter_lookup%(bf: opaque of bloomfilter, x: any%): count if ( ! bfv->Type() ) return val_mgr->Count(0); - else if ( ! same_type(bfv->Type().get(), x->GetType().get()) ) + else if ( ! same_type(bfv->Type(), x->GetType()) ) reporter->Error("incompatible Bloom filter types"); else @@ -227,7 +227,7 @@ function bloomfilter_merge%(bf1: opaque of bloomfilter, if ( bfv1->Type() && // any one 0 is ok here bfv2->Type() && - ! same_type(bfv1->Type().get(), bfv2->Type().get()) ) + ! same_type(bfv1->Type(), bfv2->Type()) ) { reporter->Error("incompatible Bloom filter types"); return nullptr; diff --git a/src/probabilistic/cardinality-counter.bif b/src/probabilistic/cardinality-counter.bif index 45e8ebbe59..370f842a38 100644 --- a/src/probabilistic/cardinality-counter.bif +++ b/src/probabilistic/cardinality-counter.bif @@ -48,7 +48,7 @@ function hll_cardinality_add%(handle: opaque of cardinality, elem: any%): bool return val_mgr->False(); } - else if ( ! same_type(cv->Type().get(), elem->GetType().get()) ) + else if ( ! same_type(cv->Type(), elem->GetType()) ) { reporter->Error("incompatible HLL data type"); return val_mgr->False(); @@ -79,7 +79,7 @@ function hll_cardinality_merge_into%(handle1: opaque of cardinality, handle2: op if ( (v1->Type() != v2->Type()) && // both 0 is ok (v1->Type() != nullptr) && // any one 0 also is ok (v2->Type() != nullptr) && - ! same_type(v1->Type().get(), v2->Type().get()) ) + ! same_type(v1->Type(), v2->Type()) ) { reporter->Error("incompatible HLL types"); return val_mgr->False(); diff --git a/src/threading/Manager.cc b/src/threading/Manager.cc index 2c1491de1a..b4025bc68d 100644 --- a/src/threading/Manager.cc +++ b/src/threading/Manager.cc @@ -166,7 +166,7 @@ bool Manager::SendEvent(MsgThread* thread, const std::string& name, const int nu Val* v = Value::ValueToVal(std::string("thread ") + thread->Name(), vals[j], convert_error); vl.emplace_back(AdoptRef{}, v); - if ( v && ! convert_error && ! same_type(type->GetFieldType(j).get(), v->GetType().get()) ) + if ( v && ! convert_error && ! same_type(type->GetFieldType(j), v->GetType()) ) { convert_error = true; type->GetFieldType(j)->Error("SendEvent types do not match", v->GetType().get());