diff --git a/src/CompHash.cc b/src/CompHash.cc index 4331603b5d..a826df8fbf 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -948,7 +948,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, for ( int i = 0; i < n; ++i ) { IntrusivePtr key; - kp1 = RecoverOneVal(k, kp1, k_end, tt->Indices(), &key, false); + kp1 = RecoverOneVal(k, kp1, k_end, tt->GetIndices().get(), &key, false); if ( t->IsSet() ) tv->Assign(std::move(key), nullptr); diff --git a/src/Expr.cc b/src/Expr.cc index 6c5410c047..04bf4d640a 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2384,7 +2384,7 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) const TableType* tt = tv->GetType()->AsTableType(); const auto& yt = tv->GetType()->Yield(); - auto index = op1->InitVal(tt->Indices(), nullptr); + auto index = op1->InitVal(tt->GetIndices().get(), nullptr); auto v = op2->InitVal(yt.get(), nullptr); if ( ! index || ! v ) @@ -3084,7 +3084,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; - const auto& indices = type->AsTableType()->Indices()->Types(); + const auto& indices = type->AsTableType()->GetIndices()->Types(); const expr_list& cle = op->AsListExpr()->Exprs(); // check and promote all index expressions in ctor list @@ -3203,7 +3203,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; - const auto& indices = type->AsTableType()->Indices()->Types(); + const auto& indices = type->AsTableType()->GetIndices()->Types(); expr_list& cle = op->AsListExpr()->Exprs(); if ( indices.size() == 1 ) @@ -3222,7 +3222,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, ListExpr* le = ce->AsListExpr(); if ( ce->Tag() == EXPR_LIST && - check_and_promote_exprs(le, type->AsTableType()->Indices()) ) + check_and_promote_exprs(le, type->AsTableType()->GetIndices().get()) ) { if ( le != cle[i] ) cle.replace(i, le); @@ -3258,7 +3258,7 @@ IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtrAsTableType()->Indices(); + const auto& index_type = t->AsTableType()->GetIndices(); auto tt = GetType(); auto tval = aggr ? IntrusivePtr{AdoptRef{}, aggr.release()->AsTableVal()} : @@ -3267,7 +3267,7 @@ IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtrEval(nullptr), index_type, true); + auto element = check_and_promote(e->Eval(nullptr), index_type.get(), true); if ( ! element || ! tval->Assign(std::move(element), nullptr) ) { @@ -3906,10 +3906,9 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) else { const auto& t1 = op1->GetType(); - const TypeList* it = - op2->GetType()->AsTableType()->Indices(); + const auto& it = op2->GetType()->AsTableType()->GetIndices(); - if ( ! same_type(t1.get(), it) ) + if ( ! same_type(t1.get(), it.get()) ) { t1->Error("indexing mismatch", op2->GetType().get()); SetError(); @@ -4462,7 +4461,7 @@ IntrusivePtr ListExpr::InitType() const if ( ti->IsSet() || ti->Tag() == TYPE_LIST ) { TypeList* til = ti->IsSet() ? - ti->AsSetType()->Indices() : + ti->AsSetType()->GetIndices().get() : ti->AsTypeList(); if ( ! til->IsPure() || @@ -4630,7 +4629,7 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) TableVal* tv = aggr->AsTableVal(); const TableType* tt = tv->GetType()->AsTableType(); - const TypeList* it = tt->Indices(); + const TypeList* it = tt->GetIndices().get(); for ( const auto& expr : exprs ) { diff --git a/src/Type.cc b/src/Type.cc index 411ee79450..297349ecb3 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -230,7 +230,7 @@ int IndexType::MatchesIndex(ListExpr* const index) const exprs.length() == 1 && exprs[0]->GetType()->Tag() == TYPE_ADDR ) return MATCHES_INDEX_SCALAR; - return check_and_promote_exprs(index, Indices()) ? + return check_and_promote_exprs(index, GetIndices().get()) ? MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX; } @@ -1416,7 +1416,7 @@ static bool is_init_compat(const BroType* t1, const BroType* t2) } if ( t1->IsSet() ) - return same_type(t1->AsSetType()->Indices(), t2, true); + return same_type(t1->AsSetType()->GetIndices().get(), t2, true); return false; } @@ -1472,12 +1472,12 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re const IndexType* it1 = (const IndexType*) t1; const IndexType* it2 = (const IndexType*) t2; - TypeList* tl1 = it1->Indices(); - TypeList* tl2 = it2->Indices(); + const auto& tl1 = it1->GetIndices(); + const auto& tl2 = it2->GetIndices(); if ( tl1 || tl2 ) { - if ( ! tl1 || ! tl2 || ! same_type(tl1, tl2, is_init, match_record_field_names) ) + if ( ! tl1 || ! tl2 || ! same_type(tl1.get(), tl2.get(), is_init, match_record_field_names) ) return false; } @@ -1981,11 +1981,12 @@ static BroType* reduce_type(BroType* t) else if ( t->IsSet() ) { - TypeList* tl = t->AsTableType()->Indices(); + const auto& tl = t->AsTableType()->GetIndices(); + if ( tl->Types().size() == 1 ) return tl->Types()[0].get(); else - return tl; + return tl.get(); } else diff --git a/src/Type.h b/src/Type.h index f23ed24e6f..c4d6989863 100644 --- a/src/Type.h +++ b/src/Type.h @@ -400,6 +400,10 @@ class IndexType : public BroType { public: int MatchesIndex(ListExpr* index) const override; + const IntrusivePtr& GetIndices() const + { return indices; } + + [[deprecated("Remove in v4.1. Use GetIndices().")]] TypeList* Indices() const { return indices.get(); } const std::vector>& IndexTypes() const diff --git a/src/Val.cc b/src/Val.cc index 5437122493..b609436cb2 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1358,7 +1358,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()->GetIndices().get(), found); find_nested_record_types(t->AsTableType()->Yield().get(), found); return; case TYPE_LIST: @@ -1416,8 +1416,7 @@ void TableVal::Init(IntrusivePtr t) else subnets = nullptr; - table_hash = new CompositeHash(IntrusivePtr(NewRef{}, - table_type->Indices())); + table_hash = new CompositeHash(table_type->GetIndices()); val.table_val = new PDict; val.table_val->SetDeleteFunc(table_entry_val_delete_func); } @@ -1520,7 +1519,7 @@ bool TableVal::Assign(IntrusivePtr index, IntrusivePtr new_val) if ( ! k ) { - index->Error("index type doesn't match table", table_type->Indices()); + index->Error("index type doesn't match table", table_type->GetIndices().get()); return false; } @@ -1777,7 +1776,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) ListVal* iv = index->AsListVal(); if ( iv->BaseTag() != TYPE_ANY ) { - if ( table_type->Indices()->Types().size() != 1 ) + if ( table_type->GetIndices()->Types().size() != 1 ) reporter->InternalError("bad singleton list index"); for ( int i = 0; i < iv->Length(); ++i ) @@ -2185,7 +2184,7 @@ ListVal* TableVal::ConvertToList(TypeTag t) const IntrusivePtr TableVal::ToPureListVal() const { - const auto& tl = table_type->Indices()->Types(); + const auto& tl = table_type->GetIndices()->Types(); if ( tl.size() != 1 ) { InternalWarning("bad index type in TableVal::ToPureListVal"); @@ -2680,8 +2679,7 @@ TableVal::ParseTimeTableState TableVal::DumpTableState() void TableVal::RebuildTable(ParseTimeTableState ptts) { delete table_hash; - table_hash = new CompositeHash(IntrusivePtr(NewRef{}, - table_type->Indices())); + table_hash = new CompositeHash(table_type->GetIndices()); for ( auto& [key, val] : ptts ) Assign(std::move(key), std::move(val)); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 2a0530a34e..42fe19d41d 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -213,7 +213,7 @@ struct val_converter { for ( auto& item : a ) { - const auto& expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->GetIndices()->Types(); broker::vector composite_key; auto indices = caf::get_if(&item); @@ -272,7 +272,7 @@ struct val_converter { for ( auto& item : a ) { - const auto& expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->GetIndices()->Types(); broker::vector composite_key; auto indices = caf::get_if(&item.first); @@ -560,7 +560,7 @@ struct type_checker { for ( const auto& item : a ) { - const auto& expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->GetIndices()->Types(); auto indices = caf::get_if(&item); vector indices_to_check; @@ -619,7 +619,7 @@ struct type_checker { for ( auto& item : a ) { - const auto& expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->GetIndices()->Types(); auto indices = caf::get_if(&item.first); vector indices_to_check; diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 2871b42ba8..8d9d82fb42 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -808,7 +808,7 @@ bool Manager::IsCompatibleType(BroType* t, bool atomic_only) if ( ! t->IsSet() ) return false; - return IsCompatibleType(t->AsSetType()->Indices()->GetPureType().get(), true); + return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true); } case TYPE_VECTOR: @@ -937,7 +937,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, bool optional = false; if ( ty == TYPE_TABLE ) - st = rec->GetFieldType(i)->AsSetType()->Indices()->GetPureType()->Tag(); + st = rec->GetFieldType(i)->AsSetType()->GetIndices()->GetPureType()->Tag(); else if ( ty == TYPE_VECTOR ) st = rec->GetFieldType(i)->AsVectorType()->Yield()->Tag(); @@ -2252,7 +2252,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ case TYPE_TABLE: { // all entries have to have the same type... - const auto& type = request_type->AsTableType()->Indices()->GetPureType(); + const auto& type = request_type->AsTableType()->GetIndices()->GetPureType(); auto set_index = make_intrusive(type); set_index->Append(type); auto s = make_intrusive(std::move(set_index), nullptr); diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 9ed946ba9b..2416ff7af0 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -45,7 +45,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) TypeTag primary = id->GetType()->Tag(); TypeTag secondary = TYPE_VOID; if ( primary == TYPE_TABLE ) - secondary = id->GetType()->AsSetType()->Indices()->GetPureType()->Tag(); + secondary = id->GetType()->AsSetType()->GetIndices()->GetPureType()->Tag(); else if ( primary == TYPE_VECTOR ) secondary = id->GetType()->AsVectorType()->Yield()->Tag(); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 5b8982191f..3499382b88 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -513,7 +513,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, TypeTag st = TYPE_VOID; if ( t->Tag() == TYPE_TABLE ) - st = t->AsSetType()->Indices()->GetPureType()->Tag(); + st = t->AsSetType()->GetIndices()->GetPureType()->Tag(); else if ( t->Tag() == TYPE_VECTOR ) st = t->AsVectorType()->Yield()->Tag(); diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index 1f6e6acd34..dbea04ef3a 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -154,7 +154,7 @@ bool Value::IsCompatibleType(BroType* t, bool atomic_only) if ( ! t->IsSet() ) return false; - return IsCompatibleType(t->AsSetType()->Indices()->GetPureType().get(), true); + return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true); } case TYPE_VECTOR: