|
17 | 17 | #include "swift/AST/Attr.h"
|
18 | 18 | #include "swift/AST/ASTContext.h"
|
19 | 19 | #include "swift/AST/ASTPrinter.h"
|
| 20 | +#include "swift/AST/AvailabilityDomain.h" |
20 | 21 | #include "swift/AST/Decl.h"
|
21 | 22 | #include "swift/AST/Expr.h"
|
22 | 23 | #include "swift/AST/GenericEnvironment.h"
|
@@ -487,36 +488,32 @@ static bool isShortFormAvailabilityImpliedByOther(const AvailableAttr *Attr,
|
487 | 488 | /// @available(iOS, introduced: 8.0)
|
488 | 489 | /// this will print:
|
489 | 490 | /// @available(OSX 10.10, iOS 8.0, *)
|
490 |
| -static void printShortFormAvailable(ArrayRef<const DeclAttribute *> Attrs, |
| 491 | +static void printShortFormAvailable(const Decl *D, |
| 492 | + ArrayRef<const DeclAttribute *> Attrs, |
491 | 493 | ASTPrinter &Printer,
|
492 | 494 | const PrintOptions &Options,
|
493 | 495 | bool forAtSpecialize = false) {
|
494 | 496 | assert(!Attrs.empty());
|
495 | 497 | if (!forAtSpecialize)
|
496 | 498 | Printer << "@available(";
|
497 | 499 | auto FirstAvail = cast<AvailableAttr>(Attrs.front());
|
498 |
| - if (Attrs.size() == 1 && |
499 |
| - FirstAvail->getPlatformAgnosticAvailability() != |
500 |
| - PlatformAgnosticAvailabilityKind::None) { |
| 500 | + auto FirstAvailDomain = D->getDomainForAvailableAttr(FirstAvail); |
| 501 | + if (Attrs.size() == 1 && !FirstAvailDomain.isPlatform()) { |
501 | 502 | assert(FirstAvail->Introduced.has_value());
|
502 |
| - if (FirstAvail->isLanguageVersionSpecific()) { |
503 |
| - Printer << "swift "; |
504 |
| - } else { |
505 |
| - assert(FirstAvail->isPackageDescriptionVersionSpecific()); |
506 |
| - Printer << "_PackageDescription "; |
507 |
| - } |
| 503 | + Printer << FirstAvailDomain.getNameForAttributePrinting() << " "; |
508 | 504 | Printer << FirstAvail->Introduced.value().getAsString();
|
509 | 505 | if (!forAtSpecialize)
|
510 | 506 | Printer << ")";
|
511 | 507 | } else {
|
512 | 508 | for (auto *DA : Attrs) {
|
513 | 509 | auto *AvailAttr = cast<AvailableAttr>(DA);
|
| 510 | + auto AvailAttrDomain = D->getDomainForAvailableAttr(AvailAttr); |
514 | 511 | assert(AvailAttr->Introduced.has_value());
|
515 | 512 | // Avoid omitting available attribute when we are printing module interface.
|
516 | 513 | if (!Options.IsForSwiftInterface &&
|
517 | 514 | isShortFormAvailabilityImpliedByOther(AvailAttr, Attrs))
|
518 | 515 | continue;
|
519 |
| - Printer << platformString(AvailAttr->getPlatform()) << " " |
| 516 | + Printer << AvailAttrDomain.getNameForAttributePrinting() << " " |
520 | 517 | << AvailAttr->Introduced.value().getAsString() << ", ";
|
521 | 518 | }
|
522 | 519 | Printer << "*";
|
@@ -848,11 +845,11 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
|
848 | 845 | }
|
849 | 846 |
|
850 | 847 | if (swiftVersionAvailableAttribute)
|
851 |
| - printShortFormAvailable(swiftVersionAvailableAttribute, Printer, Options); |
| 848 | + printShortFormAvailable(D, swiftVersionAvailableAttribute, Printer, Options); |
852 | 849 | if (packageDescriptionVersionAvailableAttribute)
|
853 |
| - printShortFormAvailable(packageDescriptionVersionAvailableAttribute, Printer, Options); |
| 850 | + printShortFormAvailable(D, packageDescriptionVersionAvailableAttribute, Printer, Options); |
854 | 851 | if (!shortAvailableAttributes.empty())
|
855 |
| - printShortFormAvailable(shortAvailableAttributes, Printer, Options); |
| 852 | + printShortFormAvailable(D, shortAvailableAttributes, Printer, Options); |
856 | 853 | if (!backDeployedAttributes.empty())
|
857 | 854 | printShortFormBackDeployed(backDeployedAttributes, Printer, Options);
|
858 | 855 |
|
@@ -901,12 +898,16 @@ ParsedDeclAttrFilter::operator()(const DeclAttribute *Attr) const {
|
901 | 898 | static void printAvailableAttr(const Decl *D, const AvailableAttr *Attr,
|
902 | 899 | ASTPrinter &Printer,
|
903 | 900 | const PrintOptions &Options) {
|
904 |
| - if (Attr->isLanguageVersionSpecific()) |
905 |
| - Printer << "swift"; |
906 |
| - else if (Attr->isPackageDescriptionVersionSpecific()) |
907 |
| - Printer << "_PackageDescription"; |
| 901 | + auto Domain = D->getDomainForAvailableAttr(Attr); |
| 902 | + |
| 903 | + // The parser rejects `@available(swift, unavailable)`, so when printing |
| 904 | + // attributes that are universally unavailable in Swift, we must print them |
| 905 | + // as universally unavailable instead. |
| 906 | + // FIXME: Reconsider this, it's a weird special case. |
| 907 | + if (Domain.isSwiftLanguage() && Attr->isUnconditionallyUnavailable()) |
| 908 | + Printer << "*"; |
908 | 909 | else
|
909 |
| - Printer << Attr->platformString(); |
| 910 | + Printer << Domain.getNameForAttributePrinting(); |
910 | 911 |
|
911 | 912 | if (Attr->isUnconditionallyUnavailable())
|
912 | 913 | Printer << ", unavailable";
|
@@ -945,8 +946,7 @@ static void printAvailableAttr(const Decl *D, const AvailableAttr *Attr,
|
945 | 946 | if (!Attr->Message.empty()) {
|
946 | 947 | Printer << ", message: ";
|
947 | 948 | Printer.printEscapedStringLiteral(Attr->Message);
|
948 |
| - } else if (Attr->getPlatformAgnosticAvailability() == |
949 |
| - PlatformAgnosticAvailabilityKind::UnavailableInSwift) |
| 949 | + } else if (Domain.isSwiftLanguage() && Attr->isUnconditionallyUnavailable()) |
950 | 950 | Printer << ", message: \"Not available in Swift\"";
|
951 | 951 | }
|
952 | 952 |
|
@@ -1257,7 +1257,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
|
1257 | 1257 | } else {
|
1258 | 1258 | SmallVector<const DeclAttribute *, 8> tmp(availAttrs.begin(),
|
1259 | 1259 | availAttrs.end());
|
1260 |
| - printShortFormAvailable(tmp, Printer, Options, |
| 1260 | + printShortFormAvailable(D, tmp, Printer, Options, |
1261 | 1261 | true /*forAtSpecialize*/);
|
1262 | 1262 | Printer << "; ";
|
1263 | 1263 | }
|
|
0 commit comments