clang 23.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 /// The default nullability, if any.
237 LLVM_PREFERRED_TYPE(NullabilityKindOrNone)
238 unsigned DefaultNullabilityOrNone : 3;
239
240 /// Whether this class has designated initializers recorded.
241 LLVM_PREFERRED_TYPE(bool)
242 unsigned HasDesignatedInits : 1;
243
244 LLVM_PREFERRED_TYPE(bool)
245 unsigned SwiftImportAsNonGenericSpecified : 1;
246 LLVM_PREFERRED_TYPE(bool)
247 unsigned SwiftImportAsNonGeneric : 1;
248
249 LLVM_PREFERRED_TYPE(bool)
250 unsigned SwiftObjCMembersSpecified : 1;
251 LLVM_PREFERRED_TYPE(bool)
252 unsigned SwiftObjCMembers : 1;
253
254public:
256 : DefaultNullabilityOrNone(0), HasDesignatedInits(0),
257 SwiftImportAsNonGenericSpecified(false), SwiftImportAsNonGeneric(false),
258 SwiftObjCMembersSpecified(false), SwiftObjCMembers(false) {}
259
260 /// Determine the default nullability for properties and methods of this
261 /// class.
262 ///
263 /// Returns the default nullability, if implied, or std::nullopt if there is
264 /// none.
269
270 /// Set the default nullability for properties and methods of this class.
272 DefaultNullabilityOrNone =
274 }
275
276 bool hasDesignatedInits() const { return HasDesignatedInits; }
277 void setHasDesignatedInits(bool Value) { HasDesignatedInits = Value; }
278
279 std::optional<bool> getSwiftImportAsNonGeneric() const {
280 return SwiftImportAsNonGenericSpecified
281 ? std::optional<bool>(SwiftImportAsNonGeneric)
282 : std::nullopt;
283 }
284 void setSwiftImportAsNonGeneric(std::optional<bool> Value) {
285 SwiftImportAsNonGenericSpecified = Value.has_value();
286 SwiftImportAsNonGeneric = Value.value_or(false);
287 }
288
289 std::optional<bool> getSwiftObjCMembers() const {
290 return SwiftObjCMembersSpecified ? std::optional<bool>(SwiftObjCMembers)
291 : std::nullopt;
292 }
293 void setSwiftObjCMembers(std::optional<bool> Value) {
294 SwiftObjCMembersSpecified = Value.has_value();
295 SwiftObjCMembers = Value.value_or(false);
296 }
297
298 friend bool operator==(const ContextInfo &, const ContextInfo &);
299
301 // Merge inherited info.
302 static_cast<CommonTypeInfo &>(*this) |= RHS;
303
304 // Merge nullability.
306 if (auto Nullability = RHS.getDefaultNullability())
307 setDefaultNullability(*Nullability);
308
309 if (!SwiftImportAsNonGenericSpecified)
311
312 if (!SwiftObjCMembersSpecified)
314
315 HasDesignatedInits |= RHS.HasDesignatedInits;
316
317 return *this;
318 }
319
320 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
321};
322
323inline bool operator==(const ContextInfo &LHS, const ContextInfo &RHS) {
324 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
326 LHS.HasDesignatedInits == RHS.HasDesignatedInits &&
329}
330
331inline bool operator!=(const ContextInfo &LHS, const ContextInfo &RHS) {
332 return !(LHS == RHS);
333}
334
336public:
344
345private:
346 /// The kind of bounds safety for this property. Only valid if the bounds
347 /// safety has been audited.
348 LLVM_PREFERRED_TYPE(BoundsSafetyKind)
349 unsigned Kind : 3;
350
351 /// Whether the bounds safety kind has been audited.
352 LLVM_PREFERRED_TYPE(bool)
353 unsigned KindAudited : 1;
354
355 /// The pointer indirection level at which the bounds annotation applies.
356 /// Only valid if LevelAudited is set.
357 unsigned Level : 3;
358
359 /// Whether the pointer indirection level has been specified.
360 LLVM_PREFERRED_TYPE(bool)
361 unsigned LevelAudited : 1;
362
363public:
364 std::string ExternalBounds;
365
367 : Kind(0), KindAudited(false), Level(0), LevelAudited(false),
368 ExternalBounds("") {}
369
370 std::optional<BoundsSafetyKind> getKind() const {
371 return KindAudited ? std::optional<BoundsSafetyKind>(
372 static_cast<BoundsSafetyKind>(Kind))
373 : std::nullopt;
374 }
375
377 KindAudited = true;
378 Kind = static_cast<unsigned>(kind);
379 }
380
381 std::optional<unsigned> getLevel() const {
382 return LevelAudited ? std::optional<unsigned>(Level) : std::nullopt;
383 }
384
385 void setLevelAudited(unsigned level) {
386 LevelAudited = true;
387 Level = level;
388 }
389
390 friend bool operator==(const BoundsSafetyInfo &, const BoundsSafetyInfo &);
391
392 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
393};
394
395inline bool operator==(const BoundsSafetyInfo &LHS,
396 const BoundsSafetyInfo &RHS) {
397 return LHS.KindAudited == RHS.KindAudited && LHS.Kind == RHS.Kind &&
398 LHS.LevelAudited == RHS.LevelAudited && LHS.Level == RHS.Level &&
400}
401
402inline bool operator!=(const BoundsSafetyInfo &LHS,
403 const BoundsSafetyInfo &RHS) {
404 return !(LHS == RHS);
405}
406
407/// API notes for a variable/property.
409 /// The kind of nullability for this property, if the nullability
410 /// has been audited.
411 LLVM_PREFERRED_TYPE(NullabilityKindOrNone)
412 unsigned NullabilityOrNone : 3;
413
414 /// The C type of the variable, as a string.
415 std::string Type;
416
417public:
418 VariableInfo() : NullabilityOrNone(0) {}
419
423
427
428 const std::string &getType() const { return Type; }
429 void setType(const std::string &type) { Type = type; }
430
431 friend bool operator==(const VariableInfo &, const VariableInfo &);
432
434 static_cast<CommonEntityInfo &>(*this) |= RHS;
435
436 if (!getNullability() && RHS.getNullability())
438 if (Type.empty())
439 Type = RHS.Type;
440
441 return *this;
442 }
443
444 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
445};
446
447inline bool operator==(const VariableInfo &LHS, const VariableInfo &RHS) {
448 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
449 LHS.NullabilityOrNone == RHS.NullabilityOrNone && LHS.Type == RHS.Type;
450}
451
452inline bool operator!=(const VariableInfo &LHS, const VariableInfo &RHS) {
453 return !(LHS == RHS);
454}
455
456/// Describes API notes data for an Objective-C property.
458 LLVM_PREFERRED_TYPE(bool)
459 unsigned SwiftImportAsAccessorsSpecified : 1;
460 LLVM_PREFERRED_TYPE(bool)
461 unsigned SwiftImportAsAccessors : 1;
462
463public:
465 : SwiftImportAsAccessorsSpecified(false), SwiftImportAsAccessors(false) {}
466
467 std::optional<bool> getSwiftImportAsAccessors() const {
468 return SwiftImportAsAccessorsSpecified
469 ? std::optional<bool>(SwiftImportAsAccessors)
470 : std::nullopt;
471 }
472 void setSwiftImportAsAccessors(std::optional<bool> Value) {
473 SwiftImportAsAccessorsSpecified = Value.has_value();
474 SwiftImportAsAccessors = Value.value_or(false);
475 }
476
477 friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &);
478
479 /// Merge class-wide information into the given property.
481 static_cast<CommonEntityInfo &>(*this) |= RHS;
482
483 // Merge nullability.
484 if (!getNullability())
485 if (auto Nullable = RHS.getDefaultNullability())
487
488 return *this;
489 }
490
492 static_cast<VariableInfo &>(*this) |= RHS;
493
494 if (!SwiftImportAsAccessorsSpecified)
496
497 return *this;
498 }
499
500 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
501};
502
503inline bool operator==(const ObjCPropertyInfo &LHS,
504 const ObjCPropertyInfo &RHS) {
505 return static_cast<const VariableInfo &>(LHS) == RHS &&
507}
508
509inline bool operator!=(const ObjCPropertyInfo &LHS,
510 const ObjCPropertyInfo &RHS) {
511 return !(LHS == RHS);
512}
513
514/// Describes a function or method parameter.
515class ParamInfo : public VariableInfo {
516 /// Whether noescape was specified.
517 LLVM_PREFERRED_TYPE(bool)
518 unsigned NoEscapeSpecified : 1;
519
520 /// Whether the this parameter has the 'noescape' attribute.
521 LLVM_PREFERRED_TYPE(bool)
522 unsigned NoEscape : 1;
523
524 /// Whether lifetimebound was specified.
525 LLVM_PREFERRED_TYPE(bool)
526 unsigned LifetimeboundSpecified : 1;
527
528 /// Whether the this parameter has the 'lifetimebound' attribute.
529 LLVM_PREFERRED_TYPE(bool)
530 unsigned Lifetimebound : 1;
531
532 /// A biased RetainCountConventionKind, where 0 means "unspecified".
533 ///
534 /// Only relevant for out-parameters.
535 unsigned RawRetainCountConvention : 3;
536
537public:
538 std::optional<BoundsSafetyInfo> BoundsSafety;
539
541 : NoEscapeSpecified(false), NoEscape(false),
542 LifetimeboundSpecified(false), Lifetimebound(false),
543 RawRetainCountConvention(), BoundsSafety(std::nullopt) {}
544
545 std::optional<bool> isNoEscape() const {
546 return NoEscapeSpecified ? std::optional<bool>(NoEscape) : std::nullopt;
547 }
548 void setNoEscape(std::optional<bool> Value) {
549 NoEscapeSpecified = Value.has_value();
550 NoEscape = Value.value_or(false);
551 }
552
553 std::optional<bool> isLifetimebound() const {
554 return LifetimeboundSpecified ? std::optional<bool>(Lifetimebound)
555 : std::nullopt;
556 }
557 void setLifetimebound(std::optional<bool> Value) {
558 LifetimeboundSpecified = Value.has_value();
559 Lifetimebound = Value.value_or(false);
560 }
561
562 std::optional<RetainCountConventionKind> getRetainCountConvention() const {
563 if (!RawRetainCountConvention)
564 return std::nullopt;
565 return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
566 }
567 void
568 setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
569 RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
570 assert(getRetainCountConvention() == Value && "bitfield too small");
571 }
572
574 static_cast<VariableInfo &>(*this) |= RHS;
575
576 if (!NoEscapeSpecified && RHS.NoEscapeSpecified) {
577 NoEscapeSpecified = true;
578 NoEscape = RHS.NoEscape;
579 }
580
581 if (!LifetimeboundSpecified && RHS.LifetimeboundSpecified) {
582 LifetimeboundSpecified = true;
583 Lifetimebound = RHS.Lifetimebound;
584 }
585
586 if (!RawRetainCountConvention)
587 RawRetainCountConvention = RHS.RawRetainCountConvention;
588
589 if (!BoundsSafety)
591
592 return *this;
593 }
594
595 friend bool operator==(const ParamInfo &, const ParamInfo &);
596
597 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
598};
599
600inline bool operator==(const ParamInfo &LHS, const ParamInfo &RHS) {
601 return static_cast<const VariableInfo &>(LHS) == RHS &&
602 LHS.NoEscapeSpecified == RHS.NoEscapeSpecified &&
603 LHS.NoEscape == RHS.NoEscape &&
604 LHS.LifetimeboundSpecified == RHS.LifetimeboundSpecified &&
605 LHS.Lifetimebound == RHS.Lifetimebound &&
606 LHS.RawRetainCountConvention == RHS.RawRetainCountConvention &&
607 LHS.BoundsSafety == RHS.BoundsSafety;
608}
609
610inline bool operator!=(const ParamInfo &LHS, const ParamInfo &RHS) {
611 return !(LHS == RHS);
612}
613
614/// API notes for a function or method.
616private:
617 static constexpr const uint64_t NullabilityKindMask = 0x3;
618 static constexpr const unsigned NullabilityKindSize = 2;
619
620 static constexpr const unsigned ReturnInfoIndex = 0;
621
622public:
623 // If yes, we consider all types to be non-nullable unless otherwise noted.
624 // If this flag is not set, the pointer types are considered to have
625 // unknown nullability.
626
627 /// Whether the signature has been audited with respect to nullability.
628 LLVM_PREFERRED_TYPE(bool)
630
631 /// Number of types whose nullability is encoded with the NullabilityPayload.
633
634 /// A biased RetainCountConventionKind, where 0 means "unspecified".
636
637 // NullabilityKindSize bits are used to encode the nullability. The info
638 // about the return type is stored at position 0, followed by the nullability
639 // of the parameters.
640
641 /// Stores the nullability of the return type and the parameters.
642 uint64_t NullabilityPayload = 0;
643
644 /// The result type of this function, as a C type.
646
647 /// Ownership convention for return value
649
650 /// The function parameters.
652
656
657 static unsigned getMaxNullabilityIndex() {
658 return ((sizeof(NullabilityPayload) * CHAR_BIT) / NullabilityKindSize);
659 }
660
662 assert(index <= getMaxNullabilityIndex());
663 assert(static_cast<unsigned>(kind) < NullabilityKindMask);
664
665 NullabilityAudited = true;
666 if (NumAdjustedNullable < index + 1)
668
669 // Mask the bits.
671 ~(NullabilityKindMask << (index * NullabilityKindSize));
672
673 // Set the value.
674 unsigned kindValue = (static_cast<unsigned>(kind))
675 << (index * NullabilityKindSize);
676 NullabilityPayload |= kindValue;
677 }
678
679 /// Adds the return type info.
681 addTypeInfo(ReturnInfoIndex, kind);
682 }
683
684 /// Adds the parameter type info.
686 addTypeInfo(index + 1, kind);
687 }
688
690 return getTypeInfo(index + 1);
691 }
692
693 NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
694
695 std::optional<RetainCountConventionKind> getRetainCountConvention() const {
697 return std::nullopt;
699 }
700 void
701 setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
702 RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
703 assert(getRetainCountConvention() == Value && "bitfield too small");
704 }
705
706 friend bool operator==(const FunctionInfo &, const FunctionInfo &);
707
708private:
709 NullabilityKind getTypeInfo(unsigned index) const {
710 assert(NullabilityAudited &&
711 "Checking the type adjustment on non-audited method.");
712
713 // If we don't have info about this parameter, return the default.
716 auto nullability = NullabilityPayload >> (index * NullabilityKindSize);
717 return static_cast<NullabilityKind>(nullability & NullabilityKindMask);
718 }
719
720public:
721 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
722};
723
724inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS) {
725 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
729 LHS.ResultType == RHS.ResultType && LHS.Params == RHS.Params &&
732}
733
734inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
735 return !(LHS == RHS);
736}
737
738/// Describes API notes data for an Objective-C method.
740public:
741 /// Whether this is a designated initializer of its class.
742 LLVM_PREFERRED_TYPE(bool)
744
745 /// Whether this is a required initializer.
746 LLVM_PREFERRED_TYPE(bool)
747 unsigned RequiredInit : 1;
748
749 std::optional<ParamInfo> Self;
750
752
753 friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
754
756 // Merge Nullability.
757 if (!NullabilityAudited) {
758 if (auto Nullable = RHS.getDefaultNullability()) {
759 NullabilityAudited = true;
761 }
762 }
763 return *this;
764 }
765
766 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
767};
768
769inline bool operator==(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
770 return static_cast<const FunctionInfo &>(LHS) == RHS &&
771 LHS.DesignatedInit == RHS.DesignatedInit &&
772 LHS.RequiredInit == RHS.RequiredInit && LHS.Self == RHS.Self;
773}
774
775inline bool operator!=(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
776 return !(LHS == RHS);
777}
778
779/// Describes API notes data for a global variable.
781public:
783};
784
785/// Describes API notes data for a global function.
787public:
789};
790
791/// Describes API notes data for a C/C++ record field.
792class FieldInfo : public VariableInfo {
793public:
795};
796
797/// Describes API notes data for a C++ method.
799public:
801
802 std::optional<ParamInfo> This;
803
804 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
805};
806
807inline bool operator==(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
808 return static_cast<const FunctionInfo &>(LHS) == RHS && LHS.This == RHS.This;
809}
810
811inline bool operator!=(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
812 return !(LHS == RHS);
813}
814
815/// Describes API notes data for an enumerator.
817public:
819};
820
821/// Describes API notes data for a tag.
822class TagInfo : public CommonTypeInfo {
823 LLVM_PREFERRED_TYPE(bool)
824 unsigned HasFlagEnum : 1;
825 LLVM_PREFERRED_TYPE(bool)
826 unsigned IsFlagEnum : 1;
827
828 LLVM_PREFERRED_TYPE(bool)
829 unsigned SwiftCopyableSpecified : 1;
830 LLVM_PREFERRED_TYPE(bool)
831 unsigned SwiftCopyable : 1;
832
833 LLVM_PREFERRED_TYPE(bool)
834 unsigned SwiftEscapableSpecified : 1;
835 LLVM_PREFERRED_TYPE(bool)
836 unsigned SwiftEscapable : 1;
837
838public:
839 std::optional<std::string> SwiftImportAs;
840 std::optional<std::string> SwiftRetainOp;
841 std::optional<std::string> SwiftReleaseOp;
842 std::optional<std::string> SwiftDestroyOp;
843 std::optional<std::string> SwiftDefaultOwnership;
844
845 std::optional<EnumExtensibilityKind> EnumExtensibility;
846
848 : HasFlagEnum(0), IsFlagEnum(0), SwiftCopyableSpecified(false),
849 SwiftCopyable(false), SwiftEscapableSpecified(false),
850 SwiftEscapable(false) {}
851
852 std::optional<bool> isFlagEnum() const {
853 if (HasFlagEnum)
854 return IsFlagEnum;
855 return std::nullopt;
856 }
857 void setFlagEnum(std::optional<bool> Value) {
858 HasFlagEnum = Value.has_value();
859 IsFlagEnum = Value.value_or(false);
860 }
861
862 std::optional<bool> isSwiftCopyable() const {
863 return SwiftCopyableSpecified ? std::optional<bool>(SwiftCopyable)
864 : std::nullopt;
865 }
866 void setSwiftCopyable(std::optional<bool> Value) {
867 SwiftCopyableSpecified = Value.has_value();
868 SwiftCopyable = Value.value_or(false);
869 }
870
871 std::optional<bool> isSwiftEscapable() const {
872 return SwiftEscapableSpecified ? std::optional<bool>(SwiftEscapable)
873 : std::nullopt;
874 }
875
876 void setSwiftEscapable(std::optional<bool> Value) {
877 SwiftEscapableSpecified = Value.has_value();
878 SwiftEscapable = Value.value_or(false);
879 }
880
882 static_cast<CommonTypeInfo &>(*this) |= RHS;
883
884 if (!SwiftImportAs)
886 if (!SwiftRetainOp)
888 if (!SwiftReleaseOp)
890 if (!SwiftDestroyOp)
894
895 if (!HasFlagEnum)
896 setFlagEnum(RHS.isFlagEnum());
897
900
901 if (!SwiftCopyableSpecified)
903
904 if (!SwiftEscapableSpecified)
906
907 return *this;
908 }
909
910 friend bool operator==(const TagInfo &, const TagInfo &);
911
912 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
913};
914
915inline bool operator==(const TagInfo &LHS, const TagInfo &RHS) {
916 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
917 LHS.SwiftImportAs == RHS.SwiftImportAs &&
918 LHS.SwiftRetainOp == RHS.SwiftRetainOp &&
919 LHS.SwiftReleaseOp == RHS.SwiftReleaseOp &&
920 LHS.SwiftDestroyOp == RHS.SwiftDestroyOp &&
922 LHS.isFlagEnum() == RHS.isFlagEnum() &&
923 LHS.isSwiftCopyable() == RHS.isSwiftCopyable() &&
924 LHS.isSwiftEscapable() == RHS.isSwiftEscapable() &&
926}
927
928inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
929 return !(LHS == RHS);
930}
931
932/// Describes API notes data for a typedef.
934public:
935 std::optional<SwiftNewTypeKind> SwiftWrapper;
936
938
940 static_cast<CommonTypeInfo &>(*this) |= RHS;
941 if (!SwiftWrapper)
943 return *this;
944 }
945
946 friend bool operator==(const TypedefInfo &, const TypedefInfo &);
947
948 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
949};
950
951inline bool operator==(const TypedefInfo &LHS, const TypedefInfo &RHS) {
952 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
953 LHS.SwiftWrapper == RHS.SwiftWrapper;
954}
955
956inline bool operator!=(const TypedefInfo &LHS, const TypedefInfo &RHS) {
957 return !(LHS == RHS);
958}
959
960/// The file extension used for the source representation of API notes.
961static const constexpr char SOURCE_APINOTES_EXTENSION[] = "apinotes";
962
963/// Opaque context ID used to refer to an Objective-C class or protocol or a C++
964/// namespace.
966public:
967 unsigned Value;
968
969 explicit ContextID(unsigned value) : Value(value) {}
970};
971
972enum class ContextKind : uint8_t {
976 Tag = 3,
977};
978
985
986/// A temporary reference to an Objective-C selector, suitable for
987/// referencing selector data on the stack.
988///
989/// Instances of this struct do not store references to any of the
990/// data they contain; it is up to the user to ensure that the data
991/// referenced by the identifier list persists.
996} // namespace api_notes
997} // namespace clang
998
999#endif
*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
Definition Types.h:370
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< unsigned > getLevel() const
Definition Types.h:381
friend bool operator==(const BoundsSafetyInfo &, const BoundsSafetyInfo &)
Definition Types.h:395
void setKindAudited(BoundsSafetyKind kind)
Definition Types.h:376
void setLevelAudited(unsigned level)
Definition Types.h:385
Describes API notes data for a C++ method.
Definition Types.h:798
std::optional< ParamInfo > This
Definition Types.h:802
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:965
ContextID(unsigned value)
Definition Types.h:969
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:279
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
std::optional< bool > getSwiftObjCMembers() const
Definition Types.h:289
void setDefaultNullability(NullabilityKind Kind)
Set the default nullability for properties and methods of this class.
Definition Types.h:271
NullabilityKindOrNone getDefaultNullability() const
Determine the default nullability for properties and methods of this class.
Definition Types.h:265
void setSwiftObjCMembers(std::optional< bool > Value)
Definition Types.h:293
bool hasDesignatedInits() const
Definition Types.h:276
void setSwiftImportAsNonGeneric(std::optional< bool > Value)
Definition Types.h:284
void setHasDesignatedInits(bool Value)
Definition Types.h:277
friend bool operator==(const ContextInfo &, const ContextInfo &)
Definition Types.h:323
ContextInfo & operator|=(const ContextInfo &RHS)
Definition Types.h:300
API notes for a function or method.
Definition Types.h:615
std::string SwiftReturnOwnership
Ownership convention for return value.
Definition Types.h:648
void addTypeInfo(unsigned index, NullabilityKind kind)
Definition Types.h:661
uint64_t NullabilityPayload
Stores the nullability of the return type and the parameters.
Definition Types.h:642
std::optional< RetainCountConventionKind > getRetainCountConvention() const
Definition Types.h:695
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition Types.h:701
unsigned RawRetainCountConvention
A biased RetainCountConventionKind, where 0 means "unspecified".
Definition Types.h:635
std::vector< ParamInfo > Params
The function parameters.
Definition Types.h:651
NullabilityKind getReturnTypeInfo() const
Definition Types.h:693
friend bool operator==(const FunctionInfo &, const FunctionInfo &)
Definition Types.h:724
NullabilityKind getParamTypeInfo(unsigned index) const
Definition Types.h:689
unsigned NumAdjustedNullable
Number of types whose nullability is encoded with the NullabilityPayload.
Definition Types.h:632
std::string ResultType
The result type of this function, as a C type.
Definition Types.h:645
static unsigned getMaxNullabilityIndex()
Definition Types.h:657
void addReturnTypeInfo(NullabilityKind kind)
Adds the return type info.
Definition Types.h:680
unsigned NullabilityAudited
Whether the signature has been audited with respect to nullability.
Definition Types.h:629
void addParamTypeInfo(unsigned index, NullabilityKind kind)
Adds the parameter type info.
Definition Types.h:685
Describes API notes data for an Objective-C method.
Definition Types.h:739
unsigned DesignatedInit
Whether this is a designated initializer of its class.
Definition Types.h:743
friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &)
Definition Types.h:769
std::optional< ParamInfo > Self
Definition Types.h:749
ObjCMethodInfo & operator|=(const ContextInfo &RHS)
Definition Types.h:755
unsigned RequiredInit
Whether this is a required initializer.
Definition Types.h:747
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
Describes API notes data for an Objective-C property.
Definition Types.h:457
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setSwiftImportAsAccessors(std::optional< bool > Value)
Definition Types.h:472
std::optional< bool > getSwiftImportAsAccessors() const
Definition Types.h:467
friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &)
Definition Types.h:503
ObjCPropertyInfo & operator|=(const ObjCPropertyInfo &RHS)
Definition Types.h:491
ObjCPropertyInfo & operator|=(const ContextInfo &RHS)
Merge class-wide information into the given property.
Definition Types.h:480
Describes a function or method parameter.
Definition Types.h:515
std::optional< BoundsSafetyInfo > BoundsSafety
Definition Types.h:538
void setNoEscape(std::optional< bool > Value)
Definition Types.h:548
std::optional< bool > isNoEscape() const
Definition Types.h:545
ParamInfo & operator|=(const ParamInfo &RHS)
Definition Types.h:573
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< bool > isLifetimebound() const
Definition Types.h:553
friend bool operator==(const ParamInfo &, const ParamInfo &)
Definition Types.h:600
void setLifetimebound(std::optional< bool > Value)
Definition Types.h:557
std::optional< RetainCountConventionKind > getRetainCountConvention() const
Definition Types.h:562
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition Types.h:568
Describes API notes data for a tag.
Definition Types.h:822
std::optional< std::string > SwiftReleaseOp
Definition Types.h:841
std::optional< std::string > SwiftRetainOp
Definition Types.h:840
std::optional< std::string > SwiftImportAs
Definition Types.h:839
std::optional< std::string > SwiftDefaultOwnership
Definition Types.h:843
std::optional< EnumExtensibilityKind > EnumExtensibility
Definition Types.h:845
void setSwiftCopyable(std::optional< bool > Value)
Definition Types.h:866
std::optional< std::string > SwiftDestroyOp
Definition Types.h:842
void setSwiftEscapable(std::optional< bool > Value)
Definition Types.h:876
std::optional< bool > isFlagEnum() const
Definition Types.h:852
TagInfo & operator|=(const TagInfo &RHS)
Definition Types.h:881
std::optional< bool > isSwiftCopyable() const
Definition Types.h:862
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
friend bool operator==(const TagInfo &, const TagInfo &)
Definition Types.h:915
std::optional< bool > isSwiftEscapable() const
Definition Types.h:871
void setFlagEnum(std::optional< bool > Value)
Definition Types.h:857
Describes API notes data for a typedef.
Definition Types.h:933
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
TypedefInfo & operator|=(const TypedefInfo &RHS)
Definition Types.h:939
friend bool operator==(const TypedefInfo &, const TypedefInfo &)
Definition Types.h:951
std::optional< SwiftNewTypeKind > SwiftWrapper
Definition Types.h:935
API notes for a variable/property.
Definition Types.h:408
void setNullabilityAudited(NullabilityKind kind)
Definition Types.h:424
void setType(const std::string &type)
Definition Types.h:429
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
VariableInfo & operator|=(const VariableInfo &RHS)
Definition Types.h:433
const std::string & getType() const
Definition Types.h:428
friend bool operator==(const VariableInfo &, const VariableInfo &)
Definition Types.h:447
NullabilityKindOrNone getNullability() const
Definition Types.h:420
#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:961
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:349
@ Nullable
Values of this type can be null.
Definition Specifiers.h:353
@ NonNull
Values of this type can never be null.
Definition Specifiers.h:351
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
OptionalUnsigned< NullabilityKind > NullabilityKindOrNone
Definition Specifiers.h:365
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
#define false
Definition stdbool.h:26
constexpr underlying_type toInternalRepresentation() const
static constexpr OptionalUnsigned fromInternalRepresentation(underlying_type Rep)
Context(ContextID id, ContextKind kind)
Definition Types.h:983
A temporary reference to an Objective-C selector, suitable for referencing selector data on the stack...
Definition Types.h:992
llvm::ArrayRef< llvm::StringRef > Identifiers
Definition Types.h:994