mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 10:08:20 +00:00
Deprecate Attr::AttrExpr(), replace with GetExpr()
This commit is contained in:
parent
2ebc20a164
commit
97636e97a5
9 changed files with 39 additions and 34 deletions
22
src/Attr.cc
22
src/Attr.cc
|
@ -262,10 +262,10 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
{
|
{
|
||||||
bool is_add = a->Tag() == ATTR_ADD_FUNC;
|
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 )
|
if ( at->Tag() != TYPE_FUNC )
|
||||||
{
|
{
|
||||||
a->AttrExpr()->Error(
|
a->GetExpr()->Error(
|
||||||
is_add ?
|
is_add ?
|
||||||
"&add_func must be a function" :
|
"&add_func must be a function" :
|
||||||
"&delete_func must be a function");
|
"&delete_func must be a function");
|
||||||
|
@ -275,7 +275,7 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
FuncType* aft = at->AsFuncType();
|
FuncType* aft = at->AsFuncType();
|
||||||
if ( ! same_type(aft->Yield(), type) )
|
if ( ! same_type(aft->Yield(), type) )
|
||||||
{
|
{
|
||||||
a->AttrExpr()->Error(
|
a->GetExpr()->Error(
|
||||||
is_add ?
|
is_add ?
|
||||||
"&add_func function must yield same type as variable" :
|
"&add_func function must yield same type as variable" :
|
||||||
"&delete_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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& atype = a->AttrExpr()->GetType();
|
const auto& atype = a->GetExpr()->GetType();
|
||||||
|
|
||||||
if ( type->Tag() != TYPE_TABLE || (type->IsSet() && ! in_record) )
|
if ( type->Tag() != TYPE_TABLE || (type->IsSet() && ! in_record) )
|
||||||
{
|
{
|
||||||
|
@ -314,7 +314,7 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
// Ok.
|
// Ok.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
auto e = check_and_promote_expr(a->AttrExpr(), type.get());
|
auto e = check_and_promote_expr(a->GetExpr().get(), type.get());
|
||||||
|
|
||||||
if ( e )
|
if ( e )
|
||||||
{
|
{
|
||||||
|
@ -323,7 +323,7 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
a->AttrExpr()->Error("&default value has inconsistent type", type.get());
|
a->GetExpr()->Error("&default value has inconsistent type", type.get());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
// Ok.
|
// Ok.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
auto e = check_and_promote_expr(a->AttrExpr(), ytype.get());
|
auto e = check_and_promote_expr(a->GetExpr().get(), ytype.get());
|
||||||
|
|
||||||
if ( e )
|
if ( e )
|
||||||
{
|
{
|
||||||
|
@ -380,7 +380,7 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
|
|
||||||
if ( (atype->Tag() == TYPE_TABLE && atype->AsTableType()->IsUnspecifiedTable()) )
|
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 )
|
if ( e )
|
||||||
{
|
{
|
||||||
|
@ -446,7 +446,7 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Expr* expire_func = a->AttrExpr();
|
const auto& expire_func = a->GetExpr();
|
||||||
|
|
||||||
if ( expire_func->GetType()->Tag() != TYPE_FUNC )
|
if ( expire_func->GetType()->Tag() != TYPE_FUNC )
|
||||||
Error("&expire_func attribute is not a function");
|
Error("&expire_func attribute is not a function");
|
||||||
|
@ -493,7 +493,7 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
break;
|
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 )
|
if ( change_func->GetType()->Tag() != TYPE_FUNC || change_func->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION )
|
||||||
Error("&on_change attribute is not a function");
|
Error("&on_change attribute is not a function");
|
||||||
|
@ -588,7 +588,7 @@ void Attributes::CheckAttr(Attr* a)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& atype = a->AttrExpr()->GetType();
|
const auto& atype = a->GetExpr()->GetType();
|
||||||
|
|
||||||
if ( atype->Tag() != TYPE_STRING ) {
|
if ( atype->Tag() != TYPE_STRING ) {
|
||||||
Error("type column needs to have a string argument");
|
Error("type column needs to have a string argument");
|
||||||
|
|
|
@ -41,8 +41,13 @@ public:
|
||||||
~Attr() override;
|
~Attr() override;
|
||||||
|
|
||||||
attr_tag Tag() const { return tag; }
|
attr_tag Tag() const { return tag; }
|
||||||
|
|
||||||
|
[[deprecated("Remove in v4.1. Use GetExpr().")]]
|
||||||
Expr* AttrExpr() const { return expr.get(); }
|
Expr* AttrExpr() const { return expr.get(); }
|
||||||
|
|
||||||
|
const IntrusivePtr<Expr>& GetExpr() const
|
||||||
|
{ return expr; }
|
||||||
|
|
||||||
template<typename E>
|
template<typename E>
|
||||||
void SetAttrExpr(E&& e) { expr = std::forward<E>(e); }
|
void SetAttrExpr(E&& e) { expr = std::forward<E>(e); }
|
||||||
|
|
||||||
|
|
|
@ -2895,7 +2895,7 @@ IntrusivePtr<Val> FieldExpr::Fold(Val* v) const
|
||||||
const Attr* def_attr = td ? td->FindAttr(ATTR_DEFAULT) : nullptr;
|
const Attr* def_attr = td ? td->FindAttr(ATTR_DEFAULT) : nullptr;
|
||||||
|
|
||||||
if ( def_attr )
|
if ( def_attr )
|
||||||
return def_attr->AttrExpr()->Eval(nullptr);
|
return def_attr->GetExpr()->Eval(nullptr);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RuntimeError("field value missing");
|
RuntimeError("field value missing");
|
||||||
|
@ -3658,7 +3658,7 @@ IntrusivePtr<Val> RecordCoerceExpr::Fold(Val* v) const
|
||||||
map[i])->FindAttr(ATTR_DEFAULT);
|
map[i])->FindAttr(ATTR_DEFAULT);
|
||||||
|
|
||||||
if ( def )
|
if ( def )
|
||||||
rhs = def->AttrExpr()->Eval(nullptr);
|
rhs = def->GetExpr()->Eval(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(rhs || GetType()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_OPTIONAL));
|
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) )
|
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& def_type = def_val->GetType();
|
||||||
const auto& field_type = GetType()->AsRecordType()->GetFieldType(i);
|
const auto& field_type = GetType()->AsRecordType()->GetFieldType(i);
|
||||||
|
|
||||||
|
@ -5010,7 +5010,7 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
def_elements.push_front(def_attr->AttrExpr());
|
def_elements.push_front(def_attr->GetExpr().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( const auto& elem : def_elements )
|
for ( const auto& elem : def_elements )
|
||||||
|
|
|
@ -855,7 +855,7 @@ static int get_func_priority(const attr_list& attrs)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto v = a->AttrExpr()->Eval(nullptr);
|
auto v = a->GetExpr()->Eval(nullptr);
|
||||||
|
|
||||||
if ( ! v )
|
if ( ! v )
|
||||||
{
|
{
|
||||||
|
|
|
@ -213,7 +213,7 @@ void ID::SetVal(IntrusivePtr<Expr> ev, init_class c)
|
||||||
if ( ! a )
|
if ( ! a )
|
||||||
Internal("no add/delete function in ID::SetVal");
|
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
|
bool ID::IsRedefinable() const
|
||||||
|
@ -291,7 +291,7 @@ std::string ID::GetDeprecationWarning() const
|
||||||
Attr* depr_attr = FindAttr(ATTR_DEPRECATED);
|
Attr* depr_attr = FindAttr(ATTR_DEPRECATED);
|
||||||
if ( depr_attr )
|
if ( depr_attr )
|
||||||
{
|
{
|
||||||
ConstExpr* expr = static_cast<ConstExpr*>(depr_attr->AttrExpr());
|
auto expr = static_cast<ConstExpr*>(depr_attr->GetExpr().get());
|
||||||
if ( expr )
|
if ( expr )
|
||||||
{
|
{
|
||||||
StringVal* text = expr->Value()->AsStringVal();
|
StringVal* text = expr->Value()->AsStringVal();
|
||||||
|
|
|
@ -689,7 +689,7 @@ IntrusivePtr<Val> RecordType::FieldDefault(int field) const
|
||||||
|
|
||||||
const Attr* def_attr = td->attrs->FindAttr(ATTR_DEFAULT);
|
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
|
int RecordType::FieldOffset(const char* field) const
|
||||||
|
@ -1010,7 +1010,7 @@ string RecordType::GetFieldDeprecationWarning(int field, bool has_check) const
|
||||||
string result;
|
string result;
|
||||||
if ( const Attr* deprecation = decl->FindAttr(ATTR_DEPRECATED) )
|
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 )
|
if ( expr )
|
||||||
{
|
{
|
||||||
StringVal* text = expr->Value()->AsStringVal();
|
StringVal* text = expr->Value()->AsStringVal();
|
||||||
|
|
24
src/Val.cc
24
src/Val.cc
|
@ -1479,12 +1479,12 @@ void TableVal::SetAttrs(IntrusivePtr<Attributes> a)
|
||||||
Attr* ef = attrs->FindAttr(ATTR_EXPIRE_FUNC);
|
Attr* ef = attrs->FindAttr(ATTR_EXPIRE_FUNC);
|
||||||
|
|
||||||
if ( ef )
|
if ( ef )
|
||||||
expire_func = {NewRef{}, ef->AttrExpr()};
|
expire_func = ef->GetExpr();
|
||||||
|
|
||||||
auto cf = attrs->FindAttr(ATTR_ON_CHANGE);
|
auto cf = attrs->FindAttr(ATTR_ON_CHANGE);
|
||||||
|
|
||||||
if ( cf )
|
if ( cf )
|
||||||
change_func = {NewRef{}, cf->AttrExpr()};
|
change_func = cf->GetExpr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableVal::CheckExpireAttr(attr_tag at)
|
void TableVal::CheckExpireAttr(attr_tag at)
|
||||||
|
@ -1493,7 +1493,7 @@ void TableVal::CheckExpireAttr(attr_tag at)
|
||||||
|
|
||||||
if ( a )
|
if ( a )
|
||||||
{
|
{
|
||||||
expire_time = {NewRef{}, a->AttrExpr()};
|
expire_time = a->GetExpr();
|
||||||
|
|
||||||
if ( expire_time->GetType()->Tag() != TYPE_INTERVAL )
|
if ( expire_time->GetType()->Tag() != TYPE_INTERVAL )
|
||||||
{
|
{
|
||||||
|
@ -1821,21 +1821,21 @@ IntrusivePtr<Val> TableVal::Default(const IntrusivePtr<Val>& index)
|
||||||
if ( ! def_val )
|
if ( ! def_val )
|
||||||
{
|
{
|
||||||
const auto& ytype = GetType()->Yield();
|
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 &&
|
if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD &&
|
||||||
! same_type(dtype, ytype) &&
|
! same_type(dtype, ytype) &&
|
||||||
record_promotion_compatible(dtype->AsRecordType(),
|
record_promotion_compatible(dtype->AsRecordType(),
|
||||||
ytype->AsRecordType()) )
|
ytype->AsRecordType()) )
|
||||||
{
|
{
|
||||||
auto coerce = make_intrusive<RecordCoerceExpr>(
|
auto rt = cast_intrusive<RecordType>(ytype);
|
||||||
IntrusivePtr{NewRef{}, def_attr->AttrExpr()},
|
auto coerce = make_intrusive<RecordCoerceExpr>(def_attr->GetExpr(),
|
||||||
IntrusivePtr{NewRef{}, ytype->AsRecordType()});
|
std::move(rt));
|
||||||
def_val = coerce->Eval(nullptr);
|
def_val = coerce->Eval(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
def_val = def_attr->AttrExpr()->Eval(nullptr);
|
def_val = def_attr->GetExpr()->Eval(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! def_val )
|
if ( ! def_val )
|
||||||
|
@ -1847,7 +1847,7 @@ IntrusivePtr<Val> TableVal::Default(const IntrusivePtr<Val>& index)
|
||||||
if ( def_val->GetType()->Tag() != TYPE_FUNC ||
|
if ( def_val->GetType()->Tag() != TYPE_FUNC ||
|
||||||
same_type(def_val->GetType(), GetType()->Yield()) )
|
same_type(def_val->GetType(), GetType()->Yield()) )
|
||||||
{
|
{
|
||||||
if ( def_attr->AttrExpr()->IsConst() )
|
if ( def_attr->GetExpr()->IsConst() )
|
||||||
return def_val;
|
return def_val;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -2345,7 +2345,7 @@ void TableVal::InitDefaultFunc(Frame* f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto& ytype = GetType()->Yield();
|
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 &&
|
if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD &&
|
||||||
! same_type(dtype, ytype) &&
|
! same_type(dtype, ytype) &&
|
||||||
|
@ -2353,7 +2353,7 @@ void TableVal::InitDefaultFunc(Frame* f)
|
||||||
ytype->AsRecordType()) )
|
ytype->AsRecordType()) )
|
||||||
return; // TableVal::Default will handle this.
|
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)
|
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();
|
Attributes* a = rt->FieldDecl(i)->attrs.get();
|
||||||
Attr* def_attr = a ? a->FindAttr(ATTR_DEFAULT) : nullptr;
|
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;
|
const auto& type = rt->FieldDecl(i)->type;
|
||||||
|
|
||||||
if ( def && type->Tag() == TYPE_RECORD &&
|
if ( def && type->Tag() == TYPE_RECORD &&
|
||||||
|
|
|
@ -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) )
|
if ( Attr* depr_attr = find_attr(attrs, ATTR_DEPRECATED) )
|
||||||
id->MakeDeprecated({NewRef{}, depr_attr->AttrExpr()});
|
id->MakeDeprecated(depr_attr->GetExpr());
|
||||||
}
|
}
|
||||||
|
|
||||||
class OuterIDBindingFinder : public TraversalCallback {
|
class OuterIDBindingFinder : public TraversalCallback {
|
||||||
|
|
|
@ -944,7 +944,7 @@ bool Manager::UnrollRecordType(vector<Field*> *fields, const RecordType *rec,
|
||||||
{
|
{
|
||||||
// we have an annotation for the second column
|
// 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);
|
||||||
assert(c->GetType()->Tag() == TYPE_STRING);
|
assert(c->GetType()->Tag() == TYPE_STRING);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue