Add support for parsing @lifetime attribute to specify lifetime dependencies on declarations

This commit is contained in:
Meghana Gupta
2024-09-01 00:36:37 -07:00
parent 854298ab3b
commit e61d87c01c
12 changed files with 200 additions and 8 deletions

View File

@@ -2011,6 +2011,8 @@ StringRef DeclAttribute::getAttrName() const {
} else {
return "_allowFeatureSuppression";
}
case DeclAttrKind::Lifetime:
return "lifetime";
}
llvm_unreachable("bad DeclAttrKind");
}
@@ -3040,6 +3042,24 @@ AllowFeatureSuppressionAttr *AllowFeatureSuppressionAttr::create(
AllowFeatureSuppressionAttr(atLoc, range, implicit, inverted, features);
}
LifetimeAttr::LifetimeAttr(SourceLoc atLoc, SourceRange baseRange,
bool implicit,
ArrayRef<LifetimeDependenceSpecifier> entries)
: DeclAttribute(DeclAttrKind::Lifetime, atLoc, baseRange, implicit),
NumEntries(entries.size()) {
std::copy(entries.begin(), entries.end(),
getTrailingObjects<LifetimeDependenceSpecifier>());
}
LifetimeAttr *
LifetimeAttr::create(ASTContext &context, SourceLoc atLoc,
SourceRange baseRange, bool implicit,
ArrayRef<LifetimeDependenceSpecifier> entries) {
unsigned size = totalSizeToAlloc<LifetimeDependenceSpecifier>(entries.size());
void *mem = context.Allocate(size, alignof(LifetimeDependenceSpecifier));
return new (mem) LifetimeAttr(atLoc, baseRange, implicit, entries);
}
void swift::simple_display(llvm::raw_ostream &out, const DeclAttribute *attr) {
if (attr)
attr->print(out);