Skip to content

Commit 188ed0e

Browse files
committed
AST: Adopt SemanticAvailableAttr more completely in AST printing.
1 parent 0421835 commit 188ed0e

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

lib/AST/Attr.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -419,27 +419,27 @@ void DeclAttributes::dump(const Decl *D) const {
419419
/// introduction version and does not support deprecation, obsoletion, or
420420
/// messages.
421421
LLVM_READONLY
422-
static bool isShortAvailable(const SemanticAvailableAttr &semanticAttr) {
423-
auto *AvailAttr = semanticAttr.getParsedAttr();
424-
if (AvailAttr->isSPI())
422+
static bool isShortAvailable(const SemanticAvailableAttr &attr) {
423+
auto parsedAttr = attr.getParsedAttr();
424+
if (parsedAttr->isSPI())
425425
return false;
426426

427-
if (!AvailAttr->Introduced.has_value())
427+
if (!attr.getIntroduced().has_value())
428428
return false;
429429

430-
if (AvailAttr->Deprecated.has_value())
430+
if (attr.getDeprecated().has_value())
431431
return false;
432432

433-
if (AvailAttr->Obsoleted.has_value())
433+
if (attr.getObsoleted().has_value())
434434
return false;
435435

436-
if (!AvailAttr->Message.empty())
436+
if (!attr.getMessage().empty())
437437
return false;
438438

439-
if (!AvailAttr->Rename.empty())
439+
if (!attr.getRename().empty())
440440
return false;
441441

442-
switch (AvailAttr->getPlatformAgnosticAvailability()) {
442+
switch (parsedAttr->getPlatformAgnosticAvailability()) {
443443
case PlatformAgnosticAvailabilityKind::Deprecated:
444444
case PlatformAgnosticAvailabilityKind::Unavailable:
445445
case PlatformAgnosticAvailabilityKind::UnavailableInSwift:
@@ -939,40 +939,39 @@ SemanticAvailableAttributes::Filter::operator()(
939939
return *semanticAttr;
940940
}
941941

942-
static void printAvailableAttr(const Decl *D,
943-
const SemanticAvailableAttr &SemanticAttr,
942+
static void printAvailableAttr(const Decl *D, const SemanticAvailableAttr &Attr,
944943
ASTPrinter &Printer,
945944
const PrintOptions &Options) {
946-
auto Attr = SemanticAttr.getParsedAttr();
947-
auto Domain = SemanticAttr.getDomain();
945+
auto ParsedAttr = Attr.getParsedAttr();
946+
auto Domain = Attr.getDomain();
948947

949948
// The parser rejects `@available(swift, unavailable)`, so when printing
950949
// attributes that are universally unavailable in Swift, we must print them
951950
// as universally unavailable instead.
952951
// FIXME: Reconsider this, it's a weird special case.
953-
if (Domain.isSwiftLanguage() && Attr->isUnconditionallyUnavailable())
952+
if (Domain.isSwiftLanguage() && Attr.isUnconditionallyUnavailable())
954953
Printer << "*";
955954
else
956955
Printer << Domain.getNameForAttributePrinting();
957956

958-
if (Attr->isUnconditionallyUnavailable())
957+
if (Attr.isUnconditionallyUnavailable())
959958
Printer << ", unavailable";
960-
else if (Attr->isUnconditionallyDeprecated())
959+
else if (Attr.isUnconditionallyDeprecated())
961960
Printer << ", deprecated";
962-
else if (Attr->isNoAsync())
961+
else if (Attr.isNoAsync())
963962
Printer << ", noasync";
964963

965-
if (Attr->Introduced)
966-
Printer << ", introduced: " << Attr->Introduced.value().getAsString();
967-
if (Attr->Deprecated)
968-
Printer << ", deprecated: " << Attr->Deprecated.value().getAsString();
969-
if (Attr->Obsoleted)
970-
Printer << ", obsoleted: " << Attr->Obsoleted.value().getAsString();
964+
if (Attr.getIntroduced())
965+
Printer << ", introduced: " << Attr.getIntroduced().value().getAsString();
966+
if (Attr.getDeprecated())
967+
Printer << ", deprecated: " << Attr.getDeprecated().value().getAsString();
968+
if (Attr.getObsoleted())
969+
Printer << ", obsoleted: " << Attr.getObsoleted().value().getAsString();
971970

972-
if (!Attr->Rename.empty()) {
973-
Printer << ", renamed: \"" << Attr->Rename << "\"";
971+
if (!Attr.getRename().empty()) {
972+
Printer << ", renamed: \"" << Attr.getRename() << "\"";
974973
} else if (auto *VD = dyn_cast<ValueDecl>(D)) {
975-
if (auto *renamedDecl = VD->getRenamedDecl(Attr)) {
974+
if (auto *renamedDecl = VD->getRenamedDecl(ParsedAttr)) {
976975
Printer << ", renamed: \"";
977976
if (auto *Accessor = dyn_cast<AccessorDecl>(renamedDecl)) {
978977
SmallString<32> Name;
@@ -989,10 +988,10 @@ static void printAvailableAttr(const Decl *D,
989988
// If there's no message, but this is specifically an imported
990989
// "unavailable in Swift" attribute, synthesize a message to look good in
991990
// the generated interface.
992-
if (!Attr->Message.empty()) {
991+
if (!Attr.getMessage().empty()) {
993992
Printer << ", message: ";
994-
Printer.printEscapedStringLiteral(Attr->Message);
995-
} else if (Domain.isSwiftLanguage() && Attr->isUnconditionallyUnavailable())
993+
Printer.printEscapedStringLiteral(Attr.getMessage());
994+
} else if (Domain.isSwiftLanguage() && Attr.isUnconditionallyUnavailable())
996995
Printer << ", message: \"Not available in Swift\"";
997996
}
998997

0 commit comments

Comments
 (0)