@@ -67,6 +67,7 @@ class CustomAttributeInitializer;
6767class GenericFunctionType ;
6868class LazyConformanceLoader ;
6969class LazyMemberLoader ;
70+ class MacroDecl ;
7071class ModuleDecl ;
7172class NominalTypeDecl ;
7273class PatternBindingInitializer ;
@@ -619,6 +620,9 @@ class DeclAttribute : public AttributeBase {
619620 DeclAttrKind kind, SourceLoc atLoc,
620621 SourceLoc attrLoc);
621622
623+ // / Attaches the attribute to the given declaration.
624+ void attachToDecl (Decl *D);
625+
622626 // / Create a copy of this attribute.
623627 DeclAttribute *clone (ASTContext &ctx) const ;
624628
@@ -629,6 +633,11 @@ class DeclAttribute : public AttributeBase {
629633 // / would have the same effect on \p attachedTo were they attached to it. A
630634 // / clone should always be equivalent to the original.
631635 bool isEquivalent (const DeclAttribute *other, Decl *attachedTo) const ;
636+
637+ private:
638+ void attachToDeclImpl (Decl *D) {
639+ // Most attributes don't need any custom logic for this.
640+ }
632641};
633642
634643#define UNIMPLEMENTED_CLONE (AttrType ) \
@@ -2292,6 +2301,8 @@ class CustomAttrOwner final {
22922301
22932302// / Defines a custom attribute.
22942303class CustomAttr final : public DeclAttribute {
2304+ friend class DeclAttribute ;
2305+
22952306 TypeExpr *typeExpr;
22962307 ArgumentList *argList;
22972308 CustomAttrOwner owner;
@@ -2322,14 +2333,17 @@ class CustomAttr final : public DeclAttribute {
23222333
23232334 // / Retrieve the Decl or DeclContext owner for the attribute.
23242335 CustomAttrOwner getOwner () const { return owner; }
2325- void setOwner (CustomAttrOwner newOwner) { owner = newOwner; }
23262336
23272337 ASTContext &getASTContext () const ;
23282338
23292339 // / Retrieve the NominalTypeDecl the CustomAttr refers to, or \c nullptr if
23302340 // / it doesn't refer to one (which can be the case for e.g macro attrs).
23312341 NominalTypeDecl *getNominalDecl () const ;
23322342
2343+ // / Retrieve the resolved macro for the CustomAttr, or \c nullptr if the
2344+ // / attribute does not refer to a macro.
2345+ MacroDecl *getResolvedMacro () const ;
2346+
23332347 // / Destructure an attribute's type repr for a macro reference.
23342348 // /
23352349 // / For a 1-level member type repr whose base and member are both identifier
@@ -2377,10 +2391,11 @@ class CustomAttr final : public DeclAttribute {
23772391 void printCustomAttr (ASTPrinter &Printer, const PrintOptions &Options) const ;
23782392
23792393private:
2394+ void attachToDeclImpl (Decl *D);
2395+
23802396 friend class CustomAttrNominalRequest ;
23812397 void resetTypeInformation (TypeExpr *repr);
23822398
2383- private:
23842399 friend class CustomAttrTypeRequest ;
23852400 void setType (Type ty);
23862401};
@@ -2517,6 +2532,7 @@ class DifferentiableAttr final
25172532 ParsedAutoDiffParameter> {
25182533 friend TrailingObjects;
25192534 friend class DifferentiableAttributeTypeCheckRequest ;
2535+ friend class DeclAttribute ;
25202536
25212537 // / The declaration on which the `@differentiable` attribute is declared.
25222538 // / May not be a valid declaration for `@differentiable` attributes.
@@ -2576,11 +2592,9 @@ class DifferentiableAttr final
25762592
25772593 Decl *getOriginalDeclaration () const { return OriginalDeclaration; }
25782594
2579- // / Sets the original declaration on which this attribute is declared.
2580- // / Should only be used by parsing and deserialization.
2581- void setOriginalDeclaration (Decl *originalDeclaration);
2582-
25832595private:
2596+ void attachToDeclImpl (Decl *D);
2597+
25842598 // / Returns true if the given `@differentiable` attribute has been
25852599 // / type-checked.
25862600 bool hasBeenTypeChecked () const ;
@@ -2695,6 +2709,7 @@ class DerivativeAttr final
26952709 private llvm::TrailingObjects<DerivativeAttr, ParsedAutoDiffParameter> {
26962710 friend TrailingObjects;
26972711 friend class DerivativeAttrOriginalDeclRequest ;
2712+ friend class DeclAttribute ;
26982713
26992714 // / The declaration on which the `@derivative` attribute is declared.
27002715 // / May not be a valid declaration for `@derivative` attributes.
@@ -2755,10 +2770,6 @@ class DerivativeAttr final
27552770
27562771 Decl *getOriginalDeclaration () const { return OriginalDeclaration; }
27572772
2758- // / Sets the original declaration on which this attribute is declared.
2759- // / Should only be used by parsing and deserialization.
2760- void setOriginalDeclaration (Decl *originalDeclaration);
2761-
27622773 TypeRepr *getBaseTypeRepr () const { return BaseTypeRepr; }
27632774 DeclNameRefWithLoc getOriginalFunctionName () const {
27642775 return OriginalFunctionName;
@@ -2803,6 +2814,9 @@ class DerivativeAttr final
28032814 // Not properly implemented (very complex and not currently needed)
28042815 return false ;
28052816 }
2817+
2818+ private:
2819+ void attachToDeclImpl (Decl *D);
28062820};
28072821
28082822// / The `@transpose(of:)` attribute registers a function as a transpose of
@@ -3538,6 +3552,8 @@ class AllowFeatureSuppressionAttr final
35383552
35393553// / Defines the @abi attribute.
35403554class ABIAttr : public DeclAttribute {
3555+ friend class DeclAttribute ;
3556+
35413557public:
35423558 ABIAttr (Decl *abiDecl, SourceLoc AtLoc, SourceRange Range, bool Implicit)
35433559 : DeclAttribute(DeclAttrKind::ABI, AtLoc, Range, Implicit),
@@ -3564,6 +3580,9 @@ class ABIAttr : public DeclAttribute {
35643580 // Unsupported: tricky to implement and unneeded.
35653581 return true ;
35663582 }
3583+
3584+ private:
3585+ void attachToDeclImpl (Decl *D);
35673586};
35683587
35693588// / Defines a @nonexhaustive attribute.
0 commit comments