Deprecate IndexType::Indices(), replace with GetIndices()

This commit is contained in:
Jon Siwek 2020-05-21 19:46:57 -07:00
parent 4e77df3c28
commit 4b17929b6b
10 changed files with 39 additions and 37 deletions

View file

@ -948,7 +948,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
for ( int i = 0; i < n; ++i ) for ( int i = 0; i < n; ++i )
{ {
IntrusivePtr<Val> key; IntrusivePtr<Val> 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() ) if ( t->IsSet() )
tv->Assign(std::move(key), nullptr); tv->Assign(std::move(key), nullptr);

View file

@ -2384,7 +2384,7 @@ IntrusivePtr<Val> AssignExpr::InitVal(const BroType* t, IntrusivePtr<Val> aggr)
const TableType* tt = tv->GetType()->AsTableType(); const TableType* tt = tv->GetType()->AsTableType();
const auto& yt = tv->GetType()->Yield(); 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); auto v = op2->InitVal(yt.get(), nullptr);
if ( ! index || ! v ) if ( ! index || ! v )
@ -3084,7 +3084,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr<ListExpr> constructor_li
attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; 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(); const expr_list& cle = op->AsListExpr()->Exprs();
// check and promote all index expressions in ctor list // check and promote all index expressions in ctor list
@ -3203,7 +3203,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr<ListExpr> constructor_list,
attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; 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(); expr_list& cle = op->AsListExpr()->Exprs();
if ( indices.size() == 1 ) if ( indices.size() == 1 )
@ -3222,7 +3222,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr<ListExpr> constructor_list,
ListExpr* le = ce->AsListExpr(); ListExpr* le = ce->AsListExpr();
if ( ce->Tag() == EXPR_LIST && 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] ) if ( le != cle[i] )
cle.replace(i, le); cle.replace(i, le);
@ -3258,7 +3258,7 @@ IntrusivePtr<Val> SetConstructorExpr::InitVal(const BroType* t, IntrusivePtr<Val
if ( IsError() ) if ( IsError() )
return nullptr; return nullptr;
const BroType* index_type = t->AsTableType()->Indices(); const auto& index_type = t->AsTableType()->GetIndices();
auto tt = GetType<TableType>(); auto tt = GetType<TableType>();
auto tval = aggr ? auto tval = aggr ?
IntrusivePtr<TableVal>{AdoptRef{}, aggr.release()->AsTableVal()} : IntrusivePtr<TableVal>{AdoptRef{}, aggr.release()->AsTableVal()} :
@ -3267,7 +3267,7 @@ IntrusivePtr<Val> SetConstructorExpr::InitVal(const BroType* t, IntrusivePtr<Val
for ( const auto& e : exprs ) for ( const auto& e : exprs )
{ {
auto element = check_and_promote(e->Eval(nullptr), index_type, true); auto element = check_and_promote(e->Eval(nullptr), index_type.get(), true);
if ( ! element || ! tval->Assign(std::move(element), nullptr) ) if ( ! element || ! tval->Assign(std::move(element), nullptr) )
{ {
@ -3906,10 +3906,9 @@ InExpr::InExpr(IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2)
else else
{ {
const auto& t1 = op1->GetType(); const auto& t1 = op1->GetType();
const TypeList* it = const auto& it = op2->GetType()->AsTableType()->GetIndices();
op2->GetType()->AsTableType()->Indices();
if ( ! same_type(t1.get(), it) ) if ( ! same_type(t1.get(), it.get()) )
{ {
t1->Error("indexing mismatch", op2->GetType().get()); t1->Error("indexing mismatch", op2->GetType().get());
SetError(); SetError();
@ -4462,7 +4461,7 @@ IntrusivePtr<BroType> ListExpr::InitType() const
if ( ti->IsSet() || ti->Tag() == TYPE_LIST ) if ( ti->IsSet() || ti->Tag() == TYPE_LIST )
{ {
TypeList* til = ti->IsSet() ? TypeList* til = ti->IsSet() ?
ti->AsSetType()->Indices() : ti->AsSetType()->GetIndices().get() :
ti->AsTypeList(); ti->AsTypeList();
if ( ! til->IsPure() || if ( ! til->IsPure() ||
@ -4630,7 +4629,7 @@ IntrusivePtr<Val> ListExpr::AddSetInit(const BroType* t, IntrusivePtr<Val> aggr)
TableVal* tv = aggr->AsTableVal(); TableVal* tv = aggr->AsTableVal();
const TableType* tt = tv->GetType()->AsTableType(); const TableType* tt = tv->GetType()->AsTableType();
const TypeList* it = tt->Indices(); const TypeList* it = tt->GetIndices().get();
for ( const auto& expr : exprs ) for ( const auto& expr : exprs )
{ {

View file

@ -230,7 +230,7 @@ int IndexType::MatchesIndex(ListExpr* const index) const
exprs.length() == 1 && exprs[0]->GetType()->Tag() == TYPE_ADDR ) exprs.length() == 1 && exprs[0]->GetType()->Tag() == TYPE_ADDR )
return MATCHES_INDEX_SCALAR; 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; 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() ) if ( t1->IsSet() )
return same_type(t1->AsSetType()->Indices(), t2, true); return same_type(t1->AsSetType()->GetIndices().get(), t2, true);
return false; 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* it1 = (const IndexType*) t1;
const IndexType* it2 = (const IndexType*) t2; const IndexType* it2 = (const IndexType*) t2;
TypeList* tl1 = it1->Indices(); const auto& tl1 = it1->GetIndices();
TypeList* tl2 = it2->Indices(); const auto& tl2 = it2->GetIndices();
if ( tl1 || tl2 ) 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; return false;
} }
@ -1981,11 +1981,12 @@ static BroType* reduce_type(BroType* t)
else if ( t->IsSet() ) else if ( t->IsSet() )
{ {
TypeList* tl = t->AsTableType()->Indices(); const auto& tl = t->AsTableType()->GetIndices();
if ( tl->Types().size() == 1 ) if ( tl->Types().size() == 1 )
return tl->Types()[0].get(); return tl->Types()[0].get();
else else
return tl; return tl.get();
} }
else else

View file

@ -400,6 +400,10 @@ class IndexType : public BroType {
public: public:
int MatchesIndex(ListExpr* index) const override; int MatchesIndex(ListExpr* index) const override;
const IntrusivePtr<TypeList>& GetIndices() const
{ return indices; }
[[deprecated("Remove in v4.1. Use GetIndices().")]]
TypeList* Indices() const { return indices.get(); } TypeList* Indices() const { return indices.get(); }
const std::vector<IntrusivePtr<BroType>>& IndexTypes() const const std::vector<IntrusivePtr<BroType>>& IndexTypes() const

View file

@ -1358,7 +1358,7 @@ static void find_nested_record_types(BroType* t, std::set<RecordType*>* found)
} }
return; return;
case TYPE_TABLE: 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); find_nested_record_types(t->AsTableType()->Yield().get(), found);
return; return;
case TYPE_LIST: case TYPE_LIST:
@ -1416,8 +1416,7 @@ void TableVal::Init(IntrusivePtr<TableType> t)
else else
subnets = nullptr; subnets = nullptr;
table_hash = new CompositeHash(IntrusivePtr<TypeList>(NewRef{}, table_hash = new CompositeHash(table_type->GetIndices());
table_type->Indices()));
val.table_val = new PDict<TableEntryVal>; val.table_val = new PDict<TableEntryVal>;
val.table_val->SetDeleteFunc(table_entry_val_delete_func); val.table_val->SetDeleteFunc(table_entry_val_delete_func);
} }
@ -1520,7 +1519,7 @@ bool TableVal::Assign(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val)
if ( ! k ) 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; return false;
} }
@ -1777,7 +1776,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val)
ListVal* iv = index->AsListVal(); ListVal* iv = index->AsListVal();
if ( iv->BaseTag() != TYPE_ANY ) 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"); reporter->InternalError("bad singleton list index");
for ( int i = 0; i < iv->Length(); ++i ) for ( int i = 0; i < iv->Length(); ++i )
@ -2185,7 +2184,7 @@ ListVal* TableVal::ConvertToList(TypeTag t) const
IntrusivePtr<ListVal> TableVal::ToPureListVal() const IntrusivePtr<ListVal> TableVal::ToPureListVal() const
{ {
const auto& tl = table_type->Indices()->Types(); const auto& tl = table_type->GetIndices()->Types();
if ( tl.size() != 1 ) if ( tl.size() != 1 )
{ {
InternalWarning("bad index type in TableVal::ToPureListVal"); InternalWarning("bad index type in TableVal::ToPureListVal");
@ -2680,8 +2679,7 @@ TableVal::ParseTimeTableState TableVal::DumpTableState()
void TableVal::RebuildTable(ParseTimeTableState ptts) void TableVal::RebuildTable(ParseTimeTableState ptts)
{ {
delete table_hash; delete table_hash;
table_hash = new CompositeHash(IntrusivePtr<TypeList>(NewRef{}, table_hash = new CompositeHash(table_type->GetIndices());
table_type->Indices()));
for ( auto& [key, val] : ptts ) for ( auto& [key, val] : ptts )
Assign(std::move(key), std::move(val)); Assign(std::move(key), std::move(val));

View file

@ -213,7 +213,7 @@ struct val_converter {
for ( auto& item : a ) for ( auto& item : a )
{ {
const auto& expected_index_types = tt->Indices()->Types(); const auto& expected_index_types = tt->GetIndices()->Types();
broker::vector composite_key; broker::vector composite_key;
auto indices = caf::get_if<broker::vector>(&item); auto indices = caf::get_if<broker::vector>(&item);
@ -272,7 +272,7 @@ struct val_converter {
for ( auto& item : a ) for ( auto& item : a )
{ {
const auto& expected_index_types = tt->Indices()->Types(); const auto& expected_index_types = tt->GetIndices()->Types();
broker::vector composite_key; broker::vector composite_key;
auto indices = caf::get_if<broker::vector>(&item.first); auto indices = caf::get_if<broker::vector>(&item.first);
@ -560,7 +560,7 @@ struct type_checker {
for ( const auto& item : a ) 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<broker::vector>(&item); auto indices = caf::get_if<broker::vector>(&item);
vector<const broker::data*> indices_to_check; vector<const broker::data*> indices_to_check;
@ -619,7 +619,7 @@ struct type_checker {
for ( auto& item : a ) 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<broker::vector>(&item.first); auto indices = caf::get_if<broker::vector>(&item.first);
vector<const broker::data*> indices_to_check; vector<const broker::data*> indices_to_check;

View file

@ -808,7 +808,7 @@ bool Manager::IsCompatibleType(BroType* t, bool atomic_only)
if ( ! t->IsSet() ) if ( ! t->IsSet() )
return false; return false;
return IsCompatibleType(t->AsSetType()->Indices()->GetPureType().get(), true); return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true);
} }
case TYPE_VECTOR: case TYPE_VECTOR:
@ -937,7 +937,7 @@ bool Manager::UnrollRecordType(vector<Field*> *fields, const RecordType *rec,
bool optional = false; bool optional = false;
if ( ty == TYPE_TABLE ) 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 ) else if ( ty == TYPE_VECTOR )
st = rec->GetFieldType(i)->AsVectorType()->Yield()->Tag(); 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: case TYPE_TABLE:
{ {
// all entries have to have the same type... // 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<TypeList>(type); auto set_index = make_intrusive<TypeList>(type);
set_index->Append(type); set_index->Append(type);
auto s = make_intrusive<SetType>(std::move(set_index), nullptr); auto s = make_intrusive<SetType>(std::move(set_index), nullptr);

View file

@ -45,7 +45,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
TypeTag primary = id->GetType()->Tag(); TypeTag primary = id->GetType()->Tag();
TypeTag secondary = TYPE_VOID; TypeTag secondary = TYPE_VOID;
if ( primary == TYPE_TABLE ) if ( primary == TYPE_TABLE )
secondary = id->GetType()->AsSetType()->Indices()->GetPureType()->Tag(); secondary = id->GetType()->AsSetType()->GetIndices()->GetPureType()->Tag();
else if ( primary == TYPE_VECTOR ) else if ( primary == TYPE_VECTOR )
secondary = id->GetType()->AsVectorType()->Yield()->Tag(); secondary = id->GetType()->AsVectorType()->Yield()->Tag();

View file

@ -513,7 +513,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt,
TypeTag st = TYPE_VOID; TypeTag st = TYPE_VOID;
if ( t->Tag() == TYPE_TABLE ) if ( t->Tag() == TYPE_TABLE )
st = t->AsSetType()->Indices()->GetPureType()->Tag(); st = t->AsSetType()->GetIndices()->GetPureType()->Tag();
else if ( t->Tag() == TYPE_VECTOR ) else if ( t->Tag() == TYPE_VECTOR )
st = t->AsVectorType()->Yield()->Tag(); st = t->AsVectorType()->Yield()->Tag();

View file

@ -154,7 +154,7 @@ bool Value::IsCompatibleType(BroType* t, bool atomic_only)
if ( ! t->IsSet() ) if ( ! t->IsSet() )
return false; return false;
return IsCompatibleType(t->AsSetType()->Indices()->GetPureType().get(), true); return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true);
} }
case TYPE_VECTOR: case TYPE_VECTOR: