@@ -34,7 +34,7 @@ using namespace swift;
3434// / that is active.
3535// FIXME: [availability] De-duplicate this with TypeCheckAvailability.cpp.
3636static bool hasActiveAvailableAttribute (const Decl *decl, ASTContext &ctx) {
37- decl = abstractSyntaxDeclForAvailableAttribute ( decl);
37+ decl = decl-> getAbstractSyntaxDeclForAttributes ( );
3838
3939 for (auto attr : decl->getSemanticAvailableAttrs ()) {
4040 if (attr.isActive (ctx))
@@ -50,36 +50,6 @@ static bool computeContainedByDeploymentTarget(AvailabilityScope *scope,
5050 AvailabilityRange::forDeploymentTarget (ctx));
5151}
5252
53- // / Given a declaration that allows availability attributes in the abstract
54- // / syntax tree, return the declaration upon which the declaration would
55- // / appear in concrete syntax. This function is necessary because for semantic
56- // / analysis, the parser attaches attributes to declarations other
57- // / than those on which they, concretely, appear. For these declarations (enum
58- // / cases and variable declarations) a Fix-It for an added availability
59- // / attribute should be suggested for the appropriate concrete location.
60- // FIXME: [availability] De-duplicate this with TypeCheckAvailability.cpp.
61- static const Decl *
62- concreteSyntaxDeclForAvailableAttribute (const Decl *abstractSyntaxDecl) {
63- // This function needs to be kept in sync with its counterpart,
64- // abstractSyntaxDeclForAvailableAttribute().
65-
66- // The source range for VarDecls does not include 'var ' (and, in any
67- // event, multiple variables can be introduced with a single 'var'),
68- // so suggest adding an attribute to the PatterningBindingDecl instead.
69- if (auto *vd = dyn_cast<VarDecl>(abstractSyntaxDecl)) {
70- if (auto *pbd = vd->getParentPatternBinding ())
71- return pbd;
72- }
73-
74- // Similarly suggest applying the Fix-It to the parent enum case rather than
75- // the enum element.
76- if (auto *ee = dyn_cast<EnumElementDecl>(abstractSyntaxDecl)) {
77- return ee->getParentCase ();
78- }
79-
80- return abstractSyntaxDecl;
81- }
82-
8353namespace {
8454// / A class that walks the AST to build the availability scope tree.
8555class AvailabilityScopeBuilder : private ASTWalker {
@@ -282,7 +252,7 @@ class AvailabilityScopeBuilder : private ASTWalker {
282252 bool shouldSkipDecl (Decl *decl) const {
283253 // Only visit a node that has a corresponding concrete syntax node if we are
284254 // already walking that concrete syntax node.
285- auto *concreteDecl = concreteSyntaxDeclForAvailableAttribute ( decl);
255+ auto *concreteDecl = decl-> getConcreteSyntaxDeclForAttributes ( );
286256 if (concreteDecl != decl) {
287257 if (ConcreteDeclStack.empty () || ConcreteDeclStack.back () != concreteDecl)
288258 return true ;
@@ -323,7 +293,7 @@ class AvailabilityScopeBuilder : private ASTWalker {
323293
324294 // If this decl is the concrete syntax decl for some abstract syntax decl,
325295 // push it onto the stack so that the abstract syntax decls may be visited.
326- auto *abstractDecl = abstractSyntaxDeclForAvailableAttribute ( decl);
296+ auto *abstractDecl = decl-> getAbstractSyntaxDeclForAttributes ( );
327297 if (abstractDecl != decl) {
328298 ConcreteDeclStack.push_back (decl);
329299 }
@@ -425,7 +395,7 @@ class AvailabilityScopeBuilder : private ASTWalker {
425395
426396 // Don't introduce for abstract syntax nodes that have separate concrete
427397 // syntax nodes. The scope will be introduced for the concrete node instead.
428- if (concreteSyntaxDeclForAvailableAttribute ( decl) != decl)
398+ if (decl-> getConcreteSyntaxDeclForAttributes ( ) != decl)
429399 return nullptr ;
430400
431401 // Declarations with explicit availability attributes always get a scope.
@@ -456,7 +426,7 @@ class AvailabilityScopeBuilder : private ASTWalker {
456426 auto effectiveIntroduction = AvailabilityRange::alwaysAvailable ();
457427
458428 // Availability attributes are found abstract syntax decls.
459- decl = abstractSyntaxDeclForAvailableAttribute ( decl);
429+ decl = decl-> getAbstractSyntaxDeclForAttributes ( );
460430
461431 // As a special case, extension decls are treated as effectively as
462432 // available as the nominal type they extend, up to the deployment target.
0 commit comments