mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
279 lines
9.0 KiB
C++
279 lines
9.0 KiB
C++
//===--- Attr.def - Swift Attributes Metaprogramming ------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 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 macros used for macro-metaprogramming with attributes.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef DECL_ATTR
|
|
#define DECL_ATTR(SPELLING, CLASS, OPTIONS, CODE)
|
|
#endif
|
|
|
|
#ifndef SIMPLE_DECL_ATTR
|
|
#define SIMPLE_DECL_ATTR(X, CLASS, OPTIONS, CODE) DECL_ATTR(X, CLASS, OPTIONS, CODE)
|
|
#endif
|
|
|
|
#ifndef DECL_ATTR_ALIAS
|
|
#define DECL_ATTR_ALIAS(SPELLING, CLASS)
|
|
#endif
|
|
|
|
#ifndef TYPE_ATTR
|
|
#define TYPE_ATTR(X)
|
|
#endif
|
|
|
|
// Type attributes
|
|
TYPE_ATTR(autoclosure)
|
|
TYPE_ATTR(convention)
|
|
TYPE_ATTR(noreturn)
|
|
TYPE_ATTR(noescape)
|
|
TYPE_ATTR(escaping)
|
|
|
|
// SIL-specific attributes
|
|
TYPE_ATTR(block_storage)
|
|
TYPE_ATTR(box)
|
|
TYPE_ATTR(dynamic_self)
|
|
TYPE_ATTR(sil_unowned)
|
|
TYPE_ATTR(sil_unmanaged)
|
|
TYPE_ATTR(sil_weak)
|
|
TYPE_ATTR(error)
|
|
TYPE_ATTR(out)
|
|
TYPE_ATTR(in)
|
|
TYPE_ATTR(inout)
|
|
TYPE_ATTR(inout_aliasable)
|
|
TYPE_ATTR(in_guaranteed)
|
|
TYPE_ATTR(owned)
|
|
TYPE_ATTR(unowned_inner_pointer)
|
|
TYPE_ATTR(guaranteed)
|
|
TYPE_ATTR(autoreleased)
|
|
TYPE_ATTR(callee_owned)
|
|
TYPE_ATTR(callee_guaranteed)
|
|
TYPE_ATTR(objc_metatype)
|
|
TYPE_ATTR(opened)
|
|
TYPE_ATTR(pseudogeneric)
|
|
|
|
// SIL metatype attributes.
|
|
TYPE_ATTR(thin)
|
|
TYPE_ATTR(thick)
|
|
|
|
// Schema for DECL_ATTR:
|
|
//
|
|
// - Attribute name.
|
|
// - Class name without the 'Attr' suffix (ignored for
|
|
// - Options for the attribute, including:
|
|
// * the declarations the attribute can appear on
|
|
// * whether duplicates are allowed
|
|
// * whether the attribute is considered a decl modifier or not (no '@')
|
|
// - Unique attribute identifier used for serialization. This
|
|
// can never be changed.
|
|
//
|
|
// SIMPLE_DECL_ATTR is the same, but the class becomes
|
|
// SimpleDeclAttr<DAK_##NAME>.
|
|
//
|
|
|
|
DECL_ATTR(_silgen_name, SILGenName,
|
|
OnFunc | OnConstructor | OnDestructor | LongAttribute |
|
|
UserInaccessible, 0)
|
|
|
|
DECL_ATTR(available, Available,
|
|
OnFunc | OnStruct | OnEnum | OnClass | OnProtocol | OnVar |
|
|
OnConstructor | OnDestructor | OnTypeAlias | OnSubscript |
|
|
OnEnumElement | OnExtension | AllowMultipleAttributes | LongAttribute, 1)
|
|
|
|
SIMPLE_DECL_ATTR(final, Final,
|
|
OnClass | OnFunc | OnVar | OnSubscript|DeclModifier, 2)
|
|
|
|
DECL_ATTR(objc, ObjC,
|
|
OnFunc | OnClass | OnProtocol | OnExtension | OnVar | OnSubscript |
|
|
OnConstructor | OnDestructor | OnEnum | OnEnumElement, 3)
|
|
|
|
SIMPLE_DECL_ATTR(required, Required,
|
|
OnConstructor|DeclModifier, 4)
|
|
|
|
SIMPLE_DECL_ATTR(optional, Optional,
|
|
OnConstructor|OnFunc|OnVar|OnSubscript|DeclModifier, 5)
|
|
|
|
/// NOTE: 6 is unused
|
|
|
|
SIMPLE_DECL_ATTR(noreturn, NoReturn, OnFunc, 7)
|
|
|
|
SIMPLE_DECL_ATTR(_exported, Exported, OnImport | UserInaccessible, 8)
|
|
|
|
/// NOTE: 9 is unused.
|
|
|
|
SIMPLE_DECL_ATTR(NSCopying, NSCopying,
|
|
OnVar, 10)
|
|
|
|
SIMPLE_DECL_ATTR(IBAction, IBAction,
|
|
OnFunc, 11)
|
|
|
|
SIMPLE_DECL_ATTR(IBDesignable, IBDesignable,
|
|
OnClass | OnExtension, 12)
|
|
|
|
SIMPLE_DECL_ATTR(IBInspectable, IBInspectable,
|
|
OnVar, 13)
|
|
|
|
SIMPLE_DECL_ATTR(IBOutlet, IBOutlet,
|
|
OnVar, 14)
|
|
|
|
SIMPLE_DECL_ATTR(NSManaged, NSManaged, OnVar | OnFunc, 15)
|
|
|
|
SIMPLE_DECL_ATTR(lazy, Lazy, OnVar|DeclModifier, 16)
|
|
|
|
SIMPLE_DECL_ATTR(LLDBDebuggerFunction, LLDBDebuggerFunction, OnFunc |
|
|
UserInaccessible, 17)
|
|
|
|
SIMPLE_DECL_ATTR(UIApplicationMain, UIApplicationMain,
|
|
OnClass, 18)
|
|
|
|
SIMPLE_DECL_ATTR(unsafe_no_objc_tagged_pointer, UnsafeNoObjCTaggedPointer,
|
|
OnProtocol | UserInaccessible, 19)
|
|
|
|
DECL_ATTR(inline, Inline, OnFunc | OnConstructor, 20)
|
|
|
|
DECL_ATTR(_semantics, Semantics,
|
|
OnFunc | OnConstructor | OnDestructor | OnSubscript |
|
|
AllowMultipleAttributes | UserInaccessible, 21)
|
|
|
|
SIMPLE_DECL_ATTR(dynamic, Dynamic,
|
|
OnFunc | OnVar | OnSubscript | OnConstructor | DeclModifier, 22)
|
|
|
|
SIMPLE_DECL_ATTR(infix , Infix , OnFunc | OnOperator | DeclModifier, 23)
|
|
SIMPLE_DECL_ATTR(prefix , Prefix , OnFunc | OnOperator | DeclModifier, 24)
|
|
SIMPLE_DECL_ATTR(postfix, Postfix, OnFunc | OnOperator | DeclModifier, 25)
|
|
|
|
SIMPLE_DECL_ATTR(_transparent, Transparent,
|
|
OnFunc|OnConstructor|OnVar|UserInaccessible, 26)
|
|
SIMPLE_DECL_ATTR(requires_stored_property_inits, RequiresStoredPropertyInits,
|
|
OnClass, 27)
|
|
DECL_ATTR(autoclosure, AutoClosure, OnParam, 28)
|
|
SIMPLE_DECL_ATTR(noescape, NoEscape, OnParam, 29)
|
|
|
|
SIMPLE_DECL_ATTR(nonobjc, NonObjC,
|
|
OnExtension | OnFunc | OnVar | OnSubscript | OnConstructor, 30)
|
|
|
|
SIMPLE_DECL_ATTR(_fixed_layout, FixedLayout,
|
|
OnVar | OnClass | OnStruct | OnEnum | UserInaccessible, 31)
|
|
|
|
SIMPLE_DECL_ATTR(_inlineable, Inlineable,
|
|
OnVar | OnSubscript | OnFunc | OnConstructor | OnDestructor |
|
|
UserInaccessible, 32)
|
|
|
|
DECL_ATTR(_specialize, Specialize,
|
|
OnConstructor | OnFunc | AllowMultipleAttributes | LongAttribute
|
|
| UserInaccessible, 33)
|
|
|
|
SIMPLE_DECL_ATTR(objcMembers, ObjCMembers, OnClass, 34)
|
|
|
|
// Non-serialized attributes.
|
|
|
|
SIMPLE_DECL_ATTR(mutating, Mutating, OnFunc | DeclModifier | NotSerialized,
|
|
/* Not serialized */ 41)
|
|
SIMPLE_DECL_ATTR(nonmutating, NonMutating, OnFunc | DeclModifier | NotSerialized,
|
|
/* Not serialized */ 42)
|
|
|
|
SIMPLE_DECL_ATTR(convenience, Convenience,
|
|
OnConstructor|DeclModifier|NotSerialized, 43)
|
|
|
|
SIMPLE_DECL_ATTR(override, Override,
|
|
OnFunc | OnVar | OnSubscript | OnConstructor | DeclModifier |
|
|
NotSerialized,
|
|
/* Not serialized */44)
|
|
|
|
SIMPLE_DECL_ATTR(sil_stored, SILStored, OnVar | NotSerialized | SILOnly,
|
|
/* Not serialized */45)
|
|
|
|
DECL_ATTR(private, Accessibility,
|
|
OnFunc | OnExtension | OnTypeAlias | OnStruct | OnEnum |
|
|
OnClass | OnProtocol | OnVar | OnSubscript | OnConstructor |
|
|
DeclModifier | NotSerialized,
|
|
/* Not serialized */ 46)
|
|
DECL_ATTR_ALIAS(fileprivate, Accessibility)
|
|
DECL_ATTR_ALIAS(internal, Accessibility)
|
|
DECL_ATTR_ALIAS(public, Accessibility)
|
|
|
|
|
|
DECL_ATTR(__accessibility, SetterAccessibility,
|
|
OnVar | OnSubscript | DeclModifier | NotSerialized | RejectByParser,
|
|
/* Not serialized */ 47)
|
|
|
|
DECL_ATTR(__raw_doc_comment, RawDocComment, OnAnyDecl |
|
|
NotSerialized | RejectByParser, /* Not serialized */48)
|
|
|
|
// Also handles unowned and unowned(weak).
|
|
DECL_ATTR(weak, Ownership, OnVar | OnParam | DeclModifier | NotSerialized,
|
|
/* Not serialized */49)
|
|
DECL_ATTR_ALIAS(unowned, Ownership)
|
|
|
|
DECL_ATTR(effects, Effects, OnFunc | OnConstructor | OnDestructor |
|
|
UserInaccessible, 50)
|
|
|
|
DECL_ATTR(__objc_bridged, ObjCBridged, OnClass | NotSerialized | RejectByParser,
|
|
/* Not serialized */51)
|
|
|
|
SIMPLE_DECL_ATTR(NSApplicationMain, NSApplicationMain,
|
|
OnClass, 52)
|
|
|
|
SIMPLE_DECL_ATTR(objc_non_lazy_realization, ObjCNonLazyRealization,
|
|
OnClass, 53)
|
|
|
|
DECL_ATTR(__synthesized_protocol, SynthesizedProtocol,
|
|
OnStruct | OnEnum | OnClass | NotSerialized | RejectByParser,
|
|
/* Not serialized */54)
|
|
|
|
SIMPLE_DECL_ATTR(testable, Testable,
|
|
OnImport | NotSerialized | UserInaccessible,
|
|
/* Not serialized */ 55)
|
|
|
|
DECL_ATTR(_alignment, Alignment, OnStruct | OnEnum | UserInaccessible, 56)
|
|
|
|
SIMPLE_DECL_ATTR(rethrows, Rethrows,
|
|
OnFunc | OnConstructor | RejectByParser, 57)
|
|
|
|
DECL_ATTR(_swift_native_objc_runtime_base, SwiftNativeObjCRuntimeBase,
|
|
OnClass | UserInaccessible, 59)
|
|
|
|
SIMPLE_DECL_ATTR(indirect, Indirect,
|
|
OnEnum | OnEnumElement | DeclModifier,
|
|
60)
|
|
|
|
SIMPLE_DECL_ATTR(warn_unqualified_access, WarnUnqualifiedAccess,
|
|
OnFunc /*| OnVar*/ | LongAttribute, 61)
|
|
|
|
SIMPLE_DECL_ATTR(_show_in_interface, ShowInInterface,
|
|
OnProtocol | UserInaccessible, 62)
|
|
|
|
DECL_ATTR(_cdecl, CDecl,
|
|
OnFunc | LongAttribute | UserInaccessible, 63)
|
|
|
|
// A testing attribute for Library Evolution ("resilience").
|
|
// FIXME: Replace with improved @available attribute.
|
|
SIMPLE_DECL_ATTR(_versioned, Versioned,
|
|
OnFunc | OnVar | OnSubscript | OnConstructor |
|
|
OnStruct | OnEnum | OnClass | OnProtocol |
|
|
LongAttribute | UserInaccessible,
|
|
64)
|
|
|
|
SIMPLE_DECL_ATTR(discardableResult, DiscardableResult,
|
|
OnFunc | OnConstructor | LongAttribute, 65)
|
|
|
|
SIMPLE_DECL_ATTR(GKInspectable, GKInspectable, OnVar, 66)
|
|
|
|
DECL_ATTR(_implements, Implements,
|
|
OnFunc | OnVar | OnSubscript | OnTypeAlias
|
|
| NotSerialized | UserInaccessible,
|
|
/* Not serialized */ 67)
|
|
|
|
#undef TYPE_ATTR
|
|
#undef DECL_ATTR_ALIAS
|
|
#undef SIMPLE_DECL_ATTR
|
|
#undef DECL_ATTR
|