Coverage Report

Created: 2021-01-19 06:58

/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() : CommonEntityInfo() {}
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
      : CommonTypeInfo(), HasDefaultNullability(0), DefaultNullability(0),
212
        HasDesignatedInits(0), SwiftImportAsNonGenericSpecified(false),
213
        SwiftImportAsNonGeneric(false), SwiftObjCMembersSpecified(false),
214
0
        SwiftObjCMembers(false) {}
215
216
  /// Determine the default nullability for properties and methods of this
217
  /// class.
218
  ///
219
  /// eturns the default nullability, if implied, or None if there is no
220
0
  llvm::Optional<NullabilityKind> getDefaultNullability() const {
221
0
    return HasDefaultNullability
222
0
               ? llvm::Optional<NullabilityKind>(
223
0
                     static_cast<NullabilityKind>(DefaultNullability))
224
0
               : llvm::None;
225
0
  }
226
227
  /// Set the default nullability for properties and methods of this class.
228
0
  void setDefaultNullability(NullabilityKind Kind) {
229
0
    HasDefaultNullability = true;
230
0
    DefaultNullability = static_cast<unsigned>(Kind);
231
0
  }
232
233
0
  bool hasDesignatedInits() const { return HasDesignatedInits; }
234
0
  void setHasDesignatedInits(bool Value) { HasDesignatedInits = Value; }
235
236
0
  llvm::Optional<bool> getSwiftImportAsNonGeneric() const {
237
0
    return SwiftImportAsNonGenericSpecified
238
0
               ? llvm::Optional<bool>(SwiftImportAsNonGeneric)
239
0
               : llvm::None;
240
0
  }
241
0
  void setSwiftImportAsNonGeneric(llvm::Optional<bool> Value) {
242
0
    SwiftImportAsNonGenericSpecified = Value.hasValue();
243
0
    SwiftImportAsNonGeneric = Value.hasValue() ? *Value : false;
244
0
  }
245
246
0
  llvm::Optional<bool> getSwiftObjCMembers() const {
247
0
    return SwiftObjCMembersSpecified ? llvm::Optional<bool>(SwiftObjCMembers)
248
0
                                     : llvm::None;
249
0
  }
250
0
  void setSwiftObjCMembers(llvm::Optional<bool> Value) {
251
0
    SwiftObjCMembersSpecified = Value.hasValue();
252
0
    SwiftObjCMembers = Value.hasValue() ? *Value : false;
253
0
  }
254
255
  /// Strip off any information within the class information structure that is
256
  /// module-local, such as 'audited' flags.
257
0
  void stripModuleLocalInfo() {
258
0
    HasDefaultNullability = false;
259
0
    DefaultNullability = 0;
260
0
  }
261
262
  friend bool operator==(const ObjCContextInfo &, const ObjCContextInfo &);
263
264
0
  ObjCContextInfo &operator|=(const ObjCContextInfo &RHS) {
265
0
    // Merge inherited info.
266
0
    static_cast<CommonTypeInfo &>(*this) |= RHS;
267
0
268
0
    // Merge nullability.
269
0
    if (!getDefaultNullability())
270
0
      if (auto Nullability = RHS.getDefaultNullability())
271
0
        setDefaultNullability(*Nullability);
272
0
273
0
    if (!SwiftImportAsNonGenericSpecified)
274
0
      setSwiftImportAsNonGeneric(RHS.getSwiftImportAsNonGeneric());
275
0
276
0
    if (!SwiftObjCMembersSpecified)
277
0
      setSwiftObjCMembers(RHS.getSwiftObjCMembers());
278
0
279
0
    HasDesignatedInits |= RHS.HasDesignatedInits;
280
0
281
0
    return *this;
282
0
  }
283
284
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
285
};
286
287
0
inline bool operator==(const ObjCContextInfo &LHS, const ObjCContextInfo &RHS) {
288
0
  return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
289
0
         LHS.getDefaultNullability() == RHS.getDefaultNullability() &&
290
0
         LHS.HasDesignatedInits == RHS.HasDesignatedInits &&
291
0
         LHS.getSwiftImportAsNonGeneric() == RHS.getSwiftImportAsNonGeneric() &&
292
0
         LHS.getSwiftObjCMembers() == RHS.getSwiftObjCMembers();
293
0
}
294
295
0
inline bool operator!=(const ObjCContextInfo &LHS, const ObjCContextInfo &RHS) {
296
0
  return !(LHS == RHS);
297
0
}
298
299
/// API notes for a variable/property.
300
class VariableInfo : public CommonEntityInfo {
301
  /// Whether this property has been audited for nullability.
302
  unsigned NullabilityAudited : 1;
303
304
  /// The kind of nullability for this property. Only valid if the nullability
305
  /// has been audited.
306
  unsigned Nullable : 2;
307
308
  /// The C type of the variable, as a string.
309
  std::string Type;
310
311
public:
312
0
  VariableInfo() : CommonEntityInfo(), NullabilityAudited(false), Nullable(0) {}
313
314
0
  llvm::Optional<NullabilityKind> getNullability() const {
315
0
    return NullabilityAudited ? llvm::Optional<NullabilityKind>(
316
0
                                    static_cast<NullabilityKind>(Nullable))
317
0
                              : llvm::None;
318
0
  }
319
320
0
  void setNullabilityAudited(NullabilityKind kind) {
321
0
    NullabilityAudited = true;
322
0
    Nullable = static_cast<unsigned>(kind);
323
0
  }
324
325
0
  const std::string &getType() const { return Type; }
326
0
  void setType(const std::string &type) { Type = type; }
327
328
  friend bool operator==(const VariableInfo &, const VariableInfo &);
329
330
0
  VariableInfo &operator|=(const VariableInfo &RHS) {
331
0
    static_cast<CommonEntityInfo &>(*this) |= RHS;
332
0
333
0
    if (!NullabilityAudited && RHS.NullabilityAudited)
334
0
      setNullabilityAudited(*RHS.getNullability());
335
0
    if (Type.empty())
336
0
      Type = RHS.Type;
337
0
338
0
    return *this;
339
0
  }
340
341
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
342
};
343
344
0
inline bool operator==(const VariableInfo &LHS, const VariableInfo &RHS) {
345
0
  return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
346
0
         LHS.NullabilityAudited == RHS.NullabilityAudited &&
347
0
         LHS.Nullable == RHS.Nullable && LHS.Type == RHS.Type;
348
0
}
349
350
0
inline bool operator!=(const VariableInfo &LHS, const VariableInfo &RHS) {
351
0
  return !(LHS == RHS);
352
0
}
353
354
/// Describes API notes data for an Objective-C property.
355
class ObjCPropertyInfo : public VariableInfo {
356
  unsigned SwiftImportAsAccessorsSpecified : 1;
357
  unsigned SwiftImportAsAccessors : 1;
358
359
public:
360
  ObjCPropertyInfo()
361
      : VariableInfo(), SwiftImportAsAccessorsSpecified(false),
362
0
        SwiftImportAsAccessors(false) {}
363
364
0
  llvm::Optional<bool> getSwiftImportAsAccessors() const {
365
0
    return SwiftImportAsAccessorsSpecified
366
0
               ? llvm::Optional<bool>(SwiftImportAsAccessors)
367
0
               : llvm::None;
368
0
  }
369
0
  void setSwiftImportAsAccessors(llvm::Optional<bool> Value) {
370
0
    SwiftImportAsAccessorsSpecified = Value.hasValue();
371
0
    SwiftImportAsAccessors = Value.hasValue() ? *Value : false;
372
0
  }
373
374
  friend bool operator==(const ObjCPropertyInfo &, const ObjCPropertyInfo &);
375
376
  /// Merge class-wide information into the given property.
377
0
  ObjCPropertyInfo &operator|=(const ObjCContextInfo &RHS) {
378
0
    static_cast<CommonEntityInfo &>(*this) |= RHS;
379
0
380
0
    // Merge nullability.
381
0
    if (!getNullability())
382
0
      if (auto Nullable = RHS.getDefaultNullability())
383
0
        setNullabilityAudited(*Nullable);
384
0
385
0
    return *this;
386
0
  }
387
388
0
  ObjCPropertyInfo &operator|=(const ObjCPropertyInfo &RHS) {
389
0
    static_cast<VariableInfo &>(*this) |= RHS;
390
0
391
0
    if (!SwiftImportAsAccessorsSpecified)
392
0
      setSwiftImportAsAccessors(RHS.getSwiftImportAsAccessors());
393
0
394
0
    return *this;
395
0
  }
396
397
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
398
};
399
400
inline bool operator==(const ObjCPropertyInfo &LHS,
401
0
                       const ObjCPropertyInfo &RHS) {
402
0
  return static_cast<const VariableInfo &>(LHS) == RHS &&
403
0
         LHS.getSwiftImportAsAccessors() == RHS.getSwiftImportAsAccessors();
404
0
}
405
406
inline bool operator!=(const ObjCPropertyInfo &LHS,
407
0
                       const ObjCPropertyInfo &RHS) {
408
0
  return !(LHS == RHS);
409
0
}
410
411
/// Describes a function or method parameter.
412
class ParamInfo : public VariableInfo {
413
  /// Whether noescape was specified.
414
  unsigned NoEscapeSpecified : 1;
415
416
  /// Whether the this parameter has the 'noescape' attribute.
417
  unsigned NoEscape : 1;
418
419
  /// A biased RetainCountConventionKind, where 0 means "unspecified".
420
  ///
421
  /// Only relevant for out-parameters.
422
  unsigned RawRetainCountConvention : 3;
423
424
public:
425
  ParamInfo()
426
      : VariableInfo(), NoEscapeSpecified(false), NoEscape(false),
427
0
        RawRetainCountConvention() {}
428
429
0
  llvm::Optional<bool> isNoEscape() const {
430
0
    if (!NoEscapeSpecified)
431
0
      return llvm::None;
432
0
    return NoEscape;
433
0
  }
434
0
  void setNoEscape(llvm::Optional<bool> Value) {
435
0
    NoEscapeSpecified = Value.hasValue();
436
0
    NoEscape = Value.hasValue() ? *Value : false;
437
0
  }
438
439
0
  llvm::Optional<RetainCountConventionKind> getRetainCountConvention() const {
440
0
    if (!RawRetainCountConvention)
441
0
      return llvm::None;
442
0
    return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
443
0
  }
444
  void
445
0
  setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
446
0
    RawRetainCountConvention =
447
0
        Value.hasValue() ? static_cast<unsigned>(Value.getValue()) + 1 : 0;
448
0
    assert(getRetainCountConvention() == Value && "bitfield too small");
449
0
  }
450
451
0
  ParamInfo &operator|=(const ParamInfo &RHS) {
452
0
    static_cast<VariableInfo &>(*this) |= RHS;
453
0
454
0
    if (!NoEscapeSpecified && RHS.NoEscapeSpecified) {
455
0
      NoEscapeSpecified = true;
456
0
      NoEscape = RHS.NoEscape;
457
0
    }
458
0
459
0
    if (!RawRetainCountConvention)
460
0
      RawRetainCountConvention = RHS.RawRetainCountConvention;
461
0
462
0
    return *this;
463
0
  }
464
465
  friend bool operator==(const ParamInfo &, const ParamInfo &);
466
467
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
468
};
469
470
0
inline bool operator==(const ParamInfo &LHS, const ParamInfo &RHS) {
471
0
  return static_cast<const VariableInfo &>(LHS) == RHS &&
472
0
         LHS.NoEscapeSpecified == RHS.NoEscapeSpecified &&
473
0
         LHS.NoEscape == RHS.NoEscape &&
474
0
         LHS.RawRetainCountConvention == RHS.RawRetainCountConvention;
475
0
}
476
477
0
inline bool operator!=(const ParamInfo &LHS, const ParamInfo &RHS) {
478
0
  return !(LHS == RHS);
479
0
}
480
481
/// API notes for a function or method.
482
class FunctionInfo : public CommonEntityInfo {
483
private:
484
  static constexpr const unsigned NullabilityKindMask = 0x3;
485
  static constexpr const unsigned NullabilityKindSize = 2;
486
487
  static constexpr const unsigned ReturnInfoIndex = 0;
488
489
public:
490
  // If yes, we consider all types to be non-nullable unless otherwise noted.
491
  // If this flag is not set, the pointer types are considered to have
492
  // unknown nullability.
493
494
  /// Whether the signature has been audited with respect to nullability.
495
  unsigned NullabilityAudited : 1;
496
497
  /// Number of types whose nullability is encoded with the NullabilityPayload.
498
  unsigned NumAdjustedNullable : 8;
499
500
  /// A biased RetainCountConventionKind, where 0 means "unspecified".
501
  unsigned RawRetainCountConvention : 3;
502
503
  // NullabilityKindSize bits are used to encode the nullability. The info
504
  // about the return type is stored at position 0, followed by the nullability
505
  // of the parameters.
506
507
  /// Stores the nullability of the return type and the parameters.
508
  uint64_t NullabilityPayload = 0;
509
510
  /// The result type of this function, as a C type.
511
  std::string ResultType;
512
513
  /// The function parameters.
514
  std::vector<ParamInfo> Params;
515
516
  FunctionInfo()
517
      : CommonEntityInfo(), NullabilityAudited(false), NumAdjustedNullable(0),
518
0
        RawRetainCountConvention() {}
519
520
0
  static unsigned getMaxNullabilityIndex() {
521
0
    return ((sizeof(NullabilityPayload) * CHAR_BIT) / NullabilityKindSize);
522
0
  }
523
524
0
  void addTypeInfo(unsigned index, NullabilityKind kind) {
525
0
    assert(index <= getMaxNullabilityIndex());
526
0
    assert(static_cast<unsigned>(kind) < NullabilityKindMask);
527
0
528
0
    NullabilityAudited = true;
529
0
    if (NumAdjustedNullable < index + 1)
530
0
      NumAdjustedNullable = index + 1;
531
0
532
0
    // Mask the bits.
533
0
    NullabilityPayload &=
534
0
        ~(NullabilityKindMask << (index * NullabilityKindSize));
535
0
536
0
    // Set the value.
537
0
    unsigned kindValue = (static_cast<unsigned>(kind))
538
0
                         << (index * NullabilityKindSize);
539
0
    NullabilityPayload |= kindValue;
540
0
  }
541
542
  /// Adds the return type info.
543
0
  void addReturnTypeInfo(NullabilityKind kind) {
544
0
    addTypeInfo(ReturnInfoIndex, kind);
545
0
  }
546
547
  /// Adds the parameter type info.
548
0
  void addParamTypeInfo(unsigned index, NullabilityKind kind) {
549
0
    addTypeInfo(index + 1, kind);
550
0
  }
551
552
0
  NullabilityKind getParamTypeInfo(unsigned index) const {
553
0
    return getTypeInfo(index + 1);
554
0
  }
555
556
0
  NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
557
558
0
  llvm::Optional<RetainCountConventionKind> getRetainCountConvention() const {
559
0
    if (!RawRetainCountConvention)
560
0
      return llvm::None;
561
0
    return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
562
0
  }
563
  void
564
0
  setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
565
0
    RawRetainCountConvention =
566
0
        Value.hasValue() ? static_cast<unsigned>(Value.getValue()) + 1 : 0;
567
0
    assert(getRetainCountConvention() == Value && "bitfield too small");
568
0
  }
569
570
  friend bool operator==(const FunctionInfo &, const FunctionInfo &);
571
572
private:
573
0
  NullabilityKind getTypeInfo(unsigned index) const {
574
0
    assert(NullabilityAudited &&
575
0
           "Checking the type adjustment on non-audited method.");
576
0
577
0
    // If we don't have info about this parameter, return the default.
578
0
    if (index > NumAdjustedNullable)
579
0
      return NullabilityKind::NonNull;
580
0
    auto nullability = NullabilityPayload >> (index * NullabilityKindSize);
581
0
    return static_cast<NullabilityKind>(nullability & NullabilityKindMask);
582
0
  }
583
584
public:
585
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
586
};
587
588
0
inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS) {
589
0
  return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
590
0
         LHS.NullabilityAudited == RHS.NullabilityAudited &&
591
0
         LHS.NumAdjustedNullable == RHS.NumAdjustedNullable &&
592
0
         LHS.NullabilityPayload == RHS.NullabilityPayload &&
593
0
         LHS.ResultType == RHS.ResultType && LHS.Params == RHS.Params &&
594
0
         LHS.RawRetainCountConvention == RHS.RawRetainCountConvention;
595
0
}
596
597
0
inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
598
0
  return !(LHS == RHS);
599
0
}
600
601
/// Describes API notes data for an Objective-C method.
602
class ObjCMethodInfo : public FunctionInfo {
603
public:
604
  /// Whether this is a designated initializer of its class.
605
  unsigned DesignatedInit : 1;
606
607
  /// Whether this is a required initializer.
608
  unsigned RequiredInit : 1;
609
610
  ObjCMethodInfo()
611
0
      : FunctionInfo(), DesignatedInit(false), RequiredInit(false) {}
612
613
  friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
614
615
0
  ObjCMethodInfo &operator|=(const ObjCContextInfo &RHS) {
616
0
    // Merge Nullability.
617
0
    if (!NullabilityAudited) {
618
0
      if (auto Nullable = RHS.getDefaultNullability()) {
619
0
        NullabilityAudited = true;
620
0
        addTypeInfo(0, *Nullable);
621
0
      }
622
0
    }
623
0
    return *this;
624
0
  }
625
626
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
627
};
628
629
0
inline bool operator==(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
630
0
  return static_cast<const FunctionInfo &>(LHS) == RHS &&
631
0
         LHS.DesignatedInit == RHS.DesignatedInit &&
632
0
         LHS.RequiredInit == RHS.RequiredInit;
633
0
}
634
635
0
inline bool operator!=(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
636
0
  return !(LHS == RHS);
637
0
}
638
639
/// Describes API notes data for a global variable.
640
class GlobalVariableInfo : public VariableInfo {
641
public:
642
0
  GlobalVariableInfo() : VariableInfo() {}
643
};
644
645
/// Describes API notes data for a global function.
646
class GlobalFunctionInfo : public FunctionInfo {
647
public:
648
0
  GlobalFunctionInfo() : FunctionInfo() {}
649
};
650
651
/// Describes API notes data for an enumerator.
652
class EnumConstantInfo : public CommonEntityInfo {
653
public:
654
0
  EnumConstantInfo() : CommonEntityInfo() {}
655
};
656
657
/// Describes API notes data for a tag.
658
class TagInfo : public CommonTypeInfo {
659
  unsigned HasFlagEnum : 1;
660
  unsigned IsFlagEnum : 1;
661
662
public:
663
  llvm::Optional<EnumExtensibilityKind> EnumExtensibility;
664
665
0
  TagInfo() : CommonTypeInfo(), HasFlagEnum(0), IsFlagEnum(0) {}
666
667
0
  llvm::Optional<bool> isFlagEnum() const {
668
0
    if (HasFlagEnum)
669
0
      return IsFlagEnum;
670
0
    return llvm::None;
671
0
  }
672
0
  void setFlagEnum(llvm::Optional<bool> Value) {
673
0
    HasFlagEnum = Value.hasValue();
674
0
    IsFlagEnum = Value.hasValue() ? *Value : false;
675
0
  }
676
677
0
  TagInfo &operator|=(const TagInfo &RHS) {
678
0
    static_cast<CommonTypeInfo &>(*this) |= RHS;
679
0
680
0
    if (!HasFlagEnum && HasFlagEnum)
681
0
      setFlagEnum(RHS.isFlagEnum());
682
0
683
0
    if (!EnumExtensibility.hasValue())
684
0
      EnumExtensibility = RHS.EnumExtensibility;
685
0
686
0
    return *this;
687
0
  }
688
689
  friend bool operator==(const TagInfo &, const TagInfo &);
690
691
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
692
};
693
694
0
inline bool operator==(const TagInfo &LHS, const TagInfo &RHS) {
695
0
  return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
696
0
         LHS.isFlagEnum() == RHS.isFlagEnum() &&
697
0
         LHS.EnumExtensibility == RHS.EnumExtensibility;
698
0
}
699
700
0
inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
701
0
  return !(LHS == RHS);
702
0
}
703
704
/// Describes API notes data for a typedef.
705
class TypedefInfo : public CommonTypeInfo {
706
public:
707
  llvm::Optional<SwiftNewTypeKind> SwiftWrapper;
708
709
0
  TypedefInfo() : CommonTypeInfo() {}
710
711
0
  TypedefInfo &operator|=(const TypedefInfo &RHS) {
712
0
    static_cast<CommonTypeInfo &>(*this) |= RHS;
713
0
    if (!SwiftWrapper.hasValue())
714
0
      SwiftWrapper = RHS.SwiftWrapper;
715
0
    return *this;
716
0
  }
717
718
  friend bool operator==(const TypedefInfo &, const TypedefInfo &);
719
720
  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS) const;
721
};
722
723
0
inline bool operator==(const TypedefInfo &LHS, const TypedefInfo &RHS) {
724
0
  return static_cast<const CommonTypeInfo &>(LHS) == RHS &&
725
0
         LHS.SwiftWrapper == RHS.SwiftWrapper;
726
0
}
727
728
0
inline bool operator!=(const TypedefInfo &LHS, const TypedefInfo &RHS) {
729
0
  return !(LHS == RHS);
730
0
}
731
} // namespace api_notes
732
} // namespace clang
733
734
#endif