@@ -619,6 +619,9 @@ class DeclAttribute : public AttributeBase {
619619 DeclAttrKind kind, SourceLoc atLoc,
620620 SourceLoc attrLoc);
621621
622+ // / Attaches the attribute to the given declaration.
623+ void attachToDecl (Decl *D);
624+
622625 // / Create a copy of this attribute.
623626 DeclAttribute *clone (ASTContext &ctx) const ;
624627
@@ -629,6 +632,11 @@ class DeclAttribute : public AttributeBase {
629632 // / would have the same effect on \p attachedTo were they attached to it. A
630633 // / clone should always be equivalent to the original.
631634 bool isEquivalent (const DeclAttribute *other, Decl *attachedTo) const ;
635+
636+ private:
637+ void attachToDeclImpl (Decl *D) {
638+ // Most attributes don't need any custom logic for this.
639+ }
632640};
633641
634642#define UNIMPLEMENTED_CLONE (AttrType ) \
@@ -2292,6 +2300,8 @@ class CustomAttrOwner final {
22922300
22932301// / Defines a custom attribute.
22942302class CustomAttr final : public DeclAttribute {
2303+ friend class DeclAttribute ;
2304+
22952305 TypeExpr *typeExpr;
22962306 ArgumentList *argList;
22972307 CustomAttrOwner owner;
@@ -2322,7 +2332,6 @@ class CustomAttr final : public DeclAttribute {
23222332
23232333 // / Retrieve the Decl or DeclContext owner for the attribute.
23242334 CustomAttrOwner getOwner () const { return owner; }
2325- void setOwner (CustomAttrOwner newOwner);
23262335
23272336 ASTContext &getASTContext () const ;
23282337
@@ -2377,10 +2386,11 @@ class CustomAttr final : public DeclAttribute {
23772386 void printCustomAttr (ASTPrinter &Printer, const PrintOptions &Options) const ;
23782387
23792388private:
2389+ void attachToDeclImpl (Decl *D);
2390+
23802391 friend class CustomAttrNominalRequest ;
23812392 void resetTypeInformation (TypeExpr *repr);
23822393
2383- private:
23842394 friend class CustomAttrTypeRequest ;
23852395 void setType (Type ty);
23862396};
@@ -2517,6 +2527,7 @@ class DifferentiableAttr final
25172527 ParsedAutoDiffParameter> {
25182528 friend TrailingObjects;
25192529 friend class DifferentiableAttributeTypeCheckRequest ;
2530+ friend class DeclAttribute ;
25202531
25212532 // / The declaration on which the `@differentiable` attribute is declared.
25222533 // / May not be a valid declaration for `@differentiable` attributes.
@@ -2576,11 +2587,9 @@ class DifferentiableAttr final
25762587
25772588 Decl *getOriginalDeclaration () const { return OriginalDeclaration; }
25782589
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-
25832590private:
2591+ void attachToDeclImpl (Decl *D);
2592+
25842593 // / Returns true if the given `@differentiable` attribute has been
25852594 // / type-checked.
25862595 bool hasBeenTypeChecked () const ;
@@ -2695,6 +2704,7 @@ class DerivativeAttr final
26952704 private llvm::TrailingObjects<DerivativeAttr, ParsedAutoDiffParameter> {
26962705 friend TrailingObjects;
26972706 friend class DerivativeAttrOriginalDeclRequest ;
2707+ friend class DeclAttribute ;
26982708
26992709 // / The declaration on which the `@derivative` attribute is declared.
27002710 // / May not be a valid declaration for `@derivative` attributes.
@@ -2755,10 +2765,6 @@ class DerivativeAttr final
27552765
27562766 Decl *getOriginalDeclaration () const { return OriginalDeclaration; }
27572767
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-
27622768 TypeRepr *getBaseTypeRepr () const { return BaseTypeRepr; }
27632769 DeclNameRefWithLoc getOriginalFunctionName () const {
27642770 return OriginalFunctionName;
@@ -2803,6 +2809,9 @@ class DerivativeAttr final
28032809 // Not properly implemented (very complex and not currently needed)
28042810 return false ;
28052811 }
2812+
2813+ private:
2814+ void attachToDeclImpl (Decl *D);
28062815};
28072816
28082817// / The `@transpose(of:)` attribute registers a function as a transpose of
@@ -3538,6 +3547,8 @@ class AllowFeatureSuppressionAttr final
35383547
35393548// / Defines the @abi attribute.
35403549class ABIAttr : public DeclAttribute {
3550+ friend class DeclAttribute ;
3551+
35413552public:
35423553 ABIAttr (Decl *abiDecl, SourceLoc AtLoc, SourceRange Range, bool Implicit)
35433554 : DeclAttribute(DeclAttrKind::ABI, AtLoc, Range, Implicit),
@@ -3564,6 +3575,9 @@ class ABIAttr : public DeclAttribute {
35643575 // Unsupported: tricky to implement and unneeded.
35653576 return true ;
35663577 }
3578+
3579+ private:
3580+ void attachToDeclImpl (Decl *D);
35673581};
35683582
35693583// / Defines a @nonexhaustive attribute.
0 commit comments