clang 20.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
144public:
146
147 const std::optional<std::string> &getSwiftBridge() const {
148 return SwiftBridge;
149 }
150
151 void setSwiftBridge(std::optional<std::string> SwiftType) {
152 SwiftBridge = SwiftType;
153 }
154
155 const std::optional<std::string> &getNSErrorDomain() const {
156 return NSErrorDomain;
157 }
158
159 void setNSErrorDomain(const std::optional<std::string> &Domain) {
160 NSErrorDomain = Domain;
161 }
162
163 void setNSErrorDomain(const std::optional<llvm::StringRef> &Domain) {
164 NSErrorDomain = Domain ? std::optional<std::string>(std::string(*Domain))
165 : std::nullopt;
166 }
167
168 friend bool operator==(const CommonTypeInfo &, const CommonTypeInfo &);
169
171 // Merge inherited info.
172 static_cast<CommonEntityInfo &>(*this) |= RHS;
173
174 if (!SwiftBridge)
176 if (!NSErrorDomain)
178
179 return *this;
180 }
181
182 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
183};
184
185inline bool operator==(const CommonTypeInfo &LHS, const CommonTypeInfo &RHS) {
186 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
187 LHS.SwiftBridge == RHS.SwiftBridge &&
188 LHS.NSErrorDomain == RHS.NSErrorDomain;
189}
190
191inline bool operator!=(const CommonTypeInfo &LHS, const CommonTypeInfo &RHS) {
192 return !(LHS == RHS);
193}
194
195/// Describes API notes data for an Objective-C class or protocol or a C++
196/// namespace.
198 /// Whether this class has a default nullability.
199 LLVM_PREFERRED_TYPE(bool)
200 unsigned HasDefaultNullability : 1;
201
202 /// The default nullability.
203 LLVM_PREFERRED_TYPE(NullabilityKind)
204 unsigned DefaultNullability : 2;
205
206 /// Whether this class has designated initializers recorded.
207 LLVM_PREFERRED_TYPE(bool)
208 unsigned HasDesignatedInits : 1;
209
210 LLVM_PREFERRED_TYPE(bool)
211 unsigned SwiftImportAsNonGenericSpecified : 1;
212 LLVM_PREFERRED_TYPE(bool)
213 unsigned SwiftImportAsNonGeneric : 1;
214
215 LLVM_PREFERRED_TYPE(bool)
216 unsigned SwiftObjCMembersSpecified : 1;
217 LLVM_PREFERRED_TYPE(bool)
218 unsigned SwiftObjCMembers : 1;
219
220public:
222 : HasDefaultNullability(0), DefaultNullability(0), HasDesignatedInits(0),
223 SwiftImportAsNonGenericSpecified(false), SwiftImportAsNonGeneric(false),
224 SwiftObjCMembersSpecified(false), SwiftObjCMembers(false) {}
225
226 /// Determine the default nullability for properties and methods of this
227 /// class.
228 ///
229 /// Returns the default nullability, if implied, or std::nullopt if there is
230 /// none.
231 std::optional<NullabilityKind> getDefaultNullability() const {
232 return HasDefaultNullability
233 ? std::optional<NullabilityKind>(
234 static_cast<NullabilityKind>(DefaultNullability))
235 : std::nullopt;
236 }
237
238 /// Set the default nullability for properties and methods of this class.
240 HasDefaultNullability = true;
241 DefaultNullability = static_cast<unsigned>(Kind);
242 }
243
244 bool hasDesignatedInits() const { return HasDesignatedInits; }
245 void setHasDesignatedInits(bool Value) { HasDesignatedInits = Value; }
246
247 std::optional<bool> getSwiftImportAsNonGeneric() const {
248 return SwiftImportAsNonGenericSpecified
249 ? std::optional<bool>(SwiftImportAsNonGeneric)
250 : std::nullopt;
251 }
252 void setSwiftImportAsNonGeneric(std::optional<bool> Value) {
253 SwiftImportAsNonGenericSpecified = Value.has_value();
254 SwiftImportAsNonGeneric = Value.value_or(false);
255 }
256
257 std::optional<bool> getSwiftObjCMembers() const {
258 return SwiftObjCMembersSpecified ? std::optional<bool>(SwiftObjCMembers)
259 : std::nullopt;
260 }
261 void setSwiftObjCMembers(std::optional<bool> Value) {
262 SwiftObjCMembersSpecified = Value.has_value();
263 SwiftObjCMembers = Value.value_or(false);
264 }
265
266 friend bool operator==(const ContextInfo &, const ContextInfo &);
267
269 // Merge inherited info.
270 static_cast<CommonTypeInfo &>(*this) |= RHS;
271
272 // Merge nullability.
274 if (auto Nullability = RHS.getDefaultNullability())
275 setDefaultNullability(*Nullability);
276
277 if (!SwiftImportAsNonGenericSpecified)
279
280 if (!SwiftObjCMembersSpecified)
282
283 HasDesignatedInits |= RHS.HasDesignatedInits;
284
285 return *this;
286 }
287
288 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
289};
290
291inline bool operator==(const ContextInfo &LHS, const ContextInfo &RHS) {
292 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
294 LHS.HasDesignatedInits == RHS.HasDesignatedInits &&
297}
298
299inline bool operator!=(const ContextInfo &LHS, const ContextInfo &RHS) {
300 return !(LHS == RHS);
301}
302
303/// API notes for a variable/property.
305 /// Whether this property has been audited for nullability.
306 LLVM_PREFERRED_TYPE(bool)
307 unsigned NullabilityAudited : 1;
308
309 /// The kind of nullability for this property. Only valid if the nullability
310 /// has been audited.
311 LLVM_PREFERRED_TYPE(NullabilityKind)
312 unsigned Nullable : 2;
313
314 /// The C type of the variable, as a string.
315 std::string Type;
316
317public:
318 VariableInfo() : NullabilityAudited(false), Nullable(0) {}
319
320 std::optional<NullabilityKind> getNullability() const {
321 return NullabilityAudited ? std::optional<NullabilityKind>(
322 static_cast<NullabilityKind>(Nullable))
323 : std::nullopt;
324 }
325
327 NullabilityAudited = true;
328 Nullable = static_cast<unsigned>(kind);
329 }
330
331 const std::string &getType() const { return Type; }
332 void setType(const std::string &type) { Type = type; }
333
334 friend bool operator==(const VariableInfo &, const VariableInfo &);
335
337 static_cast<CommonEntityInfo &>(*this) |= RHS;
338
339 if (!NullabilityAudited && RHS.NullabilityAudited)
341 if (Type.empty())
342 Type = RHS.Type;
343
344 return *this;
345 }
346
347 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
348};
349
350inline bool operator==(const VariableInfo &LHS, const VariableInfo &RHS) {
351 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
352 LHS.NullabilityAudited == RHS.NullabilityAudited &&
353 LHS.Nullable == RHS.Nullable && LHS.Type == RHS.Type;
354}
355
356inline bool operator!=(const VariableInfo &LHS, const VariableInfo &RHS) {
357 return !(LHS == RHS);
358}
359
360/// Describes API notes data for an Objective-C property.
362 LLVM_PREFERRED_TYPE(bool)
363 unsigned SwiftImportAsAccessorsSpecified : 1;
364 LLVM_PREFERRED_TYPE(bool)
365 unsigned SwiftImportAsAccessors : 1;
366
367public:
369 : SwiftImportAsAccessorsSpecified(false), SwiftImportAsAccessors(false) {}
370
371 std::optional<bool> getSwiftImportAsAccessors() const {
372 return SwiftImportAsAccessorsSpecified
373 ? std::optional<bool>(SwiftImportAsAccessors)
374 : std::nullopt;
375 }
376 void setSwiftImportAsAccessors(std::optional<bool> Value) {
377 SwiftImportAsAccessorsSpecified = Value.has_value();
378 SwiftImportAsAccessors = Value.value_or(false);
379 }
380
381 friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &);
382
383 /// Merge class-wide information into the given property.
385 static_cast<CommonEntityInfo &>(*this) |= RHS;
386
387 // Merge nullability.
388 if (!getNullability())
389 if (auto Nullable = RHS.getDefaultNullability())
391
392 return *this;
393 }
394
396 static_cast<VariableInfo &>(*this) |= RHS;
397
398 if (!SwiftImportAsAccessorsSpecified)
400
401 return *this;
402 }
403
404 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
405};
406
407inline bool operator==(const ObjCPropertyInfo &LHS,
408 const ObjCPropertyInfo &RHS) {
409 return static_cast<const VariableInfo &>(LHS) == RHS &&
411}
412
413inline bool operator!=(const ObjCPropertyInfo &LHS,
414 const ObjCPropertyInfo &RHS) {
415 return !(LHS == RHS);
416}
417
418/// Describes a function or method parameter.
419class ParamInfo : public VariableInfo {
420 /// Whether noescape was specified.
421 LLVM_PREFERRED_TYPE(bool)
422 unsigned NoEscapeSpecified : 1;
423
424 /// Whether the this parameter has the 'noescape' attribute.
425 LLVM_PREFERRED_TYPE(bool)
426 unsigned NoEscape : 1;
427
428 /// Whether lifetimebound was specified.
429 LLVM_PREFERRED_TYPE(bool)
430 unsigned LifetimeboundSpecified : 1;
431
432 /// Whether the this parameter has the 'lifetimebound' attribute.
433 LLVM_PREFERRED_TYPE(bool)
434 unsigned Lifetimebound : 1;
435
436 /// A biased RetainCountConventionKind, where 0 means "unspecified".
437 ///
438 /// Only relevant for out-parameters.
439 unsigned RawRetainCountConvention : 3;
440
441public:
443 : NoEscapeSpecified(false), NoEscape(false),
444 LifetimeboundSpecified(false), Lifetimebound(false),
445 RawRetainCountConvention() {}
446
447 std::optional<bool> isNoEscape() const {
448 return NoEscapeSpecified ? std::optional<bool>(NoEscape) : std::nullopt;
449 }
450 void setNoEscape(std::optional<bool> Value) {
451 NoEscapeSpecified = Value.has_value();
452 NoEscape = Value.value_or(false);
453 }
454
455 std::optional<bool> isLifetimebound() const {
456 return LifetimeboundSpecified ? std::optional<bool>(Lifetimebound)
457 : std::nullopt;
458 }
459 void setLifetimebound(std::optional<bool> Value) {
460 LifetimeboundSpecified = Value.has_value();
461 Lifetimebound = Value.value_or(false);
462 }
463
464 std::optional<RetainCountConventionKind> getRetainCountConvention() const {
465 if (!RawRetainCountConvention)
466 return std::nullopt;
467 return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
468 }
469 void
470 setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
471 RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
472 assert(getRetainCountConvention() == Value && "bitfield too small");
473 }
474
476 static_cast<VariableInfo &>(*this) |= RHS;
477
478 if (!NoEscapeSpecified && RHS.NoEscapeSpecified) {
479 NoEscapeSpecified = true;
480 NoEscape = RHS.NoEscape;
481 }
482
483 if (!LifetimeboundSpecified && RHS.LifetimeboundSpecified) {
484 LifetimeboundSpecified = true;
485 Lifetimebound = RHS.Lifetimebound;
486 }
487
488 if (!RawRetainCountConvention)
489 RawRetainCountConvention = RHS.RawRetainCountConvention;
490
491 return *this;
492 }
493
494 friend bool operator==(const ParamInfo &, const ParamInfo &);
495
496 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
497};
498
499inline bool operator==(const ParamInfo &LHS, const ParamInfo &RHS) {
500 return static_cast<const VariableInfo &>(LHS) == RHS &&
501 LHS.NoEscapeSpecified == RHS.NoEscapeSpecified &&
502 LHS.NoEscape == RHS.NoEscape &&
503 LHS.LifetimeboundSpecified == RHS.LifetimeboundSpecified &&
504 LHS.Lifetimebound == RHS.Lifetimebound &&
505 LHS.RawRetainCountConvention == RHS.RawRetainCountConvention;
506}
507
508inline bool operator!=(const ParamInfo &LHS, const ParamInfo &RHS) {
509 return !(LHS == RHS);
510}
511
512/// API notes for a function or method.
514private:
515 static constexpr const uint64_t NullabilityKindMask = 0x3;
516 static constexpr const unsigned NullabilityKindSize = 2;
517
518 static constexpr const unsigned ReturnInfoIndex = 0;
519
520public:
521 // If yes, we consider all types to be non-nullable unless otherwise noted.
522 // If this flag is not set, the pointer types are considered to have
523 // unknown nullability.
524
525 /// Whether the signature has been audited with respect to nullability.
526 LLVM_PREFERRED_TYPE(bool)
528
529 /// Number of types whose nullability is encoded with the NullabilityPayload.
531
532 /// A biased RetainCountConventionKind, where 0 means "unspecified".
534
535 // NullabilityKindSize bits are used to encode the nullability. The info
536 // about the return type is stored at position 0, followed by the nullability
537 // of the parameters.
538
539 /// Stores the nullability of the return type and the parameters.
540 uint64_t NullabilityPayload = 0;
541
542 /// The result type of this function, as a C type.
544
545 /// Ownership convention for return value
547
548 /// The function parameters.
550
554
555 static unsigned getMaxNullabilityIndex() {
556 return ((sizeof(NullabilityPayload) * CHAR_BIT) / NullabilityKindSize);
557 }
558
559 void addTypeInfo(unsigned index, NullabilityKind kind) {
560 assert(index <= getMaxNullabilityIndex());
561 assert(static_cast<unsigned>(kind) < NullabilityKindMask);
562
563 NullabilityAudited = true;
564 if (NumAdjustedNullable < index + 1)
565 NumAdjustedNullable = index + 1;
566
567 // Mask the bits.
569 ~(NullabilityKindMask << (index * NullabilityKindSize));
570
571 // Set the value.
572 unsigned kindValue = (static_cast<unsigned>(kind))
573 << (index * NullabilityKindSize);
574 NullabilityPayload |= kindValue;
575 }
576
577 /// Adds the return type info.
579 addTypeInfo(ReturnInfoIndex, kind);
580 }
581
582 /// Adds the parameter type info.
583 void addParamTypeInfo(unsigned index, NullabilityKind kind) {
584 addTypeInfo(index + 1, kind);
585 }
586
587 NullabilityKind getParamTypeInfo(unsigned index) const {
588 return getTypeInfo(index + 1);
589 }
590
591 NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
592
593 std::optional<RetainCountConventionKind> getRetainCountConvention() const {
595 return std::nullopt;
597 }
598 void
599 setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
600 RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
601 assert(getRetainCountConvention() == Value && "bitfield too small");
602 }
603
604 friend bool operator==(const FunctionInfo &, const FunctionInfo &);
605
606private:
607 NullabilityKind getTypeInfo(unsigned index) const {
608 assert(NullabilityAudited &&
609 "Checking the type adjustment on non-audited method.");
610
611 // If we don't have info about this parameter, return the default.
612 if (index > NumAdjustedNullable)
614 auto nullability = NullabilityPayload >> (index * NullabilityKindSize);
615 return static_cast<NullabilityKind>(nullability & NullabilityKindMask);
616 }
617
618public:
619 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
620};
621
622inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS) {
623 return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
627 LHS.ResultType == RHS.ResultType && LHS.Params == RHS.Params &&
630}
631
632inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
633 return !(LHS == RHS);
634}
635
636/// Describes API notes data for an Objective-C method.
638public:
639 /// Whether this is a designated initializer of its class.
640 LLVM_PREFERRED_TYPE(bool)
642
643 /// Whether this is a required initializer.
644 LLVM_PREFERRED_TYPE(bool)
645 unsigned RequiredInit : 1;
646
647 std::optional<ParamInfo> Self;
648
650
651 friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
652
654 // Merge Nullability.
655 if (!NullabilityAudited) {
656 if (auto Nullable = RHS.getDefaultNullability()) {
657 NullabilityAudited = true;
659 }
660 }
661 return *this;
662 }
663
664 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
665};
666
667inline bool operator==(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
668 return static_cast<const FunctionInfo &>(LHS) == RHS &&
669 LHS.DesignatedInit == RHS.DesignatedInit &&
670 LHS.RequiredInit == RHS.RequiredInit && LHS.Self == RHS.Self;
671}
672
673inline bool operator!=(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
674 return !(LHS == RHS);
675}
676
677/// Describes API notes data for a global variable.
679public:
681};
682
683/// Describes API notes data for a global function.
685public:
687};
688
689/// Describes API notes data for a C/C++ record field.
690class FieldInfo : public VariableInfo {
691public:
693};
694
695/// Describes API notes data for a C++ method.
697public:
699
700 std::optional<ParamInfo> This;
701
702 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
703};
704
705inline bool operator==(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
706 return static_cast<const FunctionInfo &>(LHS) == RHS && LHS.This == RHS.This;
707}
708
709inline bool operator!=(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
710 return !(LHS == RHS);
711}
712
713/// Describes API notes data for an enumerator.
715public:
717};
718
719/// Describes API notes data for a tag.
720class TagInfo : public CommonTypeInfo {
721 LLVM_PREFERRED_TYPE(bool)
722 unsigned HasFlagEnum : 1;
723 LLVM_PREFERRED_TYPE(bool)
724 unsigned IsFlagEnum : 1;
725
726 LLVM_PREFERRED_TYPE(bool)
727 unsigned SwiftCopyableSpecified : 1;
728 LLVM_PREFERRED_TYPE(bool)
729 unsigned SwiftCopyable : 1;
730
731 LLVM_PREFERRED_TYPE(bool)
732 unsigned SwiftEscapableSpecified : 1;
733 LLVM_PREFERRED_TYPE(bool)
734 unsigned SwiftEscapable : 1;
735
736public:
737 std::optional<std::string> SwiftImportAs;
738 std::optional<std::string> SwiftRetainOp;
739 std::optional<std::string> SwiftReleaseOp;
740
741 /// The Swift protocol that this type should be automatically conformed to.
742 std::optional<std::string> SwiftConformance;
743
744 std::optional<EnumExtensibilityKind> EnumExtensibility;
745
747 : HasFlagEnum(0), IsFlagEnum(0), SwiftCopyableSpecified(false),
748 SwiftCopyable(false), SwiftEscapableSpecified(false),
749 SwiftEscapable(false) {}
750
751 std::optional<bool> isFlagEnum() const {
752 if (HasFlagEnum)
753 return IsFlagEnum;
754 return std::nullopt;
755 }
756 void setFlagEnum(std::optional<bool> Value) {
757 HasFlagEnum = Value.has_value();
758 IsFlagEnum = Value.value_or(false);
759 }
760
761 std::optional<bool> isSwiftCopyable() const {
762 return SwiftCopyableSpecified ? std::optional<bool>(SwiftCopyable)
763 : std::nullopt;
764 }
765 void setSwiftCopyable(std::optional<bool> Value) {
766 SwiftCopyableSpecified = Value.has_value();
767 SwiftCopyable = Value.value_or(false);
768 }
769
770 std::optional<bool> isSwiftEscapable() const {
771 return SwiftEscapableSpecified ? std::optional<bool>(SwiftEscapable)
772 : std::nullopt;
773 }
774
775 void setSwiftEscapable(std::optional<bool> Value) {
776 SwiftEscapableSpecified = Value.has_value();
777 SwiftEscapable = Value.value_or(false);
778 }
779
781 static_cast<CommonTypeInfo &>(*this) |= RHS;
782
783 if (!SwiftImportAs)
785 if (!SwiftRetainOp)
787 if (!SwiftReleaseOp)
789
790 if (!SwiftConformance)
792
793 if (!HasFlagEnum)
794 setFlagEnum(RHS.isFlagEnum());
795
798
799 if (!SwiftCopyableSpecified)
801
802 if (!SwiftEscapableSpecified)
804
805 return *this;
806 }
807
808 friend bool operator==(const TagInfo &, const TagInfo &);
809
810 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
811};
812
813inline bool operator==(const TagInfo &LHS, const TagInfo &RHS) {
814 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
815 LHS.SwiftImportAs == RHS.SwiftImportAs &&
816 LHS.SwiftRetainOp == RHS.SwiftRetainOp &&
817 LHS.SwiftReleaseOp == RHS.SwiftReleaseOp &&
819 LHS.isFlagEnum() == RHS.isFlagEnum() &&
820 LHS.isSwiftCopyable() == RHS.isSwiftCopyable() &&
821 LHS.isSwiftEscapable() == RHS.isSwiftEscapable() &&
823}
824
825inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
826 return !(LHS == RHS);
827}
828
829/// Describes API notes data for a typedef.
831public:
832 std::optional<SwiftNewTypeKind> SwiftWrapper;
833
835
837 static_cast<CommonTypeInfo &>(*this) |= RHS;
838 if (!SwiftWrapper)
840 return *this;
841 }
842
843 friend bool operator==(const TypedefInfo &, const TypedefInfo &);
844
845 LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
846};
847
848inline bool operator==(const TypedefInfo &LHS, const TypedefInfo &RHS) {
849 return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
850 LHS.SwiftWrapper == RHS.SwiftWrapper;
851}
852
853inline bool operator!=(const TypedefInfo &LHS, const TypedefInfo &RHS) {
854 return !(LHS == RHS);
855}
856
857/// The file extension used for the source representation of API notes.
858static const constexpr char SOURCE_APINOTES_EXTENSION[] = "apinotes";
859
860/// Opaque context ID used to refer to an Objective-C class or protocol or a C++
861/// namespace.
863public:
864 unsigned Value;
865
866 explicit ContextID(unsigned value) : Value(value) {}
867};
868
869enum class ContextKind : uint8_t {
870 ObjCClass = 0,
871 ObjCProtocol = 1,
872 Namespace = 2,
873 Tag = 3,
874};
875
876struct Context {
879
881};
882
883/// A temporary reference to an Objective-C selector, suitable for
884/// referencing selector data on the stack.
885///
886/// Instances of this struct do not store references to any of the
887/// data they contain; it is up to the user to ensure that the data
888/// referenced by the identifier list persists.
890 unsigned NumArgs;
892};
893} // namespace api_notes
894} // namespace clang
895
896#endif
enum clang::sema::@1718::IndirectLocalPathEntry::EntryKind Kind
Defines various enumerations that describe declaration and type specifiers.
The base class of the type hierarchy.
Definition: Type.h:1828
Describes API notes data for a C++ method.
Definition: Types.h:696
std::optional< ParamInfo > This
Definition: Types.h:700
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:163
const std::optional< std::string > & getSwiftBridge() const
Definition: Types.h:147
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setNSErrorDomain(const std::optional< std::string > &Domain)
Definition: Types.h:159
friend bool operator==(const CommonTypeInfo &, const CommonTypeInfo &)
Definition: Types.h:185
const std::optional< std::string > & getNSErrorDomain() const
Definition: Types.h:155
void setSwiftBridge(std::optional< std::string > SwiftType)
Definition: Types.h:151
CommonTypeInfo & operator|=(const CommonTypeInfo &RHS)
Definition: Types.h:170
Opaque context ID used to refer to an Objective-C class or protocol or a C++ namespace.
Definition: Types.h:862
ContextID(unsigned value)
Definition: Types.h:866
Describes API notes data for an Objective-C class or protocol or a C++ namespace.
Definition: Types.h:197
std::optional< bool > getSwiftImportAsNonGeneric() const
Definition: Types.h:247
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
std::optional< bool > getSwiftObjCMembers() const
Definition: Types.h:257
void setDefaultNullability(NullabilityKind Kind)
Set the default nullability for properties and methods of this class.
Definition: Types.h:239
std::optional< NullabilityKind > getDefaultNullability() const
Determine the default nullability for properties and methods of this class.
Definition: Types.h:231
void setSwiftObjCMembers(std::optional< bool > Value)
Definition: Types.h:261
friend bool operator==(const ContextInfo &, const ContextInfo &)
Definition: Types.h:291
bool hasDesignatedInits() const
Definition: Types.h:244
void setSwiftImportAsNonGeneric(std::optional< bool > Value)
Definition: Types.h:252
void setHasDesignatedInits(bool Value)
Definition: Types.h:245
ContextInfo & operator|=(const ContextInfo &RHS)
Definition: Types.h:268
Describes API notes data for an enumerator.
Definition: Types.h:714
Describes API notes data for a C/C++ record field.
Definition: Types.h:690
API notes for a function or method.
Definition: Types.h:513
std::string SwiftReturnOwnership
Ownership convention for return value.
Definition: Types.h:546
void addTypeInfo(unsigned index, NullabilityKind kind)
Definition: Types.h:559
uint64_t NullabilityPayload
Stores the nullability of the return type and the parameters.
Definition: Types.h:540
std::optional< RetainCountConventionKind > getRetainCountConvention() const
Definition: Types.h:593
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition: Types.h:599
unsigned RawRetainCountConvention
A biased RetainCountConventionKind, where 0 means "unspecified".
Definition: Types.h:533
std::vector< ParamInfo > Params
The function parameters.
Definition: Types.h:549
NullabilityKind getReturnTypeInfo() const
Definition: Types.h:591
NullabilityKind getParamTypeInfo(unsigned index) const
Definition: Types.h:587
friend bool operator==(const FunctionInfo &, const FunctionInfo &)
Definition: Types.h:622
unsigned NumAdjustedNullable
Number of types whose nullability is encoded with the NullabilityPayload.
Definition: Types.h:530
std::string ResultType
The result type of this function, as a C type.
Definition: Types.h:543
static unsigned getMaxNullabilityIndex()
Definition: Types.h:555
void addReturnTypeInfo(NullabilityKind kind)
Adds the return type info.
Definition: Types.h:578
unsigned NullabilityAudited
Whether the signature has been audited with respect to nullability.
Definition: Types.h:527
void addParamTypeInfo(unsigned index, NullabilityKind kind)
Adds the parameter type info.
Definition: Types.h:583
Describes API notes data for a global function.
Definition: Types.h:684
Describes API notes data for a global variable.
Definition: Types.h:678
Describes API notes data for an Objective-C method.
Definition: Types.h:637
unsigned DesignatedInit
Whether this is a designated initializer of its class.
Definition: Types.h:641
friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &)
Definition: Types.h:667
std::optional< ParamInfo > Self
Definition: Types.h:647
ObjCMethodInfo & operator|=(const ContextInfo &RHS)
Definition: Types.h:653
unsigned RequiredInit
Whether this is a required initializer.
Definition: Types.h:645
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
Describes API notes data for an Objective-C property.
Definition: Types.h:361
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
void setSwiftImportAsAccessors(std::optional< bool > Value)
Definition: Types.h:376
std::optional< bool > getSwiftImportAsAccessors() const
Definition: Types.h:371
ObjCPropertyInfo & operator|=(const ObjCPropertyInfo &RHS)
Definition: Types.h:395
friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &)
Definition: Types.h:407
ObjCPropertyInfo & operator|=(const ContextInfo &RHS)
Merge class-wide information into the given property.
Definition: Types.h:384
Describes a function or method parameter.
Definition: Types.h:419
void setNoEscape(std::optional< bool > Value)
Definition: Types.h:450
std::optional< bool > isNoEscape() const
Definition: Types.h:447
ParamInfo & operator|=(const ParamInfo &RHS)
Definition: Types.h:475
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
std::optional< bool > isLifetimebound() const
Definition: Types.h:455
friend bool operator==(const ParamInfo &, const ParamInfo &)
Definition: Types.h:499
void setLifetimebound(std::optional< bool > Value)
Definition: Types.h:459
std::optional< RetainCountConventionKind > getRetainCountConvention() const
Definition: Types.h:464
void setRetainCountConvention(std::optional< RetainCountConventionKind > Value)
Definition: Types.h:470
Describes API notes data for a tag.
Definition: Types.h:720
std::optional< std::string > SwiftReleaseOp
Definition: Types.h:739
std::optional< std::string > SwiftRetainOp
Definition: Types.h:738
std::optional< std::string > SwiftImportAs
Definition: Types.h:737
std::optional< EnumExtensibilityKind > EnumExtensibility
Definition: Types.h:744
void setSwiftCopyable(std::optional< bool > Value)
Definition: Types.h:765
void setSwiftEscapable(std::optional< bool > Value)
Definition: Types.h:775
std::optional< bool > isFlagEnum() const
Definition: Types.h:751
TagInfo & operator|=(const TagInfo &RHS)
Definition: Types.h:780
std::optional< bool > isSwiftCopyable() const
Definition: Types.h:761
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS)
std::optional< bool > isSwiftEscapable() const
Definition: Types.h:770
void setFlagEnum(std::optional< bool > Value)
Definition: Types.h:756
friend bool operator==(const TagInfo &, const TagInfo &)
Definition: Types.h:813
std::optional< std::string > SwiftConformance
The Swift protocol that this type should be automatically conformed to.
Definition: Types.h:742
Describes API notes data for a typedef.
Definition: Types.h:830
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
TypedefInfo & operator|=(const TypedefInfo &RHS)
Definition: Types.h:836
std::optional< SwiftNewTypeKind > SwiftWrapper
Definition: Types.h:832
friend bool operator==(const TypedefInfo &, const TypedefInfo &)
Definition: Types.h:848
API notes for a variable/property.
Definition: Types.h:304
void setNullabilityAudited(NullabilityKind kind)
Definition: Types.h:326
void setType(const std::string &type)
Definition: Types.h:332
LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const
friend bool operator==(const VariableInfo &, const VariableInfo &)
Definition: Types.h:350
VariableInfo & operator|=(const VariableInfo &RHS)
Definition: Types.h:336
std::optional< NullabilityKind > getNullability() const
Definition: Types.h:320
const std::string & getType() const
Definition: Types.h:331
#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:858
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:336
@ 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:878
Context(ContextID id, ContextKind kind)
Definition: Types.h:880
A temporary reference to an Objective-C selector, suitable for referencing selector data on the stack...
Definition: Types.h:889
llvm::ArrayRef< llvm::StringRef > Identifiers
Definition: Types.h:891