mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Change the active-platform availability logic to not consider iOS as active on tvOS. We want all of the messiness of the fact that tvOS was branched from iOS to be handled in clang, which "transcribes" iOS availability attributes to their corresponding tvOS counterparts as long as there is not an existing explicit tvOS availability attribute on the declaration. This change exposed several places where I needed to add explicit handling of of tvOS and where we will need to handle watchOS as well. rdar://problem/20774229 tracks adding logic and tests to handle watchOS in these places. It is also unfortunately the case that llvm::triple returns true when isiOS() is called on tvOS. This means that to test whether an llvm:triple target is really iOS, we need to check for iOS then check explicitly that it is not tvOS. We will eventually change llvm's behavior here so that the double check is not needed. Swift SVN r28013
110 lines
3.6 KiB
C++
110 lines
3.6 KiB
C++
//===--- PlatformKind.cpp - Swift Language Platform Kinds -------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the platform kinds for API availability.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "swift/AST/PlatformKind.h"
|
|
#include "swift/Basic/LangOptions.h"
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
using namespace swift;
|
|
|
|
StringRef swift::platformString(PlatformKind platform) {
|
|
switch (platform) {
|
|
case PlatformKind::none:
|
|
return "*";
|
|
#define AVAILABILITY_PLATFORM(X, PrettyName) \
|
|
case PlatformKind::X: \
|
|
return #X;
|
|
#include "swift/AST/PlatformKinds.def"
|
|
}
|
|
llvm_unreachable("bad PlatformKind");
|
|
}
|
|
|
|
StringRef swift::prettyPlatformString(PlatformKind platform) {
|
|
switch (platform) {
|
|
case PlatformKind::none:
|
|
return "*";
|
|
#define AVAILABILITY_PLATFORM(X, PrettyName) \
|
|
case PlatformKind::X: \
|
|
return PrettyName;
|
|
#include "swift/AST/PlatformKinds.def"
|
|
}
|
|
llvm_unreachable("bad PlatformKind");
|
|
}
|
|
|
|
Optional<PlatformKind> swift::platformFromString(StringRef Name) {
|
|
if (Name == "*")
|
|
return PlatformKind::none;
|
|
return llvm::StringSwitch<Optional<PlatformKind>>(Name)
|
|
#define AVAILABILITY_PLATFORM(X, PrettyName) .Case(#X, PlatformKind::X)
|
|
#include "swift/AST/PlatformKinds.def"
|
|
.Default(Optional<PlatformKind>());
|
|
}
|
|
|
|
bool swift::isPlatformActive(PlatformKind Platform, LangOptions &LangOpts) {
|
|
if (Platform == PlatformKind::none)
|
|
return true;
|
|
|
|
if (Platform == PlatformKind::OSXApplicationExtension ||
|
|
Platform == PlatformKind::iOSApplicationExtension)
|
|
if (!LangOpts.EnableAppExtensionRestrictions)
|
|
return false;
|
|
|
|
// FIXME: This is an awful way to get the current OS.
|
|
switch (Platform) {
|
|
case PlatformKind::OSX:
|
|
case PlatformKind::OSXApplicationExtension:
|
|
return LangOpts.Target.isMacOSX();
|
|
case PlatformKind::iOS:
|
|
case PlatformKind::iOSApplicationExtension:
|
|
return LangOpts.Target.isiOS() && !LangOpts.Target.isTvOS();
|
|
case PlatformKind::tvOS:
|
|
case PlatformKind::tvOSApplicationExtension:
|
|
return LangOpts.Target.isTvOS();
|
|
case PlatformKind::watchOS:
|
|
case PlatformKind::watchOSApplicationExtension:
|
|
return LangOpts.Target.isWatchOS();
|
|
case PlatformKind::none:
|
|
llvm_unreachable("handled above");
|
|
}
|
|
llvm_unreachable("bad PlatformKind");
|
|
}
|
|
|
|
PlatformKind swift::targetPlatform(LangOptions &LangOpts) {
|
|
if (LangOpts.Target.isMacOSX()) {
|
|
return (LangOpts.EnableAppExtensionRestrictions
|
|
? PlatformKind::OSXApplicationExtension
|
|
: PlatformKind::OSX);
|
|
}
|
|
|
|
if (LangOpts.Target.isTvOS()) {
|
|
return (LangOpts.EnableAppExtensionRestrictions
|
|
? PlatformKind::tvOSApplicationExtension
|
|
: PlatformKind::tvOS);
|
|
}
|
|
|
|
// We need to handle watchOS here, as well.
|
|
// rdar://problem/20774229
|
|
|
|
if (LangOpts.Target.isiOS()) {
|
|
return (LangOpts.EnableAppExtensionRestrictions
|
|
? PlatformKind::iOSApplicationExtension
|
|
: PlatformKind::iOS);
|
|
}
|
|
|
|
return PlatformKind::none;
|
|
}
|