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 /// Whether the function has the [[clang::unsafe_buffer_usage]] attribute
638 LLVM_PREFERRED_TYPE(bool)
639 unsigned UnsafeBufferUsage : 1;
640
641 // NullabilityKindSize bits are used to encode the nullability. The info
642 // about the return type is stored at position 0, followed by the nullability
643 // of the parameters.
644
645 /// Stores the nullability of the return type and the parameters.
646 uint64_t NullabilityPayload = 0;
647
648 /// The result type of this function, as a C type.
650
651 /// Ownership convention for return value
653
654 /// The function parameters.
656
660
661 static unsigned getMaxNullabilityIndex() {
662 return ((sizeof(NullabilityPayload) * CHAR_BIT) / NullabilityKindSize);
663 }
664
666 assert(index <= getMaxNullabilityIndex());
667 assert(static_cast<unsigned>(kind) < NullabilityKindMask);
668
669 NullabilityAudited = true;
670 if (NumAdjustedNullable < index + 1)
672
673 // Mask the bits.
675 ~(NullabilityKindMask << (index * NullabilityKindSize));
676
677 // Set the value.
678 unsigned kindValue = (static_cast<unsigned>(kind))
679 << (index * NullabilityKindSize);
680 NullabilityPayload |= kindValue;
681 }
682
683 /// Adds the return type info.
685 addTypeInfo(ReturnInfoIndex, kind);
686 }
687
688 /// Adds the parameter type info.
690 addTypeInfo(index + 1, kind);
691 }
692
694 return getTypeInfo(index + 1);
695 }
696
697 NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
698
699 std::optional<RetainCountConventionKind> getRetainCountConvention() const {
701 return std::nullopt;
703 }
704 void
705 setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
706 RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
707 assert(getRetainCountConvention() == Value && "bitfield too small");
708 }
709
710 friend bool operator==(const FunctionInfo &, const FunctionInfo &);
711
712private:
713 NullabilityKind getTypeInfo(unsigned index) const {
714 assert(NullabilityAudited &&
715 "Checking the type adjustment on non-audited method.");
716
717 // If we don't have info about this parameter, return the default.
720 auto nullability = NullabilityPayload >> (index * NullabilityKindSize);
721 return static_cast<NullabilityKind>(nullability & NullabilityKindMask);
722 }
723
724public:
725 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
726};
727
728inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS) {
729 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
734 LHS.ResultType == RHS.ResultType && LHS.Params == RHS.Params &&
737}
738
739inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
740 return !(LHS == RHS);
741}
742
743/// Describes API notes data for an Objective-C method.
745public:
746 /// Whether this is a designated initializer of its class.
747 LLVM_PREFERRED_TYPE(bool)
749
750 /// Whether this is a required initializer.
751 LLVM_PREFERRED_TYPE(bool)
752 unsigned RequiredInit : 1;
753
754 std::optional<ParamInfo> Self;
755
757
758 friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
759
761 // Merge Nullability.
762 if (!NullabilityAudited) {
763 if (auto Nullable = RHS.getDefaultNullability()) {
764 NullabilityAudited = true;
766 }
767 }
768 return *this;
769 }
770
771 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
772};
773
774inline bool operator==(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
775 return static_cast<const FunctionInfo &>(LHS) == RHS &&
776 LHS.DesignatedInit == RHS.DesignatedInit &&
777 LHS.RequiredInit == RHS.RequiredInit && LHS.Self == RHS.Self;
778}
779
780inline bool operator!=(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
781 return !(LHS == RHS);
782}
783
784/// Describes API notes data for a global variable.
786public:
788};
789
790/// Describes API notes data for a global function.
792public:
794};
795
796/// Describes API notes data for a C/C++ record field.
797class FieldInfo : public VariableInfo {
798public:
800};
801
802/// Describes API notes data for a C++ method.
804public:
806
807 std::optional<ParamInfo> This;
808
809 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
810};
811
812inline bool operator==(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
813 return static_cast<const FunctionInfo &>(LHS) == RHS && LHS.This == RHS.This;
814}
815
816inline bool operator!=(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
817 return !(LHS == RHS);
818}
819
820/// Describes API notes data for an enumerator.
822public:
824};
825
826/// Describes API notes data for a tag.
827class TagInfo : public CommonTypeInfo {
828 LLVM_PREFERRED_TYPE(bool)
829 unsigned HasFlagEnum : 1;
830 LLVM_PREFERRED_TYPE(bool)
831 unsigned IsFlagEnum : 1;
832
833 LLVM_PREFERRED_TYPE(bool)
834 unsigned SwiftCopyableSpecified : 1;
835 LLVM_PREFERRED_TYPE(bool)
836 unsigned SwiftCopyable : 1;
837
838 LLVM_PREFERRED_TYPE(bool)
839 unsigned SwiftEscapableSpecified : 1;
840 LLVM_PREFERRED_TYPE(bool)
841 unsigned SwiftEscapable : 1;
842
843public:
844 std::optional<std::string> SwiftImportAs;
845 std::optional<std::string> SwiftRetainOp;
846 std::optional<std::string> SwiftReleaseOp;
847 std::optional<std::string> SwiftDestroyOp;
848 std::optional<std::string> SwiftDefaultOwnership;
849
850 std::optional<EnumExtensibilityKind> EnumExtensibility;
851
853 : HasFlagEnum(0), IsFlagEnum(0), SwiftCopyableSpecified(false),
854 SwiftCopyable(false), SwiftEscapableSpecified(false),
855 SwiftEscapable(false) {}
856
857 std::optional<bool> isFlagEnum() const {
858 if (HasFlagEnum)
859 return IsFlagEnum;
860 return std::nullopt;
861 }
862 void setFlagEnum(std::optional<bool> Value) {
863 HasFlagEnum = Value.has_value();
864 IsFlagEnum = Value.value_or(false);
865 }
866
867 std::optional<bool> isSwiftCopyable() const {
868 return SwiftCopyableSpecified ? std::optional<bool>(SwiftCopyable)
869 : std::nullopt;
870 }
871 void setSwiftCopyable(std::optional<bool> Value) {
872 SwiftCopyableSpecified = Value.has_value();
873 SwiftCopyable = Value.value_or(false);
874 }
875
876 std::optional<bool> isSwiftEscapable() const {
877 return SwiftEscapableSpecified ? std::optional<bool>(SwiftEscapable)
878 : std::nullopt;
879 }
880
881 void setSwiftEscapable(std::optional<bool> Value) {
882 SwiftEscapableSpecified = Value.has_value();
883 SwiftEscapable = Value.value_or(false);
884 }
885
887 static_cast<CommonTypeInfo &>(*this) |= RHS;
888
889 if (!SwiftImportAs)
891 if (!SwiftRetainOp)
893 if (!SwiftReleaseOp)
895 if (!SwiftDestroyOp)
899
900 if (!HasFlagEnum)
901 setFlagEnum(RHS.isFlagEnum());
902
905
906 if (!SwiftCopyableSpecified)
908
909 if (!SwiftEscapableSpecified)
911
912 return *this;
913 }
914
915 friend bool operator==(const TagInfo &, const TagInfo &);
916
917 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
918};
919
920inline bool operator==(const TagInfo &LHS, const TagInfo &RHS) {
921 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
922 LHS.SwiftImportAs == RHS.SwiftImportAs &&
923 LHS.SwiftRetainOp == RHS.SwiftRetainOp &&
924 LHS.SwiftReleaseOp == RHS.SwiftReleaseOp &&
925 LHS.SwiftDestroyOp == RHS.SwiftDestroyOp &&
927 LHS.isFlagEnum() == RHS.isFlagEnum() &&
928 LHS.isSwiftCopyable() == RHS.isSwiftCopyable() &&
929 LHS.isSwiftEscapable() == RHS.isSwiftEscapable() &&
931}
932
933inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
934 return !(LHS == RHS);
935}
936
937/// Describes API notes data for a typedef.
939public:
940 std::optional<SwiftNewTypeKind> SwiftWrapper;
941
943
945 static_cast<CommonTypeInfo &>(*this) |= RHS;
946 if (!SwiftWrapper)
948 return *this;
949 }
950
951 friend bool operator==(const TypedefInfo &, const TypedefInfo &);
952
953 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
954};
955
956inline bool operator==(const TypedefInfo &LHS, const TypedefInfo &RHS) {
957 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
958 LHS.SwiftWrapper == RHS.SwiftWrapper;
959}
960
961inline bool operator!=(const TypedefInfo &LHS, const TypedefInfo &RHS) {
962 return !(LHS == RHS);
963}
964
965/// The file extension used for the source representation of API notes.
966static const constexpr char SOURCE_APINOTES_EXTENSION[] = "apinotes";
967
968/// Opaque context ID used to refer to an Objective-C class or protocol or a C++
969/// namespace.
971public:
972 unsigned Value;
973
974 explicit ContextID(unsigned value) : Value(value) {}
975};
976
977enum class ContextKind : uint8_t {
981 Tag = 3,
982};
983
990
991/// A temporary reference to an Objective-C selector, suitable for
992/// referencing selector data on the stack.
993///
994/// Instances of this struct do not store references to any of the
995/// data they contain; it is up to the user to ensure that the data
996/// referenced by the identifier list persists.
1001} // namespace api_notes
1002} // namespace clang
1003
1004#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:803
std::optional< ParamInfo > This
Definition Types.h:807
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:970
ContextID(unsigned value)
Definition Types.h:974
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:652
void addTypeInfo(unsigned index, NullabilityKind kind)
Definition Types.h:665
uint64_t NullabilityPayload
Stores the nullability of the return type and the parameters.
Definition Types.h:646
std::optional< RetainCountConventionKind > getRetainCountConvention() const
Definition Types.h:699
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition Types.h:705
unsigned RawRetainCountConvention
A biased RetainCountConventionKind, where 0 means "unspecified".
Definition Types.h:635
std::vector< ParamInfo > Params
The function parameters.
Definition Types.h:655
NullabilityKind getReturnTypeInfo() const
Definition Types.h:697
friend bool operator==(const FunctionInfo &, const FunctionInfo &)
Definition Types.h:728
NullabilityKind getParamTypeInfo(unsigned index) const
Definition Types.h:693
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:649
unsigned UnsafeBufferUsage
Whether the function has the [[clang::unsafe_buffer_usage]] attribute.
Definition Types.h:639
static unsigned getMaxNullabilityIndex()
Definition Types.h:661
void addReturnTypeInfo(NullabilityKind kind)
Adds the return type info.
Definition Types.h:684
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:689
Describes API notes data for an Objective-C method.
Definition Types.h:744
unsigned DesignatedInit
Whether this is a designated initializer of its class.
Definition Types.h:748
friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &)
Definition Types.h:774
std::optional< ParamInfo > Self
Definition Types.h:754
ObjCMethodInfo & operator|=(const ContextInfo &RHS)
Definition Types.h:760
unsigned RequiredInit
Whether this is a required initializer.
Definition Types.h:752
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:827
std::optional< std::string > SwiftReleaseOp
Definition Types.h:846
std::optional< std::string > SwiftRetainOp
Definition Types.h:845
std::optional< std::string > SwiftImportAs
Definition Types.h:844
std::optional< std::string > SwiftDefaultOwnership
Definition Types.h:848
std::optional< EnumExtensibilityKind > EnumExtensibility
Definition Types.h:850
void setSwiftCopyable(std::optional< bool > Value)
Definition Types.h:871
std::optional< std::string > SwiftDestroyOp
Definition Types.h:847
void setSwiftEscapable(std::optional< bool > Value)
Definition Types.h:881
std::optional< bool > isFlagEnum() const
Definition Types.h:857
TagInfo & operator|=(const TagInfo &RHS)
Definition Types.h:886
std::optional< bool > isSwiftCopyable() const
Definition Types.h:867
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
friend bool operator==(const TagInfo &, const TagInfo &)
Definition Types.h:920
std::optional< bool > isSwiftEscapable() const
Definition Types.h:876
void setFlagEnum(std::optional< bool > Value)
Definition Types.h:862
Describes API notes data for a typedef.
Definition Types.h:938
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
TypedefInfo & operator|=(const TypedefInfo &RHS)
Definition Types.h:944
friend bool operator==(const TypedefInfo &, const TypedefInfo &)
Definition Types.h:956
std::optional< SwiftNewTypeKind > SwiftWrapper
Definition Types.h:940
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:966
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:988
A temporary reference to an Objective-C selector, suitable for referencing selector data on the stack...
Definition Types.h:997
llvm::ArrayRef< llvm::StringRef > Identifiers
Definition Types.h:999