New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#if targetEnvironment(simulator) #12964

Merged
merged 4 commits into from Nov 29, 2017
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+48 −4
Diff settings

Always

Just for now

Next

[Parse] Add platform conditional targetEnvironment(simulator)

  • Loading branch information...
graydon committed Oct 19, 2017
commit 3807b3fa1e896299333b9fd8c8ad445486d23e9f
@@ -46,6 +46,8 @@ namespace swift {
Runtime,
/// Conditional import of module
CanImport,
/// Target Environment (currently just 'simulator' or absent)
TargetEnvironment,
};

/// Describes which Swift 3 Objective-C inference warnings should be
@@ -351,7 +353,7 @@ namespace swift {
}

private:
llvm::SmallVector<std::pair<PlatformConditionKind, std::string>, 4>
llvm::SmallVector<std::pair<PlatformConditionKind, std::string>, 5>
PlatformConditionValues;
llvm::SmallVector<std::string, 2> CustomConditionalCompilationFlags;
};
Copy path View file
@@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//

#include "swift/Basic/LangOptions.h"
#include "swift/Basic/Platform.h"
#include "swift/Basic/Range.h"
#include "swift/Config.h"
#include "llvm/ADT/Hashing.h"
@@ -60,6 +61,10 @@ static const StringRef SupportedConditionalCompilationRuntimes[] = {
"_Native",
};

static const StringRef SupportedConditionalCompilationTargetEnvironments[] = {
"simulator",
};

template <size_t N>
bool contains(const StringRef (&Array)[N], const StringRef &V,
std::vector<StringRef> &suggestions) {
@@ -99,6 +104,9 @@ checkPlatformConditionSupported(PlatformConditionKind Kind, StringRef Value,
case PlatformConditionKind::Runtime:
return contains(SupportedConditionalCompilationRuntimes, Value,
suggestions);
case PlatformConditionKind::TargetEnvironment:
return contains(SupportedConditionalCompilationTargetEnvironments, Value,
suggestions);
case PlatformConditionKind::CanImport:
// All importable names are valid.
// FIXME: Perform some kind of validation of the string?
@@ -254,6 +262,13 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
else
addPlatformConditionValue(PlatformConditionKind::Runtime, "_Native");

// Set the "targetEnvironment" platform condition if targeting a simulator
// environmet. Otherwise _no_ value is present for targetEnvironment; it's

This comment has been minimized.

@DougGregor

DougGregor Nov 17, 2017

Member

Typo environmet

// an optional disambiguating refinement of the triple.
if (swift::tripleIsAnySimulator(Target))
addPlatformConditionValue(PlatformConditionKind::TargetEnvironment,
"simulator");

// If you add anything to this list, change the default size of
// PlatformConditionValues to not require an extra allocation
// in the common case.
Copy path View file
@@ -37,6 +37,7 @@ Optional<PlatformConditionKind> getPlatformConditionKind(StringRef Name) {
.Case("_endian", PlatformConditionKind::Endianness)
.Case("_runtime", PlatformConditionKind::Runtime)
.Case("canImport", PlatformConditionKind::CanImport)
.Case("targetEnvironment", PlatformConditionKind::TargetEnvironment)
.Default(None);
}

@@ -325,6 +326,8 @@ class ValidateIfConfigCondition :
DiagName = "endianness"; break;
case PlatformConditionKind::CanImport:
DiagName = "import conditional"; break;
case PlatformConditionKind::TargetEnvironment:
DiagName = "target environment"; break;
case PlatformConditionKind::Runtime:
llvm_unreachable("handled above");
}
@@ -6,9 +6,11 @@ func f2(
FOO: Int,
swift: Int, _compiler_version: Int,
os: Int, arch: Int, _endian: Int, _runtime: Int,
targetEnvironment: Int,
arm: Int, i386: Int, macOS: Int, OSX: Int, Linux: Int,
big: Int, little: Int,
_ObjC: Int, _Native: Int
_ObjC: Int, _Native: Int,
simulator: Int
) {

#if FOO
@@ -23,6 +25,8 @@ func f2(
_ = _runtime + _ObjC + _Native
#elseif swift(>=1.0) && _compiler_version("3.*.0")
_ = swift + _compiler_version
#elseif targetEnvironment(simulator)
_ = targetEnvironment + simulator
#endif

}
@@ -31,9 +35,11 @@ func f2() {
let
FOO = 1, swift = 1, _compiler_version = 1,
os = 1, arch = 1, _endian = 1, _runtime = 1,
targetEnvironment = 1,
arm = 1, i386 = 1, macOS = 1, OSX = 1, Linux = 1,
big = 1, little = 1,
_ObjC = 1, _Native = 1
_ObjC = 1, _Native = 1,
simulator = 1

#if FOO
_ = FOO
@@ -47,6 +53,8 @@ func f2() {
_ = _runtime + _ObjC + _Native
#elseif swift(>=1.0) && _compiler_version("3.*.0")
_ = swift + _compiler_version
#elseif targetEnvironment(simulator)
_ = targetEnvironment + simulator
#endif

}
@@ -55,16 +63,19 @@ struct S {
let
FOO = 1, swift = 1, _compiler_version = 1,
os = 1, arch = 1, _endian = 1, _runtime = 1,
targetEnvironment = 1,
arm = 1, i386 = 1, macOS = 1, OSX = 1, Linux = 1,
big = 1, little = 1,
_ObjC = 1, _Native = 1
_ObjC = 1, _Native = 1,
simulator = 1

#if FOO
#elseif os(macOS) && os(OSX) && os(Linux)
#elseif arch(i386) && arch(arm)
#elseif _endian(big) && _endian(little)
#elseif _runtime(_ObjC) && _runtime(_Native)
#elseif swift(>=1.0) && _compiler_version("3.*.0")
#elseif targetEnvironment(simulator)
#endif

}
@@ -0,0 +1,13 @@
// RUN: %swift -typecheck %s -verify -target x86_64-apple-ios7.0 -parse-stdlib
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target x86_64-apple-ios7.0
#if !targetEnvironment(simulator)
// This block should not parse.
let i: Int = "Hello"
#endif

#if targetEnvironment(simulator)
class C {}
var x = C()
#endif
var y = x
ProTip! Use n and p to navigate between commits in a pull request.