Deprecate Attr::AttrExpr(), replace with GetExpr()

This commit is contained in:
Jon Siwek 2020-05-26 12:13:56 -07:00
parent 2ebc20a164
commit 97636e97a5
9 changed files with 39 additions and 34 deletions

View file

@ -262,10 +262,10 @@ void Attributes::CheckAttr(Attr* a)
{
bool is_add = a->Tag() == ATTR_ADD_FUNC;
const auto& at = a->AttrExpr()->GetType();
const auto& at = a->GetExpr()->GetType();
if ( at->Tag() != TYPE_FUNC )
{
a->AttrExpr()->Error(
a->GetExpr()->Error(
is_add ?
"&add_func must be a function" :
"&delete_func must be a function");
@ -275,7 +275,7 @@ void Attributes::CheckAttr(Attr* a)
FuncType* aft = at->AsFuncType();
if ( ! same_type(aft->Yield(), type) )
{
a->AttrExpr()->Error(
a->GetExpr()->Error(
is_add ?
"&add_func function must yield same type as variable" :
"&delete_func function must yield same type as variable");
@ -294,7 +294,7 @@ void Attributes::CheckAttr(Attr* a)
break;
}
const auto& atype = a->AttrExpr()->GetType();
const auto& atype = a->GetExpr()->GetType();
if ( type->Tag() != TYPE_TABLE || (type->IsSet() && ! in_record) )
{
@ -314,7 +314,7 @@ void Attributes::CheckAttr(Attr* a)
// Ok.
break;
auto e = check_and_promote_expr(a->AttrExpr(), type.get());
auto e = check_and_promote_expr(a->GetExpr().get(), type.get());
if ( e )
{
@ -323,7 +323,7 @@ void Attributes::CheckAttr(Attr* a)
break;
}
a->AttrExpr()->Error("&default value has inconsistent type", type.get());
a->GetExpr()->Error("&default value has inconsistent type", type.get());
return;
}
@ -354,7 +354,7 @@ void Attributes::CheckAttr(Attr* a)
// Ok.
break;
auto e = check_and_promote_expr(a->AttrExpr(), ytype.get());
auto e = check_and_promote_expr(a->GetExpr().get(), ytype.get());
if ( e )
{
@ -380,7 +380,7 @@ void Attributes::CheckAttr(Attr* a)
if ( (atype->Tag() == TYPE_TABLE && atype->AsTableType()->IsUnspecifiedTable()) )
{
auto e = check_and_promote_expr(a->AttrExpr(), type.get());
auto e = check_and_promote_expr(a->GetExpr().get(), type.get());
if ( e )
{
@ -446,7 +446,7 @@ void Attributes::CheckAttr(Attr* a)
break;
}
const Expr* expire_func = a->AttrExpr();
const auto& expire_func = a->GetExpr();
if ( expire_func->GetType()->Tag() != TYPE_FUNC )
Error("&expire_func attribute is not a function");
@ -493,7 +493,7 @@ void Attributes::CheckAttr(Attr* a)
break;
}
const Expr* change_func = a->AttrExpr();
const auto& change_func = a->GetExpr();
if ( change_func->GetType()->Tag() != TYPE_FUNC || change_func->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION )
Error("&on_change attribute is not a function");
@ -588,7 +588,7 @@ void Attributes::CheckAttr(Attr* a)
break;
}
const auto& atype = a->AttrExpr()->GetType();
const auto& atype = a->GetExpr()->GetType();
if ( atype->Tag() != TYPE_STRING ) {
Error("type column needs to have a string argument");

View file

@ -41,8 +41,13 @@ public:
~Attr() override;
attr_tag Tag() const { return tag; }
[[deprecated("Remove in v4.1. Use GetExpr().")]]
Expr* AttrExpr() const { return expr.get(); }
const IntrusivePtr<Expr>& GetExpr() const
{ return expr; }
template<typename E>
void SetAttrExpr(E&& e) { expr = std::forward<E>(e); }

View file

@ -2895,7 +2895,7 @@ IntrusivePtr<Val> FieldExpr::Fold(Val* v) const
const Attr* def_attr = td ? td->FindAttr(ATTR_DEFAULT) : nullptr;
if ( def_attr )
return def_attr->AttrExpr()->Eval(nullptr);
return def_attr->GetExpr()->Eval(nullptr);
else
{
RuntimeError("field value missing");
@ -3658,7 +3658,7 @@ IntrusivePtr<Val> RecordCoerceExpr::Fold(Val* v) const
map[i])->FindAttr(ATTR_DEFAULT);
if ( def )
rhs = def->AttrExpr()->Eval(nullptr);
rhs = def->GetExpr()->Eval(nullptr);
}
assert(rhs || GetType()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_OPTIONAL));
@ -3695,7 +3695,7 @@ IntrusivePtr<Val> RecordCoerceExpr::Fold(Val* v) const
{
if ( const Attr* def = GetType()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_DEFAULT) )
{
auto def_val = def->AttrExpr()->Eval(nullptr);
auto def_val = def->GetExpr()->Eval(nullptr);
const auto& def_type = def_val->GetType();
const auto& field_type = GetType()->AsRecordType()->GetFieldType(i);
@ -5010,7 +5010,7 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types)
return false;
}
def_elements.push_front(def_attr->AttrExpr());
def_elements.push_front(def_attr->GetExpr().get());
}
for ( const auto& elem : def_elements )

View file

@ -855,7 +855,7 @@ static int get_func_priority(const attr_list& attrs)
continue;
}
auto v = a->AttrExpr()->Eval(nullptr);
auto v = a->GetExpr()->Eval(nullptr);
if ( ! v )
{

View file

@ -213,7 +213,7 @@ void ID::SetVal(IntrusivePtr<Expr> ev, init_class c)
if ( ! a )
Internal("no add/delete function in ID::SetVal");
EvalFunc({NewRef{}, a->AttrExpr()}, std::move(ev));
EvalFunc(a->GetExpr(), std::move(ev));
}
bool ID::IsRedefinable() const
@ -291,7 +291,7 @@ std::string ID::GetDeprecationWarning() const
Attr* depr_attr = FindAttr(ATTR_DEPRECATED);
if ( depr_attr )
{
ConstExpr* expr = static_cast<ConstExpr*>(depr_attr->AttrExpr());
auto expr = static_cast<ConstExpr*>(depr_attr->GetExpr().get());
if ( expr )
{
StringVal* text = expr->Value()->AsStringVal();

View file

@ -689,7 +689,7 @@ IntrusivePtr<Val> RecordType::FieldDefault(int field) const
const Attr* def_attr = td->attrs->FindAttr(ATTR_DEFAULT);
return def_attr ? def_attr->AttrExpr()->Eval(nullptr) : nullptr;
return def_attr ? def_attr->GetExpr()->Eval(nullptr) : nullptr;
}
int RecordType::FieldOffset(const char* field) const
@ -1010,7 +1010,7 @@ string RecordType::GetFieldDeprecationWarning(int field, bool has_check) const
string result;
if ( const Attr* deprecation = decl->FindAttr(ATTR_DEPRECATED) )
{
ConstExpr* expr = static_cast<ConstExpr*>(deprecation->AttrExpr());
auto expr = static_cast<ConstExpr*>(deprecation->GetExpr().get());
if ( expr )
{
StringVal* text = expr->Value()->AsStringVal();

View file

@ -1479,12 +1479,12 @@ void TableVal::SetAttrs(IntrusivePtr<Attributes> a)
Attr* ef = attrs->FindAttr(ATTR_EXPIRE_FUNC);
if ( ef )
expire_func = {NewRef{}, ef->AttrExpr()};
expire_func = ef->GetExpr();
auto cf = attrs->FindAttr(ATTR_ON_CHANGE);
if ( cf )
change_func = {NewRef{}, cf->AttrExpr()};
change_func = cf->GetExpr();
}
void TableVal::CheckExpireAttr(attr_tag at)
@ -1493,7 +1493,7 @@ void TableVal::CheckExpireAttr(attr_tag at)
if ( a )
{
expire_time = {NewRef{}, a->AttrExpr()};
expire_time = a->GetExpr();
if ( expire_time->GetType()->Tag() != TYPE_INTERVAL )
{
@ -1821,21 +1821,21 @@ IntrusivePtr<Val> TableVal::Default(const IntrusivePtr<Val>& index)
if ( ! def_val )
{
const auto& ytype = GetType()->Yield();
const auto& dtype = def_attr->AttrExpr()->GetType();
const auto& dtype = def_attr->GetExpr()->GetType();
if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD &&
! same_type(dtype, ytype) &&
record_promotion_compatible(dtype->AsRecordType(),
ytype->AsRecordType()) )
{
auto coerce = make_intrusive<RecordCoerceExpr>(
IntrusivePtr{NewRef{}, def_attr->AttrExpr()},
IntrusivePtr{NewRef{}, ytype->AsRecordType()});
auto rt = cast_intrusive<RecordType>(ytype);
auto coerce = make_intrusive<RecordCoerceExpr>(def_attr->GetExpr(),
std::move(rt));
def_val = coerce->Eval(nullptr);
}
else
def_val = def_attr->AttrExpr()->Eval(nullptr);
def_val = def_attr->GetExpr()->Eval(nullptr);
}
if ( ! def_val )
@ -1847,7 +1847,7 @@ IntrusivePtr<Val> TableVal::Default(const IntrusivePtr<Val>& index)
if ( def_val->GetType()->Tag() != TYPE_FUNC ||
same_type(def_val->GetType(), GetType()->Yield()) )
{
if ( def_attr->AttrExpr()->IsConst() )
if ( def_attr->GetExpr()->IsConst() )
return def_val;
try
@ -2345,7 +2345,7 @@ void TableVal::InitDefaultFunc(Frame* f)
return;
const auto& ytype = GetType()->Yield();
const auto& dtype = def_attr->AttrExpr()->GetType();
const auto& dtype = def_attr->GetExpr()->GetType();
if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD &&
! same_type(dtype, ytype) &&
@ -2353,7 +2353,7 @@ void TableVal::InitDefaultFunc(Frame* f)
ytype->AsRecordType()) )
return; // TableVal::Default will handle this.
def_val = def_attr->AttrExpr()->Eval(f);
def_val = def_attr->GetExpr()->Eval(f);
}
void TableVal::InitTimer(double delay)
@ -2715,7 +2715,7 @@ RecordVal::RecordVal(IntrusivePtr<RecordType> t, bool init_fields) : Val(std::mo
{
Attributes* a = rt->FieldDecl(i)->attrs.get();
Attr* def_attr = a ? a->FindAttr(ATTR_DEFAULT) : nullptr;
auto def = def_attr ? def_attr->AttrExpr()->Eval(nullptr) : nullptr;
auto def = def_attr ? def_attr->GetExpr()->Eval(nullptr) : nullptr;
const auto& type = rt->FieldDecl(i)->type;
if ( def && type->Tag() == TYPE_RECORD &&

View file

@ -574,7 +574,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
}
if ( Attr* depr_attr = find_attr(attrs, ATTR_DEPRECATED) )
id->MakeDeprecated({NewRef{}, depr_attr->AttrExpr()});
id->MakeDeprecated(depr_attr->GetExpr());
}
class OuterIDBindingFinder : public TraversalCallback {

View file

@ -944,7 +944,7 @@ bool Manager::UnrollRecordType(vector<Field*> *fields, const RecordType *rec,
{
// we have an annotation for the second column
c = rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN)->AttrExpr()->Eval(nullptr);
c = rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN)->GetExpr()->Eval(nullptr);
assert(c);
assert(c->GetType()->Tag() == TYPE_STRING);