@@ -44,6 +44,8 @@ class ASTPrinter;
44
44
class ASTContext ;
45
45
struct PrintOptions ;
46
46
class Decl ;
47
+ class AbstractFunctionDecl ;
48
+ class FuncDecl ;
47
49
class ClassDecl ;
48
50
class GenericFunctionType ;
49
51
class LazyConformanceLoader ;
@@ -205,6 +207,12 @@ class DeclAttribute : public AttributeBase {
205
207
Swift3Inferred : 1
206
208
);
207
209
210
+ SWIFT_INLINE_BITFIELD (DynamicReplacementAttr, DeclAttribute, 1 ,
211
+ // / Whether this attribute has location information that trails the main
212
+ // / record, which contains the locations of the parentheses and any names.
213
+ HasTrailingLocationInfo : 1
214
+ );
215
+
208
216
SWIFT_INLINE_BITFIELD (AbstractAccessControlAttr, DeclAttribute, 3 ,
209
217
AccessLevel : 3
210
218
);
@@ -893,6 +901,76 @@ class ObjCAttr final : public DeclAttribute,
893
901
}
894
902
};
895
903
904
+ // / The @_dynamicReplacement(for:) attribute.
905
+ class DynamicReplacementAttr final
906
+ : public DeclAttribute,
907
+ private llvm::TrailingObjects<DynamicReplacementAttr, SourceLoc> {
908
+ friend TrailingObjects;
909
+
910
+ DeclName ReplacedFunctionName;
911
+ AbstractFunctionDecl *ReplacedFunction;
912
+
913
+ // / Create an @_dynamicReplacement(for:) attribute written in the source.
914
+ DynamicReplacementAttr (SourceLoc atLoc, SourceRange baseRange,
915
+ DeclName replacedFunctionName, SourceRange parenRange);
916
+
917
+ explicit DynamicReplacementAttr (DeclName name)
918
+ : DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(),
919
+ /* Implicit=*/ false),
920
+ ReplacedFunctionName(name), ReplacedFunction(nullptr ) {
921
+ Bits.DynamicReplacementAttr .HasTrailingLocationInfo = false ;
922
+ }
923
+
924
+ // / Retrieve the trailing location information.
925
+ MutableArrayRef<SourceLoc> getTrailingLocations () {
926
+ assert (Bits.DynamicReplacementAttr .HasTrailingLocationInfo );
927
+ unsigned length = 2 ;
928
+ return {getTrailingObjects<SourceLoc>(), length};
929
+ }
930
+
931
+ // / Retrieve the trailing location information.
932
+ ArrayRef<SourceLoc> getTrailingLocations () const {
933
+ assert (Bits.DynamicReplacementAttr .HasTrailingLocationInfo );
934
+ unsigned length = 2 ; // lParens, rParens
935
+ return {getTrailingObjects<SourceLoc>(), length};
936
+ }
937
+
938
+ public:
939
+ static DynamicReplacementAttr *
940
+ create (ASTContext &Context, SourceLoc AtLoc, SourceLoc DynReplLoc,
941
+ SourceLoc LParenLoc, DeclName replacedFunction, SourceLoc RParenLoc);
942
+
943
+ static DynamicReplacementAttr *create (ASTContext &ctx,
944
+ DeclName replacedFunction);
945
+
946
+ static DynamicReplacementAttr *create (ASTContext &ctx,
947
+ DeclName replacedFunction,
948
+ AbstractFunctionDecl *replacedFuncDecl);
949
+
950
+ DeclName getReplacedFunctionName () const {
951
+ return ReplacedFunctionName;
952
+ }
953
+
954
+ AbstractFunctionDecl *getReplacedFunction () const {
955
+ return ReplacedFunction;
956
+ }
957
+
958
+ void setReplacedFunction (AbstractFunctionDecl *f) {
959
+ assert (ReplacedFunction == nullptr );
960
+ ReplacedFunction = f;
961
+ }
962
+
963
+ // / Retrieve the location of the opening parentheses, if there is one.
964
+ SourceLoc getLParenLoc () const ;
965
+
966
+ // / Retrieve the location of the closing parentheses, if there is one.
967
+ SourceLoc getRParenLoc () const ;
968
+
969
+ static bool classof (const DeclAttribute *DA) {
970
+ return DA->getKind () == DAK_DynamicReplacement;
971
+ }
972
+ };
973
+
896
974
// / Represents any sort of access control modifier.
897
975
class AbstractAccessControlAttr : public DeclAttribute {
898
976
protected:
0 commit comments