mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Deprecate SetType, as it can be replaced by TableType
This commit is contained in:
parent
b25a844210
commit
b442c25389
13 changed files with 33 additions and 84 deletions
|
@ -1410,7 +1410,7 @@ TableValPtr DNS_Mgr::empty_addr_set() {
|
||||||
auto addr_t = base_type(TYPE_ADDR);
|
auto addr_t = base_type(TYPE_ADDR);
|
||||||
auto set_index = make_intrusive<TypeList>(addr_t);
|
auto set_index = make_intrusive<TypeList>(addr_t);
|
||||||
set_index->Append(std::move(addr_t));
|
set_index->Append(std::move(addr_t));
|
||||||
auto s = make_intrusive<SetType>(std::move(set_index), nullptr);
|
auto s = make_intrusive<TableType>(std::move(set_index), nullptr);
|
||||||
return make_intrusive<TableVal>(std::move(s));
|
return make_intrusive<TableVal>(std::move(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3366,7 +3366,7 @@ SetConstructorExpr::SetConstructorExpr(ListExprPtr constructor_list, std::unique
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( op->AsListExpr()->Exprs().empty() )
|
if ( op->AsListExpr()->Exprs().empty() )
|
||||||
SetType(make_intrusive<zeek::SetType>(make_intrusive<TypeList>(base_type(TYPE_ANY)), nullptr));
|
SetType(make_intrusive<TableType>(make_intrusive<TypeList>(base_type(TYPE_ANY)), nullptr));
|
||||||
else
|
else
|
||||||
SetType(init_type(op));
|
SetType(init_type(op));
|
||||||
}
|
}
|
||||||
|
@ -4626,7 +4626,7 @@ TypePtr ListExpr::InitType() const {
|
||||||
|
|
||||||
// Collapse any embedded sets or lists.
|
// Collapse any embedded sets or lists.
|
||||||
if ( ti->IsSet() || ti->Tag() == TYPE_LIST ) {
|
if ( ti->IsSet() || ti->Tag() == TYPE_LIST ) {
|
||||||
TypeList* til = ti->IsSet() ? ti->AsSetType()->GetIndices().get() : ti->AsTypeList();
|
TypeList* til = ti->IsSet() ? ti->AsTableType()->GetIndices().get() : ti->AsTypeList();
|
||||||
|
|
||||||
if ( ! til->IsPure() || ! til->AllMatch(til->GetPureType(), true) )
|
if ( ! til->IsPure() || ! til->AllMatch(til->GetPureType(), true) )
|
||||||
tl->Append({NewRef{}, til});
|
tl->Append({NewRef{}, til});
|
||||||
|
|
62
src/Type.cc
62
src/Type.cc
|
@ -93,6 +93,10 @@ TableType* Type::AsTableType() {
|
||||||
return (TableType*)this;
|
return (TableType*)this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
#endif
|
||||||
const SetType* Type::AsSetType() const {
|
const SetType* Type::AsSetType() const {
|
||||||
if ( ! IsSet() )
|
if ( ! IsSet() )
|
||||||
BadTag("Type::AsSetType", type_name(tag));
|
BadTag("Type::AsSetType", type_name(tag));
|
||||||
|
@ -104,6 +108,9 @@ SetType* Type::AsSetType() {
|
||||||
BadTag("Type::AsSetType", type_name(tag));
|
BadTag("Type::AsSetType", type_name(tag));
|
||||||
return (SetType*)this;
|
return (SetType*)this;
|
||||||
}
|
}
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
const RecordType* Type::AsRecordType() const {
|
const RecordType* Type::AsRecordType() const {
|
||||||
CHECK_TYPE_TAG(TYPE_RECORD, "Type::AsRecordType");
|
CHECK_TYPE_TAG(TYPE_RECORD, "Type::AsRecordType");
|
||||||
|
@ -562,50 +569,6 @@ bool TableType::DoExpireCheck(const detail::AttrPtr& attr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetType::SetType(TypeListPtr ind, detail::ListExprPtr arg_elements)
|
|
||||||
: TableType(std::move(ind), nullptr), elements(std::move(arg_elements)) {
|
|
||||||
if ( elements ) {
|
|
||||||
if ( indices ) { // We already have a type.
|
|
||||||
if ( ! check_and_promote_exprs(elements.get(), indices) )
|
|
||||||
SetError();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TypeList* tl_type = elements->GetType()->AsTypeList();
|
|
||||||
const auto& tl = tl_type->GetTypes();
|
|
||||||
|
|
||||||
if ( tl.size() < 1 ) {
|
|
||||||
Error("no type given for set");
|
|
||||||
SetError();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if ( tl.size() == 1 ) {
|
|
||||||
TypePtr ft{NewRef{}, flatten_type(tl[0].get())};
|
|
||||||
indices = make_intrusive<TypeList>(ft);
|
|
||||||
indices->Append(std::move(ft));
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
auto t = merge_types(tl[0], tl[1]);
|
|
||||||
|
|
||||||
for ( size_t i = 2; t && i < tl.size(); ++i )
|
|
||||||
t = merge_types(t, tl[i]);
|
|
||||||
|
|
||||||
if ( ! t ) {
|
|
||||||
Error("bad set type");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
indices = make_intrusive<TypeList>(t);
|
|
||||||
indices->Append(std::move(t));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TypePtr SetType::ShallowClone() { return make_intrusive<SetType>(indices, elements); }
|
|
||||||
|
|
||||||
SetType::~SetType() = default;
|
|
||||||
|
|
||||||
FuncType::Capture::Capture(detail::IDPtr _id, bool _deep_copy) : id(std::move(_id)), deep_copy(_deep_copy) {
|
FuncType::Capture::Capture(detail::IDPtr _id, bool _deep_copy) : id(std::move(_id)), deep_copy(_deep_copy) {
|
||||||
is_managed = id ? ZVal::IsManagedType(id->GetType()) : false;
|
is_managed = id ? ZVal::IsManagedType(id->GetType()) : false;
|
||||||
if ( ! is_managed )
|
if ( ! is_managed )
|
||||||
|
@ -1891,7 +1854,7 @@ static bool is_init_compat(const Type& t1, const Type& t2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( t1.IsSet() )
|
if ( t1.IsSet() )
|
||||||
return same_type(*t1.AsSetType()->GetIndices(), t2, true);
|
return same_type(*t1.AsTableType()->GetIndices(), t2, true);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2331,10 +2294,7 @@ TypePtr merge_table_types(const Type* t1, const Type* t2) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( t1->IsSet() )
|
return make_intrusive<TableType>(std::move(tl3), std::move(y3));
|
||||||
return make_intrusive<SetType>(std::move(tl3), nullptr);
|
|
||||||
else
|
|
||||||
return make_intrusive<TableType>(std::move(tl3), std::move(y3));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypePtr merge_func_types(const Type* t1, const Type* t2) {
|
TypePtr merge_func_types(const Type* t1, const Type* t2) {
|
||||||
|
@ -2599,7 +2559,7 @@ static TableTypePtr init_table_type(detail::ListExpr* l) {
|
||||||
return make_intrusive<TableType>(cast_intrusive<TypeList>(index), yield);
|
return make_intrusive<TableType>(cast_intrusive<TypeList>(index), yield);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SetTypePtr init_set_type(detail::ListExpr* l) {
|
static TableTypePtr init_set_type(detail::ListExpr* l) {
|
||||||
auto& elems = l->Exprs();
|
auto& elems = l->Exprs();
|
||||||
TypePtr index;
|
TypePtr index;
|
||||||
|
|
||||||
|
@ -2626,7 +2586,7 @@ static SetTypePtr init_set_type(detail::ListExpr* l) {
|
||||||
ind_list->Append(index);
|
ind_list->Append(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return make_intrusive<SetType>(ind_list, nullptr);
|
return make_intrusive<TableType>(ind_list, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TypePtr init_type(const detail::ExprPtr& init) {
|
TypePtr init_type(const detail::ExprPtr& init) {
|
||||||
|
|
|
@ -214,7 +214,10 @@ public:
|
||||||
const TableType* AsTableType() const;
|
const TableType* AsTableType() const;
|
||||||
TableType* AsTableType();
|
TableType* AsTableType();
|
||||||
|
|
||||||
|
[[deprecated("Remove in v9.1. Use AsTableType() instead.")]]
|
||||||
const SetType* AsSetType() const;
|
const SetType* AsSetType() const;
|
||||||
|
|
||||||
|
[[deprecated("Remove in v9.1. Use AsTableType() instead.")]]
|
||||||
SetType* AsSetType();
|
SetType* AsSetType();
|
||||||
|
|
||||||
const RecordType* AsRecordType() const;
|
const RecordType* AsRecordType() const;
|
||||||
|
@ -438,7 +441,7 @@ private:
|
||||||
bool reported_error = false;
|
bool reported_error = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetType final : public TableType {
|
class [[deprecated("Remove in v9.1. Use TableType instead.")]] SetType final : public TableType {
|
||||||
public:
|
public:
|
||||||
SetType(TypeListPtr ind, detail::ListExprPtr arg_elements);
|
SetType(TypeListPtr ind, detail::ListExprPtr arg_elements);
|
||||||
~SetType() override;
|
~SetType() override;
|
||||||
|
|
10
src/Val.cc
10
src/Val.cc
|
@ -1436,7 +1436,7 @@ TableValPtr ListVal::ToSetVal() const {
|
||||||
const auto& pt = type->AsTypeList()->GetPureType();
|
const auto& pt = type->AsTypeList()->GetPureType();
|
||||||
auto set_index = make_intrusive<TypeList>(pt);
|
auto set_index = make_intrusive<TypeList>(pt);
|
||||||
set_index->Append(base_type(tag));
|
set_index->Append(base_type(tag));
|
||||||
auto s = make_intrusive<SetType>(std::move(set_index), nullptr);
|
auto s = make_intrusive<TableType>(std::move(set_index), nullptr);
|
||||||
auto t = make_intrusive<TableVal>(std::move(s));
|
auto t = make_intrusive<TableVal>(std::move(s));
|
||||||
|
|
||||||
for ( const auto& val : vals )
|
for ( const auto& val : vals )
|
||||||
|
@ -3915,7 +3915,7 @@ ValPtr cast_value_to_type(Val* v, Type* t) {
|
||||||
|
|
||||||
// Allow casting between sets and vectors if the yield types are the same.
|
// Allow casting between sets and vectors if the yield types are the same.
|
||||||
if ( v->GetType()->IsSet() && IsVector(t->Tag()) ) {
|
if ( v->GetType()->IsSet() && IsVector(t->Tag()) ) {
|
||||||
auto set_type = v->GetType<SetType>();
|
auto set_type = v->GetType<TableType>();
|
||||||
auto indices = set_type->GetIndices();
|
auto indices = set_type->GetIndices();
|
||||||
|
|
||||||
if ( indices->GetTypes().size() > 1 )
|
if ( indices->GetTypes().size() > 1 )
|
||||||
|
@ -3938,7 +3938,7 @@ ValPtr cast_value_to_type(Val* v, Type* t) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else if ( IsVector(v->GetType()->Tag()) && t->IsSet() ) {
|
else if ( IsVector(v->GetType()->Tag()) && t->IsSet() ) {
|
||||||
auto ret_type = IntrusivePtr<TableType>{NewRef{}, t->AsSetType()};
|
auto ret_type = IntrusivePtr<TableType>{NewRef{}, t->AsTableType()};
|
||||||
auto ret = make_intrusive<TableVal>(ret_type);
|
auto ret = make_intrusive<TableVal>(ret_type);
|
||||||
|
|
||||||
auto vv = v->AsVectorVal();
|
auto vv = v->AsVectorVal();
|
||||||
|
@ -3960,11 +3960,11 @@ static bool can_cast_set_and_vector(const Type* t1, const Type* t2) {
|
||||||
const VectorType* vt = nullptr;
|
const VectorType* vt = nullptr;
|
||||||
|
|
||||||
if ( t1->IsSet() && IsVector(t2->Tag()) ) {
|
if ( t1->IsSet() && IsVector(t2->Tag()) ) {
|
||||||
st = t1->AsSetType();
|
st = t1->AsTableType();
|
||||||
vt = t2->AsVectorType();
|
vt = t2->AsVectorType();
|
||||||
}
|
}
|
||||||
else if ( IsVector(t1->Tag()) && t2->IsSet() ) {
|
else if ( IsVector(t1->Tag()) && t2->IsSet() ) {
|
||||||
st = t2->AsSetType();
|
st = t2->AsTableType();
|
||||||
vt = t1->AsVectorType();
|
vt = t1->AsVectorType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
src/Var.cc
14
src/Var.cc
|
@ -216,20 +216,6 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init, std:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( t && t->IsSet() ) { // Check for set with explicit elements.
|
|
||||||
SetType* st = t->AsTableType()->AsSetType();
|
|
||||||
const auto& elements = st->Elements();
|
|
||||||
|
|
||||||
if ( elements ) {
|
|
||||||
if ( init ) {
|
|
||||||
id->Error("double initialization", init.get());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
init = elements;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! t ) { // Take type from initialization.
|
if ( ! t ) { // Take type from initialization.
|
||||||
if ( ! init ) {
|
if ( ! init ) {
|
||||||
id->Error("no type given");
|
id->Error("no type given");
|
||||||
|
|
|
@ -20,7 +20,7 @@ static bool is_string_set(const zeek::Type* type)
|
||||||
if ( ! type->IsSet() )
|
if ( ! type->IsSet() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto& index_types = type->AsSetType()->GetIndexTypes();
|
const auto& index_types = type->AsTableType()->GetIndexTypes();
|
||||||
|
|
||||||
if ( index_types.size() != 1 )
|
if ( index_types.size() != 1 )
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -789,7 +789,7 @@ bool Manager::IsCompatibleType(Type* t, bool atomic_only) {
|
||||||
if ( ! t->IsSet() )
|
if ( ! t->IsSet() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto& indices = t->AsSetType()->GetIndices();
|
const auto& indices = t->AsTableType()->GetIndices();
|
||||||
|
|
||||||
if ( indices->GetTypes().size() != 1 )
|
if ( indices->GetTypes().size() != 1 )
|
||||||
return false;
|
return false;
|
||||||
|
@ -902,7 +902,7 @@ bool Manager::UnrollRecordType(vector<Field*>* fields, const RecordType* rec, co
|
||||||
bool optional = false;
|
bool optional = false;
|
||||||
|
|
||||||
if ( ty == TYPE_TABLE )
|
if ( ty == TYPE_TABLE )
|
||||||
st = rec->GetFieldType(i)->AsSetType()->GetIndices()->GetPureType()->Tag();
|
st = rec->GetFieldType(i)->AsTableType()->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();
|
||||||
|
@ -2084,7 +2084,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, Type* request_type,
|
||||||
const auto& type = request_type->AsTableType()->GetIndices()->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<TableType>(std::move(set_index), nullptr);
|
||||||
auto t = make_intrusive<TableVal>(std::move(s));
|
auto t = make_intrusive<TableVal>(std::move(s));
|
||||||
for ( int j = 0; j < val->val.set_val.size; j++ ) {
|
for ( int j = 0; j < val->val.set_val.size; j++ ) {
|
||||||
Val* assignval = ValueToVal(i, val->val.set_val.vals[j], type.get(), have_error);
|
Val* assignval = ValueToVal(i, val->val.set_val.vals[j], type.get(), have_error);
|
||||||
|
|
|
@ -41,7 +41,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()->GetIndices()->GetPureType()->Tag();
|
secondary = id->GetType()->AsTableType()->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();
|
||||||
|
|
||||||
|
|
|
@ -852,7 +852,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, Tab
|
||||||
TypeTag st = TYPE_VOID;
|
TypeTag st = TYPE_VOID;
|
||||||
|
|
||||||
if ( t->Tag() == TYPE_TABLE )
|
if ( t->Tag() == TYPE_TABLE )
|
||||||
st = t->AsSetType()->GetIndices()->GetPureType()->Tag();
|
st = t->AsTableType()->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();
|
||||||
|
|
|
@ -1211,7 +1211,7 @@ simple_type:
|
||||||
| TOK_SET '[' type_list ']'
|
| TOK_SET '[' type_list ']'
|
||||||
{
|
{
|
||||||
set_location(@1, @4);
|
set_location(@1, @4);
|
||||||
$$ = new SetType({AdoptRef{}, $3}, nullptr);
|
$$ = new TableType({AdoptRef{}, $3}, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_RECORD '{'
|
| TOK_RECORD '{'
|
||||||
|
|
|
@ -186,7 +186,7 @@ bool Value::IsCompatibleType(Type* t, bool atomic_only) {
|
||||||
if ( ! t->IsSet() )
|
if ( ! t->IsSet() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true);
|
return IsCompatibleType(t->AsTableType()->GetIndices()->GetPureType().get(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
case TYPE_VECTOR: {
|
case TYPE_VECTOR: {
|
||||||
|
@ -518,7 +518,7 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e
|
||||||
set_index->Append(std::move(index_type));
|
set_index->Append(std::move(index_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto s = make_intrusive<SetType>(std::move(set_index), nullptr);
|
auto s = make_intrusive<TableType>(std::move(set_index), nullptr);
|
||||||
auto t = make_intrusive<TableVal>(std::move(s));
|
auto t = make_intrusive<TableVal>(std::move(s));
|
||||||
for ( int j = 0; j < val->val.set_val.size; j++ ) {
|
for ( int j = 0; j < val->val.set_val.size; j++ ) {
|
||||||
Val* assignval = ValueToVal(source, val->val.set_val.vals[j], have_error);
|
Val* assignval = ValueToVal(source, val->val.set_val.vals[j], have_error);
|
||||||
|
|
|
@ -1437,7 +1437,7 @@ function table_keys%(t: any%): any
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tl = t->GetType()->AsTableType()->GetIndices();
|
auto tl = t->GetType()->AsTableType()->GetIndices();
|
||||||
auto st = zeek::make_intrusive<zeek::SetType>(std::move(tl), nullptr);
|
auto st = zeek::make_intrusive<zeek::TableType>(std::move(tl), nullptr);
|
||||||
auto sv = zeek::make_intrusive<zeek::TableVal>(std::move(st));
|
auto sv = zeek::make_intrusive<zeek::TableVal>(std::move(st));
|
||||||
auto th = t->AsTableVal()->GetTableHash();
|
auto th = t->AsTableVal()->GetTableHash();
|
||||||
for ( const auto& iter : *t->AsTable() )
|
for ( const auto& iter : *t->AsTable() )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue