ID: Add AddAttr() helper

This is just a follow-up as code cleanup, but not required
to be backported to 5.1.
This commit is contained in:
Arne Welzel 2022-12-02 17:57:07 +01:00
parent ef920ef3f5
commit da5fdb2072
5 changed files with 13 additions and 17 deletions

View file

@ -883,9 +883,7 @@ function_ingredients::function_ingredients(ScopePtr scope, StmtPtr body,
if ( a->Tag() == ATTR_IS_USED ) if ( a->Tag() == ATTR_IS_USED )
{ {
// Associate this with the identifier, too. // Associate this with the identifier, too.
std::vector<AttrPtr> used_attr; id->AddAttr(make_intrusive<Attr>(ATTR_IS_USED));
used_attr.emplace_back(make_intrusive<Attr>(ATTR_IS_USED));
id->AddAttrs(make_intrusive<Attributes>(used_attr, nullptr, false, true));
break; break;
} }
} }

View file

@ -311,8 +311,7 @@ void ID::MakeDeprecated(ExprPtr deprecation)
if ( IsDeprecated() ) if ( IsDeprecated() )
return; return;
std::vector<AttrPtr> attrv{make_intrusive<Attr>(ATTR_DEPRECATED, std::move(deprecation))}; AddAttr(make_intrusive<Attr>(ATTR_DEPRECATED, std::move(deprecation)));
AddAttrs(make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal()));
} }
std::string ID::GetDeprecationWarning() const std::string ID::GetDeprecationWarning() const
@ -329,6 +328,13 @@ std::string ID::GetDeprecationWarning() const
return util::fmt("deprecated (%s): %s", Name(), result.c_str()); return util::fmt("deprecated (%s): %s", Name(), result.c_str());
} }
void ID::AddAttr(AttrPtr a, bool is_redef)
{
std::vector<AttrPtr> attrv{std::move(a)};
auto attrs = make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal());
AddAttrs(std::move(attrs), is_redef);
}
void ID::AddAttrs(AttributesPtr a, bool is_redef) void ID::AddAttrs(AttributesPtr a, bool is_redef)
{ {
if ( attrs ) if ( attrs )
@ -354,10 +360,7 @@ void ID::SetOption()
// option implied redefinable // option implied redefinable
if ( ! IsRedefinable() ) if ( ! IsRedefinable() )
{ AddAttr(make_intrusive<Attr>(ATTR_REDEF));
std::vector<AttrPtr> attrv{make_intrusive<Attr>(ATTR_REDEF)};
AddAttrs(make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal()));
}
} }
void ID::EvalFunc(ExprPtr ef, ExprPtr ev) void ID::EvalFunc(ExprPtr ef, ExprPtr ev)

View file

@ -116,6 +116,7 @@ public:
bool IsRedefinable() const; bool IsRedefinable() const;
void SetAttrs(AttributesPtr attr); void SetAttrs(AttributesPtr attr);
void AddAttr(AttrPtr a, bool is_redef = false);
void AddAttrs(AttributesPtr attr, bool is_redef = false); void AddAttrs(AttributesPtr attr, bool is_redef = false);
void RemoveAttr(AttrTag a); void RemoveAttr(AttrTag a);
void UpdateValAttrs(); void UpdateValAttrs();

View file

@ -181,9 +181,7 @@ RuleConditionEval::RuleConditionEval(const char* func)
"and a 'string' type", "and a 'string' type",
func); func);
std::vector<AttrPtr> attrv{make_intrusive<Attr>(ATTR_IS_USED, nullptr)}; id->AddAttr(make_intrusive<Attr>(ATTR_IS_USED));
id->AddAttrs(
make_intrusive<Attributes>(std::move(attrv), id->GetType(), false, id->IsGlobal()));
} }
} }

View file

@ -109,11 +109,7 @@ void activate_bodies__CPP(const char* fn, const char* module, bool exported, Typ
} }
if ( ! fg->GetAttr(ATTR_IS_USED) ) if ( ! fg->GetAttr(ATTR_IS_USED) )
{ fg->AddAttr(make_intrusive<Attr>(ATTR_IS_USED));
vector<AttrPtr> used_attr;
used_attr.emplace_back(make_intrusive<Attr>(ATTR_IS_USED));
fg->AddAttrs(make_intrusive<Attributes>(used_attr, nullptr, false, true));
}
auto v = fg->GetVal(); auto v = fg->GetVal();
if ( ! v ) if ( ! v )