9#ifndef LLVM_CLANG_APINOTES_TYPES_H
10#define LLVM_CLANG_APINOTES_TYPES_H
13#include "llvm/ADT/ArrayRef.h"
14#include "llvm/ADT/DenseMapInfo.h"
15#include "llvm/ADT/Hashing.h"
16#include "llvm/ADT/PointerEmbeddedInt.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringExtras.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/raw_ostream.h"
33template <
typename RangeT>
36 llvm::raw_string_ostream OS(
Result);
38 llvm::interleaveComma(Parameters, OS);
78 LLVM_PREFERRED_TYPE(
bool)
82 LLVM_PREFERRED_TYPE(
bool)
87 LLVM_PREFERRED_TYPE(
bool)
88 unsigned SwiftPrivateSpecified : 1;
91 LLVM_PREFERRED_TYPE(
bool)
92 unsigned SwiftPrivate : 1;
94 LLVM_PREFERRED_TYPE(
bool)
95 unsigned SwiftSafetyAudited : 1;
98 unsigned SwiftSafety : 2;
106 SwiftPrivate(0), SwiftSafetyAudited(0), SwiftSafety(0) {}
109 return SwiftPrivateSpecified ? std::optional<bool>(SwiftPrivate)
114 SwiftPrivateSpecified =
Private.has_value();
115 SwiftPrivate =
Private.value_or(0);
119 return SwiftSafetyAudited ? std::optional<SwiftSafetyKind>(
125 SwiftSafetyAudited = 1;
126 SwiftSafety =
static_cast<unsigned>(Safety);
145 if (!SwiftPrivateSpecified)
148 if (!SwiftSafetyAudited && RHS.SwiftSafetyAudited)
157 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS)
const;
165 LHS.SwiftPrivateSpecified == RHS.SwiftPrivateSpecified &&
166 LHS.SwiftPrivate == RHS.SwiftPrivate &&
167 LHS.SwiftSafetyAudited == RHS.SwiftSafetyAudited &&
173 return !(LHS == RHS);
181 std::optional<std::string> SwiftBridge;
184 std::optional<std::string> NSErrorDomain;
187 std::optional<std::string> SwiftConformance;
197 SwiftBridge = SwiftType;
201 return NSErrorDomain;
209 NSErrorDomain =
Domain ? std::optional<std::string>(std::string(*
Domain))
214 return SwiftConformance;
218 SwiftConformance = conformance;
231 if (SwiftConformance)
237 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS)
const;
242 LHS.SwiftBridge == RHS.SwiftBridge &&
243 LHS.NSErrorDomain == RHS.NSErrorDomain &&
244 LHS.SwiftConformance == RHS.SwiftConformance;
248 return !(LHS == RHS);
256 unsigned DefaultNullabilityOrNone : 3;
259 LLVM_PREFERRED_TYPE(
bool)
260 unsigned HasDesignatedInits : 1;
262 LLVM_PREFERRED_TYPE(
bool)
263 unsigned SwiftImportAsNonGenericSpecified : 1;
264 LLVM_PREFERRED_TYPE(
bool)
265 unsigned SwiftImportAsNonGeneric : 1;
267 LLVM_PREFERRED_TYPE(
bool)
268 unsigned SwiftObjCMembersSpecified : 1;
269 LLVM_PREFERRED_TYPE(
bool)
270 unsigned SwiftObjCMembers : 1;
274 : DefaultNullabilityOrNone(0), HasDesignatedInits(0),
275 SwiftImportAsNonGenericSpecified(
false), SwiftImportAsNonGeneric(
false),
276 SwiftObjCMembersSpecified(
false), SwiftObjCMembers(
false) {}
285 DefaultNullabilityOrNone);
290 DefaultNullabilityOrNone =
298 return SwiftImportAsNonGenericSpecified
299 ? std::optional<bool>(SwiftImportAsNonGeneric)
303 SwiftImportAsNonGenericSpecified =
Value.has_value();
304 SwiftImportAsNonGeneric =
Value.value_or(
false);
308 return SwiftObjCMembersSpecified ? std::optional<bool>(SwiftObjCMembers)
312 SwiftObjCMembersSpecified =
Value.has_value();
313 SwiftObjCMembers =
Value.value_or(
false);
327 if (!SwiftImportAsNonGenericSpecified)
330 if (!SwiftObjCMembersSpecified)
333 HasDesignatedInits |= RHS.HasDesignatedInits;
338 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS);
344 LHS.HasDesignatedInits == RHS.HasDesignatedInits &&
350 return !(LHS == RHS);
370 LLVM_PREFERRED_TYPE(
bool)
371 unsigned KindAudited : 1;
378 LLVM_PREFERRED_TYPE(
bool)
379 unsigned LevelAudited : 1;
385 : Kind(0), KindAudited(
false), Level(0), LevelAudited(
false),
388 std::optional<BoundsSafetyKind>
getKind()
const {
389 return KindAudited ? std::optional<BoundsSafetyKind>(
396 Kind =
static_cast<unsigned>(
kind);
400 return LevelAudited ? std::optional<unsigned>(Level) : std::nullopt;
410 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS)
const;
415 return LHS.KindAudited == RHS.KindAudited && LHS.Kind == RHS.Kind &&
416 LHS.LevelAudited == RHS.LevelAudited && LHS.Level == RHS.Level &&
422 return !(LHS == RHS);
430 unsigned NullabilityOrNone : 3;
446 const std::string &
getType()
const {
return Type; }
462 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS)
const;
467 LHS.NullabilityOrNone == RHS.NullabilityOrNone && LHS.Type == RHS.Type;
471 return !(LHS == RHS);
476 LLVM_PREFERRED_TYPE(
bool)
477 unsigned SwiftImportAsAccessorsSpecified : 1;
478 LLVM_PREFERRED_TYPE(
bool)
479 unsigned SwiftImportAsAccessors : 1;
483 : SwiftImportAsAccessorsSpecified(
false), SwiftImportAsAccessors(
false) {}
486 return SwiftImportAsAccessorsSpecified
487 ? std::optional<bool>(SwiftImportAsAccessors)
491 SwiftImportAsAccessorsSpecified =
Value.has_value();
492 SwiftImportAsAccessors =
Value.value_or(
false);
512 if (!SwiftImportAsAccessorsSpecified)
518 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS)
const;
529 return !(LHS == RHS);
535 LLVM_PREFERRED_TYPE(
bool)
536 unsigned NoEscapeSpecified : 1;
539 LLVM_PREFERRED_TYPE(
bool)
540 unsigned NoEscape : 1;
543 LLVM_PREFERRED_TYPE(
bool)
544 unsigned LifetimeboundSpecified : 1;
547 LLVM_PREFERRED_TYPE(
bool)
548 unsigned Lifetimebound : 1;
553 unsigned RawRetainCountConvention : 3;
560 LifetimeboundSpecified(
false), Lifetimebound(
false),
564 return NoEscapeSpecified ? std::optional<bool>(NoEscape) : std::nullopt;
567 NoEscapeSpecified =
Value.has_value();
568 NoEscape =
Value.value_or(
false);
572 return LifetimeboundSpecified ? std::optional<bool>(Lifetimebound)
576 LifetimeboundSpecified =
Value.has_value();
577 Lifetimebound =
Value.value_or(
false);
581 if (!RawRetainCountConvention)
587 RawRetainCountConvention =
Value ?
static_cast<unsigned>(*Value) + 1 : 0;
594 if (!NoEscapeSpecified && RHS.NoEscapeSpecified) {
595 NoEscapeSpecified =
true;
596 NoEscape = RHS.NoEscape;
599 if (!LifetimeboundSpecified && RHS.LifetimeboundSpecified) {
600 LifetimeboundSpecified =
true;
601 Lifetimebound = RHS.Lifetimebound;
604 if (!RawRetainCountConvention)
605 RawRetainCountConvention = RHS.RawRetainCountConvention;
615 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS)
const;
620 LHS.NoEscapeSpecified == RHS.NoEscapeSpecified &&
621 LHS.NoEscape == RHS.NoEscape &&
622 LHS.LifetimeboundSpecified == RHS.LifetimeboundSpecified &&
623 LHS.Lifetimebound == RHS.Lifetimebound &&
624 LHS.RawRetainCountConvention == RHS.RawRetainCountConvention &&
629 return !(LHS == RHS);
635 static constexpr const uint64_t NullabilityKindMask = 0x3;
636 static constexpr const unsigned NullabilityKindSize = 2;
638 static constexpr const unsigned ReturnInfoIndex = 0;
646 LLVM_PREFERRED_TYPE(
bool)
656 LLVM_PREFERRED_TYPE(
bool)
685 assert(
static_cast<unsigned>(
kind) < NullabilityKindMask);
693 ~(NullabilityKindMask << (
index * NullabilityKindSize));
696 unsigned kindValue = (
static_cast<unsigned>(
kind))
697 << (
index * NullabilityKindSize);
712 return getTypeInfo(
index + 1);
733 "Checking the type adjustment on non-audited method.");
739 return static_cast<NullabilityKind>(nullability & NullabilityKindMask);
743 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS)
const;
758 return !(LHS == RHS);
765 LLVM_PREFERRED_TYPE(
bool)
769 LLVM_PREFERRED_TYPE(
bool)
789 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS);
799 return !(LHS == RHS);
827 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS);
835 return !(LHS == RHS);
846 LLVM_PREFERRED_TYPE(
bool)
847 unsigned HasFlagEnum : 1;
848 LLVM_PREFERRED_TYPE(
bool)
849 unsigned IsFlagEnum : 1;
851 LLVM_PREFERRED_TYPE(
bool)
852 unsigned SwiftCopyableSpecified : 1;
853 LLVM_PREFERRED_TYPE(
bool)
854 unsigned SwiftCopyable : 1;
856 LLVM_PREFERRED_TYPE(
bool)
857 unsigned SwiftEscapableSpecified : 1;
858 LLVM_PREFERRED_TYPE(
bool)
859 unsigned SwiftEscapable : 1;
871 : HasFlagEnum(0), IsFlagEnum(0), SwiftCopyableSpecified(
false),
872 SwiftCopyable(
false), SwiftEscapableSpecified(
false),
873 SwiftEscapable(
false) {}
881 HasFlagEnum =
Value.has_value();
882 IsFlagEnum =
Value.value_or(
false);
886 return SwiftCopyableSpecified ? std::optional<bool>(SwiftCopyable)
890 SwiftCopyableSpecified =
Value.has_value();
891 SwiftCopyable =
Value.value_or(
false);
895 return SwiftEscapableSpecified ? std::optional<bool>(SwiftEscapable)
900 SwiftEscapableSpecified =
Value.has_value();
901 SwiftEscapable =
Value.value_or(
false);
924 if (!SwiftCopyableSpecified)
927 if (!SwiftEscapableSpecified)
935 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS);
952 return !(LHS == RHS);
971 LLVM_DUMP_METHOD
void dump(llvm::raw_ostream &OS)
const;
980 return !(LHS == RHS);
1028 parameterTypeIDs.emplace(ParameterTypeIDs.begin(), ParameterTypeIDs.end());
1041 parameterTypeIDs.emplace(ParameterTypeIDs.begin(), ParameterTypeIDs.end());
1050 Hash = llvm::hash_combine(Hash,
static_cast<unsigned>(TypeID));
1100template <>
struct DenseMapInfo<
clang::api_notes::FunctionTableKey> {
1111template <>
struct DenseMapInfo<
clang::api_notes::APINotesFunctionSelectorKey> {
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
Defines various enumerations that describe declaration and type specifiers.
std::optional< BoundsSafetyKind > getKind() const
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< unsigned > getLevel() const
friend bool operator==(const BoundsSafetyInfo &, const BoundsSafetyInfo &)
std::string ExternalBounds
void setKindAudited(BoundsSafetyKind kind)
void setLevelAudited(unsigned level)
Describes API notes data for a C++ method.
std::optional< ParamInfo > This
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
Describes API notes data for any entity.
unsigned UnavailableInSwift
Whether this entity is marked unavailable in Swift.
unsigned Unavailable
Whether this entity is marked unavailable.
std::string SwiftName
Swift name of this entity.
void setSwiftSafety(SwiftSafetyKind Safety)
void setSwiftPrivate(std::optional< bool > Private)
friend bool operator==(const CommonEntityInfo &, const CommonEntityInfo &)
std::string UnavailableMsg
Message to use when this entity is unavailable.
std::optional< SwiftSafetyKind > getSwiftSafety() const
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< bool > isSwiftPrivate() const
CommonEntityInfo & operator|=(const CommonEntityInfo &RHS)
Describes API notes for types.
void setNSErrorDomain(const std::optional< llvm::StringRef > &Domain)
friend bool operator==(const CommonTypeInfo &, const CommonTypeInfo &)
std::optional< std::string > getSwiftConformance() const
const std::optional< std::string > & getSwiftBridge() const
void setSwiftConformance(std::optional< std::string > conformance)
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setNSErrorDomain(const std::optional< std::string > &Domain)
const std::optional< std::string > & getNSErrorDomain() const
void setSwiftBridge(std::optional< std::string > SwiftType)
CommonTypeInfo & operator|=(const CommonTypeInfo &RHS)
Opaque context ID used to refer to an Objective-C class or protocol or a C++ namespace.
ContextID(unsigned value)
Describes API notes data for an Objective-C class or protocol or a C++ namespace.
std::optional< bool > getSwiftImportAsNonGeneric() const
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
std::optional< bool > getSwiftObjCMembers() const
void setDefaultNullability(NullabilityKind Kind)
Set the default nullability for properties and methods of this class.
NullabilityKindOrNone getDefaultNullability() const
Determine the default nullability for properties and methods of this class.
void setSwiftObjCMembers(std::optional< bool > Value)
bool hasDesignatedInits() const
void setSwiftImportAsNonGeneric(std::optional< bool > Value)
void setHasDesignatedInits(bool Value)
friend bool operator==(const ContextInfo &, const ContextInfo &)
ContextInfo & operator|=(const ContextInfo &RHS)
API notes for a function or method.
std::string SwiftReturnOwnership
Ownership convention for return value.
void addTypeInfo(unsigned index, NullabilityKind kind)
uint64_t NullabilityPayload
Stores the nullability of the return type and the parameters.
std::optional< RetainCountConventionKind > getRetainCountConvention() const
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
unsigned RawRetainCountConvention
A biased RetainCountConventionKind, where 0 means "unspecified".
std::vector< ParamInfo > Params
The function parameters.
NullabilityKind getReturnTypeInfo() const
friend bool operator==(const FunctionInfo &, const FunctionInfo &)
NullabilityKind getParamTypeInfo(unsigned index) const
unsigned NumAdjustedNullable
Number of types whose nullability is encoded with the NullabilityPayload.
std::string ResultType
The result type of this function, as a C type.
unsigned UnsafeBufferUsage
Whether the function has the [[clang::unsafe_buffer_usage]] attribute.
static unsigned getMaxNullabilityIndex()
void addReturnTypeInfo(NullabilityKind kind)
Adds the return type info.
unsigned NullabilityAudited
Whether the signature has been audited with respect to nullability.
void addParamTypeInfo(unsigned index, NullabilityKind kind)
Adds the parameter type info.
Describes API notes data for an Objective-C method.
unsigned DesignatedInit
Whether this is a designated initializer of its class.
friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &)
std::optional< ParamInfo > Self
ObjCMethodInfo & operator|=(const ContextInfo &RHS)
unsigned RequiredInit
Whether this is a required initializer.
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
Describes API notes data for an Objective-C property.
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setSwiftImportAsAccessors(std::optional< bool > Value)
std::optional< bool > getSwiftImportAsAccessors() const
friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &)
ObjCPropertyInfo & operator|=(const ObjCPropertyInfo &RHS)
ObjCPropertyInfo & operator|=(const ContextInfo &RHS)
Merge class-wide information into the given property.
Describes a function or method parameter.
std::optional< BoundsSafetyInfo > BoundsSafety
void setNoEscape(std::optional< bool > Value)
std::optional< bool > isNoEscape() const
ParamInfo & operator|=(const ParamInfo &RHS)
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< bool > isLifetimebound() const
friend bool operator==(const ParamInfo &, const ParamInfo &)
void setLifetimebound(std::optional< bool > Value)
std::optional< RetainCountConventionKind > getRetainCountConvention() const
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Describes API notes data for a tag.
std::optional< std::string > SwiftReleaseOp
std::optional< std::string > SwiftRetainOp
std::optional< std::string > SwiftImportAs
std::optional< std::string > SwiftDefaultOwnership
std::optional< EnumExtensibilityKind > EnumExtensibility
void setSwiftCopyable(std::optional< bool > Value)
std::optional< std::string > SwiftDestroyOp
void setSwiftEscapable(std::optional< bool > Value)
std::optional< bool > isFlagEnum() const
TagInfo & operator|=(const TagInfo &RHS)
std::optional< bool > isSwiftCopyable() const
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
friend bool operator==(const TagInfo &, const TagInfo &)
std::optional< bool > isSwiftEscapable() const
void setFlagEnum(std::optional< bool > Value)
Describes API notes data for a typedef.
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
TypedefInfo & operator|=(const TypedefInfo &RHS)
friend bool operator==(const TypedefInfo &, const TypedefInfo &)
std::optional< SwiftNewTypeKind > SwiftWrapper
API notes for a variable/property.
void setNullabilityAudited(NullabilityKind kind)
void setType(const std::string &type)
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
VariableInfo & operator|=(const VariableInfo &RHS)
const std::string & getType() const
friend bool operator==(const VariableInfo &, const VariableInfo &)
NullabilityKindOrNone getNullability() const
bool operator!=(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
bool operator==(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
RetainCountConventionKind
llvm::PointerEmbeddedInt< unsigned, 31 > IdentifierID
SwiftNewTypeKind
The kind of a swift_wrapper/swift_newtype.
EnumExtensibilityKind
The payload for an enum_extensibility attribute.
std::string formatAPINotesParameterSelector(RangeT &&Parameters)
static const constexpr char SOURCE_APINOTES_EXTENSION[]
The file extension used for the source representation of API notes.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Top level wrappers for InstallAPI frontend operations.
NullabilityKind
Describes the nullability of a particular type.
@ Nullable
Values of this type can be null.
@ NonNull
Values of this type can never be null.
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
@ Result
The result type of a method or function.
OptionalUnsigned< NullabilityKind > NullabilityKindOrNone
Diagnostic wrappers for TextAPI types for error reporting.
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
constexpr underlying_type toInternalRepresentation() const
static constexpr OptionalUnsigned fromInternalRepresentation(underlying_type Rep)
Stable reader-facing identity for an API notes function selector entry.
APINotesFunctionSelectorKey getWithoutParameterSelector() const
llvm::hash_code hashValue() const
Context(ContextID id, ContextKind kind)
A key for a stored global-function or C++-method API notes entry.
FunctionTableKey(std::optional< Context > ParentCtx, IdentifierID NameID)
std::optional< llvm::SmallVector< IdentifierID, 2 > > parameterTypeIDs
llvm::hash_code hashValue() const
FunctionTableKey(uint32_t ParentContextID, uint32_t NameID)
FunctionTableKey(uint32_t ParentContextID, uint32_t NameID, const llvm::SmallVectorImpl< IdentifierID > &ParameterTypeIDs)
FunctionTableKey(std::optional< Context > ParentCtx, IdentifierID NameID, const llvm::SmallVectorImpl< IdentifierID > &ParameterTypeIDs)
A temporary reference to an Objective-C selector, suitable for referencing selector data on the stack...
llvm::ArrayRef< llvm::StringRef > Identifiers
static bool isEqual(const clang::api_notes::APINotesFunctionSelectorKey &LHS, const clang::api_notes::APINotesFunctionSelectorKey &RHS)
static unsigned getHashValue(const clang::api_notes::APINotesFunctionSelectorKey &Key)
static unsigned getHashValue(const clang::api_notes::FunctionTableKey &Key)
static bool isEqual(const clang::api_notes::FunctionTableKey &LHS, const clang::api_notes::FunctionTableKey &RHS)