clang 22.0.0git
Types.h
Go to the documentation of this file.
1//===-- Types.h - API Notes Data Types --------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_APINOTES_TYPES_H
10#define LLVM_CLANG_APINOTES_TYPES_H
11
13#include "llvm/ADT/ArrayRef.h"
14#include "llvm/ADT/StringRef.h"
15#include <climits>
16#include <optional>
17#include <vector>
18
19namespace llvm {
20class raw_ostream;
21} // namespace llvm
22
23namespace clang {
24namespace api_notes {
32
33/// The payload for an enum_extensibility attribute. This is a tri-state rather
34/// than just a boolean because the presence of the attribute indicates
35/// auditing.
41
42/// The kind of a swift_wrapper/swift_newtype.
48
50
51/// Describes API notes data for any entity.
52///
53/// This is used as the base of all API notes.
55public:
56 /// Message to use when this entity is unavailable.
57 std::string UnavailableMsg;
58
59 /// Whether this entity is marked unavailable.
60 LLVM_PREFERRED_TYPE(bool)
62
63 /// Whether this entity is marked unavailable in Swift.
64 LLVM_PREFERRED_TYPE(bool)
65 unsigned UnavailableInSwift : 1;
66
67private:
68 /// Whether SwiftPrivate was specified.
69 LLVM_PREFERRED_TYPE(bool)
70 unsigned SwiftPrivateSpecified : 1;
71
72 /// Whether this entity is considered "private" to a Swift overlay.
73 LLVM_PREFERRED_TYPE(bool)
74 unsigned SwiftPrivate : 1;
75
76 LLVM_PREFERRED_TYPE(bool)
77 unsigned SwiftSafetyAudited : 1;
78
79 LLVM_PREFERRED_TYPE(SwiftSafetyKind)
80 unsigned SwiftSafety : 2;
81
82public:
83 /// Swift name of this entity.
84 std::string SwiftName;
85
87 : Unavailable(0), UnavailableInSwift(0), SwiftPrivateSpecified(0),
88 SwiftPrivate(0), SwiftSafetyAudited(0), SwiftSafety(0) {}
89
90 std::optional<bool> isSwiftPrivate() const {
91 return SwiftPrivateSpecified ? std::optional<bool>(SwiftPrivate)
92 : std::nullopt;
93 }
94
95 void setSwiftPrivate(std::optional<bool> Private) {
96 SwiftPrivateSpecified = Private.has_value();
97 SwiftPrivate = Private.value_or(0);
98 }
99
100 std::optional<SwiftSafetyKind> getSwiftSafety() const {
101 return SwiftSafetyAudited ? std::optional<SwiftSafetyKind>(
102 static_cast<SwiftSafetyKind>(SwiftSafety))
103 : std::nullopt;
104 }
105
107 SwiftSafetyAudited = 1;
108 SwiftSafety = static_cast<unsigned>(Safety);
109 }
110
111 friend bool operator==(const CommonEntityInfo &, const CommonEntityInfo &);
112
114 // Merge unavailability.
115 if (RHS.Unavailable) {
116 Unavailable = true;
117 if (UnavailableMsg.empty())
119 }
120
121 if (RHS.UnavailableInSwift) {
122 UnavailableInSwift = true;
123 if (UnavailableMsg.empty())
125 }
126
127 if (!SwiftPrivateSpecified)
129
130 if (!SwiftSafetyAudited && RHS.SwiftSafetyAudited)
132
133 if (SwiftName.empty())
134 SwiftName = RHS.SwiftName;
135
136 return *this;
137 }
138
139 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
140};
141
142inline bool operator==(const CommonEntityInfo &LHS,
143 const CommonEntityInfo &RHS) {
144 return LHS.UnavailableMsg == RHS.UnavailableMsg &&
145 LHS.Unavailable == RHS.Unavailable &&
147 LHS.SwiftPrivateSpecified == RHS.SwiftPrivateSpecified &&
148 LHS.SwiftPrivate == RHS.SwiftPrivate &&
149 LHS.SwiftSafetyAudited == RHS.SwiftSafetyAudited &&
150 LHS.SwiftSafety == RHS.SwiftSafety && LHS.SwiftName == RHS.SwiftName;
151}
152
153inline bool operator!=(const CommonEntityInfo &LHS,
154 const CommonEntityInfo &RHS) {
155 return !(LHS == RHS);
156}
157
158/// Describes API notes for types.
160 /// The Swift type to which a given type is bridged.
161 ///
162 /// Reflects the swift_bridge attribute.
163 std::optional<std::string> SwiftBridge;
164
165 /// The NS error domain for this type.
166 std::optional<std::string> NSErrorDomain;
167
168 /// The Swift protocol that this type should be automatically conformed to.
169 std::optional<std::string> SwiftConformance;
170
171public:
173
174 const std::optional<std::string> &getSwiftBridge() const {
175 return SwiftBridge;
176 }
177
178 void setSwiftBridge(std::optional<std::string> SwiftType) {
179 SwiftBridge = SwiftType;
180 }
181
182 const std::optional<std::string> &getNSErrorDomain() const {
183 return NSErrorDomain;
184 }
185
186 void setNSErrorDomain(const std::optional<std::string> &Domain) {
187 NSErrorDomain = Domain;
188 }
189
190 void setNSErrorDomain(const std::optional<llvm::StringRef> &Domain) {
191 NSErrorDomain = Domain ? std::optional<std::string>(std::string(*Domain))
192 : std::nullopt;
193 }
194
195 std::optional<std::string> getSwiftConformance() const {
196 return SwiftConformance;
197 }
198
199 void setSwiftConformance(std::optional<std::string> conformance) {
200 SwiftConformance = conformance;
201 }
202
203 friend bool operator==(const CommonTypeInfo &, const CommonTypeInfo &);
204
206 // Merge inherited info.
207 static_cast<CommonEntityInfo &>(*this) |= RHS;
208
209 if (!SwiftBridge)
211 if (!NSErrorDomain)
213 if (SwiftConformance)
215
216 return *this;
217 }
218
219 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
220};
221
222inline bool operator==(const CommonTypeInfo &LHS, const CommonTypeInfo &RHS) {
223 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
224 LHS.SwiftBridge == RHS.SwiftBridge &&
225 LHS.NSErrorDomain == RHS.NSErrorDomain &&
226 LHS.SwiftConformance == RHS.SwiftConformance;
227}
228
229inline bool operator!=(const CommonTypeInfo &LHS, const CommonTypeInfo &RHS) {
230 return !(LHS == RHS);
231}
232
233/// Describes API notes data for an Objective-C class or protocol or a C++
234/// namespace.
236 /// Whether this class has a default nullability.
237 LLVM_PREFERRED_TYPE(bool)
238 unsigned HasDefaultNullability : 1;
239
240 /// The default nullability.
241 LLVM_PREFERRED_TYPE(NullabilityKind)
242 unsigned DefaultNullability : 2;
243
244 /// Whether this class has designated initializers recorded.
245 LLVM_PREFERRED_TYPE(bool)
246 unsigned HasDesignatedInits : 1;
247
248 LLVM_PREFERRED_TYPE(bool)
249 unsigned SwiftImportAsNonGenericSpecified : 1;
250 LLVM_PREFERRED_TYPE(bool)
251 unsigned SwiftImportAsNonGeneric : 1;
252
253 LLVM_PREFERRED_TYPE(bool)
254 unsigned SwiftObjCMembersSpecified : 1;
255 LLVM_PREFERRED_TYPE(bool)
256 unsigned SwiftObjCMembers : 1;
257
258public:
260 : HasDefaultNullability(0), DefaultNullability(0), HasDesignatedInits(0),
261 SwiftImportAsNonGenericSpecified(false), SwiftImportAsNonGeneric(false),
262 SwiftObjCMembersSpecified(false), SwiftObjCMembers(false) {}
263
264 /// Determine the default nullability for properties and methods of this
265 /// class.
266 ///
267 /// Returns the default nullability, if implied, or std::nullopt if there is
268 /// none.
269 std::optional<NullabilityKind> getDefaultNullability() const {
270 return HasDefaultNullability
271 ? std::optional<NullabilityKind>(
272 static_cast<NullabilityKind>(DefaultNullability))
273 : std::nullopt;
274 }
275
276 /// Set the default nullability for properties and methods of this class.
278 HasDefaultNullability = true;
279 DefaultNullability = static_cast<unsigned>(Kind);
280 }
281
282 bool hasDesignatedInits() const { return HasDesignatedInits; }
283 void setHasDesignatedInits(bool Value) { HasDesignatedInits = Value; }
284
285 std::optional<bool> getSwiftImportAsNonGeneric() const {
286 return SwiftImportAsNonGenericSpecified
287 ? std::optional<bool>(SwiftImportAsNonGeneric)
288 : std::nullopt;
289 }
290 void setSwiftImportAsNonGeneric(std::optional<bool> Value) {
291 SwiftImportAsNonGenericSpecified = Value.has_value();
292 SwiftImportAsNonGeneric = Value.value_or(false);
293 }
294
295 std::optional<bool> getSwiftObjCMembers() const {
296 return SwiftObjCMembersSpecified ? std::optional<bool>(SwiftObjCMembers)
297 : std::nullopt;
298 }
299 void setSwiftObjCMembers(std::optional<bool> Value) {
300 SwiftObjCMembersSpecified = Value.has_value();
301 SwiftObjCMembers = Value.value_or(false);
302 }
303
304 friend bool operator==(const ContextInfo &, const ContextInfo &);
305
307 // Merge inherited info.
308 static_cast<CommonTypeInfo &>(*this) |= RHS;
309
310 // Merge nullability.
312 if (auto Nullability = RHS.getDefaultNullability())
313 setDefaultNullability(*Nullability);
314
315 if (!SwiftImportAsNonGenericSpecified)
317
318 if (!SwiftObjCMembersSpecified)
320
321 HasDesignatedInits |= RHS.HasDesignatedInits;
322
323 return *this;
324 }
325
326 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
327};
328
329inline bool operator==(const ContextInfo &LHS, const ContextInfo &RHS) {
330 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
332 LHS.HasDesignatedInits == RHS.HasDesignatedInits &&
335}
336
337inline bool operator!=(const ContextInfo &LHS, const ContextInfo &RHS) {
338 return !(LHS == RHS);
339}
340
341/// API notes for a variable/property.
343 /// Whether this property has been audited for nullability.
344 LLVM_PREFERRED_TYPE(bool)
345 unsigned NullabilityAudited : 1;
346
347 /// The kind of nullability for this property. Only valid if the nullability
348 /// has been audited.
349 LLVM_PREFERRED_TYPE(NullabilityKind)
350 unsigned Nullable : 2;
351
352 /// The C type of the variable, as a string.
353 std::string Type;
354
355public:
356 VariableInfo() : NullabilityAudited(false), Nullable(0) {}
357
358 std::optional<NullabilityKind> getNullability() const {
359 return NullabilityAudited ? std::optional<NullabilityKind>(
360 static_cast<NullabilityKind>(Nullable))
361 : std::nullopt;
362 }
363
365 NullabilityAudited = true;
366 Nullable = static_cast<unsigned>(kind);
367 }
368
369 const std::string &getType() const { return Type; }
370 void setType(const std::string &type) { Type = type; }
371
372 friend bool operator==(const VariableInfo &, const VariableInfo &);
373
375 static_cast<CommonEntityInfo &>(*this) |= RHS;
376
377 if (!NullabilityAudited && RHS.NullabilityAudited)
379 if (Type.empty())
380 Type = RHS.Type;
381
382 return *this;
383 }
384
385 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
386};
387
388inline bool operator==(const VariableInfo &LHS, const VariableInfo &RHS) {
389 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
390 LHS.NullabilityAudited == RHS.NullabilityAudited &&
391 LHS.Nullable == RHS.Nullable && LHS.Type == RHS.Type;
392}
393
394inline bool operator!=(const VariableInfo &LHS, const VariableInfo &RHS) {
395 return !(LHS == RHS);
396}
397
398/// Describes API notes data for an Objective-C property.
400 LLVM_PREFERRED_TYPE(bool)
401 unsigned SwiftImportAsAccessorsSpecified : 1;
402 LLVM_PREFERRED_TYPE(bool)
403 unsigned SwiftImportAsAccessors : 1;
404
405public:
407 : SwiftImportAsAccessorsSpecified(false), SwiftImportAsAccessors(false) {}
408
409 std::optional<bool> getSwiftImportAsAccessors() const {
410 return SwiftImportAsAccessorsSpecified
411 ? std::optional<bool>(SwiftImportAsAccessors)
412 : std::nullopt;
413 }
414 void setSwiftImportAsAccessors(std::optional<bool> Value) {
415 SwiftImportAsAccessorsSpecified = Value.has_value();
416 SwiftImportAsAccessors = Value.value_or(false);
417 }
418
419 friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &);
420
421 /// Merge class-wide information into the given property.
423 static_cast<CommonEntityInfo &>(*this) |= RHS;
424
425 // Merge nullability.
426 if (!getNullability())
427 if (auto Nullable = RHS.getDefaultNullability())
428 setNullabilityAudited(*Nullable);
429
430 return *this;
431 }
432
434 static_cast<VariableInfo &>(*this) |= RHS;
435
436 if (!SwiftImportAsAccessorsSpecified)
438
439 return *this;
440 }
441
442 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
443};
444
445inline bool operator==(const ObjCPropertyInfo &LHS,
446 const ObjCPropertyInfo &RHS) {
447 return static_cast<const VariableInfo &>(LHS) == RHS &&
449}
450
451inline bool operator!=(const ObjCPropertyInfo &LHS,
452 const ObjCPropertyInfo &RHS) {
453 return !(LHS == RHS);
454}
455
456/// Describes a function or method parameter.
457class ParamInfo : public VariableInfo {
458 /// Whether noescape was specified.
459 LLVM_PREFERRED_TYPE(bool)
460 unsigned NoEscapeSpecified : 1;
461
462 /// Whether the this parameter has the 'noescape' attribute.
463 LLVM_PREFERRED_TYPE(bool)
464 unsigned NoEscape : 1;
465
466 /// Whether lifetimebound was specified.
467 LLVM_PREFERRED_TYPE(bool)
468 unsigned LifetimeboundSpecified : 1;
469
470 /// Whether the this parameter has the 'lifetimebound' attribute.
471 LLVM_PREFERRED_TYPE(bool)
472 unsigned Lifetimebound : 1;
473
474 /// A biased RetainCountConventionKind, where 0 means "unspecified".
475 ///
476 /// Only relevant for out-parameters.
477 unsigned RawRetainCountConvention : 3;
478
479public:
481 : NoEscapeSpecified(false), NoEscape(false),
482 LifetimeboundSpecified(false), Lifetimebound(false),
483 RawRetainCountConvention() {}
484
485 std::optional<bool> isNoEscape() const {
486 return NoEscapeSpecified ? std::optional<bool>(NoEscape) : std::nullopt;
487 }
488 void setNoEscape(std::optional<bool> Value) {
489 NoEscapeSpecified = Value.has_value();
490 NoEscape = Value.value_or(false);
491 }
492
493 std::optional<bool> isLifetimebound() const {
494 return LifetimeboundSpecified ? std::optional<bool>(Lifetimebound)
495 : std::nullopt;
496 }
497 void setLifetimebound(std::optional<bool> Value) {
498 LifetimeboundSpecified = Value.has_value();
499 Lifetimebound = Value.value_or(false);
500 }
501
502 std::optional<RetainCountConventionKind> getRetainCountConvention() const {
503 if (!RawRetainCountConvention)
504 return std::nullopt;
505 return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
506 }
507 void
508 setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
509 RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
510 assert(getRetainCountConvention() == Value && "bitfield too small");
511 }
512
514 static_cast<VariableInfo &>(*this) |= RHS;
515
516 if (!NoEscapeSpecified && RHS.NoEscapeSpecified) {
517 NoEscapeSpecified = true;
518 NoEscape = RHS.NoEscape;
519 }
520
521 if (!LifetimeboundSpecified && RHS.LifetimeboundSpecified) {
522 LifetimeboundSpecified = true;
523 Lifetimebound = RHS.Lifetimebound;
524 }
525
526 if (!RawRetainCountConvention)
527 RawRetainCountConvention = RHS.RawRetainCountConvention;
528
529 return *this;
530 }
531
532 friend bool operator==(const ParamInfo &, const ParamInfo &);
533
534 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
535};
536
537inline bool operator==(const ParamInfo &LHS, const ParamInfo &RHS) {
538 return static_cast<const VariableInfo &>(LHS) == RHS &&
539 LHS.NoEscapeSpecified == RHS.NoEscapeSpecified &&
540 LHS.NoEscape == RHS.NoEscape &&
541 LHS.LifetimeboundSpecified == RHS.LifetimeboundSpecified &&
542 LHS.Lifetimebound == RHS.Lifetimebound &&
543 LHS.RawRetainCountConvention == RHS.RawRetainCountConvention;
544}
545
546inline bool operator!=(const ParamInfo &LHS, const ParamInfo &RHS) {
547 return !(LHS == RHS);
548}
549
550/// API notes for a function or method.
552private:
553 static constexpr const uint64_t NullabilityKindMask = 0x3;
554 static constexpr const unsigned NullabilityKindSize = 2;
555
556 static constexpr const unsigned ReturnInfoIndex = 0;
557
558public:
559 // If yes, we consider all types to be non-nullable unless otherwise noted.
560 // If this flag is not set, the pointer types are considered to have
561 // unknown nullability.
562
563 /// Whether the signature has been audited with respect to nullability.
564 LLVM_PREFERRED_TYPE(bool)
566
567 /// Number of types whose nullability is encoded with the NullabilityPayload.
569
570 /// A biased RetainCountConventionKind, where 0 means "unspecified".
572
573 // NullabilityKindSize bits are used to encode the nullability. The info
574 // about the return type is stored at position 0, followed by the nullability
575 // of the parameters.
576
577 /// Stores the nullability of the return type and the parameters.
578 uint64_t NullabilityPayload = 0;
579
580 /// The result type of this function, as a C type.
582
583 /// Ownership convention for return value
585
586 /// The function parameters.
588
592
593 static unsigned getMaxNullabilityIndex() {
594 return ((sizeof(NullabilityPayload) * CHAR_BIT) / NullabilityKindSize);
595 }
596
597 void addTypeInfo(unsigned index, NullabilityKind kind) {
598 assert(index <= getMaxNullabilityIndex());
599 assert(static_cast<unsigned>(kind) < NullabilityKindMask);
600
601 NullabilityAudited = true;
602 if (NumAdjustedNullable < index + 1)
604
605 // Mask the bits.
607 ~(NullabilityKindMask << (index * NullabilityKindSize));
608
609 // Set the value.
610 unsigned kindValue = (static_cast<unsigned>(kind))
611 << (index * NullabilityKindSize);
612 NullabilityPayload |= kindValue;
613 }
614
615 /// Adds the return type info.
617 addTypeInfo(ReturnInfoIndex, kind);
618 }
619
620 /// Adds the parameter type info.
622 addTypeInfo(index + 1, kind);
623 }
624
626 return getTypeInfo(index + 1);
627 }
628
629 NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
630
631 std::optional<RetainCountConventionKind> getRetainCountConvention() const {
633 return std::nullopt;
635 }
636 void
637 setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
638 RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
639 assert(getRetainCountConvention() == Value && "bitfield too small");
640 }
641
642 friend bool operator==(const FunctionInfo &, const FunctionInfo &);
643
644private:
645 NullabilityKind getTypeInfo(unsigned index) const {
646 assert(NullabilityAudited &&
647 "Checking the type adjustment on non-audited method.");
648
649 // If we don't have info about this parameter, return the default.
652 auto nullability = NullabilityPayload >> (index * NullabilityKindSize);
653 return static_cast<NullabilityKind>(nullability & NullabilityKindMask);
654 }
655
656public:
657 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
658};
659
660inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS) {
661 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
665 LHS.ResultType == RHS.ResultType && LHS.Params == RHS.Params &&
668}
669
670inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
671 return !(LHS == RHS);
672}
673
674/// Describes API notes data for an Objective-C method.
676public:
677 /// Whether this is a designated initializer of its class.
678 LLVM_PREFERRED_TYPE(bool)
680
681 /// Whether this is a required initializer.
682 LLVM_PREFERRED_TYPE(bool)
683 unsigned RequiredInit : 1;
684
685 std::optional<ParamInfo> Self;
686
688
689 friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
690
692 // Merge Nullability.
693 if (!NullabilityAudited) {
694 if (auto Nullable = RHS.getDefaultNullability()) {
695 NullabilityAudited = true;
697 }
698 }
699 return *this;
700 }
701
702 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
703};
704
705inline bool operator==(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
706 return static_cast<const FunctionInfo &>(LHS) == RHS &&
707 LHS.DesignatedInit == RHS.DesignatedInit &&
708 LHS.RequiredInit == RHS.RequiredInit && LHS.Self == RHS.Self;
709}
710
711inline bool operator!=(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
712 return !(LHS == RHS);
713}
714
715/// Describes API notes data for a global variable.
717public:
719};
720
721/// Describes API notes data for a global function.
723public:
725};
726
727/// Describes API notes data for a C/C++ record field.
728class FieldInfo : public VariableInfo {
729public:
731};
732
733/// Describes API notes data for a C++ method.
735public:
737
738 std::optional<ParamInfo> This;
739
740 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
741};
742
743inline bool operator==(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
744 return static_cast<const FunctionInfo &>(LHS) == RHS && LHS.This == RHS.This;
745}
746
747inline bool operator!=(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
748 return !(LHS == RHS);
749}
750
751/// Describes API notes data for an enumerator.
753public:
755};
756
757/// Describes API notes data for a tag.
758class TagInfo : public CommonTypeInfo {
759 LLVM_PREFERRED_TYPE(bool)
760 unsigned HasFlagEnum : 1;
761 LLVM_PREFERRED_TYPE(bool)
762 unsigned IsFlagEnum : 1;
763
764 LLVM_PREFERRED_TYPE(bool)
765 unsigned SwiftCopyableSpecified : 1;
766 LLVM_PREFERRED_TYPE(bool)
767 unsigned SwiftCopyable : 1;
768
769 LLVM_PREFERRED_TYPE(bool)
770 unsigned SwiftEscapableSpecified : 1;
771 LLVM_PREFERRED_TYPE(bool)
772 unsigned SwiftEscapable : 1;
773
774public:
775 std::optional<std::string> SwiftImportAs;
776 std::optional<std::string> SwiftRetainOp;
777 std::optional<std::string> SwiftReleaseOp;
778 std::optional<std::string> SwiftDestroyOp;
779 std::optional<std::string> SwiftDefaultOwnership;
780
781 std::optional<EnumExtensibilityKind> EnumExtensibility;
782
784 : HasFlagEnum(0), IsFlagEnum(0), SwiftCopyableSpecified(false),
785 SwiftCopyable(false), SwiftEscapableSpecified(false),
786 SwiftEscapable(false) {}
787
788 std::optional<bool> isFlagEnum() const {
789 if (HasFlagEnum)
790 return IsFlagEnum;
791 return std::nullopt;
792 }
793 void setFlagEnum(std::optional<bool> Value) {
794 HasFlagEnum = Value.has_value();
795 IsFlagEnum = Value.value_or(false);
796 }
797
798 std::optional<bool> isSwiftCopyable() const {
799 return SwiftCopyableSpecified ? std::optional<bool>(SwiftCopyable)
800 : std::nullopt;
801 }
802 void setSwiftCopyable(std::optional<bool> Value) {
803 SwiftCopyableSpecified = Value.has_value();
804 SwiftCopyable = Value.value_or(false);
805 }
806
807 std::optional<bool> isSwiftEscapable() const {
808 return SwiftEscapableSpecified ? std::optional<bool>(SwiftEscapable)
809 : std::nullopt;
810 }
811
812 void setSwiftEscapable(std::optional<bool> Value) {
813 SwiftEscapableSpecified = Value.has_value();
814 SwiftEscapable = Value.value_or(false);
815 }
816
818 static_cast<CommonTypeInfo &>(*this) |= RHS;
819
820 if (!SwiftImportAs)
822 if (!SwiftRetainOp)
824 if (!SwiftReleaseOp)
826 if (!SwiftDestroyOp)
830
831 if (!HasFlagEnum)
832 setFlagEnum(RHS.isFlagEnum());
833
836
837 if (!SwiftCopyableSpecified)
839
840 if (!SwiftEscapableSpecified)
842
843 return *this;
844 }
845
846 friend bool operator==(const TagInfo &, const TagInfo &);
847
848 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
849};
850
851inline bool operator==(const TagInfo &LHS, const TagInfo &RHS) {
852 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
853 LHS.SwiftImportAs == RHS.SwiftImportAs &&
854 LHS.SwiftRetainOp == RHS.SwiftRetainOp &&
855 LHS.SwiftReleaseOp == RHS.SwiftReleaseOp &&
856 LHS.SwiftDestroyOp == RHS.SwiftDestroyOp &&
858 LHS.isFlagEnum() == RHS.isFlagEnum() &&
859 LHS.isSwiftCopyable() == RHS.isSwiftCopyable() &&
860 LHS.isSwiftEscapable() == RHS.isSwiftEscapable() &&
862}
863
864inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
865 return !(LHS == RHS);
866}
867
868/// Describes API notes data for a typedef.
870public:
871 std::optional<SwiftNewTypeKind> SwiftWrapper;
872
874
876 static_cast<CommonTypeInfo &>(*this) |= RHS;
877 if (!SwiftWrapper)
879 return *this;
880 }
881
882 friend bool operator==(const TypedefInfo &, const TypedefInfo &);
883
884 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
885};
886
887inline bool operator==(const TypedefInfo &LHS, const TypedefInfo &RHS) {
888 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
889 LHS.SwiftWrapper == RHS.SwiftWrapper;
890}
891
892inline bool operator!=(const TypedefInfo &LHS, const TypedefInfo &RHS) {
893 return !(LHS == RHS);
894}
895
896/// The file extension used for the source representation of API notes.
897static const constexpr char SOURCE_APINOTES_EXTENSION[] = "apinotes";
898
899/// Opaque context ID used to refer to an Objective-C class or protocol or a C++
900/// namespace.
902public:
903 unsigned Value;
904
905 explicit ContextID(unsigned value) : Value(value) {}
906};
907
908enum class ContextKind : uint8_t {
912 Tag = 3,
913};
914
921
922/// A temporary reference to an Objective-C selector, suitable for
923/// referencing selector data on the stack.
924///
925/// Instances of this struct do not store references to any of the
926/// data they contain; it is up to the user to ensure that the data
927/// referenced by the identifier list persists.
932} // namespace api_notes
933} // namespace clang
934
935#endif
Defines various enumerations that describe declaration and type specifiers.
Describes API notes data for a C++ method.
Definition Types.h:734
std::optional< ParamInfo > This
Definition Types.h:738
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
Describes API notes data for any entity.
Definition Types.h:54
unsigned UnavailableInSwift
Whether this entity is marked unavailable in Swift.
Definition Types.h:65
unsigned Unavailable
Whether this entity is marked unavailable.
Definition Types.h:61
std::string SwiftName
Swift name of this entity.
Definition Types.h:84
void setSwiftSafety(SwiftSafetyKind Safety)
Definition Types.h:106
void setSwiftPrivate(std::optional< bool > Private)
Definition Types.h:95
friend bool operator==(const CommonEntityInfo &, const CommonEntityInfo &)
Definition Types.h:142
std::string UnavailableMsg
Message to use when this entity is unavailable.
Definition Types.h:57
std::optional< SwiftSafetyKind > getSwiftSafety() const
Definition Types.h:100
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< bool > isSwiftPrivate() const
Definition Types.h:90
CommonEntityInfo & operator|=(const CommonEntityInfo &RHS)
Definition Types.h:113
Describes API notes for types.
Definition Types.h:159
void setNSErrorDomain(const std::optional< llvm::StringRef > &Domain)
Definition Types.h:190
friend bool operator==(const CommonTypeInfo &, const CommonTypeInfo &)
Definition Types.h:222
std::optional< std::string > getSwiftConformance() const
Definition Types.h:195
const std::optional< std::string > & getSwiftBridge() const
Definition Types.h:174
void setSwiftConformance(std::optional< std::string > conformance)
Definition Types.h:199
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setNSErrorDomain(const std::optional< std::string > &Domain)
Definition Types.h:186
const std::optional< std::string > & getNSErrorDomain() const
Definition Types.h:182
void setSwiftBridge(std::optional< std::string > SwiftType)
Definition Types.h:178
CommonTypeInfo & operator|=(const CommonTypeInfo &RHS)
Definition Types.h:205
Opaque context ID used to refer to an Objective-C class or protocol or a C++ namespace.
Definition Types.h:901
ContextID(unsigned value)
Definition Types.h:905
Describes API notes data for an Objective-C class or protocol or a C++ namespace.
Definition Types.h:235
std::optional< bool > getSwiftImportAsNonGeneric() const
Definition Types.h:285
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
std::optional< bool > getSwiftObjCMembers() const
Definition Types.h:295
void setDefaultNullability(NullabilityKind Kind)
Set the default nullability for properties and methods of this class.
Definition Types.h:277
std::optional< NullabilityKind > getDefaultNullability() const
Determine the default nullability for properties and methods of this class.
Definition Types.h:269
void setSwiftObjCMembers(std::optional< bool > Value)
Definition Types.h:299
bool hasDesignatedInits() const
Definition Types.h:282
void setSwiftImportAsNonGeneric(std::optional< bool > Value)
Definition Types.h:290
void setHasDesignatedInits(bool Value)
Definition Types.h:283
friend bool operator==(const ContextInfo &, const ContextInfo &)
Definition Types.h:329
ContextInfo & operator|=(const ContextInfo &RHS)
Definition Types.h:306
API notes for a function or method.
Definition Types.h:551
std::string SwiftReturnOwnership
Ownership convention for return value.
Definition Types.h:584
void addTypeInfo(unsigned index, NullabilityKind kind)
Definition Types.h:597
uint64_t NullabilityPayload
Stores the nullability of the return type and the parameters.
Definition Types.h:578
std::optional< RetainCountConventionKind > getRetainCountConvention() const
Definition Types.h:631
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition Types.h:637
unsigned RawRetainCountConvention
A biased RetainCountConventionKind, where 0 means "unspecified".
Definition Types.h:571
std::vector< ParamInfo > Params
The function parameters.
Definition Types.h:587
NullabilityKind getReturnTypeInfo() const
Definition Types.h:629
friend bool operator==(const FunctionInfo &, const FunctionInfo &)
Definition Types.h:660
NullabilityKind getParamTypeInfo(unsigned index) const
Definition Types.h:625
unsigned NumAdjustedNullable
Number of types whose nullability is encoded with the NullabilityPayload.
Definition Types.h:568
std::string ResultType
The result type of this function, as a C type.
Definition Types.h:581
static unsigned getMaxNullabilityIndex()
Definition Types.h:593
void addReturnTypeInfo(NullabilityKind kind)
Adds the return type info.
Definition Types.h:616
unsigned NullabilityAudited
Whether the signature has been audited with respect to nullability.
Definition Types.h:565
void addParamTypeInfo(unsigned index, NullabilityKind kind)
Adds the parameter type info.
Definition Types.h:621
Describes API notes data for an Objective-C method.
Definition Types.h:675
unsigned DesignatedInit
Whether this is a designated initializer of its class.
Definition Types.h:679
friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &)
Definition Types.h:705
std::optional< ParamInfo > Self
Definition Types.h:685
ObjCMethodInfo & operator|=(const ContextInfo &RHS)
Definition Types.h:691
unsigned RequiredInit
Whether this is a required initializer.
Definition Types.h:683
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
Describes API notes data for an Objective-C property.
Definition Types.h:399
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setSwiftImportAsAccessors(std::optional< bool > Value)
Definition Types.h:414
std::optional< bool > getSwiftImportAsAccessors() const
Definition Types.h:409
friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &)
Definition Types.h:445
ObjCPropertyInfo & operator|=(const ObjCPropertyInfo &RHS)
Definition Types.h:433
ObjCPropertyInfo & operator|=(const ContextInfo &RHS)
Merge class-wide information into the given property.
Definition Types.h:422
Describes a function or method parameter.
Definition Types.h:457
void setNoEscape(std::optional< bool > Value)
Definition Types.h:488
std::optional< bool > isNoEscape() const
Definition Types.h:485
ParamInfo & operator|=(const ParamInfo &RHS)
Definition Types.h:513
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< bool > isLifetimebound() const
Definition Types.h:493
friend bool operator==(const ParamInfo &, const ParamInfo &)
Definition Types.h:537
void setLifetimebound(std::optional< bool > Value)
Definition Types.h:497
std::optional< RetainCountConventionKind > getRetainCountConvention() const
Definition Types.h:502
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition Types.h:508
Describes API notes data for a tag.
Definition Types.h:758
std::optional< std::string > SwiftReleaseOp
Definition Types.h:777
std::optional< std::string > SwiftRetainOp
Definition Types.h:776
std::optional< std::string > SwiftImportAs
Definition Types.h:775
std::optional< std::string > SwiftDefaultOwnership
Definition Types.h:779
std::optional< EnumExtensibilityKind > EnumExtensibility
Definition Types.h:781
void setSwiftCopyable(std::optional< bool > Value)
Definition Types.h:802
std::optional< std::string > SwiftDestroyOp
Definition Types.h:778
void setSwiftEscapable(std::optional< bool > Value)
Definition Types.h:812
std::optional< bool > isFlagEnum() const
Definition Types.h:788
TagInfo & operator|=(const TagInfo &RHS)
Definition Types.h:817
std::optional< bool > isSwiftCopyable() const
Definition Types.h:798
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
friend bool operator==(const TagInfo &, const TagInfo &)
Definition Types.h:851
std::optional< bool > isSwiftEscapable() const
Definition Types.h:807
void setFlagEnum(std::optional< bool > Value)
Definition Types.h:793
Describes API notes data for a typedef.
Definition Types.h:869
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
TypedefInfo & operator|=(const TypedefInfo &RHS)
Definition Types.h:875
friend bool operator==(const TypedefInfo &, const TypedefInfo &)
Definition Types.h:887
std::optional< SwiftNewTypeKind > SwiftWrapper
Definition Types.h:871
API notes for a variable/property.
Definition Types.h:342
void setNullabilityAudited(NullabilityKind kind)
Definition Types.h:364
void setType(const std::string &type)
Definition Types.h:370
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
VariableInfo & operator|=(const VariableInfo &RHS)
Definition Types.h:374
std::optional< NullabilityKind > getNullability() const
Definition Types.h:358
const std::string & getType() const
Definition Types.h:369
friend bool operator==(const VariableInfo &, const VariableInfo &)
Definition Types.h:388
#define CHAR_BIT
Definition limits.h:71
bool operator!=(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
Definition Types.h:153
bool operator==(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
Definition Types.h:142
RetainCountConventionKind
Definition Types.h:25
SwiftNewTypeKind
The kind of a swift_wrapper/swift_newtype.
Definition Types.h:43
EnumExtensibilityKind
The payload for an enum_extensibility attribute.
Definition Types.h:36
static const constexpr char SOURCE_APINOTES_EXTENSION[]
The file extension used for the source representation of API notes.
Definition Types.h:897
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
NullabilityKind
Describes the nullability of a particular type.
Definition Specifiers.h:348
@ Nullable
Values of this type can be null.
Definition Specifiers.h:352
@ NonNull
Values of this type can never be null.
Definition Specifiers.h:350
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
#define false
Definition stdbool.h:26
Context(ContextID id, ContextKind kind)
Definition Types.h:919
A temporary reference to an Objective-C selector, suitable for referencing selector data on the stack...
Definition Types.h:928
llvm::ArrayRef< llvm::StringRef > Identifiers
Definition Types.h:930