|
32 | 32 | #include "swift/AST/StorageImpl.h"
|
33 | 33 | #include "swift/Basic/Debug.h"
|
34 | 34 | #include "swift/Basic/EnumTraits.h"
|
| 35 | +#include "swift/Basic/Feature.h" |
35 | 36 | #include "swift/Basic/InlineBitfield.h"
|
36 | 37 | #include "swift/Basic/Located.h"
|
37 | 38 | #include "swift/Basic/OptimizationMode.h"
|
@@ -491,6 +492,8 @@ class DeclAttribute : public AttributeBase {
|
491 | 492 | LLVM_READNONE
|
492 | 493 | static bool canAttributeAppearOnDeclKind(DeclAttrKind DAK, DeclKind DK);
|
493 | 494 |
|
| 495 | + static std::optional<Feature> getRequiredFeature(DeclAttrKind DK); |
| 496 | + |
494 | 497 | /// Returns the source name of the attribute, without the @ or any arguments.
|
495 | 498 | StringRef getAttrName() const;
|
496 | 499 |
|
@@ -2875,6 +2878,12 @@ template <typename ATTR, bool AllowInvalid> struct ToAttributeKind {
|
2875 | 2878 | return cast<ATTR>(Attr);
|
2876 | 2879 | return std::nullopt;
|
2877 | 2880 | }
|
| 2881 | + |
| 2882 | + std::optional<ATTR *> operator()(DeclAttribute *Attr) { |
| 2883 | + if (isa<ATTR>(Attr) && (Attr->isValid() || AllowInvalid)) |
| 2884 | + return cast<ATTR>(Attr); |
| 2885 | + return std::nullopt; |
| 2886 | + } |
2878 | 2887 | };
|
2879 | 2888 |
|
2880 | 2889 | /// The @_allowFeatureSuppression(Foo, Bar) attribute. The feature
|
@@ -2908,6 +2917,31 @@ class AllowFeatureSuppressionAttr final
|
2908 | 2917 | UNIMPLEMENTED_CLONE(AllowFeatureSuppressionAttr)
|
2909 | 2918 | };
|
2910 | 2919 |
|
| 2920 | +/// Defines the @abi attribute. |
| 2921 | +class ABIAttr : public DeclAttribute { |
| 2922 | +public: |
| 2923 | + ABIAttr(Decl *abiDecl, SourceLoc AtLoc, SourceRange Range, bool Implicit) |
| 2924 | + : DeclAttribute(DeclAttrKind::ABI, AtLoc, Range, Implicit), |
| 2925 | + abiDecl(abiDecl) |
| 2926 | + { } |
| 2927 | + |
| 2928 | + ABIAttr(Decl *abiDecl, bool Implicit) |
| 2929 | + : ABIAttr(abiDecl, SourceLoc(), SourceRange(), Implicit) {} |
| 2930 | + |
| 2931 | + /// The declaration which will be used to compute a mangled name. |
| 2932 | + /// |
| 2933 | + /// \note For a \c VarDecl with a parent \c PatternBindingDecl , this should |
| 2934 | + /// point to the parent \c PatternBindingDecl . (That accommodates the way |
| 2935 | + /// sibling \c VarDecl s share attributes.) |
| 2936 | + Decl *abiDecl; |
| 2937 | + |
| 2938 | + static bool classof(const DeclAttribute *DA) { |
| 2939 | + return DA->getKind() == DeclAttrKind::ABI; |
| 2940 | + } |
| 2941 | + |
| 2942 | + UNIMPLEMENTED_CLONE(ABIAttr) |
| 2943 | +}; |
| 2944 | + |
2911 | 2945 | /// Attributes that may be applied to declarations.
|
2912 | 2946 | class DeclAttributes {
|
2913 | 2947 | /// Linked list of declaration attributes.
|
@@ -3047,17 +3081,25 @@ class DeclAttributes {
|
3047 | 3081 | }
|
3048 | 3082 |
|
3049 | 3083 | public:
|
3050 |
| - template <typename ATTR, bool AllowInvalid> |
| 3084 | + template <typename ATTR, typename Iterator, bool AllowInvalid> |
3051 | 3085 | using AttributeKindRange =
|
3052 |
| - OptionalTransformRange<iterator_range<const_iterator>, |
| 3086 | + OptionalTransformRange<iterator_range<Iterator>, |
3053 | 3087 | ToAttributeKind<ATTR, AllowInvalid>,
|
3054 |
| - const_iterator>; |
| 3088 | + Iterator>; |
| 3089 | + |
| 3090 | + /// Return a range with all attributes in DeclAttributes with AttrKind |
| 3091 | + /// ATTR. |
| 3092 | + template <typename ATTR, bool AllowInvalid = false> |
| 3093 | + AttributeKindRange<ATTR, const_iterator, AllowInvalid> getAttributes() const { |
| 3094 | + return AttributeKindRange<ATTR, const_iterator, AllowInvalid>( |
| 3095 | + make_range(begin(), end()), ToAttributeKind<ATTR, AllowInvalid>()); |
| 3096 | + } |
3055 | 3097 |
|
3056 | 3098 | /// Return a range with all attributes in DeclAttributes with AttrKind
|
3057 | 3099 | /// ATTR.
|
3058 | 3100 | template <typename ATTR, bool AllowInvalid = false>
|
3059 |
| - AttributeKindRange<ATTR, AllowInvalid> getAttributes() const { |
3060 |
| - return AttributeKindRange<ATTR, AllowInvalid>( |
| 3101 | + AttributeKindRange<ATTR, iterator, AllowInvalid> getAttributes() { |
| 3102 | + return AttributeKindRange<ATTR, iterator, AllowInvalid>( |
3061 | 3103 | make_range(begin(), end()), ToAttributeKind<ATTR, AllowInvalid>());
|
3062 | 3104 | }
|
3063 | 3105 |
|
|
0 commit comments