diff --git a/src/Attr.cc b/src/Attr.cc index 093e2d7f28..9536be2554 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -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"); diff --git a/src/Attr.h b/src/Attr.h index 7271bdd1f6..7e050d1a49 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -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& GetExpr() const + { return expr; } + template void SetAttrExpr(E&& e) { expr = std::forward(e); } diff --git a/src/Expr.cc b/src/Expr.cc index 93c5d8f84e..c2a22bb3cc 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2895,7 +2895,7 @@ IntrusivePtr 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 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 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 ) diff --git a/src/Func.cc b/src/Func.cc index b35736db92..18875ff742 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -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 ) { diff --git a/src/ID.cc b/src/ID.cc index e39de42804..87185eb4e9 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -213,7 +213,7 @@ void ID::SetVal(IntrusivePtr 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(depr_attr->AttrExpr()); + auto expr = static_cast(depr_attr->GetExpr().get()); if ( expr ) { StringVal* text = expr->Value()->AsStringVal(); diff --git a/src/Type.cc b/src/Type.cc index 7260c4194c..1c204ec052 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -689,7 +689,7 @@ IntrusivePtr 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(deprecation->AttrExpr()); + auto expr = static_cast(deprecation->GetExpr().get()); if ( expr ) { StringVal* text = expr->Value()->AsStringVal(); diff --git a/src/Val.cc b/src/Val.cc index 4fa0733091..f541cfd61a 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1479,12 +1479,12 @@ void TableVal::SetAttrs(IntrusivePtr 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 TableVal::Default(const IntrusivePtr& 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( - IntrusivePtr{NewRef{}, def_attr->AttrExpr()}, - IntrusivePtr{NewRef{}, ytype->AsRecordType()}); + auto rt = cast_intrusive(ytype); + auto coerce = make_intrusive(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 TableVal::Default(const IntrusivePtr& 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 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 && diff --git a/src/Var.cc b/src/Var.cc index 0665169abc..47d34307c6 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -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 { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 88b30f098f..1dc1a0beb5 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -944,7 +944,7 @@ bool Manager::UnrollRecordType(vector *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);