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