Skip to content

Commit 40b6e7a

Browse files
author
Nathan Hawes
authored
Merge pull request swiftlang#32867 from nathawes/prefer-macos-to-osx-spelling-in-interfacegen
[5.3][ASTPrinter][IDE] Print PlatformKind::OSX as "macOS" rather than "OSX" in generated interfaces
2 parents d99417b + 8806368 commit 40b6e7a

File tree

9 files changed

+129
-112
lines changed

9 files changed

+129
-112
lines changed

include/swift/AST/Attr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ class AvailableAttr : public DeclAttribute {
814814
}
815815

816816
/// Returns the string for the platform of the attribute.
817-
StringRef platformString() const {
818-
return swift::platformString(Platform);
817+
StringRef platformString(bool PreferMacOSSpelling = false) const {
818+
return swift::platformString(Platform, PreferMacOSSpelling);
819819
}
820820

821821
/// Returns the human-readable string for the platform of the attribute.

include/swift/AST/PlatformKind.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ enum class PlatformKind: uint8_t {
3535

3636
/// Returns the short string representing the platform, suitable for
3737
/// use in availability specifications (e.g., "OSX").
38-
StringRef platformString(PlatformKind platform);
38+
///
39+
/// \param useMacOSSpelling whether use the "macOS" spelling in place of "OSX".
40+
StringRef platformString(PlatformKind platform, bool useMacOSSpelling = false);
3941

4042
/// Returns the platform kind corresponding to the passed-in short platform name
4143
/// or None if such a platform kind does not exist.

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ struct PrintOptions {
442442
/// (e.g. MyFramework).
443443
bool MapCrossImportOverlaysToDeclaringModule = false;
444444

445+
bool PreferMacOSSpelling = false;
446+
445447
bool PrintAsMember = false;
446448

447449
/// Whether to print parameter specifiers as 'let' and 'var'.
@@ -530,6 +532,7 @@ struct PrintOptions {
530532
result.SkipUnderscoredKeywords = true;
531533
result.EnumRawValues = EnumRawValueMode::PrintObjCOnly;
532534
result.MapCrossImportOverlaysToDeclaringModule = true;
535+
result.PreferMacOSSpelling = true;
533536
return result;
534537
}
535538

lib/AST/Attr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ static void printShortFormAvailable(ArrayRef<const DeclAttribute *> Attrs,
427427
assert(AvailAttr->Introduced.hasValue());
428428
if (isShortFormAvailabilityImpliedByOther(AvailAttr, Attrs))
429429
continue;
430-
Printer << platformString(AvailAttr->Platform) << " "
430+
Printer << platformString(AvailAttr->Platform,
431+
Options.PreferMacOSSpelling) << " "
431432
<< AvailAttr->Introduced.getValue().getAsString() << ", ";
432433
}
433434
Printer << "*)";
@@ -844,8 +845,8 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
844845
Printer << "(module: ";
845846
auto Attr = cast<OriginallyDefinedInAttr>(this);
846847
Printer << "\"" << Attr->OriginalModuleName << "\", ";
847-
Printer << platformString(Attr->Platform) << " " <<
848-
Attr->MovedVersion.getAsString();
848+
Printer << platformString(Attr->Platform, Options.PreferMacOSSpelling) <<
849+
" " << Attr->MovedVersion.getAsString();
849850
Printer << ")";
850851
break;
851852
}
@@ -859,7 +860,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
859860
else if (Attr->isPackageDescriptionVersionSpecific())
860861
Printer << "_PackageDescription";
861862
else
862-
Printer << Attr->platformString();
863+
Printer << Attr->platformString(Options.PreferMacOSSpelling);
863864

864865
if (Attr->isUnconditionallyUnavailable())
865866
Printer << ", unavailable";

lib/AST/PlatformKind.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@
2323

2424
using namespace swift;
2525

26-
StringRef swift::platformString(PlatformKind platform) {
26+
StringRef swift::platformString(PlatformKind platform, bool useMacOSSpelling) {
27+
if (useMacOSSpelling) {
28+
switch (platform) {
29+
case PlatformKind::OSX:
30+
return "macOS";
31+
case PlatformKind::OSXApplicationExtension:
32+
return "macOSApplicationExtension";
33+
default:
34+
break;
35+
}
36+
}
37+
2738
switch (platform) {
2839
case PlatformKind::none:
2940
return "*";

test/IDE/print_swift_module_with_available.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public extension C1 {
1414
func ext_foo() {}
1515
}
1616

17-
// CHECK1: @available(OSX 10.11, iOS 8.0, *)
17+
// CHECK1: @available(macOS 10.11, iOS 8.0, *)
1818
// CHECK1-NEXT: public class C1 {
1919

20-
// CHECK1: @available(OSX 10.12, *)
20+
// CHECK1: @available(macOS 10.12, *)
2121
// CHECK1-NEXT: extension C1 {

test/IDE/print_synthesized_extensions_nomerge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public extension S1 {
1515
func bar() {}
1616
}
1717

18-
// CHECK1: <decl:Extension>@available(OSX 10.15, *)
18+
// CHECK1: <decl:Extension>@available(macOS 10.15, *)
1919
// CHECK1: extension <loc><ref:Struct>S1</ref></loc> {
2020
// CHECK1: <decl:Extension>@available(iOS 13, *)
2121
// CHECK1: extension <loc><ref:Struct>S1</ref></loc> {

test/SourceKit/DocSupport/doc_swift_module.swift.response

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ func shouldPrintAnyAsKeyword(x x: Any)
21692169
},
21702170
{
21712171
key.kind: source.lang.swift.decl.extension.class,
2172-
key.doc.full_as_xml: "<Other><Name></Name><Declaration>@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)\nextension C1</Declaration><CommentParts><Abstract><Para>some comments</Para></Abstract></CommentParts></Other>",
2172+
key.doc.full_as_xml: "<Other><Name></Name><Declaration>@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)\nextension C1</Declaration><CommentParts><Abstract><Para>some comments</Para></Abstract></CommentParts></Other>",
21732173
key.offset: 473,
21742174
key.length: 37,
21752175
key.extends: {
@@ -2426,7 +2426,7 @@ func shouldPrintAnyAsKeyword(x x: Any)
24262426
},
24272427
{
24282428
key.kind: source.lang.swift.decl.extension.class,
2429-
key.doc.full_as_xml: "<Other><Name></Name><Declaration>@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)\nextension C2</Declaration><CommentParts><Abstract><Para>some comments</Para></Abstract></CommentParts></Other>",
2429+
key.doc.full_as_xml: "<Other><Name></Name><Declaration>@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)\nextension C2</Declaration><CommentParts><Abstract><Para>some comments</Para></Abstract></CommentParts></Other>",
24302430
key.offset: 982,
24312431
key.length: 37,
24322432
key.extends: {

0 commit comments

Comments
 (0)