Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ namespace swift {
/// Returns the value for the given platform condition or an empty string.
StringRef getPlatformConditionValue(PlatformConditionKind Kind) const;

/// Check whether the given platform condition matches the given value.
bool checkPlatformCondition(PlatformConditionKind Kind, StringRef Value) const;

/// Explicit conditional compilation flags, initialized via the '-D'
/// compiler flag.
void addCustomConditionalCompilationFlag(StringRef Name) {
Expand Down
15 changes: 15 additions & 0 deletions lib/Basic/LangOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ LangOptions::getPlatformConditionValue(PlatformConditionKind Kind) const {
return StringRef();
}

bool LangOptions::
checkPlatformCondition(PlatformConditionKind Kind, StringRef Value) const {
// Check a special case that "macOS" is an alias of "OSX".
if (Kind == PlatformConditionKind::OS && Value == "macOS")
return checkPlatformCondition(Kind, "OSX");

for (auto &Opt : reversed(PlatformConditionValues)) {
if (Opt.first == Kind)
if (Opt.second == Value)
return true;
}

return false;
}

bool LangOptions::isCustomConditionalCompilationFlagSet(StringRef Name) const {
return std::find(CustomConditionalCompilationFlags.begin(),
CustomConditionalCompilationFlags.end(), Name)
Expand Down
12 changes: 1 addition & 11 deletions lib/Parse/ParseIfConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,6 @@ class ValidateIfConfigCondition :
return nullptr;
}

// FIXME: Perform the replacement macOS -> OSX elsewhere.
if (Kind == PlatformConditionKind::OS && *ArgStr == "macOS") {
*ArgStr = "OSX";
ArgP->setSubExpr(
new (Ctx) UnresolvedDeclRefExpr(Ctx.getIdentifier(*ArgStr),
DeclRefKind::Ordinary,
DeclNameLoc(Arg->getLoc())));
}

std::vector<StringRef> suggestions;
if (!LangOptions::checkPlatformConditionSupported(*Kind, *ArgStr,
suggestions)) {
Expand Down Expand Up @@ -460,8 +451,7 @@ class EvaluateIfConfigCondition :

auto Val = getDeclRefStr(Arg);
auto Kind = getPlatformConditionKind(KindName).getValue();
auto Target = Ctx.LangOpts.getPlatformConditionValue(Kind);
return Target == Val;
return Ctx.LangOpts.checkPlatformCondition(Kind, Val);
}

bool visitPrefixUnaryExpr(PrefixUnaryExpr *E) {
Expand Down
4 changes: 4 additions & 0 deletions test/IDE/coloring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,10 @@ func keywordInCaseAndLocalArgLabel(_ for: Int, for in: Int, class _: Int) {
}
}

#if os(macOS)
#endif
// CHECK: <#kw>#if</#kw> <#id>os</#id>(<#id>macOS</#id>)

// Keep this as the last test
/**
Trailing off ...
Expand Down