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)
|
#define TYPE_ATTR(X)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef AVAILABILITY_PLATFORM
|
|
||||||
#define AVAILABILITY_PLATFORM(X, PrettyName)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Type attributes
|
// Type attributes
|
||||||
TYPE_ATTR(autoclosure)
|
TYPE_ATTR(autoclosure)
|
||||||
TYPE_ATTR(cc)
|
TYPE_ATTR(cc)
|
||||||
@@ -198,13 +194,6 @@ DECL_ATTR(__objc_bridged, ObjCBridged, OnClass | NotSerialized,
|
|||||||
SIMPLE_DECL_ATTR(NSApplicationMain, NSApplicationMain,
|
SIMPLE_DECL_ATTR(NSApplicationMain, NSApplicationMain,
|
||||||
OnClass, 52)
|
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 TYPE_ATTR
|
||||||
#undef DECL_ATTR_ALIAS
|
#undef DECL_ATTR_ALIAS
|
||||||
#undef SIMPLE_DECL_ATTR
|
#undef SIMPLE_DECL_ATTR
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "swift/Basic/SourceLoc.h"
|
#include "swift/Basic/SourceLoc.h"
|
||||||
#include "swift/AST/Identifier.h"
|
#include "swift/AST/Identifier.h"
|
||||||
#include "swift/AST/Ownership.h"
|
#include "swift/AST/Ownership.h"
|
||||||
|
#include "swift/AST/PlatformKind.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
@@ -586,12 +587,6 @@ enum class MinVersionComparison {
|
|||||||
/// Defines the @availability attribute.
|
/// Defines the @availability attribute.
|
||||||
class AvailabilityAttr : public DeclAttribute {
|
class AvailabilityAttr : public DeclAttribute {
|
||||||
public:
|
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)\
|
#define INIT_VER_TUPLE(X)\
|
||||||
X(X.empty() ? Optional<clang::VersionTuple>() : 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
|
StringRef
|
||||||
AvailabilityAttr::platformString(AvailabilityAttr::PlatformKind platform) {
|
AvailabilityAttr::platformString(PlatformKind platform) {
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case none: return "*";
|
case PlatformKind::none: return "*";
|
||||||
#define AVAILABILITY_PLATFORM(X, PrettyName) case X: return #X;
|
#define AVAILABILITY_PLATFORM(X, PrettyName) case PlatformKind::X: return #X;
|
||||||
#include "swift/AST/Attr.def"
|
#include "swift/AST/PlatformKinds.def"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StringRef AvailabilityAttr::prettyPlatformString(
|
StringRef AvailabilityAttr::prettyPlatformString(
|
||||||
AvailabilityAttr::PlatformKind platform) {
|
PlatformKind platform) {
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case none: return "*";
|
case PlatformKind::none: return "*";
|
||||||
#define AVAILABILITY_PLATFORM(X, PrettyName) case X: return PrettyName;
|
#define AVAILABILITY_PLATFORM(X, PrettyName) case PlatformKind::X: \
|
||||||
#include "swift/AST/Attr.def"
|
return PrettyName;
|
||||||
|
#include "swift/AST/PlatformKinds.def"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<AvailabilityAttr::PlatformKind>
|
Optional<PlatformKind>
|
||||||
AvailabilityAttr::platformFromString(StringRef Name) {
|
AvailabilityAttr::platformFromString(StringRef Name) {
|
||||||
if (Name == "*")
|
if (Name == "*")
|
||||||
return PlatformKind::none;
|
return PlatformKind::none;
|
||||||
return
|
return
|
||||||
llvm::StringSwitch<Optional<AvailabilityAttr::PlatformKind>>(Name)
|
llvm::StringSwitch<Optional<PlatformKind>>(Name)
|
||||||
#define AVAILABILITY_PLATFORM(X, PrettyName) .Case(#X, X)
|
#define AVAILABILITY_PLATFORM(X, PrettyName) .Case(#X, PlatformKind::X)
|
||||||
#include "swift/AST/Attr.def"
|
#include "swift/AST/PlatformKinds.def"
|
||||||
.Default(Optional<AvailabilityAttr::PlatformKind>());
|
.Default(Optional<PlatformKind>());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AvailabilityAttr::isActivePlatform(const ASTContext &ctx) const {
|
bool AvailabilityAttr::isActivePlatform(const ASTContext &ctx) const {
|
||||||
if (!hasPlatform())
|
if (!hasPlatform())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (Platform == OSXApplicationExtension ||
|
if (Platform == PlatformKind::OSXApplicationExtension ||
|
||||||
Platform == iOSApplicationExtension)
|
Platform == PlatformKind::iOSApplicationExtension)
|
||||||
if (!ctx.LangOpts.EnableAppExtensionRestrictions)
|
if (!ctx.LangOpts.EnableAppExtensionRestrictions)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// FIXME: This is an awful way to get the current OS.
|
// FIXME: This is an awful way to get the current OS.
|
||||||
switch (Platform) {
|
switch (Platform) {
|
||||||
case OSX:
|
case PlatformKind::OSX:
|
||||||
case OSXApplicationExtension:
|
case PlatformKind::OSXApplicationExtension:
|
||||||
return ctx.LangOpts.getTargetConfigOption("os") == "OSX";
|
return ctx.LangOpts.getTargetConfigOption("os") == "OSX";
|
||||||
case iOS:
|
case PlatformKind::iOS:
|
||||||
case iOSApplicationExtension:
|
case PlatformKind::iOSApplicationExtension:
|
||||||
return ctx.LangOpts.getTargetConfigOption("os") == "iOS";
|
return ctx.LangOpts.getTargetConfigOption("os") == "iOS";
|
||||||
case none:
|
case PlatformKind::none:
|
||||||
llvm_unreachable("handled above");
|
llvm_unreachable("handled above");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4702,12 +4702,12 @@ void ClangImporter::Implementation::importAttributes(
|
|||||||
|
|
||||||
// Translate from Clang platform strings to known Swift platforms.
|
// Translate from Clang platform strings to known Swift platforms.
|
||||||
auto platformK =
|
auto platformK =
|
||||||
llvm::StringSwitch<Optional<AvailabilityAttr::PlatformKind>>(Platform)
|
llvm::StringSwitch<Optional<PlatformKind>>(Platform)
|
||||||
.Case("ios", AvailabilityAttr::iOS)
|
.Case("ios", PlatformKind::iOS)
|
||||||
.Case("macosx", AvailabilityAttr::OSX)
|
.Case("macosx", PlatformKind::OSX)
|
||||||
.Case("ios_app_extension", AvailabilityAttr::iOSApplicationExtension)
|
.Case("ios_app_extension", PlatformKind::iOSApplicationExtension)
|
||||||
.Case("macosx_app_extension",
|
.Case("macosx_app_extension",
|
||||||
AvailabilityAttr::OSXApplicationExtension)
|
PlatformKind::OSXApplicationExtension)
|
||||||
.Default(Nothing);
|
.Default(Nothing);
|
||||||
if (!platformK)
|
if (!platformK)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -1584,7 +1584,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
|||||||
|
|
||||||
Attr = new (ctx) AvailabilityAttr(
|
Attr = new (ctx) AvailabilityAttr(
|
||||||
SourceLoc(), SourceRange(),
|
SourceLoc(), SourceRange(),
|
||||||
(AvailabilityAttr::PlatformKind)platform, message, rename,
|
(PlatformKind)platform, message, rename,
|
||||||
Introduced, Deprecated, Obsoleted,
|
Introduced, Deprecated, Obsoleted,
|
||||||
isUnavailable, isImplicit);
|
isUnavailable, isImplicit);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1398,7 +1398,7 @@ void Serializer::writeDeclAttribute(const DeclAttribute *DA) {
|
|||||||
LIST_VER_TUPLE_PIECES(Introduced),
|
LIST_VER_TUPLE_PIECES(Introduced),
|
||||||
LIST_VER_TUPLE_PIECES(Deprecated),
|
LIST_VER_TUPLE_PIECES(Deprecated),
|
||||||
LIST_VER_TUPLE_PIECES(Obsoleted),
|
LIST_VER_TUPLE_PIECES(Obsoleted),
|
||||||
theAttr->Platform,
|
static_cast<unsigned>(theAttr->Platform),
|
||||||
theAttr->Message.size(),
|
theAttr->Message.size(),
|
||||||
theAttr->Rename.size(),
|
theAttr->Rename.size(),
|
||||||
blob);
|
blob);
|
||||||
|
|||||||
Reference in New Issue
Block a user