mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
ASTBridging: Bridge swift::DeclAttrKind directly
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
//
|
||||
|
||||
#include "swift/AST/AccessorKind.h"
|
||||
#include "swift/AST/AttrKind.h"
|
||||
#include "swift/AST/DiagnosticKind.h"
|
||||
#include "swift/AST/DiagnosticList.h"
|
||||
#include "swift/Basic/BasicBridging.h"
|
||||
@@ -830,14 +831,11 @@ public:
|
||||
// MARK: DeclAttributes
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedDeclAttrKind {
|
||||
#define DECL_ATTR(_, CLASS, ...) BridgedDeclAttrKind##CLASS,
|
||||
#include "swift/AST/DeclAttr.def"
|
||||
BridgedDeclAttrKindNone,
|
||||
};
|
||||
BRIDGED_OPTIONAL(swift::DeclAttrKind, DeclAttrKind)
|
||||
|
||||
SWIFT_NAME("BridgedDeclAttrKind.init(from:)")
|
||||
BridgedDeclAttrKind BridgedDeclAttrKind_fromString(BridgedStringRef cStr);
|
||||
SWIFT_NAME("BridgedOptionalDeclAttrKind.init(from:)")
|
||||
BridgedOptionalDeclAttrKind
|
||||
BridgedOptionalDeclAttrKind_fromString(BridgedStringRef cStr);
|
||||
|
||||
struct BridgedDeclAttributes {
|
||||
BridgedNullableDeclAttribute chain;
|
||||
@@ -850,10 +848,10 @@ struct BridgedDeclAttributes {
|
||||
};
|
||||
|
||||
SWIFT_NAME("BridgedDeclAttribute.shouldBeRejectedByParser(_:)")
|
||||
bool BridgedDeclAttribute_shouldBeRejectedByParser(BridgedDeclAttrKind cKind);
|
||||
bool BridgedDeclAttribute_shouldBeRejectedByParser(swift::DeclAttrKind kind);
|
||||
|
||||
SWIFT_NAME("BridgedDeclAttribute.isDeclModifier(_:)")
|
||||
bool BridgedDeclAttribute_isDeclModifier(BridgedDeclAttrKind cKind);
|
||||
bool BridgedDeclAttribute_isDeclModifier(swift::DeclAttrKind kind);
|
||||
|
||||
SWIFT_NAME("BridgedDeclAttributes.add(self:_:)")
|
||||
void BridgedDeclAttributes_add(BridgedDeclAttributes *_Nonnull attrs,
|
||||
@@ -861,7 +859,7 @@ void BridgedDeclAttributes_add(BridgedDeclAttributes *_Nonnull attrs,
|
||||
|
||||
SWIFT_NAME("BridgedDeclAttribute.createSimple(_:kind:atLoc:nameLoc:)")
|
||||
BridgedDeclAttribute BridgedDeclAttribute_createSimple(
|
||||
BridgedASTContext cContext, BridgedDeclAttrKind cKind,
|
||||
BridgedASTContext cContext, swift::DeclAttrKind kind,
|
||||
BridgedSourceLoc cAtLoc, BridgedSourceLoc cNameLoc);
|
||||
|
||||
SWIFT_NAME("BridgedABIAttr.createParsed(_:atLoc:range:abiDecl:)")
|
||||
|
||||
@@ -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
|
||||
@@ -106,7 +106,41 @@ protected:
|
||||
class DeclAttributes;
|
||||
enum class DeclKind : uint8_t;
|
||||
|
||||
/// Represents one declaration attribute.
|
||||
enum : unsigned {
|
||||
NumInlineKindBits =
|
||||
countBitsUsed(static_cast<unsigned>(InlineKind::Last_InlineKind))
|
||||
};
|
||||
|
||||
enum : unsigned {
|
||||
NumEffectsKindBits =
|
||||
countBitsUsed(static_cast<unsigned>(EffectsKind::Last_EffectsKind))
|
||||
};
|
||||
|
||||
enum : unsigned {
|
||||
NumExposureKindBits =
|
||||
countBitsUsed(static_cast<unsigned>(ExposureKind::Last_ExposureKind))
|
||||
};
|
||||
|
||||
enum : unsigned {
|
||||
NumExternKindBits =
|
||||
countBitsUsed(static_cast<unsigned>(ExternKind::Last_ExternKind))
|
||||
};
|
||||
|
||||
enum : unsigned {
|
||||
NumNonIsolatedModifierBits = countBitsUsed(
|
||||
static_cast<unsigned>(NonIsolatedModifier::Last_NonIsolatedModifier))
|
||||
};
|
||||
|
||||
enum : unsigned {
|
||||
NumInheritActorContextKindBits = countBitsUsed(static_cast<unsigned>(
|
||||
InheritActorContextModifier::Last_InheritActorContextKind))
|
||||
};
|
||||
|
||||
enum : unsigned { NumDeclAttrKindBits = countBitsUsed(NumDeclAttrKinds - 1) };
|
||||
|
||||
enum : unsigned { NumTypeAttrKindBits = countBitsUsed(NumTypeAttrKinds - 1) };
|
||||
|
||||
/// Represents one declaration attribute.
|
||||
class DeclAttribute : public AttributeBase {
|
||||
friend class DeclAttributes;
|
||||
|
||||
@@ -3466,6 +3500,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/// The kind of unary operator, if any.
|
||||
enum class UnaryOperatorKind : uint8_t { None, Prefix, Postfix };
|
||||
|
||||
/// Attributes that may be applied to declarations.
|
||||
class DeclAttributes {
|
||||
/// Linked list of declaration attributes.
|
||||
|
||||
@@ -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
|
||||
@@ -17,10 +17,14 @@
|
||||
#ifndef SWIFT_ATTRKIND_H
|
||||
#define SWIFT_ATTRKIND_H
|
||||
|
||||
#include "swift/Basic/InlineBitfield.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Config.h"
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
/// 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 llvm {
|
||||
class StringRef;
|
||||
}
|
||||
|
||||
namespace swift {
|
||||
|
||||
@@ -41,14 +45,8 @@ enum class Associativity : uint8_t {
|
||||
};
|
||||
|
||||
/// Returns the in-source spelling of the given associativity.
|
||||
StringRef getAssociativitySpelling(Associativity value);
|
||||
|
||||
/// The kind of unary operator, if any.
|
||||
enum class UnaryOperatorKind : uint8_t {
|
||||
None,
|
||||
Prefix,
|
||||
Postfix
|
||||
};
|
||||
SWIFT_UNAVAILABLE("Unavailable in Swift")
|
||||
llvm::StringRef getAssociativitySpelling(Associativity value);
|
||||
|
||||
/// Access control levels.
|
||||
// These are used in diagnostics and with < and similar operations,
|
||||
@@ -74,7 +72,8 @@ enum class AccessLevel : uint8_t {
|
||||
};
|
||||
|
||||
/// Returns the in-source spelling of the given access level.
|
||||
StringRef getAccessLevelSpelling(AccessLevel value);
|
||||
SWIFT_UNAVAILABLE("Unavailable in Swift")
|
||||
llvm::StringRef getAccessLevelSpelling(AccessLevel value);
|
||||
|
||||
enum class InlineKind : uint8_t {
|
||||
Never = 0,
|
||||
@@ -82,10 +81,6 @@ enum class InlineKind : uint8_t {
|
||||
Last_InlineKind = Always
|
||||
};
|
||||
|
||||
enum : unsigned { NumInlineKindBits =
|
||||
countBitsUsed(static_cast<unsigned>(InlineKind::Last_InlineKind)) };
|
||||
|
||||
|
||||
/// This enum represents the possible values of the @_effects attribute.
|
||||
/// These values are ordered from the strongest guarantee to the weakest,
|
||||
/// so please do not reorder existing values.
|
||||
@@ -99,19 +94,9 @@ enum class EffectsKind : uint8_t {
|
||||
Last_EffectsKind = Unspecified
|
||||
};
|
||||
|
||||
enum : unsigned { NumEffectsKindBits =
|
||||
countBitsUsed(static_cast<unsigned>(EffectsKind::Last_EffectsKind)) };
|
||||
|
||||
/// This enum represents the possible values of the @_expose attribute.
|
||||
enum class ExposureKind: uint8_t {
|
||||
Cxx,
|
||||
Wasm,
|
||||
Last_ExposureKind = Wasm
|
||||
};
|
||||
enum class ExposureKind : uint8_t { Cxx, Wasm, Last_ExposureKind = Wasm };
|
||||
|
||||
enum : unsigned { NumExposureKindBits =
|
||||
countBitsUsed(static_cast<unsigned>(ExposureKind::Last_ExposureKind)) };
|
||||
|
||||
/// This enum represents the possible values of the @_extern attribute.
|
||||
enum class ExternKind: uint8_t {
|
||||
/// Reference an externally defined C function.
|
||||
@@ -127,9 +112,6 @@ enum class ExternKind: uint8_t {
|
||||
Last_ExternKind = Wasm
|
||||
};
|
||||
|
||||
enum : unsigned { NumExternKindBits =
|
||||
countBitsUsed(static_cast<unsigned>(ExternKind::Last_ExternKind)) };
|
||||
|
||||
enum class NonIsolatedModifier : uint8_t {
|
||||
None = 0,
|
||||
Unsafe,
|
||||
@@ -137,11 +119,6 @@ enum class NonIsolatedModifier : uint8_t {
|
||||
Last_NonIsolatedModifier = NonSending
|
||||
};
|
||||
|
||||
enum : unsigned {
|
||||
NumNonIsolatedModifierBits = countBitsUsed(
|
||||
static_cast<unsigned>(NonIsolatedModifier::Last_NonIsolatedModifier))
|
||||
};
|
||||
|
||||
enum class InheritActorContextModifier : uint8_t {
|
||||
/// Inherit the actor execution context if the isolated parameter was
|
||||
/// captured by the closure, context is nonisolated or isolated to a
|
||||
@@ -153,22 +130,17 @@ enum class InheritActorContextModifier : uint8_t {
|
||||
Last_InheritActorContextKind = Always
|
||||
};
|
||||
|
||||
enum : unsigned {
|
||||
NumInheritActorContextKindBits = countBitsUsed(static_cast<unsigned>(
|
||||
InheritActorContextModifier::Last_InheritActorContextKind))
|
||||
};
|
||||
|
||||
enum class DeclAttrKind : unsigned {
|
||||
enum class ENUM_EXTENSIBILITY_ATTR(closed) DeclAttrKind : unsigned {
|
||||
#define DECL_ATTR(_, CLASS, ...) CLASS,
|
||||
#define LAST_DECL_ATTR(CLASS) Last_DeclAttr = CLASS,
|
||||
#include "swift/AST/DeclAttr.def"
|
||||
};
|
||||
|
||||
StringRef getDeclAttrKindID(DeclAttrKind kind);
|
||||
SWIFT_UNAVAILABLE("Unavailable in Swift")
|
||||
llvm::StringRef getDeclAttrKindID(DeclAttrKind kind);
|
||||
|
||||
enum : unsigned {
|
||||
NumDeclAttrKinds = static_cast<unsigned>(DeclAttrKind::Last_DeclAttr) + 1,
|
||||
NumDeclAttrKindBits = countBitsUsed(NumDeclAttrKinds - 1),
|
||||
NumDeclAttrKinds = static_cast<unsigned>(DeclAttrKind::Last_DeclAttr) + 1
|
||||
};
|
||||
|
||||
// Define enumerators for each type attribute, e.g. TypeAttrKind::Weak.
|
||||
@@ -179,8 +151,7 @@ enum class TypeAttrKind {
|
||||
};
|
||||
|
||||
enum : unsigned {
|
||||
NumTypeAttrKinds = static_cast<unsigned>(TypeAttrKind::Last_TypeAttr) + 1,
|
||||
NumTypeAttrKindBits = countBitsUsed(NumTypeAttrKinds - 1),
|
||||
NumTypeAttrKinds = static_cast<unsigned>(TypeAttrKind::Last_TypeAttr) + 1
|
||||
};
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
@@ -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
|
||||
@@ -14,6 +14,7 @@
|
||||
#define SWIFT_AST_KNOWNPROTOCOLS_H
|
||||
|
||||
#include "swift/ABI/InvertibleProtocols.h"
|
||||
#include "swift/Basic/InlineBitfield.h"
|
||||
#include "swift/Config.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@@ -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,6 +26,7 @@
|
||||
#include "swift/Basic/ArrayRefView.h"
|
||||
#include "swift/Basic/Compiler.h"
|
||||
#include "swift/Basic/Debug.h"
|
||||
#include "swift/Basic/InlineBitfield.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Basic/OptionSet.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
|
||||
@@ -55,13 +55,6 @@
|
||||
#include <vector>
|
||||
#endif
|
||||
|
||||
#if __has_attribute(availability)
|
||||
#define SWIFT_UNAVAILABLE(msg) \
|
||||
__attribute__((availability(swift, unavailable, message=msg)))
|
||||
#else
|
||||
#define SWIFT_UNAVAILABLE(msg)
|
||||
#endif
|
||||
|
||||
#ifdef PURE_BRIDGING_MODE
|
||||
// In PURE_BRIDGING_MODE, briding functions are not inlined
|
||||
#define BRIDGED_INLINE
|
||||
|
||||
@@ -89,5 +89,12 @@
|
||||
#define SWIFT_NAME(_name)
|
||||
#endif
|
||||
|
||||
#if __has_attribute(availability)
|
||||
#define SWIFT_UNAVAILABLE(msg) \
|
||||
__attribute__((availability(swift, unavailable, message = msg)))
|
||||
#else
|
||||
#define SWIFT_UNAVAILABLE(msg)
|
||||
#endif
|
||||
|
||||
#endif // SWIFT_BASIC_SWIFT_BRIDGING_H
|
||||
|
||||
|
||||
@@ -68,51 +68,28 @@ ParsedAutoDiffParameter BridgedParsedAutoDiffParameter::unbridged() const {
|
||||
}
|
||||
#include "swift/AST/DeclAttr.def"
|
||||
|
||||
BridgedDeclAttrKind BridgedDeclAttrKind_fromString(BridgedStringRef cStr) {
|
||||
BridgedOptionalDeclAttrKind
|
||||
BridgedOptionalDeclAttrKind_fromString(BridgedStringRef cStr) {
|
||||
auto optKind = DeclAttribute::getAttrKindFromString(cStr.unbridged());
|
||||
if (!optKind)
|
||||
return BridgedDeclAttrKindNone;
|
||||
switch (*optKind) {
|
||||
#define DECL_ATTR(_, CLASS, ...) \
|
||||
case DeclAttrKind::CLASS: \
|
||||
return BridgedDeclAttrKind##CLASS;
|
||||
#include "swift/AST/DeclAttr.def"
|
||||
if (!optKind) {
|
||||
return BridgedOptionalDeclAttrKind();
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<DeclAttrKind> unbridged(BridgedDeclAttrKind kind) {
|
||||
switch (kind) {
|
||||
#define DECL_ATTR(_, CLASS, ...) \
|
||||
case BridgedDeclAttrKind##CLASS: \
|
||||
return DeclAttrKind::CLASS;
|
||||
#include "swift/AST/DeclAttr.def"
|
||||
case BridgedDeclAttrKindNone:
|
||||
return std::nullopt;
|
||||
}
|
||||
llvm_unreachable("unhandled enum value");
|
||||
return *optKind;
|
||||
}
|
||||
|
||||
BridgedDeclAttribute BridgedDeclAttribute_createSimple(
|
||||
BridgedASTContext cContext, BridgedDeclAttrKind cKind,
|
||||
BridgedASTContext cContext, swift::DeclAttrKind kind,
|
||||
BridgedSourceLoc cAtLoc, BridgedSourceLoc cAttrLoc) {
|
||||
auto optKind = unbridged(cKind);
|
||||
assert(optKind && "creating attribute of invalid kind?");
|
||||
return DeclAttribute::createSimple(cContext.unbridged(), *optKind,
|
||||
return DeclAttribute::createSimple(cContext.unbridged(), kind,
|
||||
cAtLoc.unbridged(), cAttrLoc.unbridged());
|
||||
}
|
||||
|
||||
bool BridgedDeclAttribute_shouldBeRejectedByParser(BridgedDeclAttrKind cKind) {
|
||||
auto optKind = unbridged(cKind);
|
||||
if (!optKind)
|
||||
return false;
|
||||
return DeclAttribute::shouldBeRejectedByParser(*optKind);
|
||||
bool BridgedDeclAttribute_shouldBeRejectedByParser(swift::DeclAttrKind kind) {
|
||||
return DeclAttribute::shouldBeRejectedByParser(kind);
|
||||
}
|
||||
|
||||
bool BridgedDeclAttribute_isDeclModifier(BridgedDeclAttrKind cKind) {
|
||||
auto optKind = unbridged(cKind);
|
||||
if (!optKind)
|
||||
return false;
|
||||
return DeclAttribute::isDeclModifier(*optKind);
|
||||
bool BridgedDeclAttribute_isDeclModifier(swift::DeclAttrKind kind) {
|
||||
return DeclAttribute::isDeclModifier(kind);
|
||||
}
|
||||
|
||||
void BridgedDeclAttributes_add(BridgedDeclAttributes *cAttrs,
|
||||
|
||||
@@ -115,243 +115,252 @@ extension ASTGenVisitor {
|
||||
|
||||
if let identTy = node.attributeName.as(IdentifierTypeSyntax.self) {
|
||||
let attrName = identTy.name.rawText
|
||||
let attrKind = BridgedDeclAttrKind(from: attrName.bridged)
|
||||
let attrKind: swift.DeclAttrKind?
|
||||
do {
|
||||
let bridgedOptional = BridgedOptionalDeclAttrKind(from: attrName.bridged)
|
||||
attrKind = if bridgedOptional.hasValue {
|
||||
bridgedOptional.value
|
||||
} else {
|
||||
nil
|
||||
}
|
||||
}
|
||||
|
||||
switch attrKind {
|
||||
case .ABI:
|
||||
return handle(self.generateABIAttr(attribute: node)?.asDeclAttribute)
|
||||
case .alignment:
|
||||
case .Alignment:
|
||||
return handle(self.generateAlignmentAttr(attribute: node)?.asDeclAttribute)
|
||||
case .allowFeatureSuppression:
|
||||
case .AllowFeatureSuppression:
|
||||
return handle(self.generateAllowFeatureSuppressionAttr(attribute: node, attrName: attrName)?.asDeclAttribute)
|
||||
case .available:
|
||||
case .Available:
|
||||
return self.generateAvailableAttr(attribute: node, attrName: attrName).forEach { handle($0.asDeclAttribute) }
|
||||
case .backDeployed:
|
||||
case .BackDeployed:
|
||||
return self.generateBackDeployedAttr(attribute: node).forEach { handle($0.asDeclAttribute) }
|
||||
case .cDecl:
|
||||
case .CDecl:
|
||||
return handle(self.generateCDeclAttr(attribute: node)?.asDeclAttribute)
|
||||
case .derivative:
|
||||
case .Derivative:
|
||||
return handle(self.generateDerivativeAttr(attribute: node)?.asDeclAttribute)
|
||||
case .differentiable:
|
||||
case .Differentiable:
|
||||
return handle(self.generateDifferentiableAttr(attribute: node)?.asDeclAttribute)
|
||||
case .dynamicReplacement:
|
||||
case .DynamicReplacement:
|
||||
return handle(self.generateDynamicReplacementAttr(attribute: node)?.asDeclAttribute)
|
||||
case .documentation:
|
||||
case .Documentation:
|
||||
return handle(self.generateDocumentationAttr(attribute: node)?.asDeclAttribute)
|
||||
case .effects:
|
||||
case .Effects:
|
||||
return handle(self.generateEffectsAttr(attribute: node)?.asDeclAttribute)
|
||||
case .exclusivity:
|
||||
case .Exclusivity:
|
||||
return handle(self.generateExclusivityAttr(attribute: node)?.asDeclAttribute)
|
||||
case .expose:
|
||||
case .Expose:
|
||||
return handle(self.generateExposeAttr(attribute: node)?.asDeclAttribute)
|
||||
case .extern:
|
||||
case .Extern:
|
||||
return handle(self.generateExternAttr(attribute: node)?.asDeclAttribute)
|
||||
case .implements:
|
||||
case .Implements:
|
||||
return handle(self.generateImplementsAttr(attribute: node)?.asDeclAttribute)
|
||||
case .inline:
|
||||
case .Inline:
|
||||
return handle(self.generateInlineAttr(attribute: node)?.asDeclAttribute)
|
||||
case .lifetime:
|
||||
case .Lifetime:
|
||||
return handle(self.generateLifetimeAttr(attribute: node)?.asDeclAttribute)
|
||||
case .macroRole:
|
||||
case .MacroRole:
|
||||
return handle(self.generateMacroRoleAttr(attribute: node, attrName: attrName)?.asDeclAttribute)
|
||||
case .nonSendable:
|
||||
case .NonSendable:
|
||||
return handle(self.generateNonSendableAttr(attribute: node)?.asDeclAttribute)
|
||||
case .objC:
|
||||
case .ObjC:
|
||||
return handle(self.generateObjCAttr(attribute: node)?.asDeclAttribute)
|
||||
case .objCImplementation:
|
||||
case .ObjCImplementation:
|
||||
return handle(self.generateObjCImplementationAttr(attribute: node)?.asDeclAttribute)
|
||||
case .objCRuntimeName:
|
||||
case .ObjCRuntimeName:
|
||||
return handle(self.generateObjCRuntimeNameAttr(attribute: node)?.asDeclAttribute)
|
||||
case .optimize:
|
||||
case .Optimize:
|
||||
return handle(self.generateOptimizeAttr(attribute: node)?.asDeclAttribute)
|
||||
case .originallyDefinedIn:
|
||||
case .OriginallyDefinedIn:
|
||||
return self.generateOriginallyDefinedInAttr(attribute: node).forEach { handle($0.asDeclAttribute) }
|
||||
case .privateImport:
|
||||
case .PrivateImport:
|
||||
return handle(self.generatePrivateImportAttr(attribute: node)?.asDeclAttribute)
|
||||
case .projectedValueProperty:
|
||||
case .ProjectedValueProperty:
|
||||
return handle(self.generateProjectedValuePropertyAttr(attribute: node)?.asDeclAttribute)
|
||||
case .rawLayout:
|
||||
case .RawLayout:
|
||||
return handle(self.generateRawLayoutAttr(attribute: node)?.asDeclAttribute)
|
||||
case .section:
|
||||
case .Section:
|
||||
return handle(self.generateSectionAttr(attribute: node)?.asDeclAttribute)
|
||||
case .semantics:
|
||||
case .Semantics:
|
||||
return handle(self.generateSemanticsAttr(attribute: node)?.asDeclAttribute)
|
||||
case .silGenName:
|
||||
case .SILGenName:
|
||||
return handle(self.generateSILGenNameAttr(attribute: node)?.asDeclAttribute)
|
||||
case .specialize:
|
||||
case .Specialize:
|
||||
return handle(self.generateSpecializeAttr(attribute: node, attrName: attrName)?.asDeclAttribute)
|
||||
case .specialized:
|
||||
case .Specialized:
|
||||
return handle(self.generateSpecializedAttr(attribute: node, attrName: attrName)?.asDeclAttribute)
|
||||
case .spiAccessControl:
|
||||
case .SPIAccessControl:
|
||||
return handle(self.generateSPIAccessControlAttr(attribute: node)?.asDeclAttribute)
|
||||
case .storageRestrictions:
|
||||
case .StorageRestrictions:
|
||||
return handle(self.generateStorageRestrictionAttr(attribute: node)?.asDeclAttribute)
|
||||
case .swiftNativeObjCRuntimeBase:
|
||||
case .SwiftNativeObjCRuntimeBase:
|
||||
return handle(self.generateSwiftNativeObjCRuntimeBaseAttr(attribute: node)?.asDeclAttribute)
|
||||
case .transpose:
|
||||
case .Transpose:
|
||||
return handle(self.generateTransposeAttr(attribute: node)?.asDeclAttribute)
|
||||
case .typeEraser:
|
||||
case .TypeEraser:
|
||||
return handle(self.generateTypeEraserAttr(attribute: node)?.asDeclAttribute)
|
||||
case .unavailableFromAsync:
|
||||
case .UnavailableFromAsync:
|
||||
return handle(self.generateUnavailableFromAsyncAttr(attribute: node)?.asDeclAttribute)
|
||||
case .reasync:
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .atReasync))
|
||||
case .rethrows:
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .atRethrows))
|
||||
case .concurrent:
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .concurrent))
|
||||
case .none where attrName == "_unavailableInEmbedded":
|
||||
case .Reasync:
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .AtReasync))
|
||||
case .Rethrows:
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .AtRethrows))
|
||||
case .Concurrent:
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .Concurrent))
|
||||
case nil where attrName == "_unavailableInEmbedded":
|
||||
return handle(self.generateUnavailableInEmbeddedAttr(attribute: node)?.asDeclAttribute)
|
||||
|
||||
// Renamed attributes.
|
||||
case .none where attrName == "_functionBuilder":
|
||||
case nil where attrName == "_functionBuilder":
|
||||
// TODO: Diagnostics. '_functionBuilder' is renamed to 'resultBuilder'
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .resultBuilder))
|
||||
case .none where attrName == "_inlineable":
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .ResultBuilder))
|
||||
case nil where attrName == "_inlineable":
|
||||
// TODO: Diagnose.
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .inlinable))
|
||||
case .none where attrName == "inlineable":
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .Inlinable))
|
||||
case nil where attrName == "inlineable":
|
||||
// TODO: Diagnose.
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .inlinable))
|
||||
case .none where attrName == "_versioned":
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .Inlinable))
|
||||
case nil where attrName == "_versioned":
|
||||
// TODO: Diagnose.
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .usableFromInline))
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .UsableFromInline))
|
||||
|
||||
// Simple attributes.
|
||||
case .addressableSelf,
|
||||
.addressableForDependencies,
|
||||
.alwaysEmitConformanceMetadata,
|
||||
.alwaysEmitIntoClient,
|
||||
.atReasync,
|
||||
.atRethrows,
|
||||
.borrowed,
|
||||
.compilerInitialized,
|
||||
.constVal,
|
||||
.constInitialized,
|
||||
.dynamicCallable,
|
||||
.eagerMove,
|
||||
.exported,
|
||||
.extensible,
|
||||
.preEnumExtensibility,
|
||||
.discardableResult,
|
||||
.disfavoredOverload,
|
||||
.dynamicMemberLookup,
|
||||
.emitAssemblyVisionRemarks,
|
||||
.extractConstantsFromMembers,
|
||||
.fixedLayout,
|
||||
.frozen,
|
||||
.gkInspectable,
|
||||
.globalActor,
|
||||
.hasInitialValue,
|
||||
.hasMissingDesignatedInitializers,
|
||||
.hasStorage,
|
||||
.ibAction,
|
||||
.ibDesignable,
|
||||
.ibInspectable,
|
||||
.ibOutlet,
|
||||
.ibSegueAction,
|
||||
.implementationOnly,
|
||||
.implicitSelfCapture,
|
||||
.inheritsConvenienceInitializers,
|
||||
.inlinable,
|
||||
.isolated,
|
||||
.lexicalLifetimes,
|
||||
.lldbDebuggerFunction,
|
||||
.mainType,
|
||||
.marker,
|
||||
.moveOnly,
|
||||
.noAllocation,
|
||||
.noDerivative,
|
||||
.noEagerMove,
|
||||
.noExistentials,
|
||||
.noRuntime,
|
||||
.noImplicitCopy,
|
||||
.noLocks,
|
||||
.noMetadata,
|
||||
.noObjCBridging,
|
||||
.nonEphemeral,
|
||||
.nonEscapable,
|
||||
.nonObjC,
|
||||
.nonOverride,
|
||||
.nsApplicationMain,
|
||||
.nsCopying,
|
||||
.nsManaged,
|
||||
.objCMembers,
|
||||
.objCNonLazyRealization,
|
||||
.preconcurrency,
|
||||
.preInverseGenerics,
|
||||
.propertyWrapper,
|
||||
.requiresStoredPropertyInits,
|
||||
.resultBuilder,
|
||||
.safe,
|
||||
.sendable,
|
||||
.sensitive,
|
||||
.spiOnly,
|
||||
.showInInterface,
|
||||
.specializeExtension,
|
||||
.staticExclusiveOnly,
|
||||
.testable,
|
||||
.transparent,
|
||||
.uiApplicationMain,
|
||||
.unsafe,
|
||||
.unsafeInheritExecutor,
|
||||
.unsafeNoObjCTaggedPointer,
|
||||
.unsafeNonEscapableResult,
|
||||
.usableFromInline,
|
||||
.used,
|
||||
.warnUnqualifiedAccess,
|
||||
.weakLinked:
|
||||
case .AddressableSelf,
|
||||
.AddressableForDependencies,
|
||||
.AlwaysEmitConformanceMetadata,
|
||||
.AlwaysEmitIntoClient,
|
||||
.AtReasync,
|
||||
.AtRethrows,
|
||||
.Borrowed,
|
||||
.CompilerInitialized,
|
||||
.ConstVal,
|
||||
.ConstInitialized,
|
||||
.DynamicCallable,
|
||||
.EagerMove,
|
||||
.Exported,
|
||||
.Extensible,
|
||||
.PreEnumExtensibility,
|
||||
.DiscardableResult,
|
||||
.DisfavoredOverload,
|
||||
.DynamicMemberLookup,
|
||||
.EmitAssemblyVisionRemarks,
|
||||
.ExtractConstantsFromMembers,
|
||||
.FixedLayout,
|
||||
.Frozen,
|
||||
.GKInspectable,
|
||||
.GlobalActor,
|
||||
.HasInitialValue,
|
||||
.HasMissingDesignatedInitializers,
|
||||
.HasStorage,
|
||||
.IBAction,
|
||||
.IBDesignable,
|
||||
.IBInspectable,
|
||||
.IBOutlet,
|
||||
.IBSegueAction,
|
||||
.ImplementationOnly,
|
||||
.ImplicitSelfCapture,
|
||||
.InheritsConvenienceInitializers,
|
||||
.Inlinable,
|
||||
.Isolated,
|
||||
.LexicalLifetimes,
|
||||
.LLDBDebuggerFunction,
|
||||
.MainType,
|
||||
.Marker,
|
||||
.MoveOnly,
|
||||
.NoAllocation,
|
||||
.NoDerivative,
|
||||
.NoEagerMove,
|
||||
.NoExistentials,
|
||||
.NoRuntime,
|
||||
.NoImplicitCopy,
|
||||
.NoLocks,
|
||||
.NoMetadata,
|
||||
.NoObjCBridging,
|
||||
.NonEphemeral,
|
||||
.NonEscapable,
|
||||
.NonObjC,
|
||||
.NonOverride,
|
||||
.NSApplicationMain,
|
||||
.NSCopying,
|
||||
.NSManaged,
|
||||
.ObjCMembers,
|
||||
.ObjCNonLazyRealization,
|
||||
.Preconcurrency,
|
||||
.PreInverseGenerics,
|
||||
.PropertyWrapper,
|
||||
.RequiresStoredPropertyInits,
|
||||
.ResultBuilder,
|
||||
.Safe,
|
||||
.Sendable,
|
||||
.Sensitive,
|
||||
.SPIOnly,
|
||||
.ShowInInterface,
|
||||
.SpecializeExtension,
|
||||
.StaticExclusiveOnly,
|
||||
.Testable,
|
||||
.Transparent,
|
||||
.UIApplicationMain,
|
||||
.Unsafe,
|
||||
.UnsafeInheritExecutor,
|
||||
.UnsafeNoObjCTaggedPointer,
|
||||
.UnsafeNonEscapableResult,
|
||||
.UsableFromInline,
|
||||
.Used,
|
||||
.WarnUnqualifiedAccess,
|
||||
.WeakLinked:
|
||||
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: attrKind))
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: attrKind!))
|
||||
|
||||
// Modifers.
|
||||
case .accessControl:
|
||||
case .AccessControl:
|
||||
// TODO: Diagnose and generateAccessControl().
|
||||
fatalError("unimplemented (access control modifier parsed as attributes)")
|
||||
case .nonisolated:
|
||||
case .Nonisolated:
|
||||
// TODO: Diagnose.
|
||||
return handle(self.generateNonisolatedAttr(attribute: node)?.asDeclAttribute)
|
||||
case .referenceOwnership:
|
||||
case .ReferenceOwnership:
|
||||
// TODO: Diagnose.
|
||||
return handle(self.generateReferenceOwnershipAttr(attribute: node, attrName: attrName)?.asDeclAttribute)
|
||||
case .inheritActorContext:
|
||||
case .InheritActorContext:
|
||||
return handle(self.generateInheritActorContextAttr(attribute: node)?.asDeclAttribute)
|
||||
|
||||
case .async,
|
||||
.consuming,
|
||||
.borrowing,
|
||||
.actor,
|
||||
.distributedActor,
|
||||
.required,
|
||||
.optional,
|
||||
.lazy,
|
||||
.dynamic,
|
||||
.infix,
|
||||
.prefix,
|
||||
.postfix,
|
||||
.legacyConsuming,
|
||||
.mutating,
|
||||
.nonMutating,
|
||||
.convenience,
|
||||
.override,
|
||||
.indirect,
|
||||
.final,
|
||||
.knownToBeLocal,
|
||||
.compileTimeLiteral:
|
||||
case .Async,
|
||||
.Consuming,
|
||||
.Borrowing,
|
||||
.Actor,
|
||||
.DistributedActor,
|
||||
.Required,
|
||||
.Optional,
|
||||
.Lazy,
|
||||
.Dynamic,
|
||||
.Infix,
|
||||
.Prefix,
|
||||
.Postfix,
|
||||
.LegacyConsuming,
|
||||
.Mutating,
|
||||
.NonMutating,
|
||||
.Convenience,
|
||||
.Override,
|
||||
.Indirect,
|
||||
.Final,
|
||||
.KnownToBeLocal,
|
||||
.CompileTimeLiteral:
|
||||
|
||||
// generateSimpleDeclAttr will diagnose and fix-it to change it to modifiers.
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: attrKind))
|
||||
return handle(self.generateSimpleDeclAttr(attribute: node, kind: attrKind!))
|
||||
|
||||
// 'RejectByParser', these attribute kind should not be parsed as built-in attributes.
|
||||
case .rawDocComment,
|
||||
.objCBridged,
|
||||
.synthesizedProtocol,
|
||||
.staticInitializeObjCMetadata,
|
||||
.restatedObjCConformance,
|
||||
.clangImporterSynthesizedType,
|
||||
.forbidSerializingReference,
|
||||
.custom,
|
||||
.setterAccess:
|
||||
assert(BridgedDeclAttribute.shouldBeRejectedByParser(attrKind))
|
||||
case .RawDocComment,
|
||||
.ObjCBridged,
|
||||
.SynthesizedProtocol,
|
||||
.StaticInitializeObjCMetadata,
|
||||
.RestatedObjCConformance,
|
||||
.ClangImporterSynthesizedType,
|
||||
.ForbidSerializingReference,
|
||||
.Custom,
|
||||
.SetterAccess:
|
||||
assert(BridgedDeclAttribute.shouldBeRejectedByParser(attrKind!))
|
||||
// Fall back to CustomAttr.
|
||||
break
|
||||
|
||||
@@ -2213,7 +2222,7 @@ extension ASTGenVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
func generateSimpleDeclAttr(attribute node: AttributeSyntax, kind: BridgedDeclAttrKind) -> BridgedDeclAttribute? {
|
||||
func generateSimpleDeclAttr(attribute node: AttributeSyntax, kind: swift.DeclAttrKind) -> BridgedDeclAttribute? {
|
||||
// TODO: Diagnose extraneous arguments.
|
||||
// TODO: Diagnose if `kind` is a modifier.
|
||||
return BridgedDeclAttribute.createSimple(
|
||||
@@ -2401,16 +2410,16 @@ extension ASTGenVisitor {
|
||||
return self.generateReferenceOwnershipAttr(declModifier: node)?.asDeclAttribute
|
||||
default:
|
||||
// Other modifiers are all "simple" attributes.
|
||||
let kind = BridgedDeclAttrKind(from: node.name.rawText.bridged)
|
||||
guard kind != .none else {
|
||||
let kind = BridgedOptionalDeclAttrKind(from: node.name.rawText.bridged)
|
||||
guard kind.hasValue else {
|
||||
// TODO: Diagnose.
|
||||
fatalError("(compiler bug) unknown decl modifier")
|
||||
}
|
||||
if !BridgedDeclAttribute.isDeclModifier(kind) {
|
||||
if !BridgedDeclAttribute.isDeclModifier(kind.value) {
|
||||
// TODO: Diagnose.
|
||||
fatalError("(compiler bug) decl attribute was parsed as a modifier")
|
||||
}
|
||||
return self.generateSimpleDeclAttr(declModifier: node, kind: kind)
|
||||
return self.generateSimpleDeclAttr(declModifier: node, kind: kind.value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2497,7 +2506,7 @@ extension ASTGenVisitor {
|
||||
)
|
||||
}
|
||||
|
||||
func generateSimpleDeclAttr(declModifier node: DeclModifierSyntax, kind: BridgedDeclAttrKind) -> BridgedDeclAttribute? {
|
||||
func generateSimpleDeclAttr(declModifier node: DeclModifierSyntax, kind: swift.DeclAttrKind) -> BridgedDeclAttribute? {
|
||||
// TODO: Diagnose non-modifier kind? Parser shouldn't accept them, though.
|
||||
// Simple modifier don't accept any detail.
|
||||
precondition(node.detail == nil, "decl modifiers can't have arguments except access control modifiers")
|
||||
|
||||
@@ -726,10 +726,10 @@ extension ASTGenVisitor {
|
||||
genericWhereClause: self.generate(genericWhereClause: node.genericWhereClause)
|
||||
)
|
||||
if signature.isReasync {
|
||||
attrs.attributes.add(BridgedDeclAttribute.createSimple(self.ctx, kind: .reasync, atLoc: nil, nameLoc: signature.asyncLoc))
|
||||
attrs.attributes.add(BridgedDeclAttribute.createSimple(self.ctx, kind: .Reasync, atLoc: nil, nameLoc: signature.asyncLoc))
|
||||
}
|
||||
if signature.isRethrows {
|
||||
attrs.attributes.add(BridgedDeclAttribute.createSimple(self.ctx, kind: .rethrows, atLoc: nil, nameLoc: signature.throwsLoc))
|
||||
attrs.attributes.add(BridgedDeclAttribute.createSimple(self.ctx, kind: .Rethrows, atLoc: nil, nameLoc: signature.throwsLoc))
|
||||
}
|
||||
decl.asDecl.attachParsedAttrs(attrs.attributes)
|
||||
|
||||
@@ -763,10 +763,10 @@ extension ASTGenVisitor {
|
||||
genericWhereClause: self.generate(genericWhereClause: node.genericWhereClause)
|
||||
)
|
||||
if signature.isReasync {
|
||||
attrs.attributes.add(BridgedDeclAttribute.createSimple(self.ctx, kind: .reasync, atLoc: nil, nameLoc: signature.asyncLoc))
|
||||
attrs.attributes.add(BridgedDeclAttribute.createSimple(self.ctx, kind: .Reasync, atLoc: nil, nameLoc: signature.asyncLoc))
|
||||
}
|
||||
if signature.isRethrows {
|
||||
attrs.attributes.add(BridgedDeclAttribute.createSimple(self.ctx, kind: .rethrows, atLoc: nil, nameLoc: signature.throwsLoc))
|
||||
attrs.attributes.add(BridgedDeclAttribute.createSimple(self.ctx, kind: .Rethrows, atLoc: nil, nameLoc: signature.throwsLoc))
|
||||
}
|
||||
decl.asDecl.attachParsedAttrs(attrs.attributes)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user