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 /// 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
342public:
350
351private:
352 /// The kind of bounds safety for this property. Only valid if the bounds
353 /// safety has been audited.
354 LLVM_PREFERRED_TYPE(BoundsSafetyKind)
355 unsigned Kind : 3;
356
357 /// Whether the bounds safety kind has been audited.
358 LLVM_PREFERRED_TYPE(bool)
359 unsigned KindAudited : 1;
360
361 /// The pointer indirection level at which the bounds annotation applies.
362 /// Only valid if LevelAudited is set.
363 unsigned Level : 3;
364
365 /// Whether the pointer indirection level has been specified.
366 LLVM_PREFERRED_TYPE(bool)
367 unsigned LevelAudited : 1;
368
369public:
370 std::string ExternalBounds;
371
373 : Kind(0), KindAudited(false), Level(0), LevelAudited(false),
374 ExternalBounds("") {}
375
376 std::optional<BoundsSafetyKind> getKind() const {
377 return KindAudited ? std::optional<BoundsSafetyKind>(
378 static_cast<BoundsSafetyKind>(Kind))
379 : std::nullopt;
380 }
381
383 KindAudited = true;
384 Kind = static_cast<unsigned>(kind);
385 }
386
387 std::optional<unsigned> getLevel() const {
388 return LevelAudited ? std::optional<unsigned>(Level) : std::nullopt;
389 }
390
391 void setLevelAudited(unsigned level) {
392 LevelAudited = true;
393 Level = level;
394 }
395
396 friend bool operator==(const BoundsSafetyInfo &, const BoundsSafetyInfo &);
397
398 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
399};
400
401inline bool operator==(const BoundsSafetyInfo &LHS,
402 const BoundsSafetyInfo &RHS) {
403 return LHS.KindAudited == RHS.KindAudited && LHS.Kind == RHS.Kind &&
404 LHS.LevelAudited == RHS.LevelAudited && LHS.Level == RHS.Level &&
406}
407
408inline bool operator!=(const BoundsSafetyInfo &LHS,
409 const BoundsSafetyInfo &RHS) {
410 return !(LHS == RHS);
411}
412
413/// API notes for a variable/property.
415 /// Whether this property has been audited for nullability.
416 LLVM_PREFERRED_TYPE(bool)
417 unsigned NullabilityAudited : 1;
418
419 /// The kind of nullability for this property. Only valid if the nullability
420 /// has been audited.
421 LLVM_PREFERRED_TYPE(NullabilityKind)
422 unsigned Nullable : 2;
423
424 /// The C type of the variable, as a string.
425 std::string Type;
426
427public:
428 VariableInfo() : NullabilityAudited(false), Nullable(0) {}
429
430 std::optional<NullabilityKind> getNullability() const {
431 return NullabilityAudited ? std::optional<NullabilityKind>(
432 static_cast<NullabilityKind>(Nullable))
433 : std::nullopt;
434 }
435
437 NullabilityAudited = true;
438 Nullable = static_cast<unsigned>(kind);
439 }
440
441 const std::string &getType() const { return Type; }
442 void setType(const std::string &type) { Type = type; }
443
444 friend bool operator==(const VariableInfo &, const VariableInfo &);
445
447 static_cast<CommonEntityInfo &>(*this) |= RHS;
448
449 if (!NullabilityAudited && RHS.NullabilityAudited)
451 if (Type.empty())
452 Type = RHS.Type;
453
454 return *this;
455 }
456
457 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
458};
459
460inline bool operator==(const VariableInfo &LHS, const VariableInfo &RHS) {
461 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
462 LHS.NullabilityAudited == RHS.NullabilityAudited &&
463 LHS.Nullable == RHS.Nullable && LHS.Type == RHS.Type;
464}
465
466inline bool operator!=(const VariableInfo &LHS, const VariableInfo &RHS) {
467 return !(LHS == RHS);
468}
469
470/// Describes API notes data for an Objective-C property.
472 LLVM_PREFERRED_TYPE(bool)
473 unsigned SwiftImportAsAccessorsSpecified : 1;
474 LLVM_PREFERRED_TYPE(bool)
475 unsigned SwiftImportAsAccessors : 1;
476
477public:
479 : SwiftImportAsAccessorsSpecified(false), SwiftImportAsAccessors(false) {}
480
481 std::optional<bool> getSwiftImportAsAccessors() const {
482 return SwiftImportAsAccessorsSpecified
483 ? std::optional<bool>(SwiftImportAsAccessors)
484 : std::nullopt;
485 }
486 void setSwiftImportAsAccessors(std::optional<bool> Value) {
487 SwiftImportAsAccessorsSpecified = Value.has_value();
488 SwiftImportAsAccessors = Value.value_or(false);
489 }
490
491 friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &);
492
493 /// Merge class-wide information into the given property.
495 static_cast<CommonEntityInfo &>(*this) |= RHS;
496
497 // Merge nullability.
498 if (!getNullability())
499 if (auto Nullable = RHS.getDefaultNullability())
500 setNullabilityAudited(*Nullable);
501
502 return *this;
503 }
504
506 static_cast<VariableInfo &>(*this) |= RHS;
507
508 if (!SwiftImportAsAccessorsSpecified)
510
511 return *this;
512 }
513
514 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
515};
516
517inline bool operator==(const ObjCPropertyInfo &LHS,
518 const ObjCPropertyInfo &RHS) {
519 return static_cast<const VariableInfo &>(LHS) == RHS &&
521}
522
523inline bool operator!=(const ObjCPropertyInfo &LHS,
524 const ObjCPropertyInfo &RHS) {
525 return !(LHS == RHS);
526}
527
528/// Describes a function or method parameter.
529class ParamInfo : public VariableInfo {
530 /// Whether noescape was specified.
531 LLVM_PREFERRED_TYPE(bool)
532 unsigned NoEscapeSpecified : 1;
533
534 /// Whether the this parameter has the 'noescape' attribute.
535 LLVM_PREFERRED_TYPE(bool)
536 unsigned NoEscape : 1;
537
538 /// Whether lifetimebound was specified.
539 LLVM_PREFERRED_TYPE(bool)
540 unsigned LifetimeboundSpecified : 1;
541
542 /// Whether the this parameter has the 'lifetimebound' attribute.
543 LLVM_PREFERRED_TYPE(bool)
544 unsigned Lifetimebound : 1;
545
546 /// A biased RetainCountConventionKind, where 0 means "unspecified".
547 ///
548 /// Only relevant for out-parameters.
549 unsigned RawRetainCountConvention : 3;
550
551public:
552 std::optional<BoundsSafetyInfo> BoundsSafety;
553
555 : NoEscapeSpecified(false), NoEscape(false),
556 LifetimeboundSpecified(false), Lifetimebound(false),
557 RawRetainCountConvention(), BoundsSafety(std::nullopt) {}
558
559 std::optional<bool> isNoEscape() const {
560 return NoEscapeSpecified ? std::optional<bool>(NoEscape) : std::nullopt;
561 }
562 void setNoEscape(std::optional<bool> Value) {
563 NoEscapeSpecified = Value.has_value();
564 NoEscape = Value.value_or(false);
565 }
566
567 std::optional<bool> isLifetimebound() const {
568 return LifetimeboundSpecified ? std::optional<bool>(Lifetimebound)
569 : std::nullopt;
570 }
571 void setLifetimebound(std::optional<bool> Value) {
572 LifetimeboundSpecified = Value.has_value();
573 Lifetimebound = Value.value_or(false);
574 }
575
576 std::optional<RetainCountConventionKind> getRetainCountConvention() const {
577 if (!RawRetainCountConvention)
578 return std::nullopt;
579 return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
580 }
581 void
582 setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
583 RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
584 assert(getRetainCountConvention() == Value && "bitfield too small");
585 }
586
588 static_cast<VariableInfo &>(*this) |= RHS;
589
590 if (!NoEscapeSpecified && RHS.NoEscapeSpecified) {
591 NoEscapeSpecified = true;
592 NoEscape = RHS.NoEscape;
593 }
594
595 if (!LifetimeboundSpecified && RHS.LifetimeboundSpecified) {
596 LifetimeboundSpecified = true;
597 Lifetimebound = RHS.Lifetimebound;
598 }
599
600 if (!RawRetainCountConvention)
601 RawRetainCountConvention = RHS.RawRetainCountConvention;
602
603 if (!BoundsSafety)
605
606 return *this;
607 }
608
609 friend bool operator==(const ParamInfo &, const ParamInfo &);
610
611 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
612};
613
614inline bool operator==(const ParamInfo &LHS, const ParamInfo &RHS) {
615 return static_cast<const VariableInfo &>(LHS) == RHS &&
616 LHS.NoEscapeSpecified == RHS.NoEscapeSpecified &&
617 LHS.NoEscape == RHS.NoEscape &&
618 LHS.LifetimeboundSpecified == RHS.LifetimeboundSpecified &&
619 LHS.Lifetimebound == RHS.Lifetimebound &&
620 LHS.RawRetainCountConvention == RHS.RawRetainCountConvention &&
621 LHS.BoundsSafety == RHS.BoundsSafety;
622}
623
624inline bool operator!=(const ParamInfo &LHS, const ParamInfo &RHS) {
625 return !(LHS == RHS);
626}
627
628/// API notes for a function or method.
630private:
631 static constexpr const uint64_t NullabilityKindMask = 0x3;
632 static constexpr const unsigned NullabilityKindSize = 2;
633
634 static constexpr const unsigned ReturnInfoIndex = 0;
635
636public:
637 // If yes, we consider all types to be non-nullable unless otherwise noted.
638 // If this flag is not set, the pointer types are considered to have
639 // unknown nullability.
640
641 /// Whether the signature has been audited with respect to nullability.
642 LLVM_PREFERRED_TYPE(bool)
644
645 /// Number of types whose nullability is encoded with the NullabilityPayload.
647
648 /// A biased RetainCountConventionKind, where 0 means "unspecified".
650
651 // NullabilityKindSize bits are used to encode the nullability. The info
652 // about the return type is stored at position 0, followed by the nullability
653 // of the parameters.
654
655 /// Stores the nullability of the return type and the parameters.
656 uint64_t NullabilityPayload = 0;
657
658 /// The result type of this function, as a C type.
660
661 /// Ownership convention for return value
663
664 /// The function parameters.
666
670
671 static unsigned getMaxNullabilityIndex() {
672 return ((sizeof(NullabilityPayload) * CHAR_BIT) / NullabilityKindSize);
673 }
674
676 assert(index <= getMaxNullabilityIndex());
677 assert(static_cast<unsigned>(kind) < NullabilityKindMask);
678
679 NullabilityAudited = true;
680 if (NumAdjustedNullable < index + 1)
682
683 // Mask the bits.
685 ~(NullabilityKindMask << (index * NullabilityKindSize));
686
687 // Set the value.
688 unsigned kindValue = (static_cast<unsigned>(kind))
689 << (index * NullabilityKindSize);
690 NullabilityPayload |= kindValue;
691 }
692
693 /// Adds the return type info.
695 addTypeInfo(ReturnInfoIndex, kind);
696 }
697
698 /// Adds the parameter type info.
700 addTypeInfo(index + 1, kind);
701 }
702
704 return getTypeInfo(index + 1);
705 }
706
707 NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
708
709 std::optional<RetainCountConventionKind> getRetainCountConvention() const {
711 return std::nullopt;
713 }
714 void
715 setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
716 RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
717 assert(getRetainCountConvention() == Value && "bitfield too small");
718 }
719
720 friend bool operator==(const FunctionInfo &, const FunctionInfo &);
721
722private:
723 NullabilityKind getTypeInfo(unsigned index) const {
724 assert(NullabilityAudited &&
725 "Checking the type adjustment on non-audited method.");
726
727 // If we don't have info about this parameter, return the default.
730 auto nullability = NullabilityPayload >> (index * NullabilityKindSize);
731 return static_cast<NullabilityKind>(nullability & NullabilityKindMask);
732 }
733
734public:
735 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
736};
737
738inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS) {
739 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
743 LHS.ResultType == RHS.ResultType && LHS.Params == RHS.Params &&
746}
747
748inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
749 return !(LHS == RHS);
750}
751
752/// Describes API notes data for an Objective-C method.
754public:
755 /// Whether this is a designated initializer of its class.
756 LLVM_PREFERRED_TYPE(bool)
758
759 /// Whether this is a required initializer.
760 LLVM_PREFERRED_TYPE(bool)
761 unsigned RequiredInit : 1;
762
763 std::optional<ParamInfo> Self;
764
766
767 friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
768
770 // Merge Nullability.
771 if (!NullabilityAudited) {
772 if (auto Nullable = RHS.getDefaultNullability()) {
773 NullabilityAudited = true;
775 }
776 }
777 return *this;
778 }
779
780 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
781};
782
783inline bool operator==(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
784 return static_cast<const FunctionInfo &>(LHS) == RHS &&
785 LHS.DesignatedInit == RHS.DesignatedInit &&
786 LHS.RequiredInit == RHS.RequiredInit && LHS.Self == RHS.Self;
787}
788
789inline bool operator!=(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
790 return !(LHS == RHS);
791}
792
793/// Describes API notes data for a global variable.
795public:
797};
798
799/// Describes API notes data for a global function.
801public:
803};
804
805/// Describes API notes data for a C/C++ record field.
806class FieldInfo : public VariableInfo {
807public:
809};
810
811/// Describes API notes data for a C++ method.
813public:
815
816 std::optional<ParamInfo> This;
817
818 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
819};
820
821inline bool operator==(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
822 return static_cast<const FunctionInfo &>(LHS) == RHS && LHS.This == RHS.This;
823}
824
825inline bool operator!=(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
826 return !(LHS == RHS);
827}
828
829/// Describes API notes data for an enumerator.
831public:
833};
834
835/// Describes API notes data for a tag.
836class TagInfo : public CommonTypeInfo {
837 LLVM_PREFERRED_TYPE(bool)
838 unsigned HasFlagEnum : 1;
839 LLVM_PREFERRED_TYPE(bool)
840 unsigned IsFlagEnum : 1;
841
842 LLVM_PREFERRED_TYPE(bool)
843 unsigned SwiftCopyableSpecified : 1;
844 LLVM_PREFERRED_TYPE(bool)
845 unsigned SwiftCopyable : 1;
846
847 LLVM_PREFERRED_TYPE(bool)
848 unsigned SwiftEscapableSpecified : 1;
849 LLVM_PREFERRED_TYPE(bool)
850 unsigned SwiftEscapable : 1;
851
852public:
853 std::optional<std::string> SwiftImportAs;
854 std::optional<std::string> SwiftRetainOp;
855 std::optional<std::string> SwiftReleaseOp;
856 std::optional<std::string> SwiftDestroyOp;
857 std::optional<std::string> SwiftDefaultOwnership;
858
859 std::optional<EnumExtensibilityKind> EnumExtensibility;
860
862 : HasFlagEnum(0), IsFlagEnum(0), SwiftCopyableSpecified(false),
863 SwiftCopyable(false), SwiftEscapableSpecified(false),
864 SwiftEscapable(false) {}
865
866 std::optional<bool> isFlagEnum() const {
867 if (HasFlagEnum)
868 return IsFlagEnum;
869 return std::nullopt;
870 }
871 void setFlagEnum(std::optional<bool> Value) {
872 HasFlagEnum = Value.has_value();
873 IsFlagEnum = Value.value_or(false);
874 }
875
876 std::optional<bool> isSwiftCopyable() const {
877 return SwiftCopyableSpecified ? std::optional<bool>(SwiftCopyable)
878 : std::nullopt;
879 }
880 void setSwiftCopyable(std::optional<bool> Value) {
881 SwiftCopyableSpecified = Value.has_value();
882 SwiftCopyable = Value.value_or(false);
883 }
884
885 std::optional<bool> isSwiftEscapable() const {
886 return SwiftEscapableSpecified ? std::optional<bool>(SwiftEscapable)
887 : std::nullopt;
888 }
889
890 void setSwiftEscapable(std::optional<bool> Value) {
891 SwiftEscapableSpecified = Value.has_value();
892 SwiftEscapable = Value.value_or(false);
893 }
894
896 static_cast<CommonTypeInfo &>(*this) |= RHS;
897
898 if (!SwiftImportAs)
900 if (!SwiftRetainOp)
902 if (!SwiftReleaseOp)
904 if (!SwiftDestroyOp)
908
909 if (!HasFlagEnum)
910 setFlagEnum(RHS.isFlagEnum());
911
914
915 if (!SwiftCopyableSpecified)
917
918 if (!SwiftEscapableSpecified)
920
921 return *this;
922 }
923
924 friend bool operator==(const TagInfo &, const TagInfo &);
925
926 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
927};
928
929inline bool operator==(const TagInfo &LHS, const TagInfo &RHS) {
930 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
931 LHS.SwiftImportAs == RHS.SwiftImportAs &&
932 LHS.SwiftRetainOp == RHS.SwiftRetainOp &&
933 LHS.SwiftReleaseOp == RHS.SwiftReleaseOp &&
934 LHS.SwiftDestroyOp == RHS.SwiftDestroyOp &&
936 LHS.isFlagEnum() == RHS.isFlagEnum() &&
937 LHS.isSwiftCopyable() == RHS.isSwiftCopyable() &&
938 LHS.isSwiftEscapable() == RHS.isSwiftEscapable() &&
940}
941
942inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
943 return !(LHS == RHS);
944}
945
946/// Describes API notes data for a typedef.
948public:
949 std::optional<SwiftNewTypeKind> SwiftWrapper;
950
952
954 static_cast<CommonTypeInfo &>(*this) |= RHS;
955 if (!SwiftWrapper)
957 return *this;
958 }
959
960 friend bool operator==(const TypedefInfo &, const TypedefInfo &);
961
962 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
963};
964
965inline bool operator==(const TypedefInfo &LHS, const TypedefInfo &RHS) {
966 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
967 LHS.SwiftWrapper == RHS.SwiftWrapper;
968}
969
970inline bool operator!=(const TypedefInfo &LHS, const TypedefInfo &RHS) {
971 return !(LHS == RHS);
972}
973
974/// The file extension used for the source representation of API notes.
975static const constexpr char SOURCE_APINOTES_EXTENSION[] = "apinotes";
976
977/// Opaque context ID used to refer to an Objective-C class or protocol or a C++
978/// namespace.
980public:
981 unsigned Value;
982
983 explicit ContextID(unsigned value) : Value(value) {}
984};
985
986enum class ContextKind : uint8_t {
990 Tag = 3,
991};
992
999
1000/// A temporary reference to an Objective-C selector, suitable for
1001/// referencing selector data on the stack.
1002///
1003/// Instances of this struct do not store references to any of the
1004/// data they contain; it is up to the user to ensure that the data
1005/// referenced by the identifier list persists.
1010} // namespace api_notes
1011} // namespace clang
1012
1013#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:376
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< unsigned > getLevel() const
Definition Types.h:387
friend bool operator==(const BoundsSafetyInfo &, const BoundsSafetyInfo &)
Definition Types.h:401
void setKindAudited(BoundsSafetyKind kind)
Definition Types.h:382
void setLevelAudited(unsigned level)
Definition Types.h:391
Describes API notes data for a C++ method.
Definition Types.h:812
std::optional< ParamInfo > This
Definition Types.h:816
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:979
ContextID(unsigned value)
Definition Types.h:983
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:629
std::string SwiftReturnOwnership
Ownership convention for return value.
Definition Types.h:662
void addTypeInfo(unsigned index, NullabilityKind kind)
Definition Types.h:675
uint64_t NullabilityPayload
Stores the nullability of the return type and the parameters.
Definition Types.h:656
std::optional< RetainCountConventionKind > getRetainCountConvention() const
Definition Types.h:709
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition Types.h:715
unsigned RawRetainCountConvention
A biased RetainCountConventionKind, where 0 means "unspecified".
Definition Types.h:649
std::vector< ParamInfo > Params
The function parameters.
Definition Types.h:665
NullabilityKind getReturnTypeInfo() const
Definition Types.h:707
friend bool operator==(const FunctionInfo &, const FunctionInfo &)
Definition Types.h:738
NullabilityKind getParamTypeInfo(unsigned index) const
Definition Types.h:703
unsigned NumAdjustedNullable
Number of types whose nullability is encoded with the NullabilityPayload.
Definition Types.h:646
std::string ResultType
The result type of this function, as a C type.
Definition Types.h:659
static unsigned getMaxNullabilityIndex()
Definition Types.h:671
void addReturnTypeInfo(NullabilityKind kind)
Adds the return type info.
Definition Types.h:694
unsigned NullabilityAudited
Whether the signature has been audited with respect to nullability.
Definition Types.h:643
void addParamTypeInfo(unsigned index, NullabilityKind kind)
Adds the parameter type info.
Definition Types.h:699
Describes API notes data for an Objective-C method.
Definition Types.h:753
unsigned DesignatedInit
Whether this is a designated initializer of its class.
Definition Types.h:757
friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &)
Definition Types.h:783
std::optional< ParamInfo > Self
Definition Types.h:763
ObjCMethodInfo & operator|=(const ContextInfo &RHS)
Definition Types.h:769
unsigned RequiredInit
Whether this is a required initializer.
Definition Types.h:761
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
Describes API notes data for an Objective-C property.
Definition Types.h:471
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setSwiftImportAsAccessors(std::optional< bool > Value)
Definition Types.h:486
std::optional< bool > getSwiftImportAsAccessors() const
Definition Types.h:481
friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &)
Definition Types.h:517
ObjCPropertyInfo & operator|=(const ObjCPropertyInfo &RHS)
Definition Types.h:505
ObjCPropertyInfo & operator|=(const ContextInfo &RHS)
Merge class-wide information into the given property.
Definition Types.h:494
Describes a function or method parameter.
Definition Types.h:529
std::optional< BoundsSafetyInfo > BoundsSafety
Definition Types.h:552
void setNoEscape(std::optional< bool > Value)
Definition Types.h:562
std::optional< bool > isNoEscape() const
Definition Types.h:559
ParamInfo & operator|=(const ParamInfo &RHS)
Definition Types.h:587
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< bool > isLifetimebound() const
Definition Types.h:567
friend bool operator==(const ParamInfo &, const ParamInfo &)
Definition Types.h:614
void setLifetimebound(std::optional< bool > Value)
Definition Types.h:571
std::optional< RetainCountConventionKind > getRetainCountConvention() const
Definition Types.h:576
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition Types.h:582
Describes API notes data for a tag.
Definition Types.h:836
std::optional< std::string > SwiftReleaseOp
Definition Types.h:855
std::optional< std::string > SwiftRetainOp
Definition Types.h:854
std::optional< std::string > SwiftImportAs
Definition Types.h:853
std::optional< std::string > SwiftDefaultOwnership
Definition Types.h:857
std::optional< EnumExtensibilityKind > EnumExtensibility
Definition Types.h:859
void setSwiftCopyable(std::optional< bool > Value)
Definition Types.h:880
std::optional< std::string > SwiftDestroyOp
Definition Types.h:856
void setSwiftEscapable(std::optional< bool > Value)
Definition Types.h:890
std::optional< bool > isFlagEnum() const
Definition Types.h:866
TagInfo & operator|=(const TagInfo &RHS)
Definition Types.h:895
std::optional< bool > isSwiftCopyable() const
Definition Types.h:876
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
friend bool operator==(const TagInfo &, const TagInfo &)
Definition Types.h:929
std::optional< bool > isSwiftEscapable() const
Definition Types.h:885
void setFlagEnum(std::optional< bool > Value)
Definition Types.h:871
Describes API notes data for a typedef.
Definition Types.h:947
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
TypedefInfo & operator|=(const TypedefInfo &RHS)
Definition Types.h:953
friend bool operator==(const TypedefInfo &, const TypedefInfo &)
Definition Types.h:965
std::optional< SwiftNewTypeKind > SwiftWrapper
Definition Types.h:949
API notes for a variable/property.
Definition Types.h:414
void setNullabilityAudited(NullabilityKind kind)
Definition Types.h:436
void setType(const std::string &type)
Definition Types.h:442
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
VariableInfo & operator|=(const VariableInfo &RHS)
Definition Types.h:446
std::optional< NullabilityKind > getNullability() const
Definition Types.h:430
const std::string & getType() const
Definition Types.h:441
friend bool operator==(const VariableInfo &, const VariableInfo &)
Definition Types.h:460
#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:975
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:997
A temporary reference to an Objective-C selector, suitable for referencing selector data on the stack...
Definition Types.h:1006
llvm::ArrayRef< llvm::StringRef > Identifiers
Definition Types.h:1008