mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Move AvailabilityAttr::PlatformKind into its own file
Swift SVN r21728
This commit is contained in:
@@ -30,10 +30,6 @@
|
||||
#define TYPE_ATTR(X)
|
||||
#endif
|
||||
|
||||
#ifndef AVAILABILITY_PLATFORM
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName)
|
||||
#endif
|
||||
|
||||
// Type attributes
|
||||
TYPE_ATTR(autoclosure)
|
||||
TYPE_ATTR(cc)
|
||||
@@ -198,13 +194,6 @@ DECL_ATTR(__objc_bridged, ObjCBridged, OnClass | NotSerialized,
|
||||
SIMPLE_DECL_ATTR(NSApplicationMain, NSApplicationMain,
|
||||
OnClass, 52)
|
||||
|
||||
// Reordering these platforms will break serialization.
|
||||
AVAILABILITY_PLATFORM(iOS, "iOS")
|
||||
AVAILABILITY_PLATFORM(OSX, "OS X")
|
||||
AVAILABILITY_PLATFORM(iOSApplicationExtension, "iOS application extension")
|
||||
AVAILABILITY_PLATFORM(OSXApplicationExtension, "OS X application extension")
|
||||
|
||||
#undef AVAILABILITY_PLATFORM
|
||||
#undef TYPE_ATTR
|
||||
#undef DECL_ATTR_ALIAS
|
||||
#undef SIMPLE_DECL_ATTR
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "swift/Basic/SourceLoc.h"
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include "swift/AST/Ownership.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
@@ -586,12 +587,6 @@ enum class MinVersionComparison {
|
||||
/// Defines the @availability attribute.
|
||||
class AvailabilityAttr : public DeclAttribute {
|
||||
public:
|
||||
/// Available platforms for the availability attribute.
|
||||
enum PlatformKind {
|
||||
none,
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) X,
|
||||
#include "swift/AST/Attr.def"
|
||||
};
|
||||
|
||||
#define INIT_VER_TUPLE(X)\
|
||||
X(X.empty() ? Optional<clang::VersionTuple>() : X)
|
||||
|
||||
31
include/swift/AST/PlatformKind.h
Normal file
31
include/swift/AST/PlatformKind.h
Normal file
@@ -0,0 +1,31 @@
|
||||
//===--- PlatformKinds.h - 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 defines the platform kinds for API availability.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_AST_PLATFORM_KIND_H
|
||||
#define SWIFT_AST_PLATFORM_KIND_H
|
||||
|
||||
namespace swift {
|
||||
|
||||
/// Available platforms for the availability attribute.
|
||||
enum class PlatformKind {
|
||||
none,
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) X,
|
||||
#include "swift/AST/PlatformKinds.def"
|
||||
};
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif
|
||||
30
include/swift/AST/PlatformKinds.def
Normal file
30
include/swift/AST/PlatformKinds.def
Normal file
@@ -0,0 +1,30 @@
|
||||
//===--- PlatformKinds.def - Swift PlatformKind Metaprogramming -*- 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 defines macros used for macro-metaprogramming with platform kinds.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// AVAILABILITY_PLATFORM(X, PrettyName)
|
||||
/// X - The name of the platform
|
||||
/// PrettyName - A string with the platform name for pretty printing
|
||||
#ifndef AVAILABILITY_PLATFORM
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName)
|
||||
#endif
|
||||
|
||||
// Reordering these platforms will break serialization.
|
||||
AVAILABILITY_PLATFORM(iOS, "iOS")
|
||||
AVAILABILITY_PLATFORM(OSX, "OS X")
|
||||
AVAILABILITY_PLATFORM(iOSApplicationExtension, "iOS application extension")
|
||||
AVAILABILITY_PLATFORM(OSXApplicationExtension, "OS X application extension")
|
||||
|
||||
#undef AVAILABILITY_PLATFORM
|
||||
@@ -398,52 +398,53 @@ AvailabilityAttr *AvailabilityAttr::createUnavailableAttr(ASTContext &C,
|
||||
}
|
||||
|
||||
StringRef
|
||||
AvailabilityAttr::platformString(AvailabilityAttr::PlatformKind platform) {
|
||||
AvailabilityAttr::platformString(PlatformKind platform) {
|
||||
switch (platform) {
|
||||
case none: return "*";
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) case X: return #X;
|
||||
#include "swift/AST/Attr.def"
|
||||
case PlatformKind::none: return "*";
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) case PlatformKind::X: return #X;
|
||||
#include "swift/AST/PlatformKinds.def"
|
||||
}
|
||||
}
|
||||
|
||||
StringRef AvailabilityAttr::prettyPlatformString(
|
||||
AvailabilityAttr::PlatformKind platform) {
|
||||
PlatformKind platform) {
|
||||
switch (platform) {
|
||||
case none: return "*";
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) case X: return PrettyName;
|
||||
#include "swift/AST/Attr.def"
|
||||
case PlatformKind::none: return "*";
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) case PlatformKind::X: \
|
||||
return PrettyName;
|
||||
#include "swift/AST/PlatformKinds.def"
|
||||
}
|
||||
}
|
||||
|
||||
Optional<AvailabilityAttr::PlatformKind>
|
||||
Optional<PlatformKind>
|
||||
AvailabilityAttr::platformFromString(StringRef Name) {
|
||||
if (Name == "*")
|
||||
return PlatformKind::none;
|
||||
return
|
||||
llvm::StringSwitch<Optional<AvailabilityAttr::PlatformKind>>(Name)
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) .Case(#X, X)
|
||||
#include "swift/AST/Attr.def"
|
||||
.Default(Optional<AvailabilityAttr::PlatformKind>());
|
||||
llvm::StringSwitch<Optional<PlatformKind>>(Name)
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) .Case(#X, PlatformKind::X)
|
||||
#include "swift/AST/PlatformKinds.def"
|
||||
.Default(Optional<PlatformKind>());
|
||||
}
|
||||
|
||||
bool AvailabilityAttr::isActivePlatform(const ASTContext &ctx) const {
|
||||
if (!hasPlatform())
|
||||
return true;
|
||||
|
||||
if (Platform == OSXApplicationExtension ||
|
||||
Platform == iOSApplicationExtension)
|
||||
if (Platform == PlatformKind::OSXApplicationExtension ||
|
||||
Platform == PlatformKind::iOSApplicationExtension)
|
||||
if (!ctx.LangOpts.EnableAppExtensionRestrictions)
|
||||
return false;
|
||||
|
||||
// FIXME: This is an awful way to get the current OS.
|
||||
switch (Platform) {
|
||||
case OSX:
|
||||
case OSXApplicationExtension:
|
||||
case PlatformKind::OSX:
|
||||
case PlatformKind::OSXApplicationExtension:
|
||||
return ctx.LangOpts.getTargetConfigOption("os") == "OSX";
|
||||
case iOS:
|
||||
case iOSApplicationExtension:
|
||||
case PlatformKind::iOS:
|
||||
case PlatformKind::iOSApplicationExtension:
|
||||
return ctx.LangOpts.getTargetConfigOption("os") == "iOS";
|
||||
case none:
|
||||
case PlatformKind::none:
|
||||
llvm_unreachable("handled above");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4702,12 +4702,12 @@ void ClangImporter::Implementation::importAttributes(
|
||||
|
||||
// Translate from Clang platform strings to known Swift platforms.
|
||||
auto platformK =
|
||||
llvm::StringSwitch<Optional<AvailabilityAttr::PlatformKind>>(Platform)
|
||||
.Case("ios", AvailabilityAttr::iOS)
|
||||
.Case("macosx", AvailabilityAttr::OSX)
|
||||
.Case("ios_app_extension", AvailabilityAttr::iOSApplicationExtension)
|
||||
llvm::StringSwitch<Optional<PlatformKind>>(Platform)
|
||||
.Case("ios", PlatformKind::iOS)
|
||||
.Case("macosx", PlatformKind::OSX)
|
||||
.Case("ios_app_extension", PlatformKind::iOSApplicationExtension)
|
||||
.Case("macosx_app_extension",
|
||||
AvailabilityAttr::OSXApplicationExtension)
|
||||
PlatformKind::OSXApplicationExtension)
|
||||
.Default(Nothing);
|
||||
if (!platformK)
|
||||
continue;
|
||||
|
||||
@@ -1584,7 +1584,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
|
||||
Attr = new (ctx) AvailabilityAttr(
|
||||
SourceLoc(), SourceRange(),
|
||||
(AvailabilityAttr::PlatformKind)platform, message, rename,
|
||||
(PlatformKind)platform, message, rename,
|
||||
Introduced, Deprecated, Obsoleted,
|
||||
isUnavailable, isImplicit);
|
||||
break;
|
||||
|
||||
@@ -1398,7 +1398,7 @@ void Serializer::writeDeclAttribute(const DeclAttribute *DA) {
|
||||
LIST_VER_TUPLE_PIECES(Introduced),
|
||||
LIST_VER_TUPLE_PIECES(Deprecated),
|
||||
LIST_VER_TUPLE_PIECES(Obsoleted),
|
||||
theAttr->Platform,
|
||||
static_cast<unsigned>(theAttr->Platform),
|
||||
theAttr->Message.size(),
|
||||
theAttr->Rename.size(),
|
||||
blob);
|
||||
|
||||
Reference in New Issue
Block a user