mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
ASTBridging: Bridge swift::PlatformKind directly
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "swift/AST/DiagnosticList.h"
|
||||
#include "swift/AST/GenericTypeParamKind.h"
|
||||
#include "swift/AST/LayoutConstraintKind.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/Basic/BasicBridging.h"
|
||||
|
||||
#ifdef USED_IN_CPP_SOURCE
|
||||
@@ -67,7 +68,6 @@ class MacroIntroducedDeclName;
|
||||
enum class MacroIntroducedDeclNameKind;
|
||||
enum class ParamSpecifier : uint8_t;
|
||||
class ParsedAutoDiffParameter;
|
||||
enum class PlatformKind : uint8_t;
|
||||
class ProtocolConformanceRef;
|
||||
class RegexLiteralPatternFeature;
|
||||
class RegexLiteralPatternFeatureKind;
|
||||
@@ -88,7 +88,6 @@ struct BridgedSubstitutionMap;
|
||||
struct BridgedGenericSignature;
|
||||
struct BridgedConformance;
|
||||
class BridgedParameterList;
|
||||
enum BridgedPlatformKind : size_t;
|
||||
|
||||
// Forward declare the underlying AST node type for each wrapper.
|
||||
namespace swift {
|
||||
@@ -683,20 +682,14 @@ BridgedClosureExpr_asDeclContext(BridgedClosureExpr cClosure);
|
||||
// MARK: Availability
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedPlatformKind : size_t {
|
||||
BridgedPlatformKind_None,
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) BridgedPlatformKind_##X,
|
||||
#include "swift/AST/PlatformKinds.def"
|
||||
};
|
||||
BRIDGED_OPTIONAL(swift::PlatformKind, PlatformKind)
|
||||
|
||||
SWIFT_NAME("BridgedPlatformKind.init(from:)")
|
||||
BridgedPlatformKind BridgedPlatformKind_fromString(BridgedStringRef cStr);
|
||||
SWIFT_NAME("BridgedOptionalPlatformKind.init(from:)")
|
||||
BridgedOptionalPlatformKind PlatformKind_fromString(BridgedStringRef cStr);
|
||||
|
||||
SWIFT_NAME("BridgedPlatformKind.init(from:)")
|
||||
BridgedPlatformKind
|
||||
BridgedPlatformKind_fromIdentifier(BridgedIdentifier cIdent);
|
||||
|
||||
swift::PlatformKind unbridge(BridgedPlatformKind cPlatform);
|
||||
SWIFT_NAME("BridgedOptionalPlatformKind.init(from:)")
|
||||
BridgedOptionalPlatformKind
|
||||
PlatformKind_fromIdentifier(BridgedIdentifier cIdent);
|
||||
|
||||
SWIFT_NAME("BridgedAvailabilityMacroMap.has(self:name:)")
|
||||
bool BridgedAvailabilityMacroMap_hasName(BridgedAvailabilityMacroMap map,
|
||||
@@ -931,7 +924,7 @@ SWIFT_NAME(
|
||||
"BridgedBackDeployedAttr.createParsed(_:atLoc:range:platform:version:)")
|
||||
BridgedBackDeployedAttr BridgedBackDeployedAttr_createParsed(
|
||||
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
|
||||
BridgedSourceRange cRange, BridgedPlatformKind cPlatform,
|
||||
BridgedSourceRange cRange, swift::PlatformKind platform,
|
||||
BridgedVersionTuple cVersion);
|
||||
|
||||
SWIFT_NAME("BridgedCDeclAttr.createParsed(_:atLoc:range:name:)")
|
||||
@@ -1161,7 +1154,7 @@ SWIFT_NAME("BridgedOriginallyDefinedInAttr.createParsed(_:atLoc:range:"
|
||||
BridgedOriginallyDefinedInAttr BridgedOriginallyDefinedInAttr_createParsed(
|
||||
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
|
||||
BridgedSourceRange cRange, BridgedStringRef cModuleName,
|
||||
BridgedPlatformKind cPlatform, BridgedVersionTuple cVersion);
|
||||
swift::PlatformKind platform, BridgedVersionTuple cVersion);
|
||||
|
||||
SWIFT_NAME("BridgedStorageRestrictionsAttr.createParsed(_:atLoc:range:"
|
||||
"initializes:accesses:)")
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "swift/AST/LifetimeDependence.h"
|
||||
#include "swift/AST/MacroDeclaration.h"
|
||||
#include "swift/AST/Ownership.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/AST/PlatformKindUtils.h"
|
||||
#include "swift/AST/StorageImpl.h"
|
||||
#include "swift/Basic/Debug.h"
|
||||
#include "swift/Basic/EnumTraits.h"
|
||||
@@ -41,10 +41,10 @@
|
||||
#include "swift/Basic/SourceLoc.h"
|
||||
#include "swift/Basic/UUID.h"
|
||||
#include "swift/Basic/Version.h"
|
||||
#include "llvm/ADT/bit.h"
|
||||
#include "llvm/ADT/DenseMapInfo.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/bit.h"
|
||||
#include "llvm/ADT/iterator_range.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/TrailingObjects.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2024 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "swift/AST/Attr.h"
|
||||
#include "swift/AST/AvailabilityDomain.h"
|
||||
#include "swift/AST/AvailabilityRange.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/AST/PlatformKindUtils.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Basic/OptionSet.h"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2024 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "swift/AST/AvailabilityDomain.h"
|
||||
#include "swift/AST/AvailabilityRange.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/AST/PlatformKindUtils.h"
|
||||
#include "swift/Basic/Debug.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include <optional>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2024 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "swift/AST/ASTAllocated.h"
|
||||
#include "swift/AST/AvailabilityRange.h"
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/AST/PlatformKindUtils.h"
|
||||
#include "swift/Basic/Assertions.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Basic/SourceLoc.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "swift/AST/ASTAllocated.h"
|
||||
#include "swift/AST/AvailabilityDomain.h"
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/AST/PlatformKindUtils.h"
|
||||
#include "swift/Basic/STLExtras.h"
|
||||
#include "swift/Basic/SourceLoc.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
|
||||
@@ -1,108 +1,36 @@
|
||||
//===--- PlatformKind.h - Swift Language Platform Kinds ---------*- C++ -*-===//
|
||||
//===--- AST/PlatformKind.h - Swift Language Platform Kinds -----*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the platform kinds for API availability.
|
||||
//
|
||||
///
|
||||
/// This file defines the platform kinds for API availability.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_AST_PLATFORM_KIND_H
|
||||
#define SWIFT_AST_PLATFORM_KIND_H
|
||||
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Config.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/VersionTuple.h"
|
||||
#include "llvm/TargetParser/Triple.h"
|
||||
#include <optional>
|
||||
/// This header is included in a bridging header. Be *very* careful with what
|
||||
/// you include here! See include caveats in `ASTBridging.h`.
|
||||
#include "swift/Basic/SwiftBridging.h"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace swift {
|
||||
|
||||
class LangOptions;
|
||||
|
||||
/// Available platforms for the availability attribute.
|
||||
enum class PlatformKind: uint8_t {
|
||||
enum class ENUM_EXTENSIBILITY_ATTR(closed) PlatformKind : uint8_t {
|
||||
none,
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) X,
|
||||
#include "swift/AST/PlatformKinds.def"
|
||||
};
|
||||
|
||||
/// Returns the short string representing the platform, suitable for
|
||||
/// use in availability specifications (e.g., "OSX").
|
||||
StringRef platformString(PlatformKind platform);
|
||||
|
||||
/// Returns the platform kind corresponding to the passed-in short platform name
|
||||
/// or None if such a platform kind does not exist.
|
||||
std::optional<PlatformKind> platformFromString(StringRef Name);
|
||||
|
||||
/// Safely converts the given unsigned value to a valid \c PlatformKind value or
|
||||
/// \c nullopt otherwise.
|
||||
std::optional<PlatformKind> platformFromUnsigned(unsigned value);
|
||||
|
||||
/// Returns a valid platform string that is closest to the candidate string
|
||||
/// based on edit distance. Returns \c None if the closest valid platform
|
||||
/// distance is not within a minimum threshold.
|
||||
std::optional<StringRef> closestCorrectedPlatformString(StringRef candidate);
|
||||
|
||||
/// Returns a human-readable version of the platform name as a string, suitable
|
||||
/// for emission in diagnostics (e.g., "macOS").
|
||||
StringRef prettyPlatformString(PlatformKind platform);
|
||||
|
||||
/// Returns the base platform for an application-extension platform. For example
|
||||
/// `iOS` would be returned for `iOSApplicationExtension`. Returns `None` for
|
||||
/// platforms which are not application extension platforms.
|
||||
std::optional<PlatformKind>
|
||||
basePlatformForExtensionPlatform(PlatformKind Platform);
|
||||
|
||||
/// Returns true if \p Platform represents and application extension platform,
|
||||
/// e.g. `iOSApplicationExtension`.
|
||||
inline bool isApplicationExtensionPlatform(PlatformKind Platform) {
|
||||
return basePlatformForExtensionPlatform(Platform).has_value();
|
||||
}
|
||||
|
||||
/// Returns whether the passed-in platform is active, given the language
|
||||
/// options. A platform is active if either it is the target platform or its
|
||||
/// AppExtension variant is the target platform. For example, OS X is
|
||||
/// considered active when the target operating system is OS X and app extension
|
||||
/// restrictions are enabled, but OSXApplicationExtension is not considered
|
||||
/// active when the target platform is OS X and app extension restrictions are
|
||||
/// disabled. PlatformKind::none is always considered active.
|
||||
/// If ForTargetVariant is true then for zippered builds the target-variant
|
||||
/// triple will be used rather than the target to determine whether the
|
||||
/// platform is active.
|
||||
bool isPlatformActive(PlatformKind Platform, const LangOptions &LangOpts,
|
||||
bool ForTargetVariant = false, bool ForRuntimeQuery = false);
|
||||
|
||||
/// Returns the target platform for the given language options.
|
||||
PlatformKind targetPlatform(const LangOptions &LangOpts);
|
||||
|
||||
/// Returns the target variant platform for the given language options.
|
||||
PlatformKind targetVariantPlatform(const LangOptions &LangOpts);
|
||||
|
||||
/// Returns true when availability attributes from the "parent" platform
|
||||
/// should also apply to the "child" platform for declarations without
|
||||
/// an explicit attribute for the child.
|
||||
bool inheritsAvailabilityFromPlatform(PlatformKind Child, PlatformKind Parent);
|
||||
|
||||
/// Returns the LLVM triple OS type for the given platform, if there is one.
|
||||
std::optional<llvm::Triple::OSType>
|
||||
tripleOSTypeForPlatform(PlatformKind platform);
|
||||
|
||||
llvm::VersionTuple canonicalizePlatformVersion(
|
||||
PlatformKind platform, const llvm::VersionTuple &version);
|
||||
|
||||
/// Returns true if \p Platform should be considered to be SPI and therefore not
|
||||
/// printed in public `.swiftinterface` files, for example.
|
||||
bool isPlatformSPI(PlatformKind Platform);
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif
|
||||
#endif // SWIFT_AST_PLATFORM_KIND_H
|
||||
|
||||
101
include/swift/AST/PlatformKindUtils.h
Normal file
101
include/swift/AST/PlatformKindUtils.h
Normal file
@@ -0,0 +1,101 @@
|
||||
//===--- AST/PlatformKindUtils.h --------------------------------*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
///
|
||||
/// This file declares operations for working with `PlatformKind`.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_AST_PLATFORM_KIND_UTILS_H
|
||||
#define SWIFT_AST_PLATFORM_KIND_UTILS_H
|
||||
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Config.h"
|
||||
#include "llvm/Support/VersionTuple.h"
|
||||
#include "llvm/TargetParser/Triple.h"
|
||||
#include <optional>
|
||||
|
||||
namespace swift {
|
||||
|
||||
class LangOptions;
|
||||
|
||||
/// Returns the short string representing the platform, suitable for
|
||||
/// use in availability specifications (e.g., "OSX").
|
||||
StringRef platformString(PlatformKind platform);
|
||||
|
||||
/// Returns the platform kind corresponding to the passed-in short platform name
|
||||
/// or None if such a platform kind does not exist.
|
||||
std::optional<PlatformKind> platformFromString(StringRef Name);
|
||||
|
||||
/// Safely converts the given unsigned value to a valid \c PlatformKind value or
|
||||
/// \c nullopt otherwise.
|
||||
std::optional<PlatformKind> platformFromUnsigned(unsigned value);
|
||||
|
||||
/// Returns a valid platform string that is closest to the candidate string
|
||||
/// based on edit distance. Returns \c None if the closest valid platform
|
||||
/// distance is not within a minimum threshold.
|
||||
std::optional<StringRef> closestCorrectedPlatformString(StringRef candidate);
|
||||
|
||||
/// Returns a human-readable version of the platform name as a string, suitable
|
||||
/// for emission in diagnostics (e.g., "macOS").
|
||||
StringRef prettyPlatformString(PlatformKind platform);
|
||||
|
||||
/// Returns the base platform for an application-extension platform. For example
|
||||
/// `iOS` would be returned for `iOSApplicationExtension`. Returns `None` for
|
||||
/// platforms which are not application extension platforms.
|
||||
std::optional<PlatformKind>
|
||||
basePlatformForExtensionPlatform(PlatformKind Platform);
|
||||
|
||||
/// Returns true if \p Platform represents and application extension platform,
|
||||
/// e.g. `iOSApplicationExtension`.
|
||||
inline bool isApplicationExtensionPlatform(PlatformKind Platform) {
|
||||
return basePlatformForExtensionPlatform(Platform).has_value();
|
||||
}
|
||||
|
||||
/// Returns whether the passed-in platform is active, given the language
|
||||
/// options. A platform is active if either it is the target platform or its
|
||||
/// AppExtension variant is the target platform. For example, OS X is
|
||||
/// considered active when the target operating system is OS X and app extension
|
||||
/// restrictions are enabled, but OSXApplicationExtension is not considered
|
||||
/// active when the target platform is OS X and app extension restrictions are
|
||||
/// disabled. PlatformKind::none is always considered active.
|
||||
/// If ForTargetVariant is true then for zippered builds the target-variant
|
||||
/// triple will be used rather than the target to determine whether the
|
||||
/// platform is active.
|
||||
bool isPlatformActive(PlatformKind Platform, const LangOptions &LangOpts,
|
||||
bool ForTargetVariant = false, bool ForRuntimeQuery = false);
|
||||
|
||||
/// Returns the target platform for the given language options.
|
||||
PlatformKind targetPlatform(const LangOptions &LangOpts);
|
||||
|
||||
/// Returns the target variant platform for the given language options.
|
||||
PlatformKind targetVariantPlatform(const LangOptions &LangOpts);
|
||||
|
||||
/// Returns true when availability attributes from the "parent" platform
|
||||
/// should also apply to the "child" platform for declarations without
|
||||
/// an explicit attribute for the child.
|
||||
bool inheritsAvailabilityFromPlatform(PlatformKind Child, PlatformKind Parent);
|
||||
|
||||
/// Returns the LLVM triple OS type for the given platform, if there is one.
|
||||
std::optional<llvm::Triple::OSType>
|
||||
tripleOSTypeForPlatform(PlatformKind platform);
|
||||
|
||||
llvm::VersionTuple canonicalizePlatformVersion(
|
||||
PlatformKind platform, const llvm::VersionTuple &version);
|
||||
|
||||
/// Returns true if \p Platform should be considered to be SPI and therefore not
|
||||
/// printed in public `.swiftinterface` files, for example.
|
||||
bool isPlatformSPI(PlatformKind Platform);
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif // SWIFT_AST_PLATFORM_KIND_UTILS_H
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
@@ -26,7 +26,7 @@
|
||||
// FIXME: [availability] Remove this when possible
|
||||
#include "swift/AST/DiagnosticsParse.h"
|
||||
#include "swift/AST/DiagnosticsSema.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/AST/PlatformKindUtils.h"
|
||||
#include "swift/AST/TypeCheckRequests.h"
|
||||
#include "swift/AST/TypeWalker.h"
|
||||
#include "swift/AST/Types.h"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#include "swift/AST/ASTBridging.h"
|
||||
#include "swift/AST/AvailabilitySpec.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/AST/PlatformKindUtils.h"
|
||||
|
||||
using namespace swift;
|
||||
|
||||
@@ -43,36 +43,17 @@ BridgedAvailabilityMacroMap_getSpecs(BridgedAvailabilityMacroMap map,
|
||||
// MARK: PlatformKind
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
BridgedPlatformKind BridgedPlatformKind_fromString(BridgedStringRef cStr) {
|
||||
BridgedOptionalPlatformKind PlatformKind_fromString(BridgedStringRef cStr) {
|
||||
auto optKind = platformFromString(cStr.unbridged());
|
||||
if (!optKind)
|
||||
return BridgedPlatformKind_None;
|
||||
|
||||
switch (*optKind) {
|
||||
case PlatformKind::none:
|
||||
return BridgedPlatformKind_None;
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) \
|
||||
case PlatformKind::X: \
|
||||
return BridgedPlatformKind_##X;
|
||||
#include "swift/AST/PlatformKinds.def"
|
||||
if (!optKind) {
|
||||
return BridgedOptionalPlatformKind();
|
||||
}
|
||||
return *optKind;
|
||||
}
|
||||
|
||||
BridgedPlatformKind
|
||||
BridgedPlatformKind_fromIdentifier(BridgedIdentifier cIdent) {
|
||||
return BridgedPlatformKind_fromString(cIdent.unbridged().str());
|
||||
}
|
||||
|
||||
PlatformKind unbridge(BridgedPlatformKind platform) {
|
||||
switch (platform) {
|
||||
case BridgedPlatformKind_None:
|
||||
return PlatformKind::none;
|
||||
#define AVAILABILITY_PLATFORM(X, PrettyName) \
|
||||
case BridgedPlatformKind_##X: \
|
||||
return PlatformKind::X;
|
||||
#include "swift/AST/PlatformKinds.def"
|
||||
}
|
||||
llvm_unreachable("unhandled enum value");
|
||||
BridgedOptionalPlatformKind
|
||||
PlatformKind_fromIdentifier(BridgedIdentifier cIdent) {
|
||||
return PlatformKind_fromString(cIdent.unbridged().str());
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@@ -194,11 +194,11 @@ BridgedAllowFeatureSuppressionAttr_createParsed(BridgedASTContext cContext,
|
||||
|
||||
BridgedBackDeployedAttr BridgedBackDeployedAttr_createParsed(
|
||||
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
|
||||
BridgedSourceRange cRange, BridgedPlatformKind cPlatform,
|
||||
BridgedSourceRange cRange, swift::PlatformKind platform,
|
||||
BridgedVersionTuple cVersion) {
|
||||
return new (cContext.unbridged()) BackDeployedAttr(
|
||||
cAtLoc.unbridged(), cRange.unbridged(), unbridge(cPlatform),
|
||||
cVersion.unbridged(), /*Implicit=*/false);
|
||||
return new (cContext.unbridged())
|
||||
BackDeployedAttr(cAtLoc.unbridged(), cRange.unbridged(), platform,
|
||||
cVersion.unbridged(), /*Implicit=*/false);
|
||||
}
|
||||
|
||||
BridgedCDeclAttr BridgedCDeclAttr_createParsed(BridgedASTContext cContext,
|
||||
@@ -485,10 +485,10 @@ BridgedMacroRoleAttr BridgedMacroRoleAttr_createParsed(
|
||||
BridgedOriginallyDefinedInAttr BridgedOriginallyDefinedInAttr_createParsed(
|
||||
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
|
||||
BridgedSourceRange cRange, BridgedStringRef cModuleName,
|
||||
BridgedPlatformKind cPlatform, BridgedVersionTuple cVersion) {
|
||||
swift::PlatformKind platform, BridgedVersionTuple cVersion) {
|
||||
return new (cContext.unbridged()) OriginallyDefinedInAttr(
|
||||
cAtLoc.unbridged(), cRange.unbridged(), cModuleName.unbridged(),
|
||||
unbridge(cPlatform), cVersion.unbridged(),
|
||||
cAtLoc.unbridged(), cRange.unbridged(), cModuleName.unbridged(), platform,
|
||||
cVersion.unbridged(),
|
||||
/*Implicit=*/false);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ add_swift_host_library(swiftAST STATIC
|
||||
ParameterPack.cpp
|
||||
Parameter.cpp
|
||||
Pattern.cpp
|
||||
PlatformKind.cpp
|
||||
PlatformKindUtils.cpp
|
||||
PluginLoader.cpp
|
||||
PluginRegistry.cpp
|
||||
PrettyStackTrace.cpp
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
//===--- PlatformKind.cpp - Swift Language Platform Kinds -----------------===//
|
||||
//===--- AST/PlatformKindUtils.cpp ------------------------------*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the platform kinds for API availability.
|
||||
//
|
||||
///
|
||||
/// This file implements operations for working with `PlatformKind`.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/AST/PlatformKindUtils.h"
|
||||
#include "swift/Basic/Assertions.h"
|
||||
#include "swift/Basic/LangOptions.h"
|
||||
#include "swift/Basic/Platform.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
|
||||
|
||||
using namespace swift;
|
||||
|
||||
StringRef swift::platformString(PlatformKind platform) {
|
||||
@@ -369,7 +369,7 @@ extension ASTGenVisitor {
|
||||
return result
|
||||
}
|
||||
|
||||
typealias GeneratedPlatformVersion = (platform: BridgedPlatformKind, version: BridgedVersionTuple)
|
||||
typealias GeneratedPlatformVersion = (platform: swift.PlatformKind, version: BridgedVersionTuple)
|
||||
|
||||
func generate(platformVersionList node: PlatformVersionItemListSyntax) -> [GeneratedPlatformVersion] {
|
||||
var result: [GeneratedPlatformVersion] = []
|
||||
@@ -380,9 +380,9 @@ extension ASTGenVisitor {
|
||||
let version = self.generate(versionTuple: platformVersionNode.version)?.bridged ?? BridgedVersionTuple()
|
||||
|
||||
// If the name is a platform name, use it.
|
||||
let platform = BridgedPlatformKind(from: platformName.bridged)
|
||||
if platform != .none {
|
||||
result.append((platform: platform, version: version))
|
||||
let platform = BridgedOptionalPlatformKind(from: platformName.bridged)
|
||||
guard !platform.hasValue else {
|
||||
result.append((platform: platform.value, version: version))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -397,11 +397,12 @@ extension ASTGenVisitor {
|
||||
let spec = BridgedAvailabilitySpec(raw: UnsafeMutableRawPointer(mutating: ptr))
|
||||
let domainOrIdentifier = spec.domainOrIdentifier
|
||||
precondition(!domainOrIdentifier.isDomain)
|
||||
let platform = BridgedPlatformKind(from: domainOrIdentifier.asIdentifier)
|
||||
guard platform != .none else {
|
||||
let platform = BridgedOptionalPlatformKind(from: domainOrIdentifier.asIdentifier)
|
||||
guard platform.hasValue else {
|
||||
// TODO: Diagnose?
|
||||
continue
|
||||
}
|
||||
result.append((platform: platform, version: spec.rawVersion))
|
||||
result.append((platform: platform.value, version: spec.rawVersion))
|
||||
}
|
||||
}
|
||||
continue
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "ToolChains.h"
|
||||
|
||||
#include "swift/AST/DiagnosticsDriver.h"
|
||||
#include "swift/AST/PlatformKind.h"
|
||||
#include "swift/AST/PlatformKindUtils.h"
|
||||
#include "swift/Basic/Assertions.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Basic/Platform.h"
|
||||
|
||||
Reference in New Issue
Block a user