mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add support for parsing @lifetime attribute to specify lifetime dependencies on declarations
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "swift/AST/DeclNameLoc.h"
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include "swift/AST/KnownProtocols.h"
|
||||
#include "swift/AST/LifetimeDependence.h"
|
||||
#include "swift/AST/MacroDeclaration.h"
|
||||
#include "swift/AST/Ownership.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
@@ -2627,6 +2628,27 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class LifetimeAttr final
|
||||
: public DeclAttribute,
|
||||
private llvm::TrailingObjects<LifetimeAttr, LifetimeDependenceSpecifier> {
|
||||
|
||||
friend TrailingObjects;
|
||||
|
||||
unsigned NumEntries = 0;
|
||||
|
||||
explicit LifetimeAttr(SourceLoc atLoc, SourceRange baseRange, bool implicit,
|
||||
ArrayRef<LifetimeDependenceSpecifier> entries);
|
||||
|
||||
public:
|
||||
static LifetimeAttr *create(ASTContext &context, SourceLoc atLoc,
|
||||
SourceRange baseRange, bool implicit,
|
||||
ArrayRef<LifetimeDependenceSpecifier> entries);
|
||||
|
||||
static bool classof(const DeclAttribute *DA) {
|
||||
return DA->getKind() == DeclAttrKind::Lifetime;
|
||||
}
|
||||
};
|
||||
|
||||
/// Predicate used to filter MatchingAttributeRange.
|
||||
template <typename ATTR, bool AllowInvalid> struct ToAttributeKind {
|
||||
ToAttributeKind() {}
|
||||
|
||||
@@ -506,6 +506,10 @@ SIMPLE_DECL_ATTR(unsafe, Unsafe,
|
||||
ABIStableToAdd | ABIStableToRemove | APIBreakingToAdd | APIStableToRemove,
|
||||
160)
|
||||
|
||||
DECL_ATTR(lifetime, Lifetime,
|
||||
OnAccessor | OnConstructor | OnFunc | OnSubscript | LongAttribute | ABIBreakingToAdd | ABIStableToRemove | APIBreakingToAdd | APIStableToRemove,
|
||||
161)
|
||||
|
||||
LAST_DECL_ATTR(Unsafe)
|
||||
|
||||
#undef DECL_ATTR_ALIAS
|
||||
|
||||
@@ -74,7 +74,9 @@ private:
|
||||
|
||||
public:
|
||||
static LifetimeDependenceSpecifier getNamedLifetimeDependenceSpecifier(
|
||||
SourceLoc loc, ParsedLifetimeDependenceKind kind, Identifier name) {
|
||||
SourceLoc loc, Identifier name,
|
||||
ParsedLifetimeDependenceKind kind =
|
||||
ParsedLifetimeDependenceKind::Default) {
|
||||
return {loc, SpecifierKind::Named, kind, name};
|
||||
}
|
||||
|
||||
@@ -84,13 +86,15 @@ public:
|
||||
}
|
||||
|
||||
static LifetimeDependenceSpecifier getOrderedLifetimeDependenceSpecifier(
|
||||
SourceLoc loc, ParsedLifetimeDependenceKind kind, unsigned index) {
|
||||
SourceLoc loc, unsigned index,
|
||||
ParsedLifetimeDependenceKind kind =
|
||||
ParsedLifetimeDependenceKind::Default) {
|
||||
return {loc, SpecifierKind::Ordered, kind, index};
|
||||
}
|
||||
|
||||
static LifetimeDependenceSpecifier
|
||||
getSelfLifetimeDependenceSpecifier(SourceLoc loc,
|
||||
ParsedLifetimeDependenceKind kind) {
|
||||
static LifetimeDependenceSpecifier getSelfLifetimeDependenceSpecifier(
|
||||
SourceLoc loc, ParsedLifetimeDependenceKind kind =
|
||||
ParsedLifetimeDependenceKind::Default) {
|
||||
return {loc, SpecifierKind::Self, kind, {}};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user