Deprecate SetType, as it can be replaced by TableType

This commit is contained in:
Vern Paxson 2025-09-15 13:42:40 -07:00 committed by Tim Wojtulewicz
parent b25a844210
commit b442c25389
13 changed files with 33 additions and 84 deletions

View file

@ -93,6 +93,10 @@ TableType* Type::AsTableType() {
return (TableType*)this;
}
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
const SetType* Type::AsSetType() const {
if ( ! IsSet() )
BadTag("Type::AsSetType", type_name(tag));
@ -104,6 +108,9 @@ SetType* Type::AsSetType() {
BadTag("Type::AsSetType", type_name(tag));
return (SetType*)this;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
const RecordType* Type::AsRecordType() const {
CHECK_TYPE_TAG(TYPE_RECORD, "Type::AsRecordType");
@ -562,50 +569,6 @@ bool TableType::DoExpireCheck(const detail::AttrPtr& attr) {
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) {
is_managed = id ? ZVal::IsManagedType(id->GetType()) : false;
if ( ! is_managed )
@ -1891,7 +1854,7 @@ static bool is_init_compat(const Type& t1, const Type& t2) {
}
if ( t1.IsSet() )
return same_type(*t1.AsSetType()->GetIndices(), t2, true);
return same_type(*t1.AsTableType()->GetIndices(), t2, true);
return false;
}
@ -2331,10 +2294,7 @@ TypePtr merge_table_types(const Type* t1, const Type* t2) {
return nullptr;
}
if ( t1->IsSet() )
return make_intrusive<SetType>(std::move(tl3), nullptr);
else
return make_intrusive<TableType>(std::move(tl3), std::move(y3));
return make_intrusive<TableType>(std::move(tl3), std::move(y3));
}
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);
}
static SetTypePtr init_set_type(detail::ListExpr* l) {
static TableTypePtr init_set_type(detail::ListExpr* l) {
auto& elems = l->Exprs();
TypePtr index;
@ -2626,7 +2586,7 @@ static SetTypePtr init_set_type(detail::ListExpr* l) {
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) {