AST: Implement parsing support for the accepted spelling of @backDeployed for SE-0376.

For source compatibility `@_backDeploy` continues to be accepted as a spelling.

rdar://102792909
This commit is contained in:
Allan Shortlidge
2023-01-31 17:00:18 -08:00
parent df1750d8b7
commit d2524a6de8
20 changed files with 93 additions and 91 deletions

View File

@@ -400,23 +400,24 @@ const AvailableAttr *DeclAttributes::getNoAsync(const ASTContext &ctx) const {
return bestAttr;
}
const BackDeployAttr *
DeclAttributes::getBackDeploy(const ASTContext &ctx) const {
const BackDeployAttr *bestAttr = nullptr;
const BackDeployedAttr *
DeclAttributes::getBackDeployed(const ASTContext &ctx) const {
const BackDeployedAttr *bestAttr = nullptr;
for (auto attr : *this) {
auto *backDeployAttr = dyn_cast<BackDeployAttr>(attr);
if (!backDeployAttr)
auto *backDeployedAttr = dyn_cast<BackDeployedAttr>(attr);
if (!backDeployedAttr)
continue;
if (backDeployAttr->isInvalid() || !backDeployAttr->isActivePlatform(ctx))
if (backDeployedAttr->isInvalid() ||
!backDeployedAttr->isActivePlatform(ctx))
continue;
// We have an attribute that is active for the platform, but
// is it more specific than our current best?
if (!bestAttr || inheritsAvailabilityFromPlatform(backDeployAttr->Platform,
bestAttr->Platform)) {
bestAttr = backDeployAttr;
if (!bestAttr || inheritsAvailabilityFromPlatform(
backDeployedAttr->Platform, bestAttr->Platform)) {
bestAttr = backDeployedAttr;
}
}
@@ -547,13 +548,14 @@ static void printShortFormBackDeployed(ArrayRef<const DeclAttribute *> Attrs,
ASTPrinter &Printer,
const PrintOptions &Options) {
assert(!Attrs.empty());
// TODO: Print `@backDeployed` in swiftinterfaces (rdar://104920183)
Printer << "@_backDeploy(before: ";
bool isFirst = true;
for (auto *DA : Attrs) {
if (!isFirst)
Printer << ", ";
auto *attr = cast<BackDeployAttr>(DA);
auto *attr = cast<BackDeployedAttr>(DA);
Printer << platformString(attr->Platform) << " "
<< attr->Version.getAsString();
isFirst = false;
@@ -773,7 +775,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
AttributeVector shortAvailableAttributes;
const DeclAttribute *swiftVersionAvailableAttribute = nullptr;
const DeclAttribute *packageDescriptionVersionAvailableAttribute = nullptr;
AttributeVector backDeployAttributes;
AttributeVector backDeployedAttributes;
AttributeVector longAttributes;
AttributeVector attributes;
AttributeVector modifiers;
@@ -811,7 +813,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
}
AttributeVector &which = DA->isDeclModifier() ? modifiers :
isa<BackDeployAttr>(DA) ? backDeployAttributes :
isa<BackDeployedAttr>(DA) ? backDeployedAttributes :
isShortAvailable(DA) ? shortAvailableAttributes :
DA->isLongAttribute() ? longAttributes :
attributes;
@@ -824,8 +826,8 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
printShortFormAvailable(packageDescriptionVersionAvailableAttribute, Printer, Options);
if (!shortAvailableAttributes.empty())
printShortFormAvailable(shortAvailableAttributes, Printer, Options);
if (!backDeployAttributes.empty())
printShortFormBackDeployed(backDeployAttributes, Printer, Options);
if (!backDeployedAttributes.empty())
printShortFormBackDeployed(backDeployedAttributes, Printer, Options);
for (auto DA : longAttributes)
DA->print(Printer, Options, D);
@@ -1324,10 +1326,11 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
break;
}
case DAK_BackDeploy: {
case DAK_BackDeployed: {
// TODO: Print `@backDeployed` in swiftinterfaces (rdar://104920183)
Printer.printAttrName("@_backDeploy");
Printer << "(before: ";
auto Attr = cast<BackDeployAttr>(this);
auto Attr = cast<BackDeployedAttr>(this);
Printer << platformString(Attr->Platform) << " " <<
Attr->Version.getAsString();
Printer << ")";
@@ -1534,8 +1537,8 @@ StringRef DeclAttribute::getAttrName() const {
return "transpose";
case DAK_UnavailableFromAsync:
return "_unavailableFromAsync";
case DAK_BackDeploy:
return "_backDeploy";
case DAK_BackDeployed:
return "backDeployed";
case DAK_Expose:
return "_expose";
case DAK_Documentation:
@@ -1791,7 +1794,7 @@ bool AvailableAttr::isActivePlatform(const ASTContext &ctx) const {
return isPlatformActive(Platform, ctx.LangOpts);
}
bool BackDeployAttr::isActivePlatform(const ASTContext &ctx) const {
bool BackDeployedAttr::isActivePlatform(const ASTContext &ctx) const {
return isPlatformActive(Platform, ctx.LangOpts);
}