Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/APINotes/Types.h
Line
Count
Source (jump to first uncovered line)
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
12
#include "clang/Basic/Specifiers.h"
13
#include "llvm/ADT/Optional.h"
14
#include "llvm/ADT/StringRef.h"
15
#include <climits>
16
#include <vector>
17
18
namespace clang {
19
namespace api_notes {
20
enum class RetainCountConventionKind {
21
  None,
22
  CFReturnsRetained,
23
  CFReturnsNotRetained,
24
  NSReturnsRetained,
25
  NSReturnsNotRetained,
26
};
27
28
/// The payload for an enum_extensibility attribute. This is a tri-state rather
29
/// than just a boolean because the presence of the attribute indicates
30
/// auditing.
31
enum class EnumExtensibilityKind {
32
  None,
33
  Open,
34
  Closed,
35
};
36
37
/// The kind of a swift_wrapper/swift_newtype.
38
enum class SwiftNewTypeKind {
39
  None,
40
  Struct,
41
  Enum,
42
};
43
44
/// Describes API notes data for any entity.
45
///
46
/// This is used as the base of all API notes.
47
class CommonEntityInfo {
48
public:
49
  /// Message to use when this entity is unavailable.
50
  std::string UnavailableMsg;
51
52
  /// Whether this entity is marked unavailable.
53
  unsigned Unavailable : 1;
54
55
  /// Whether this entity is marked unavailable in Swift.
56
  unsigned UnavailableInSwift : 1;
57
58
private:
59
  /// Whether SwiftPrivate was specified.
60
  unsigned SwiftPrivateSpecified : 1;
61
62
  /// Whether this entity is considered "private" to a Swift overlay.
63
  unsigned SwiftPrivate : 1;
64
65
public:
66
  /// Swift name of this entity.
67
  std::string SwiftName;
68
69
  CommonEntityInfo()
70
      : Unavailable(0), UnavailableInSwift(0), SwiftPrivateSpecified(0),
71
0
        SwiftPrivate(0) {}
72
73
0
  llvm::Optional<bool> isSwiftPrivate() const {
74
0
    return SwiftPrivateSpecified ? llvm::Optional<bool>(SwiftPrivate)
75
0
                                 : llvm::None;
76
0
  }
77
78
0
  void setSwiftPrivate(llvm::Optional<bool> Private) {
79
0
    SwiftPrivateSpecified = Private.has_value();
80
0
    SwiftPrivate = Private.value_or(0);
81
0
  }
82
83
  friend bool operator==(const CommonEntityInfo &, const CommonEntityInfo &);
84
85
0
  CommonEntityInfo &operator|=(const CommonEntityInfo &RHS) {
86
0
    // Merge unavailability.
87
0
    if (RHS.Unavailable) {
88
0
      Unavailable = true;
89
0
      if (UnavailableMsg.empty())
90
0
        UnavailableMsg = RHS.UnavailableMsg;
91
0
    }
92
0
93
0
    if (RHS.UnavailableInSwift) {
94
0
      UnavailableInSwift = true;
95
0
      if (UnavailableMsg.empty())
96
0
        UnavailableMsg = RHS.UnavailableMsg;
97
0
    }
98
0
99
0
    if (!SwiftPrivateSpecified)
100
0
      setSwiftPrivate(RHS.isSwiftPrivate());
101
0
102
0
    if (SwiftName.empty())
103
0
      SwiftName = RHS.SwiftName;
104
0
105
0
    return *this;
106
0
  }
107
108
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
109
};
110
111
inline bool operator==(const CommonEntityInfo &LHS,
112
0
                       const CommonEntityInfo &RHS) {
113
0
  return LHS.UnavailableMsg == RHS.UnavailableMsg &&
114
0
         LHS.Unavailable == RHS.Unavailable &&
115
0
         LHS.UnavailableInSwift == RHS.UnavailableInSwift &&
116
0
         LHS.SwiftPrivateSpecified == RHS.SwiftPrivateSpecified &&
117
0
         LHS.SwiftPrivate == RHS.SwiftPrivate && LHS.SwiftName == RHS.SwiftName;
118
0
}
119
120
inline bool operator!=(const CommonEntityInfo &LHS,
121
0
                       const CommonEntityInfo &RHS) {
122
0
  return !(LHS == RHS);
123
0
}
124
125
/// Describes API notes for types.
126
class CommonTypeInfo : public CommonEntityInfo {
127
  /// The Swift type to which a given type is bridged.
128
  ///
129
  /// Reflects the swift_bridge attribute.
130
  llvm::Optional<std::string> SwiftBridge;
131
132
  /// The NS error domain for this type.
133
  llvm::Optional<std::string> NSErrorDomain;
134
135
public:
136
0
  CommonTypeInfo() {}
137
138
0
  const llvm::Optional<std::string> &getSwiftBridge() const {
139
0
    return SwiftBridge;
140
0
  }
141
142
0
  void setSwiftBridge(const llvm::Optional<std::string> &SwiftType) {
143
0
    SwiftBridge = SwiftType;
144
0
  }
145
146
0
  void setSwiftBridge(const llvm::Optional<llvm::StringRef> &SwiftType) {
147
0
    SwiftBridge = SwiftType
148
0
                      ? llvm::Optional<std::string>(std::string(*SwiftType))
149
0
                      : llvm::None;
150
0
  }
151
152
0
  const llvm::Optional<std::string> &getNSErrorDomain() const {
153
0
    return NSErrorDomain;
154
0
  }
155
156
0
  void setNSErrorDomain(const llvm::Optional<std::string> &Domain) {
157
0
    NSErrorDomain = Domain;
158
0
  }
159
160
0
  void setNSErrorDomain(const llvm::Optional<llvm::StringRef> &Domain) {
161
0
    NSErrorDomain =
162
0
        Domain ? llvm::Optional<std::string>(std::string(*Domain)) : llvm::None;
163
0
  }
164
165
  friend bool operator==(const CommonTypeInfo &, const CommonTypeInfo &);
166
167
0
  CommonTypeInfo &operator|=(const CommonTypeInfo &RHS) {
168
0
    // Merge inherited info.
169
0
    static_cast<CommonEntityInfo &>(*this) |= RHS;
170
0
171
0
    if (!SwiftBridge)
172
0
      setSwiftBridge(RHS.getSwiftBridge());
173
0
    if (!NSErrorDomain)
174
0
      setNSErrorDomain(RHS.getNSErrorDomain());
175
0
176
0
    return *this;
177
0
  }
178
179
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
180
};
181
182
0
inline bool operator==(const CommonTypeInfo &LHS, const CommonTypeInfo &RHS) {
183
0
  return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
184
0
         LHS.SwiftBridge == RHS.SwiftBridge &&
185
0
         LHS.NSErrorDomain == RHS.NSErrorDomain;
186
0
}
187
188
0
inline bool operator!=(const CommonTypeInfo &LHS, const CommonTypeInfo &RHS) {
189
0
  return !(LHS == RHS);
190
0
}
191
192
/// Describes API notes data for an Objective-C class or protocol.
193
class ObjCContextInfo : public CommonTypeInfo {
194
  /// Whether this class has a default nullability.
195
  unsigned HasDefaultNullability : 1;
196
197
  /// The default nullability.
198
  unsigned DefaultNullability : 2;
199
200
  /// Whether this class has designated initializers recorded.
201
  unsigned HasDesignatedInits : 1;
202
203
  unsigned SwiftImportAsNonGenericSpecified : 1;
204
  unsigned SwiftImportAsNonGeneric : 1;
205
206
  unsigned SwiftObjCMembersSpecified : 1;
207
  unsigned SwiftObjCMembers : 1;
208
209
public:
210
  ObjCContextInfo()
211
      : HasDefaultNullability(0), DefaultNullability(0), HasDesignatedInits(0),
212
        SwiftImportAsNonGenericSpecified(false), SwiftImportAsNonGeneric(false),
213
0
        SwiftObjCMembersSpecified(false), SwiftObjCMembers(false) {}
214
215
  /// Determine the default nullability for properties and methods of this
216
  /// class.
217
  ///
218
  /// eturns the default nullability, if implied, or None if there is no
219
0
  llvm::Optional<NullabilityKind> getDefaultNullability() const {
220
0
    return HasDefaultNullability
221
0
               ? llvm::Optional<NullabilityKind>(
222
0
                     static_cast<NullabilityKind>(DefaultNullability))
223
0
               : llvm::None;
224
0
  }
225
226
  /// Set the default nullability for properties and methods of this class.
227
0
  void setDefaultNullability(NullabilityKind Kind) {
228
0
    HasDefaultNullability = true;
229
0
    DefaultNullability = static_cast<unsigned>(Kind);
230
0
  }
231
232
0
  bool hasDesignatedInits() const { return HasDesignatedInits; }
233
0
  void setHasDesignatedInits(bool Value) { HasDesignatedInits = Value; }
234
235
0
  llvm::Optional<bool> getSwiftImportAsNonGeneric() const {
236
0
    return SwiftImportAsNonGenericSpecified
237
0
               ? llvm::Optional<bool>(SwiftImportAsNonGeneric)
238
0
               : llvm::None;
239
0
  }
240
0
  void setSwiftImportAsNonGeneric(llvm::Optional<bool> Value) {
241
0
    SwiftImportAsNonGenericSpecified = Value.has_value();
242
0
    SwiftImportAsNonGeneric = Value.value_or(false);
243
0
  }
244
245
0
  llvm::Optional<bool> getSwiftObjCMembers() const {
246
0
    return SwiftObjCMembersSpecified ? llvm::Optional<bool>(SwiftObjCMembers)
247
0
                                     : llvm::None;
248
0
  }
249
0
  void setSwiftObjCMembers(llvm::Optional<bool> Value) {
250
0
    SwiftObjCMembersSpecified = Value.has_value();
251
0
    SwiftObjCMembers = Value.value_or(false);
252
0
  }
253
254
  /// Strip off any information within the class information structure that is
255
  /// module-local, such as 'audited' flags.
256
0
  void stripModuleLocalInfo() {
257
0
    HasDefaultNullability = false;
258
0
    DefaultNullability = 0;
259
0
  }
260
261
  friend bool operator==(const ObjCContextInfo &, const ObjCContextInfo &);
262
263
0
  ObjCContextInfo &operator|=(const ObjCContextInfo &RHS) {
264
0
    // Merge inherited info.
265
0
    static_cast<CommonTypeInfo &>(*this) |= RHS;
266
0
267
0
    // Merge nullability.
268
0
    if (!getDefaultNullability())
269
0
      if (auto Nullability = RHS.getDefaultNullability())
270
0
        setDefaultNullability(*Nullability);
271
0
272
0
    if (!SwiftImportAsNonGenericSpecified)
273
0
      setSwiftImportAsNonGeneric(RHS.getSwiftImportAsNonGeneric());
274
0
275
0
    if (!SwiftObjCMembersSpecified)
276
0
      setSwiftObjCMembers(RHS.getSwiftObjCMembers());
277
0
278
0
    HasDesignatedInits |= RHS.HasDesignatedInits;
279
0
280
0
    return *this;
281
0
  }
282
283
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
284
};
285
286
0
inline bool operator==(const ObjCContextInfo &LHS, const ObjCContextInfo &RHS) {
287
0
  return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
288
0
         LHS.getDefaultNullability() == RHS.getDefaultNullability() &&
289
0
         LHS.HasDesignatedInits == RHS.HasDesignatedInits &&
290
0
         LHS.getSwiftImportAsNonGeneric() == RHS.getSwiftImportAsNonGeneric() &&
291
0
         LHS.getSwiftObjCMembers() == RHS.getSwiftObjCMembers();
292
0
}
293
294
0
inline bool operator!=(const ObjCContextInfo &LHS, const ObjCContextInfo &RHS) {
295
0
  return !(LHS == RHS);
296
0
}
297
298
/// API notes for a variable/property.
299
class VariableInfo : public CommonEntityInfo {
300
  /// Whether this property has been audited for nullability.
301
  unsigned NullabilityAudited : 1;
302
303
  /// The kind of nullability for this property. Only valid if the nullability
304
  /// has been audited.
305
  unsigned Nullable : 2;
306
307
  /// The C type of the variable, as a string.
308
  std::string Type;
309
310
public:
311
0
  VariableInfo() : NullabilityAudited(false), Nullable(0) {}
312
313
0
  llvm::Optional<NullabilityKind> getNullability() const {
314
0
    return NullabilityAudited ? llvm::Optional<NullabilityKind>(
315
0
                                    static_cast<NullabilityKind>(Nullable))
316
0
                              : llvm::None;
317
0
  }
318
319
0
  void setNullabilityAudited(NullabilityKind kind) {
320
0
    NullabilityAudited = true;
321
0
    Nullable = static_cast<unsigned>(kind);
322
0
  }
323
324
0
  const std::string &getType() const { return Type; }
325
0
  void setType(const std::string &type) { Type = type; }
326
327
  friend bool operator==(const VariableInfo &, const VariableInfo &);
328
329
0
  VariableInfo &operator|=(const VariableInfo &RHS) {
330
0
    static_cast<CommonEntityInfo &>(*this) |= RHS;
331
0
332
0
    if (!NullabilityAudited && RHS.NullabilityAudited)
333
0
      setNullabilityAudited(*RHS.getNullability());
334
0
    if (Type.empty())
335
0
      Type = RHS.Type;
336
0
337
0
    return *this;
338
0
  }
339
340
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
341
};
342
343
0
inline bool operator==(const VariableInfo &LHS, const VariableInfo &RHS) {
344
0
  return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
345
0
         LHS.NullabilityAudited == RHS.NullabilityAudited &&
346
0
         LHS.Nullable == RHS.Nullable && LHS.Type == RHS.Type;
347
0
}
348
349
0
inline bool operator!=(const VariableInfo &LHS, const VariableInfo &RHS) {
350
0
  return !(LHS == RHS);
351
0
}
352
353
/// Describes API notes data for an Objective-C property.
354
class ObjCPropertyInfo : public VariableInfo {
355
  unsigned SwiftImportAsAccessorsSpecified : 1;
356
  unsigned SwiftImportAsAccessors : 1;
357
358
public:
359
  ObjCPropertyInfo()
360
0
      : SwiftImportAsAccessorsSpecified(false), SwiftImportAsAccessors(false) {}
361
362
0
  llvm::Optional<bool> getSwiftImportAsAccessors() const {
363
0
    return SwiftImportAsAccessorsSpecified
364
0
               ? llvm::Optional<bool>(SwiftImportAsAccessors)
365
0
               : llvm::None;
366
0
  }
367
0
  void setSwiftImportAsAccessors(llvm::Optional<bool> Value) {
368
0
    SwiftImportAsAccessorsSpecified = Value.has_value();
369
0
    SwiftImportAsAccessors = Value.value_or(false);
370
0
  }
371
372
  friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &);
373
374
  /// Merge class-wide information into the given property.
375
0
  ObjCPropertyInfo &operator|=(const ObjCContextInfo &RHS) {
376
0
    static_cast<CommonEntityInfo &>(*this) |= RHS;
377
0
378
0
    // Merge nullability.
379
0
    if (!getNullability())
380
0
      if (auto Nullable = RHS.getDefaultNullability())
381
0
        setNullabilityAudited(*Nullable);
382
0
383
0
    return *this;
384
0
  }
385
386
0
  ObjCPropertyInfo &operator|=(const ObjCPropertyInfo &RHS) {
387
0
    static_cast<VariableInfo &>(*this) |= RHS;
388
0
389
0
    if (!SwiftImportAsAccessorsSpecified)
390
0
      setSwiftImportAsAccessors(RHS.getSwiftImportAsAccessors());
391
0
392
0
    return *this;
393
0
  }
394
395
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
396
};
397
398
inline bool operator==(const ObjCPropertyInfo &LHS,
399
0
                       const ObjCPropertyInfo &RHS) {
400
0
  return static_cast<const VariableInfo &>(LHS) == RHS &&
401
0
         LHS.getSwiftImportAsAccessors() == RHS.getSwiftImportAsAccessors();
402
0
}
403
404
inline bool operator!=(const ObjCPropertyInfo &LHS,
405
0
                       const ObjCPropertyInfo &RHS) {
406
0
  return !(LHS == RHS);
407
0
}
408
409
/// Describes a function or method parameter.
410
class ParamInfo : public VariableInfo {
411
  /// Whether noescape was specified.
412
  unsigned NoEscapeSpecified : 1;
413
414
  /// Whether the this parameter has the 'noescape' attribute.
415
  unsigned NoEscape : 1;
416
417
  /// A biased RetainCountConventionKind, where 0 means "unspecified".
418
  ///
419
  /// Only relevant for out-parameters.
420
  unsigned RawRetainCountConvention : 3;
421
422
public:
423
  ParamInfo()
424
0
      : NoEscapeSpecified(false), NoEscape(false), RawRetainCountConvention() {}
425
426
0
  llvm::Optional<bool> isNoEscape() const {
427
0
    if (!NoEscapeSpecified)
428
0
      return llvm::None;
429
0
    return NoEscape;
430
0
  }
431
0
  void setNoEscape(llvm::Optional<bool> Value) {
432
0
    NoEscapeSpecified = Value.has_value();
433
0
    NoEscape = Value.value_or(false);
434
0
  }
435
436
0
  llvm::Optional<RetainCountConventionKind> getRetainCountConvention() const {
437
0
    if (!RawRetainCountConvention)
438
0
      return llvm::None;
439
0
    return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
440
0
  }
441
  void
442
0
  setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
443
0
    RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
444
0
    assert(getRetainCountConvention() == Value && "bitfield too small");
445
0
  }
446
447
0
  ParamInfo &operator|=(const ParamInfo &RHS) {
448
0
    static_cast<VariableInfo &>(*this) |= RHS;
449
0
450
0
    if (!NoEscapeSpecified && RHS.NoEscapeSpecified) {
451
0
      NoEscapeSpecified = true;
452
0
      NoEscape = RHS.NoEscape;
453
0
    }
454
0
455
0
    if (!RawRetainCountConvention)
456
0
      RawRetainCountConvention = RHS.RawRetainCountConvention;
457
0
458
0
    return *this;
459
0
  }
460
461
  friend bool operator==(const ParamInfo &, const ParamInfo &);
462
463
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
464
};
465
466
0
inline bool operator==(const ParamInfo &LHS, const ParamInfo &RHS) {
467
0
  return static_cast<const VariableInfo &>(LHS) == RHS &&
468
0
         LHS.NoEscapeSpecified == RHS.NoEscapeSpecified &&
469
0
         LHS.NoEscape == RHS.NoEscape &&
470
0
         LHS.RawRetainCountConvention == RHS.RawRetainCountConvention;
471
0
}
472
473
0
inline bool operator!=(const ParamInfo &LHS, const ParamInfo &RHS) {
474
0
  return !(LHS == RHS);
475
0
}
476
477
/// API notes for a function or method.
478
class FunctionInfo : public CommonEntityInfo {
479
private:
480
  static constexpr const unsigned NullabilityKindMask = 0x3;
481
  static constexpr const unsigned NullabilityKindSize = 2;
482
483
  static constexpr const unsigned ReturnInfoIndex = 0;
484
485
public:
486
  // If yes, we consider all types to be non-nullable unless otherwise noted.
487
  // If this flag is not set, the pointer types are considered to have
488
  // unknown nullability.
489
490
  /// Whether the signature has been audited with respect to nullability.
491
  unsigned NullabilityAudited : 1;
492
493
  /// Number of types whose nullability is encoded with the NullabilityPayload.
494
  unsigned NumAdjustedNullable : 8;
495
496
  /// A biased RetainCountConventionKind, where 0 means "unspecified".
497
  unsigned RawRetainCountConvention : 3;
498
499
  // NullabilityKindSize bits are used to encode the nullability. The info
500
  // about the return type is stored at position 0, followed by the nullability
501
  // of the parameters.
502
503
  /// Stores the nullability of the return type and the parameters.
504
  uint64_t NullabilityPayload = 0;
505
506
  /// The result type of this function, as a C type.
507
  std::string ResultType;
508
509
  /// The function parameters.
510
  std::vector<ParamInfo> Params;
511
512
  FunctionInfo()
513
      : NullabilityAudited(false), NumAdjustedNullable(0),
514
0
        RawRetainCountConvention() {}
515
516
0
  static unsigned getMaxNullabilityIndex() {
517
0
    return ((sizeof(NullabilityPayload) * CHAR_BIT) / NullabilityKindSize);
518
0
  }
519
520
0
  void addTypeInfo(unsigned index, NullabilityKind kind) {
521
0
    assert(index <= getMaxNullabilityIndex());
522
0
    assert(static_cast<unsigned>(kind) < NullabilityKindMask);
523
0
524
0
    NullabilityAudited = true;
525
0
    if (NumAdjustedNullable < index + 1)
526
0
      NumAdjustedNullable = index + 1;
527
0
528
0
    // Mask the bits.
529
0
    NullabilityPayload &=
530
0
        ~(NullabilityKindMask << (index * NullabilityKindSize));
531
0
532
0
    // Set the value.
533
0
    unsigned kindValue = (static_cast<unsigned>(kind))
534
0
                         << (index * NullabilityKindSize);
535
0
    NullabilityPayload |= kindValue;
536
0
  }
537
538
  /// Adds the return type info.
539
0
  void addReturnTypeInfo(NullabilityKind kind) {
540
0
    addTypeInfo(ReturnInfoIndex, kind);
541
0
  }
542
543
  /// Adds the parameter type info.
544
0
  void addParamTypeInfo(unsigned index, NullabilityKind kind) {
545
0
    addTypeInfo(index + 1, kind);
546
0
  }
547
548
0
  NullabilityKind getParamTypeInfo(unsigned index) const {
549
0
    return getTypeInfo(index + 1);
550
0
  }
551
552
0
  NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
553
554
0
  llvm::Optional<RetainCountConventionKind> getRetainCountConvention() const {
555
0
    if (!RawRetainCountConvention)
556
0
      return llvm::None;
557
0
    return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
558
0
  }
559
  void
560
0
  setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
561
0
    RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
562
0
    assert(getRetainCountConvention() == Value && "bitfield too small");
563
0
  }
564
565
  friend bool operator==(const FunctionInfo &, const FunctionInfo &);
566
567
private:
568
0
  NullabilityKind getTypeInfo(unsigned index) const {
569
0
    assert(NullabilityAudited &&
570
0
           "Checking the type adjustment on non-audited method.");
571
0
572
0
    // If we don't have info about this parameter, return the default.
573
0
    if (index > NumAdjustedNullable)
574
0
      return NullabilityKind::NonNull;
575
0
    auto nullability = NullabilityPayload >> (index * NullabilityKindSize);
576
0
    return static_cast<NullabilityKind>(nullability & NullabilityKindMask);
577
0
  }
578
579
public:
580
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
581
};
582
583
0
inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS) {
584
0
  return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
585
0
         LHS.NullabilityAudited == RHS.NullabilityAudited &&
586
0
         LHS.NumAdjustedNullable == RHS.NumAdjustedNullable &&
587
0
         LHS.NullabilityPayload == RHS.NullabilityPayload &&
588
0
         LHS.ResultType == RHS.ResultType && LHS.Params == RHS.Params &&
589
0
         LHS.RawRetainCountConvention == RHS.RawRetainCountConvention;
590
0
}
591
592
0
inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
593
0
  return !(LHS == RHS);
594
0
}
595
596
/// Describes API notes data for an Objective-C method.
597
class ObjCMethodInfo : public FunctionInfo {
598
public:
599
  /// Whether this is a designated initializer of its class.
600
  unsigned DesignatedInit : 1;
601
602
  /// Whether this is a required initializer.
603
  unsigned RequiredInit : 1;
604
605
0
  ObjCMethodInfo() : DesignatedInit(false), RequiredInit(false) {}
606
607
  friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
608
609
0
  ObjCMethodInfo &operator|=(const ObjCContextInfo &RHS) {
610
0
    // Merge Nullability.
611
0
    if (!NullabilityAudited) {
612
0
      if (auto Nullable = RHS.getDefaultNullability()) {
613
0
        NullabilityAudited = true;
614
0
        addTypeInfo(0, *Nullable);
615
0
      }
616
0
    }
617
0
    return *this;
618
0
  }
619
620
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
621
};
622
623
0
inline bool operator==(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
624
0
  return static_cast<const FunctionInfo &>(LHS) == RHS &&
625
0
         LHS.DesignatedInit == RHS.DesignatedInit &&
626
0
         LHS.RequiredInit == RHS.RequiredInit;
627
0
}
628
629
0
inline bool operator!=(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
630
0
  return !(LHS == RHS);
631
0
}
632
633
/// Describes API notes data for a global variable.
634
class GlobalVariableInfo : public VariableInfo {
635
public:
636
0
  GlobalVariableInfo() {}
637
};
638
639
/// Describes API notes data for a global function.
640
class GlobalFunctionInfo : public FunctionInfo {
641
public:
642
0
  GlobalFunctionInfo() {}
643
};
644
645
/// Describes API notes data for an enumerator.
646
class EnumConstantInfo : public CommonEntityInfo {
647
public:
648
0
  EnumConstantInfo() {}
649
};
650
651
/// Describes API notes data for a tag.
652
class TagInfo : public CommonTypeInfo {
653
  unsigned HasFlagEnum : 1;
654
  unsigned IsFlagEnum : 1;
655
656
public:
657
  llvm::Optional<EnumExtensibilityKind> EnumExtensibility;
658
659
0
  TagInfo() : HasFlagEnum(0), IsFlagEnum(0) {}
660
661
0
  llvm::Optional<bool> isFlagEnum() const {
662
0
    if (HasFlagEnum)
663
0
      return IsFlagEnum;
664
0
    return llvm::None;
665
0
  }
666
0
  void setFlagEnum(llvm::Optional<bool> Value) {
667
0
    HasFlagEnum = Value.has_value();
668
0
    IsFlagEnum = Value.value_or(false);
669
0
  }
670
671
0
  TagInfo &operator|=(const TagInfo &RHS) {
672
0
    static_cast<CommonTypeInfo &>(*this) |= RHS;
673
0
674
0
    if (!HasFlagEnum)
675
0
      setFlagEnum(RHS.isFlagEnum());
676
0
677
0
    if (!EnumExtensibility)
678
0
      EnumExtensibility = RHS.EnumExtensibility;
679
0
680
0
    return *this;
681
0
  }
682
683
  friend bool operator==(const TagInfo &, const TagInfo &);
684
685
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
686
};
687
688
0
inline bool operator==(const TagInfo &LHS, const TagInfo &RHS) {
689
0
  return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
690
0
         LHS.isFlagEnum() == RHS.isFlagEnum() &&
691
0
         LHS.EnumExtensibility == RHS.EnumExtensibility;
692
0
}
693
694
0
inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
695
0
  return !(LHS == RHS);
696
0
}
697
698
/// Describes API notes data for a typedef.
699
class TypedefInfo : public CommonTypeInfo {
700
public:
701
  llvm::Optional<SwiftNewTypeKind> SwiftWrapper;
702
703
0
  TypedefInfo() {}
704
705
0
  TypedefInfo &operator|=(const TypedefInfo &RHS) {
706
0
    static_cast<CommonTypeInfo &>(*this) |= RHS;
707
0
    if (!SwiftWrapper)
708
0
      SwiftWrapper = RHS.SwiftWrapper;
709
0
    return *this;
710
0
  }
711
712
  friend bool operator==(const TypedefInfo &, const TypedefInfo &);
713
714
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
715
};
716
717
0
inline bool operator==(const TypedefInfo &LHS, const TypedefInfo &RHS) {
718
0
  return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
719
0
         LHS.SwiftWrapper == RHS.SwiftWrapper;
720
0
}
721
722
0
inline bool operator!=(const TypedefInfo &LHS, const TypedefInfo &RHS) {
723
0
  return !(LHS == RHS);
724
0
}
725
} // namespace api_notes
726
} // namespace clang
727
728
#endif