Skip to content

Commit d0b418b

Browse files
committed
PrintAsClang: Adopt SemanticAvailableAttr more thoroughly.
1 parent 680bb5b commit d0b418b

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,43 +1688,41 @@ class DeclAndTypePrinter::Implementation
16881688
hasPrintedAnything = true;
16891689
};
16901690

1691-
for (auto semanticAttr : D->getSemanticAvailableAttrs()) {
1692-
auto AvAttr = semanticAttr.getParsedAttr();
1693-
1694-
if (AvAttr->getPlatform() == PlatformKind::none) {
1695-
if (AvAttr->getPlatformAgnosticAvailability() ==
1696-
PlatformAgnosticAvailabilityKind::Unavailable) {
1691+
for (auto AvAttr : D->getSemanticAvailableAttrs()) {
1692+
if (AvAttr.getPlatform() == PlatformKind::none) {
1693+
if (AvAttr.isUnconditionallyUnavailable() &&
1694+
!AvAttr.getDomain().isSwiftLanguage()) {
16971695
// Availability for *
1698-
if (!AvAttr->Rename.empty() && isa<ValueDecl>(D)) {
1696+
if (!AvAttr.getRename().empty() && isa<ValueDecl>(D)) {
16991697
// rename
17001698
maybePrintLeadingSpace();
17011699
os << "SWIFT_UNAVAILABLE_MSG(\"'"
17021700
<< cast<ValueDecl>(D)->getBaseName()
17031701
<< "' has been renamed to '";
17041702
printRenameForDecl(os, AvAttr, cast<ValueDecl>(D), false);
17051703
os << '\'';
1706-
if (!AvAttr->Message.empty()) {
1704+
if (!AvAttr.getMessage().empty()) {
17071705
os << ": ";
1708-
printEncodedString(os, AvAttr->Message, false);
1706+
printEncodedString(os, AvAttr.getMessage(), false);
17091707
}
17101708
os << "\")";
1711-
} else if (!AvAttr->Message.empty()) {
1709+
} else if (!AvAttr.getMessage().empty()) {
17121710
maybePrintLeadingSpace();
17131711
os << "SWIFT_UNAVAILABLE_MSG(";
1714-
printEncodedString(os, AvAttr->Message);
1712+
printEncodedString(os, AvAttr.getMessage());
17151713
os << ")";
17161714
} else {
17171715
maybePrintLeadingSpace();
17181716
os << "SWIFT_UNAVAILABLE";
17191717
}
17201718
break;
17211719
}
1722-
if (AvAttr->isUnconditionallyDeprecated()) {
1723-
if (!AvAttr->Rename.empty() || !AvAttr->Message.empty()) {
1720+
if (AvAttr.isUnconditionallyDeprecated()) {
1721+
if (!AvAttr.getRename().empty() || !AvAttr.getMessage().empty()) {
17241722
maybePrintLeadingSpace();
17251723
os << "SWIFT_DEPRECATED_MSG(";
1726-
printEncodedString(os, AvAttr->Message);
1727-
if (!AvAttr->Rename.empty()) {
1724+
printEncodedString(os, AvAttr.getMessage());
1725+
if (!AvAttr.getRename().empty()) {
17281726
os << ", ";
17291727
printRenameForDecl(os, AvAttr, cast<ValueDecl>(D), true);
17301728
}
@@ -1738,15 +1736,16 @@ class DeclAndTypePrinter::Implementation
17381736
}
17391737

17401738
// Availability for a specific platform
1741-
if (!AvAttr->Introduced.has_value() && !AvAttr->Deprecated.has_value() &&
1742-
!AvAttr->Obsoleted.has_value() &&
1743-
!AvAttr->isUnconditionallyDeprecated() &&
1744-
!AvAttr->isUnconditionallyUnavailable()) {
1739+
if (!AvAttr.getIntroduced().has_value() &&
1740+
!AvAttr.getDeprecated().has_value() &&
1741+
!AvAttr.getObsoleted().has_value() &&
1742+
!AvAttr.isUnconditionallyDeprecated() &&
1743+
!AvAttr.isUnconditionallyUnavailable()) {
17451744
continue;
17461745
}
17471746

17481747
const char *plat;
1749-
switch (AvAttr->getPlatform()) {
1748+
switch (AvAttr.getPlatform()) {
17501749
case PlatformKind::macOS:
17511750
plat = "macos";
17521751
break;
@@ -1795,52 +1794,53 @@ class DeclAndTypePrinter::Implementation
17951794

17961795
maybePrintLeadingSpace();
17971796
os << "SWIFT_AVAILABILITY(" << plat;
1798-
if (AvAttr->isUnconditionallyUnavailable()) {
1797+
if (AvAttr.isUnconditionallyUnavailable()) {
17991798
os << ",unavailable";
18001799
} else {
1801-
if (AvAttr->Introduced.has_value()) {
1802-
os << ",introduced=" << AvAttr->Introduced.value().getAsString();
1800+
if (AvAttr.getIntroduced().has_value()) {
1801+
os << ",introduced=" << AvAttr.getIntroduced().value().getAsString();
18031802
}
1804-
if (AvAttr->Deprecated.has_value()) {
1805-
os << ",deprecated=" << AvAttr->Deprecated.value().getAsString();
1806-
} else if (AvAttr->isUnconditionallyDeprecated()) {
1803+
if (AvAttr.getDeprecated().has_value()) {
1804+
os << ",deprecated=" << AvAttr.getDeprecated().value().getAsString();
1805+
} else if (AvAttr.isUnconditionallyDeprecated()) {
18071806
// We need to specify some version, we can't just say deprecated.
18081807
// We also can't deprecate it before it's introduced.
1809-
if (AvAttr->Introduced.has_value()) {
1810-
os << ",deprecated=" << AvAttr->Introduced.value().getAsString();
1808+
if (AvAttr.getIntroduced().has_value()) {
1809+
os << ",deprecated="
1810+
<< AvAttr.getIntroduced().value().getAsString();
18111811
} else {
18121812
os << ",deprecated=0.0.1";
18131813
}
18141814
}
1815-
if (AvAttr->Obsoleted.has_value()) {
1816-
os << ",obsoleted=" << AvAttr->Obsoleted.value().getAsString();
1815+
if (AvAttr.getObsoleted().has_value()) {
1816+
os << ",obsoleted=" << AvAttr.getObsoleted().value().getAsString();
18171817
}
18181818
}
1819-
if (!AvAttr->Rename.empty() && isa<ValueDecl>(D)) {
1819+
if (!AvAttr.getRename().empty() && isa<ValueDecl>(D)) {
18201820
os << ",message=\"'" << cast<ValueDecl>(D)->getBaseName()
18211821
<< "' has been renamed to '";
18221822
printRenameForDecl(os, AvAttr, cast<ValueDecl>(D), false);
18231823
os << '\'';
1824-
if (!AvAttr->Message.empty()) {
1824+
if (!AvAttr.getMessage().empty()) {
18251825
os << ": ";
1826-
printEncodedString(os, AvAttr->Message, false);
1826+
printEncodedString(os, AvAttr.getMessage(), false);
18271827
}
18281828
os << "\"";
1829-
} else if (!AvAttr->Message.empty()) {
1829+
} else if (!AvAttr.getMessage().empty()) {
18301830
os << ",message=";
1831-
printEncodedString(os, AvAttr->Message);
1831+
printEncodedString(os, AvAttr.getMessage());
18321832
}
18331833
os << ")";
18341834
}
18351835
return hasPrintedAnything;
18361836
}
18371837

18381838
private:
1839-
void printRenameForDecl(raw_ostream &os, const AvailableAttr *AvAttr,
1839+
void printRenameForDecl(raw_ostream &os, SemanticAvailableAttr AvAttr,
18401840
const ValueDecl *D, bool includeQuotes) {
1841-
assert(!AvAttr->Rename.empty());
1841+
assert(!AvAttr.getRename().empty());
18421842

1843-
auto *renamedDecl = D->getRenamedDecl(AvAttr);
1843+
auto *renamedDecl = D->getRenamedDecl(AvAttr.getParsedAttr());
18441844
if (renamedDecl) {
18451845
assert(shouldInclude(renamedDecl) &&
18461846
"ObjC printer logic mismatch with renamed decl");
@@ -1849,7 +1849,7 @@ class DeclAndTypePrinter::Implementation
18491849
renamedDecl->getObjCRuntimeName()->getString(scratch);
18501850
printEncodedString(os, renamedObjCRuntimeName, includeQuotes);
18511851
} else {
1852-
printEncodedString(os, AvAttr->Rename, includeQuotes);
1852+
printEncodedString(os, AvAttr.getRename(), includeQuotes);
18531853
}
18541854
}
18551855

0 commit comments

Comments
 (0)