Coverage Report

Created: 2022-05-17 06:19

/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.hasValue();
80
0
    SwiftPrivate = Private.hasValue() ? *Private : 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.hasValue();
242
0
    SwiftImportAsNonGeneric = Value.getValueOr(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.hasValue();
251
0
    SwiftObjCMembers = Value.getValueOr(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.hasValue();
369
0
    SwiftImportAsAccessors = Value.getValueOr(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.hasValue();
433
0
    NoEscape = Value.getValueOr(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 =
444
0
        Value.hasValue() ? static_cast<unsigned>(Value.getValue()) + 1 : 0;
445
0
    assert(getRetainCountConvention() == Value && "bitfield too small");
446
0
  }
447
448
0
  ParamInfo &operator|=(const ParamInfo &RHS) {
449
0
    static_cast<VariableInfo &>(*this) |= RHS;
450
0
451
0
    if (!NoEscapeSpecified && RHS.NoEscapeSpecified) {
452
0
      NoEscapeSpecified = true;
453
0
      NoEscape = RHS.NoEscape;
454
0
    }
455
0
456
0
    if (!RawRetainCountConvention)
457
0
      RawRetainCountConvention = RHS.RawRetainCountConvention;
458
0
459
0
    return *this;
460
0
  }
461
462
  friend bool operator==(const ParamInfo &, const ParamInfo &);
463
464
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
465
};
466
467
0
inline bool operator==(const ParamInfo &LHS, const ParamInfo &RHS) {
468
0
  return static_cast<const VariableInfo &>(LHS) == RHS &&
469
0
         LHS.NoEscapeSpecified == RHS.NoEscapeSpecified &&
470
0
         LHS.NoEscape == RHS.NoEscape &&
471
0
         LHS.RawRetainCountConvention == RHS.RawRetainCountConvention;
472
0
}
473
474
0
inline bool operator!=(const ParamInfo &LHS, const ParamInfo &RHS) {
475
0
  return !(LHS == RHS);
476
0
}
477
478
/// API notes for a function or method.
479
class FunctionInfo : public CommonEntityInfo {
480
private:
481
  static constexpr const unsigned NullabilityKindMask = 0x3;
482
  static constexpr const unsigned NullabilityKindSize = 2;
483
484
  static constexpr const unsigned ReturnInfoIndex = 0;
485
486
public:
487
  // If yes, we consider all types to be non-nullable unless otherwise noted.
488
  // If this flag is not set, the pointer types are considered to have
489
  // unknown nullability.
490
491
  /// Whether the signature has been audited with respect to nullability.
492
  unsigned NullabilityAudited : 1;
493
494
  /// Number of types whose nullability is encoded with the NullabilityPayload.
495
  unsigned NumAdjustedNullable : 8;
496
497
  /// A biased RetainCountConventionKind, where 0 means "unspecified".
498
  unsigned RawRetainCountConvention : 3;
499
500
  // NullabilityKindSize bits are used to encode the nullability. The info
501
  // about the return type is stored at position 0, followed by the nullability
502
  // of the parameters.
503
504
  /// Stores the nullability of the return type and the parameters.
505
  uint64_t NullabilityPayload = 0;
506
507
  /// The result type of this function, as a C type.
508
  std::string ResultType;
509
510
  /// The function parameters.
511
  std::vector<ParamInfo> Params;
512
513
  FunctionInfo()
514
      : NullabilityAudited(false), NumAdjustedNullable(0),
515
0
        RawRetainCountConvention() {}
516
517
0
  static unsigned getMaxNullabilityIndex() {
518
0
    return ((sizeof(NullabilityPayload) * CHAR_BIT) / NullabilityKindSize);
519
0
  }
520
521
0
  void addTypeInfo(unsigned index, NullabilityKind kind) {
522
0
    assert(index <= getMaxNullabilityIndex());
523
0
    assert(static_cast<unsigned>(kind) < NullabilityKindMask);
524
0
525
0
    NullabilityAudited = true;
526
0
    if (NumAdjustedNullable < index + 1)
527
0
      NumAdjustedNullable = index + 1;
528
0
529
0
    // Mask the bits.
530
0
    NullabilityPayload &=
531
0
        ~(NullabilityKindMask << (index * NullabilityKindSize));
532
0
533
0
    // Set the value.
534
0
    unsigned kindValue = (static_cast<unsigned>(kind))
535
0
                         << (index * NullabilityKindSize);
536
0
    NullabilityPayload |= kindValue;
537
0
  }
538
539
  /// Adds the return type info.
540
0
  void addReturnTypeInfo(NullabilityKind kind) {
541
0
    addTypeInfo(ReturnInfoIndex, kind);
542
0
  }
543
544
  /// Adds the parameter type info.
545
0
  void addParamTypeInfo(unsigned index, NullabilityKind kind) {
546
0
    addTypeInfo(index + 1, kind);
547
0
  }
548
549
0
  NullabilityKind getParamTypeInfo(unsigned index) const {
550
0
    return getTypeInfo(index + 1);
551
0
  }
552
553
0
  NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
554
555
0
  llvm::Optional<RetainCountConventionKind> getRetainCountConvention() const {
556
0
    if (!RawRetainCountConvention)
557
0
      return llvm::None;
558
0
    return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
559
0
  }
560
  void
561
0
  setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
562
0
    RawRetainCountConvention =
563
0
        Value.hasValue() ? static_cast<unsigned>(Value.getValue()) + 1 : 0;
564
0
    assert(getRetainCountConvention() == Value && "bitfield too small");
565
0
  }
566
567
  friend bool operator==(const FunctionInfo &, const FunctionInfo &);
568
569
private:
570
0
  NullabilityKind getTypeInfo(unsigned index) const {
571
0
    assert(NullabilityAudited &&
572
0
           "Checking the type adjustment on non-audited method.");
573
0
574
0
    // If we don't have info about this parameter, return the default.
575
0
    if (index > NumAdjustedNullable)
576
0
      return NullabilityKind::NonNull;
577
0
    auto nullability = NullabilityPayload >> (index * NullabilityKindSize);
578
0
    return static_cast<NullabilityKind>(nullability & NullabilityKindMask);
579
0
  }
580
581
public:
582
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
583
};
584
585
0
inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS) {
586
0
  return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
587
0
         LHS.NullabilityAudited == RHS.NullabilityAudited &&
588
0
         LHS.NumAdjustedNullable == RHS.NumAdjustedNullable &&
589
0
         LHS.NullabilityPayload == RHS.NullabilityPayload &&
590
0
         LHS.ResultType == RHS.ResultType && LHS.Params == RHS.Params &&
591
0
         LHS.RawRetainCountConvention == RHS.RawRetainCountConvention;
592
0
}
593
594
0
inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
595
0
  return !(LHS == RHS);
596
0
}
597
598
/// Describes API notes data for an Objective-C method.
599
class ObjCMethodInfo : public FunctionInfo {
600
public:
601
  /// Whether this is a designated initializer of its class.
602
  unsigned DesignatedInit : 1;
603
604
  /// Whether this is a required initializer.
605
  unsigned RequiredInit : 1;
606
607
0
  ObjCMethodInfo() : DesignatedInit(false), RequiredInit(false) {}
608
609
  friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
610
611
0
  ObjCMethodInfo &operator|=(const ObjCContextInfo &RHS) {
612
0
    // Merge Nullability.
613
0
    if (!NullabilityAudited) {
614
0
      if (auto Nullable = RHS.getDefaultNullability()) {
615
0
        NullabilityAudited = true;
616
0
        addTypeInfo(0, *Nullable);
617
0
      }
618
0
    }
619
0
    return *this;
620
0
  }
621
622
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
623
};
624
625
0
inline bool operator==(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
626
0
  return static_cast<const FunctionInfo &>(LHS) == RHS &&
627
0
         LHS.DesignatedInit == RHS.DesignatedInit &&
628
0
         LHS.RequiredInit == RHS.RequiredInit;
629
0
}
630
631
0
inline bool operator!=(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
632
0
  return !(LHS == RHS);
633
0
}
634
635
/// Describes API notes data for a global variable.
636
class GlobalVariableInfo : public VariableInfo {
637
public:
638
0
  GlobalVariableInfo() {}
639
};
640
641
/// Describes API notes data for a global function.
642
class GlobalFunctionInfo : public FunctionInfo {
643
public:
644
0
  GlobalFunctionInfo() {}
645
};
646
647
/// Describes API notes data for an enumerator.
648
class EnumConstantInfo : public CommonEntityInfo {
649
public:
650
0
  EnumConstantInfo() {}
651
};
652
653
/// Describes API notes data for a tag.
654
class TagInfo : public CommonTypeInfo {
655
  unsigned HasFlagEnum : 1;
656
  unsigned IsFlagEnum : 1;
657
658
public:
659
  llvm::Optional<EnumExtensibilityKind> EnumExtensibility;
660
661
0
  TagInfo() : HasFlagEnum(0), IsFlagEnum(0) {}
662
663
0
  llvm::Optional<bool> isFlagEnum() const {
664
0
    if (HasFlagEnum)
665
0
      return IsFlagEnum;
666
0
    return llvm::None;
667
0
  }
668
0
  void setFlagEnum(llvm::Optional<bool> Value) {
669
0
    HasFlagEnum = Value.hasValue();
670
0
    IsFlagEnum = Value.getValueOr(false);
671
0
  }
672
673
0
  TagInfo &operator|=(const TagInfo &RHS) {
674
0
    static_cast<CommonTypeInfo &>(*this) |= RHS;
675
0
676
0
    if (!HasFlagEnum && HasFlagEnum)
677
0
      setFlagEnum(RHS.isFlagEnum());
678
0
679
0
    if (!EnumExtensibility.hasValue())
680
0
      EnumExtensibility = RHS.EnumExtensibility;
681
0
682
0
    return *this;
683
0
  }
684
685
  friend bool operator==(const TagInfo &, const TagInfo &);
686
687
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
688
};
689
690
0
inline bool operator==(const TagInfo &LHS, const TagInfo &RHS) {
691
0
  return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
692
0
         LHS.isFlagEnum() == RHS.isFlagEnum() &&
693
0
         LHS.EnumExtensibility == RHS.EnumExtensibility;
694
0
}
695
696
0
inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
697
0
  return !(LHS == RHS);
698
0
}
699
700
/// Describes API notes data for a typedef.
701
class TypedefInfo : public CommonTypeInfo {
702
public:
703
  llvm::Optional<SwiftNewTypeKind> SwiftWrapper;
704
705
0
  TypedefInfo() {}
706
707
0
  TypedefInfo &operator|=(const TypedefInfo &RHS) {
708
0
    static_cast<CommonTypeInfo &>(*this) |= RHS;
709
0
    if (!SwiftWrapper.hasValue())
710
0
      SwiftWrapper = RHS.SwiftWrapper;
711
0
    return *this;
712
0
  }
713
714
  friend bool operator==(const TypedefInfo &, const TypedefInfo &);
715
716
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
717
};
718
719
0
inline bool operator==(const TypedefInfo &LHS, const TypedefInfo &RHS) {
720
0
  return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
721
0
         LHS.SwiftWrapper == RHS.SwiftWrapper;
722
0
}
723
724
0
inline bool operator!=(const TypedefInfo &LHS, const TypedefInfo &RHS) {
725
0
  return !(LHS == RHS);
726
0
}
727
} // namespace api_notes
728
} // namespace clang
729
730
#endif