Skip to content

Commit d6a726e

Browse files
committed
SE-0106: Add "macOS" as an alias of "OSX" for #if.
...by canonicalizing it to the known platform name. This isn't a wonderful answer, but it preserves the invariant that a platform condition has at most one value. A later commit will switch which one is the default.
1 parent 77bb14b commit d6a726e

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ namespace swift {
235235

236236
/// Returns true if the 'os' platform condition argument represents
237237
/// a supported target operating system.
238-
static bool isPlatformConditionOSSupported(StringRef OSName);
238+
///
239+
/// Note that this also canonicalizes the OS name if the check returns
240+
/// true.
241+
static bool checkPlatformConditionOS(StringRef &OSName);
239242

240243
/// Returns true if the 'arch' platform condition argument represents
241244
/// a supported target architecture.

lib/Basic/LangOptions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ bool contains(const Type (&Array)[N], const Type &V) {
5555
return std::find(std::begin(Array), std::end(Array), V) != std::end(Array);
5656
}
5757

58-
bool LangOptions::isPlatformConditionOSSupported(StringRef OSName) {
58+
bool LangOptions::checkPlatformConditionOS(StringRef &OSName) {
59+
if (OSName == "macOS")
60+
OSName = "OSX";
5961
return contains(SupportedConditionalCompilationOSs, OSName);
6062
}
6163

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ Parser::evaluateConditionalCompilationExpr(Expr *condition) {
17111711
return ConditionalCompilationExprState::error();
17121712
}
17131713
if (fnName == "os") {
1714-
if (!LangOptions::isPlatformConditionOSSupported(argument)) {
1714+
if (!LangOptions::checkPlatformConditionOS(argument)) {
17151715
diagnose(UDRE->getLoc(), diag::unknown_platform_condition_argument,
17161716
"operating system", fnName);
17171717
return ConditionalCompilationExprState::error();

test/Parse/ConditionalCompilation/x64OSXTarget.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ class C {}
66
var x = C()
77
#endif
88
var y = x
9+
10+
11+
#if arch(x86_64) && os(macOS) && _runtime(_ObjC) && _endian(little)
12+
class CC {}
13+
var xx = CC()
14+
#endif
15+
var yy = xx

0 commit comments

Comments
 (0)