Coverage Report

Created: 2018-12-11 17:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/DeclarationName.h
Line
Count
Source (jump to first uncovered line)
1
//===- DeclarationName.h - Representation of declaration names --*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file declares the DeclarationName and DeclarationNameTable classes.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
15
#define LLVM_CLANG_AST_DECLARATIONNAME_H
16
17
#include "clang/AST/Type.h"
18
#include "clang/Basic/Diagnostic.h"
19
#include "clang/Basic/IdentifierTable.h"
20
#include "clang/Basic/OperatorKinds.h"
21
#include "clang/Basic/PartialDiagnostic.h"
22
#include "clang/Basic/SourceLocation.h"
23
#include "llvm/ADT/DenseMapInfo.h"
24
#include "llvm/ADT/FoldingSet.h"
25
#include "llvm/Support/Compiler.h"
26
#include "llvm/Support/type_traits.h"
27
#include <cassert>
28
#include <cstdint>
29
#include <cstring>
30
#include <string>
31
32
namespace clang {
33
34
class ASTContext;
35
template <typename> class CanQual;
36
class DeclarationName;
37
class DeclarationNameTable;
38
class MultiKeywordSelector;
39
struct PrintingPolicy;
40
class TemplateDecl;
41
class TypeSourceInfo;
42
class UsingDirectiveDecl;
43
44
using CanQualType = CanQual<Type>;
45
46
namespace detail {
47
48
/// CXXSpecialNameExtra records the type associated with one of the "special"
49
/// kinds of declaration names in C++, e.g., constructors, destructors, and
50
/// conversion functions. Note that CXXSpecialName is used for C++ constructor,
51
/// destructor and conversion functions, but the actual kind is not stored in
52
/// CXXSpecialName. Instead we use three different FoldingSet<CXXSpecialName>
53
/// in DeclarationNameTable.
54
class alignas(IdentifierInfoAlignment) CXXSpecialNameExtra
55
    : public llvm::FoldingSetNode {
56
  friend class clang::DeclarationName;
57
  friend class clang::DeclarationNameTable;
58
59
  /// The type associated with this declaration name.
60
  QualType Type;
61
62
  /// Extra information associated with this declaration name that
63
  /// can be used by the front end. All bits are really needed
64
  /// so it is not possible to stash something in the low order bits.
65
  void *FETokenInfo;
66
67
2.81M
  CXXSpecialNameExtra(QualType QT) : Type(QT), FETokenInfo(nullptr) {}
68
69
public:
70
11.8M
  void Profile(llvm::FoldingSetNodeID &ID) {
71
11.8M
    ID.AddPointer(Type.getAsOpaquePtr());
72
11.8M
  }
73
};
74
75
/// Contains extra information for the name of a C++ deduction guide.
76
class alignas(IdentifierInfoAlignment) CXXDeductionGuideNameExtra
77
    : public detail::DeclarationNameExtra,
78
      public llvm::FoldingSetNode {
79
  friend class clang::DeclarationName;
80
  friend class clang::DeclarationNameTable;
81
82
  /// The template named by the deduction guide.
83
  TemplateDecl *Template;
84
85
  /// Extra information associated with this operator name that
86
  /// can be used by the front end. All bits are really needed
87
  /// so it is not possible to stash something in the low order bits.
88
  void *FETokenInfo;
89
90
  CXXDeductionGuideNameExtra(TemplateDecl *TD)
91
      : DeclarationNameExtra(CXXDeductionGuideName), Template(TD),
92
93
        FETokenInfo(nullptr) {}
93
94
public:
95
987
  void Profile(llvm::FoldingSetNodeID &ID) { ID.AddPointer(Template); }
96
};
97
98
/// Contains extra information for the name of an overloaded operator
99
/// in C++, such as "operator+. This do not includes literal or conversion
100
/// operators. For literal operators see CXXLiteralOperatorIdName and for
101
/// conversion operators see CXXSpecialNameExtra.
102
class alignas(IdentifierInfoAlignment) CXXOperatorIdName {
103
  friend class clang::DeclarationName;
104
  friend class clang::DeclarationNameTable;
105
106
  /// The kind of this operator.
107
  OverloadedOperatorKind Kind = OO_None;
108
109
  /// Extra information associated with this operator name that
110
  /// can be used by the front end. All bits are really needed
111
  /// so it is not possible to stash something in the low order bits.
112
  void *FETokenInfo = nullptr;
113
};
114
115
/// Contains the actual identifier that makes up the
116
/// name of a C++ literal operator.
117
class alignas(IdentifierInfoAlignment) CXXLiteralOperatorIdName
118
    : public detail::DeclarationNameExtra,
119
      public llvm::FoldingSetNode {
120
  friend class clang::DeclarationName;
121
  friend class clang::DeclarationNameTable;
122
123
  IdentifierInfo *ID;
124
125
  /// Extra information associated with this operator name that
126
  /// can be used by the front end. All bits are really needed
127
  /// so it is not possible to stash something in the low order bits.
128
  void *FETokenInfo;
129
130
  CXXLiteralOperatorIdName(IdentifierInfo *II)
131
      : DeclarationNameExtra(CXXLiteralOperatorName), ID(II),
132
901
        FETokenInfo(nullptr) {}
133
134
public:
135
6.49k
  void Profile(llvm::FoldingSetNodeID &FSID) { FSID.AddPointer(ID); }
136
};
137
138
} // namespace detail
139
140
/// The name of a declaration. In the common case, this just stores
141
/// an IdentifierInfo pointer to a normal name. However, it also provides
142
/// encodings for Objective-C selectors (optimizing zero- and one-argument
143
/// selectors, which make up 78% percent of all selectors in Cocoa.h),
144
/// special C++ names for constructors, destructors, and conversion functions,
145
/// and C++ overloaded operators.
146
0
class DeclarationName {
Unexecuted instantiation: clang::DeclarationName::operator=(clang::DeclarationName const&)
Unexecuted instantiation: clang::DeclarationName::operator=(clang::DeclarationName&&)
147
  friend class DeclarationNameTable;
148
  friend class NamedDecl;
149
150
  /// StoredNameKind represent the kind of name that is actually stored in the
151
  /// upper bits of the Ptr field. This is only used internally.
152
  ///
153
  /// NameKind, StoredNameKind, and DeclarationNameExtra::ExtraKind
154
  /// must satisfy the following properties. These properties enable
155
  /// efficient conversion between the various kinds.
156
  ///
157
  /// * The first seven enumerators of StoredNameKind must have the same
158
  ///   numerical value as the first seven enumerators of NameKind.
159
  ///   This enable efficient conversion between the two enumerations
160
  ///   in the usual case.
161
  ///
162
  /// * The enumerations values of DeclarationNameExtra::ExtraKind must start
163
  ///   at zero, and correspond to the numerical value of the first non-inline
164
  ///   enumeration values of NameKind minus an offset. This makes conversion
165
  ///   between DeclarationNameExtra::ExtraKind and NameKind possible with
166
  ///   a single addition/substraction.
167
  ///
168
  /// * The enumeration values of Selector::IdentifierInfoFlag must correspond
169
  ///   to the relevant enumeration values of StoredNameKind.
170
  ///   More specifically:
171
  ///    * ZeroArg == StoredObjCZeroArgSelector,
172
  ///    * OneArg == StoredObjCOneArgSelector,
173
  ///    * MultiArg == StoredDeclarationNameExtra
174
  ///
175
  /// * PtrMask must mask the low 3 bits of Ptr.
176
  enum StoredNameKind {
177
    StoredIdentifier = 0,
178
    StoredObjCZeroArgSelector = Selector::ZeroArg,
179
    StoredObjCOneArgSelector = Selector::OneArg,
180
    StoredCXXConstructorName = 3,
181
    StoredCXXDestructorName = 4,
182
    StoredCXXConversionFunctionName = 5,
183
    StoredCXXOperatorName = 6,
184
    StoredDeclarationNameExtra = Selector::MultiArg,
185
    PtrMask = 7,
186
    UncommonNameKindOffset = 8
187
  };
188
189
  static_assert(alignof(IdentifierInfo) >= 8 &&
190
                    alignof(detail::DeclarationNameExtra) >= 8 &&
191
                    alignof(detail::CXXSpecialNameExtra) >= 8 &&
192
                    alignof(detail::CXXOperatorIdName) >= 8 &&
193
                    alignof(detail::CXXDeductionGuideNameExtra) >= 8 &&
194
                    alignof(detail::CXXLiteralOperatorIdName) >= 8,
195
                "The various classes that DeclarationName::Ptr can point to"
196
                " must be at least aligned to 8 bytes!");
197
198
public:
199
  /// The kind of the name stored in this DeclarationName.
200
  /// The first 7 enumeration values are stored inline and correspond
201
  /// to frequently used kinds. The rest is stored in DeclarationNameExtra
202
  /// and correspond to infrequently used kinds.
203
  enum NameKind {
204
    Identifier = StoredIdentifier,
205
    ObjCZeroArgSelector = StoredObjCZeroArgSelector,
206
    ObjCOneArgSelector = StoredObjCOneArgSelector,
207
    CXXConstructorName = StoredCXXConstructorName,
208
    CXXDestructorName = StoredCXXDestructorName,
209
    CXXConversionFunctionName = StoredCXXConversionFunctionName,
210
    CXXOperatorName = StoredCXXOperatorName,
211
    CXXDeductionGuideName = UncommonNameKindOffset +
212
                            detail::DeclarationNameExtra::CXXDeductionGuideName,
213
    CXXLiteralOperatorName =
214
        UncommonNameKindOffset +
215
        detail::DeclarationNameExtra::CXXLiteralOperatorName,
216
    CXXUsingDirective = UncommonNameKindOffset +
217
                        detail::DeclarationNameExtra::CXXUsingDirective,
218
    ObjCMultiArgSelector = UncommonNameKindOffset +
219
                           detail::DeclarationNameExtra::ObjCMultiArgSelector
220
  };
221
222
private:
223
  /// The lowest three bits of Ptr are used to express what kind of name
224
  /// we're actually storing, using the values of StoredNameKind. Depending
225
  /// on the kind of name this is, the upper bits of Ptr may have one
226
  /// of several different meanings:
227
  ///
228
  ///   StoredIdentifier - The name is a normal identifier, and Ptr is
229
  ///   a normal IdentifierInfo pointer.
230
  ///
231
  ///   StoredObjCZeroArgSelector - The name is an Objective-C
232
  ///   selector with zero arguments, and Ptr is an IdentifierInfo
233
  ///   pointer pointing to the selector name.
234
  ///
235
  ///   StoredObjCOneArgSelector - The name is an Objective-C selector
236
  ///   with one argument, and Ptr is an IdentifierInfo pointer
237
  ///   pointing to the selector name.
238
  ///
239
  ///   StoredCXXConstructorName - The name of a C++ constructor,
240
  ///   Ptr points to a CXXSpecialNameExtra.
241
  ///
242
  ///   StoredCXXDestructorName - The name of a C++ destructor,
243
  ///   Ptr points to a CXXSpecialNameExtra.
244
  ///
245
  ///   StoredCXXConversionFunctionName - The name of a C++ conversion function,
246
  ///   Ptr points to a CXXSpecialNameExtra.
247
  ///
248
  ///   StoredCXXOperatorName - The name of an overloaded C++ operator,
249
  ///   Ptr points to a CXXOperatorIdName.
250
  ///
251
  ///   StoredDeclarationNameExtra - Ptr is actually a pointer to a
252
  ///   DeclarationNameExtra structure, whose first value will tell us
253
  ///   whether this is an Objective-C selector, C++ deduction guide,
254
  ///   C++ literal operator, or C++ using directive.
255
  uintptr_t Ptr = 0;
256
257
1.63G
  StoredNameKind getStoredNameKind() const {
258
1.63G
    return static_cast<StoredNameKind>(Ptr & PtrMask);
259
1.63G
  }
260
261
1.17G
  void *getPtr() const { return reinterpret_cast<void *>(Ptr & ~PtrMask); }
262
263
992M
  void setPtrAndKind(const void *P, StoredNameKind Kind) {
264
992M
    uintptr_t PAsInteger = reinterpret_cast<uintptr_t>(P);
265
992M
    assert((Kind & ~PtrMask) == 0 &&
266
992M
           "Invalid StoredNameKind in setPtrAndKind!");
267
992M
    assert((PAsInteger & PtrMask) == 0 &&
268
992M
           "Improperly aligned pointer in setPtrAndKind!");
269
992M
    Ptr = PAsInteger | Kind;
270
992M
  }
271
272
  /// Construct a declaration name from a DeclarationNameExtra.
273
99.8M
  DeclarationName(detail::DeclarationNameExtra *Name) {
274
99.8M
    setPtrAndKind(Name, StoredDeclarationNameExtra);
275
99.8M
  }
276
277
  /// Construct a declaration name from a CXXSpecialNameExtra.
278
  DeclarationName(detail::CXXSpecialNameExtra *Name,
279
7.31M
                  StoredNameKind StoredKind) {
280
7.31M
    assert((StoredKind == StoredCXXConstructorName ||
281
7.31M
           StoredKind == StoredCXXDestructorName ||
282
7.31M
           StoredKind == StoredCXXConversionFunctionName) &&
283
7.31M
               "Invalid StoredNameKind when constructing a DeclarationName"
284
7.31M
               " from a CXXSpecialNameExtra!");
285
7.31M
    setPtrAndKind(Name, StoredKind);
286
7.31M
  }
287
288
  /// Construct a DeclarationName from a CXXOperatorIdName.
289
10.6M
  DeclarationName(detail::CXXOperatorIdName *Name) {
290
10.6M
    setPtrAndKind(Name, StoredCXXOperatorName);
291
10.6M
  }
292
293
  /// Assert that the stored pointer points to an IdentifierInfo and return it.
294
833M
  IdentifierInfo *castAsIdentifierInfo() const {
295
833M
    assert((getStoredNameKind() == StoredIdentifier) &&
296
833M
           "DeclarationName does not store an IdentifierInfo!");
297
833M
    return static_cast<IdentifierInfo *>(getPtr());
298
833M
  }
299
300
  /// Assert that the stored pointer points to a DeclarationNameExtra
301
  /// and return it.
302
69.8k
  detail::DeclarationNameExtra *castAsExtra() const {
303
69.8k
    assert((getStoredNameKind() == StoredDeclarationNameExtra) &&
304
69.8k
           "DeclarationName does not store an Extra structure!");
305
69.8k
    return static_cast<detail::DeclarationNameExtra *>(getPtr());
306
69.8k
  }
307
308
  /// Assert that the stored pointer points to a CXXSpecialNameExtra
309
  /// and return it.
310
6.33M
  detail::CXXSpecialNameExtra *castAsCXXSpecialNameExtra() const {
311
6.33M
    assert((getStoredNameKind() == StoredCXXConstructorName ||
312
6.33M
           getStoredNameKind() == StoredCXXDestructorName ||
313
6.33M
           getStoredNameKind() == StoredCXXConversionFunctionName) &&
314
6.33M
               "DeclarationName does not store a CXXSpecialNameExtra!");
315
6.33M
    return static_cast<detail::CXXSpecialNameExtra *>(getPtr());
316
6.33M
  }
317
318
  /// Assert that the stored pointer points to a CXXOperatorIdName
319
  /// and return it.
320
44.0M
  detail::CXXOperatorIdName *castAsCXXOperatorIdName() const {
321
44.0M
    assert((getStoredNameKind() == StoredCXXOperatorName) &&
322
44.0M
           "DeclarationName does not store a CXXOperatorIdName!");
323
44.0M
    return static_cast<detail::CXXOperatorIdName *>(getPtr());
324
44.0M
  }
325
326
  /// Assert that the stored pointer points to a CXXDeductionGuideNameExtra
327
  /// and return it.
328
2.95k
  detail::CXXDeductionGuideNameExtra *castAsCXXDeductionGuideNameExtra() const {
329
2.95k
    assert(getNameKind() == CXXDeductionGuideName &&
330
2.95k
           "DeclarationName does not store a CXXDeductionGuideNameExtra!");
331
2.95k
    return static_cast<detail::CXXDeductionGuideNameExtra *>(getPtr());
332
2.95k
  }
333
334
  /// Assert that the stored pointer points to a CXXLiteralOperatorIdName
335
  /// and return it.
336
23.3k
  detail::CXXLiteralOperatorIdName *castAsCXXLiteralOperatorIdName() const {
337
23.3k
    assert(getNameKind() == CXXLiteralOperatorName &&
338
23.3k
           "DeclarationName does not store a CXXLiteralOperatorIdName!");
339
23.3k
    return static_cast<detail::CXXLiteralOperatorIdName *>(getPtr());
340
23.3k
  }
341
342
  /// Get and set the FETokenInfo in the less common cases where the
343
  /// declaration name do not point to an identifier.
344
  void *getFETokenInfoSlow() const;
345
  void setFETokenInfoSlow(void *T);
346
347
public:
348
  /// Construct an empty declaration name.
349
657M
  DeclarationName() { setPtrAndKind(nullptr, StoredIdentifier); }
350
351
  /// Construct a declaration name from an IdentifierInfo *.
352
217M
  DeclarationName(const IdentifierInfo *II) {
353
217M
    setPtrAndKind(II, StoredIdentifier);
354
217M
  }
355
356
  /// Construct a declaration name from an Objective-C selector.
357
601k
  DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) {}
358
359
  /// Returns the name for all C++ using-directives.
360
99.8M
  static DeclarationName getUsingDirectiveName() {
361
99.8M
    // Single instance of DeclarationNameExtra for using-directive
362
99.8M
    static detail::DeclarationNameExtra UDirExtra(
363
99.8M
        detail::DeclarationNameExtra::CXXUsingDirective);
364
99.8M
    return DeclarationName(&UDirExtra);
365
99.8M
  }
366
367
  /// Evaluates true when this declaration name is non-empty.
368
292M
  explicit operator bool() const {
369
292M
    return getPtr() || 
(getStoredNameKind() != StoredIdentifier)7.70M
;
370
292M
  }
371
372
  /// Evaluates true when this declaration name is empty.
373
971k
  bool isEmpty() const { return !*this; }
374
375
  /// Predicate functions for querying what type of name this is.
376
587M
  bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
377
1.79k
  bool isObjCZeroArgSelector() const {
378
1.79k
    return getStoredNameKind() == StoredObjCZeroArgSelector;
379
1.79k
  }
380
  bool isObjCOneArgSelector() const {
381
    return getStoredNameKind() == StoredObjCOneArgSelector;
382
  }
383
384
  /// Determine what kind of name this is.
385
562M
  NameKind getNameKind() const {
386
562M
    // We rely on the fact that the first 7 NameKind and StoredNameKind
387
562M
    // have the same numerical value. This makes the usual case efficient.
388
562M
    StoredNameKind StoredKind = getStoredNameKind();
389
562M
    if (StoredKind != StoredDeclarationNameExtra)
390
562M
      return static_cast<NameKind>(StoredKind);
391
69.8k
    // We have to consult DeclarationNameExtra. We rely on the fact that the
392
69.8k
    // enumeration values of ExtraKind correspond to the enumeration values of
393
69.8k
    // NameKind minus an offset of UncommonNameKindOffset.
394
69.8k
    unsigned ExtraKind = castAsExtra()->getKind();
395
69.8k
    return static_cast<NameKind>(UncommonNameKindOffset + ExtraKind);
396
69.8k
  }
397
398
  /// Determines whether the name itself is dependent, e.g., because it
399
  /// involves a C++ type that is itself dependent.
400
  ///
401
  /// Note that this does not capture all of the notions of "dependent name",
402
  /// because an identifier can be a dependent name if it is used as the
403
  /// callee in a call expression with dependent arguments.
404
  bool isDependentName() const;
405
406
  /// Retrieve the human-readable string for this name.
407
  std::string getAsString() const;
408
409
  /// Retrieve the IdentifierInfo * stored in this declaration name,
410
  /// or null if this declaration name isn't a simple identifier.
411
579M
  IdentifierInfo *getAsIdentifierInfo() const {
412
579M
    if (isIdentifier())
413
554M
      return castAsIdentifierInfo();
414
24.9M
    return nullptr;
415
24.9M
  }
416
417
  /// Get the representation of this declaration name as an opaque integer.
418
332k
  uintptr_t getAsOpaqueInteger() const { return Ptr; }
419
420
  /// Get the representation of this declaration name as an opaque pointer.
421
250M
  void *getAsOpaquePtr() const { return reinterpret_cast<void *>(Ptr); }
422
423
  /// Get a declaration name from an opaque pointer returned by getAsOpaquePtr.
424
  static DeclarationName getFromOpaquePtr(void *P) {
425
    DeclarationName N;
426
    N.Ptr = reinterpret_cast<uintptr_t>(P);
427
    return N;
428
  }
429
430
  /// Get a declaration name from an opaque integer
431
  /// returned by getAsOpaqueInteger.
432
16.6k
  static DeclarationName getFromOpaqueInteger(uintptr_t P) {
433
16.6k
    DeclarationName N;
434
16.6k
    N.Ptr = P;
435
16.6k
    return N;
436
16.6k
  }
437
438
  /// If this name is one of the C++ names (of a constructor, destructor,
439
  /// or conversion function), return the type associated with that name.
440
3.05M
  QualType getCXXNameType() const {
441
3.05M
    if (getStoredNameKind() == StoredCXXConstructorName ||
442
3.05M
        
getStoredNameKind() == StoredCXXDestructorName2.24M
||
443
3.05M
        
getStoredNameKind() == StoredCXXConversionFunctionName2.22M
) {
444
1.99M
      assert(getPtr() && "getCXXNameType on a null DeclarationName!");
445
1.99M
      return castAsCXXSpecialNameExtra()->Type;
446
1.99M
    }
447
1.06M
    return QualType();
448
1.06M
  }
449
450
  /// If this name is the name of a C++ deduction guide, return the
451
  /// template associated with that name.
452
1.06M
  TemplateDecl *getCXXDeductionGuideTemplate() const {
453
1.06M
    if (getNameKind() == CXXDeductionGuideName) {
454
986
      assert(getPtr() &&
455
986
             "getCXXDeductionGuideTemplate on a null DeclarationName!");
456
986
      return castAsCXXDeductionGuideNameExtra()->Template;
457
986
    }
458
1.06M
    return nullptr;
459
1.06M
  }
460
461
  /// If this name is the name of an overloadable operator in C++
462
  /// (e.g., @c operator+), retrieve the kind of overloaded operator.
463
174M
  OverloadedOperatorKind getCXXOverloadedOperator() const {
464
174M
    if (getStoredNameKind() == StoredCXXOperatorName) {
465
36.5M
      assert(getPtr() && "getCXXOverloadedOperator on a null DeclarationName!");
466
36.5M
      return castAsCXXOperatorIdName()->Kind;
467
36.5M
    }
468
138M
    return OO_None;
469
138M
  }
470
471
  /// If this name is the name of a literal operator,
472
  /// retrieve the identifier associated with it.
473
6.91k
  IdentifierInfo *getCXXLiteralIdentifier() const {
474
6.91k
    if (getNameKind() == CXXLiteralOperatorName) {
475
6.91k
      assert(getPtr() && "getCXXLiteralIdentifier on a null DeclarationName!");
476
6.91k
      return castAsCXXLiteralOperatorIdName()->ID;
477
6.91k
    }
478
0
    return nullptr;
479
0
  }
480
481
  /// Get the Objective-C selector stored in this declaration name.
482
945k
  Selector getObjCSelector() const {
483
945k
    assert((getNameKind() == ObjCZeroArgSelector ||
484
945k
            getNameKind() == ObjCOneArgSelector ||
485
945k
            getNameKind() == ObjCMultiArgSelector || !getPtr()) &&
486
945k
           "Not a selector!");
487
945k
    return Selector(Ptr);
488
945k
  }
489
490
  /// Get and set FETokenInfo. The language front-end is allowed to associate
491
  /// arbitrary metadata with some kinds of declaration names, including normal
492
  /// identifiers and C++ constructors, destructors, and conversion functions.
493
226M
  void *getFETokenInfo() const {
494
226M
    assert(getPtr() && "getFETokenInfo on an empty DeclarationName!");
495
226M
    if (getStoredNameKind() == StoredIdentifier)
496
215M
      return castAsIdentifierInfo()->getFETokenInfo();
497
10.8M
    return getFETokenInfoSlow();
498
10.8M
  }
499
500
63.7M
  void setFETokenInfo(void *T) {
501
63.7M
    assert(getPtr() && "setFETokenInfo on an empty DeclarationName!");
502
63.7M
    if (getStoredNameKind() == StoredIdentifier)
503
62.7M
      castAsIdentifierInfo()->setFETokenInfo(T);
504
1.01M
    else
505
1.01M
      setFETokenInfoSlow(T);
506
63.7M
  }
507
508
  /// Determine whether the specified names are identical.
509
1.49G
  friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
510
1.49G
    return LHS.Ptr == RHS.Ptr;
511
1.49G
  }
512
513
  /// Determine whether the specified names are different.
514
267k
  friend bool operator!=(DeclarationName LHS, DeclarationName RHS) {
515
267k
    return LHS.Ptr != RHS.Ptr;
516
267k
  }
517
518
269M
  static DeclarationName getEmptyMarker() {
519
269M
    DeclarationName Name;
520
269M
    Name.Ptr = uintptr_t(-1);
521
269M
    return Name;
522
269M
  }
523
524
248M
  static DeclarationName getTombstoneMarker() {
525
248M
    DeclarationName Name;
526
248M
    Name.Ptr = uintptr_t(-2);
527
248M
    return Name;
528
248M
  }
529
530
  static int compare(DeclarationName LHS, DeclarationName RHS);
531
532
  void print(raw_ostream &OS, const PrintingPolicy &Policy);
533
534
  void dump() const;
535
};
536
537
raw_ostream &operator<<(raw_ostream &OS, DeclarationName N);
538
539
/// Ordering on two declaration names. If both names are identifiers,
540
/// this provides a lexicographical ordering.
541
108k
inline bool operator<(DeclarationName LHS, DeclarationName RHS) {
542
108k
  return DeclarationName::compare(LHS, RHS) < 0;
543
108k
}
544
545
/// Ordering on two declaration names. If both names are identifiers,
546
/// this provides a lexicographical ordering.
547
0
inline bool operator>(DeclarationName LHS, DeclarationName RHS) {
548
0
  return DeclarationName::compare(LHS, RHS) > 0;
549
0
}
550
551
/// Ordering on two declaration names. If both names are identifiers,
552
/// this provides a lexicographical ordering.
553
0
inline bool operator<=(DeclarationName LHS, DeclarationName RHS) {
554
0
  return DeclarationName::compare(LHS, RHS) <= 0;
555
0
}
556
557
/// Ordering on two declaration names. If both names are identifiers,
558
/// this provides a lexicographical ordering.
559
0
inline bool operator>=(DeclarationName LHS, DeclarationName RHS) {
560
0
  return DeclarationName::compare(LHS, RHS) >= 0;
561
0
}
562
563
/// DeclarationNameTable is used to store and retrieve DeclarationName
564
/// instances for the various kinds of declaration names, e.g., normal
565
/// identifiers, C++ constructor names, etc. This class contains
566
/// uniqued versions of each of the C++ special names, which can be
567
/// retrieved using its member functions (e.g., getCXXConstructorName).
568
class DeclarationNameTable {
569
  /// Used to allocate elements in the FoldingSets below.
570
  const ASTContext &Ctx;
571
572
  /// Manage the uniqued CXXSpecialNameExtra representing C++ constructors.
573
  /// getCXXConstructorName and getCXXSpecialName can be used to obtain
574
  /// a DeclarationName from the corresponding type of the constructor.
575
  llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConstructorNames;
576
577
  /// Manage the uniqued CXXSpecialNameExtra representing C++ destructors.
578
  /// getCXXDestructorName and getCXXSpecialName can be used to obtain
579
  /// a DeclarationName from the corresponding type of the destructor.
580
  llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXDestructorNames;
581
582
  /// Manage the uniqued CXXSpecialNameExtra representing C++ conversion
583
  /// functions. getCXXConversionFunctionName and getCXXSpecialName can be
584
  /// used to obtain a DeclarationName from the corresponding type of the
585
  /// conversion function.
586
  llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConversionFunctionNames;
587
588
  /// Manage the uniqued CXXOperatorIdName, which contain extra information
589
  /// for the name of overloaded C++ operators. getCXXOperatorName
590
  /// can be used to obtain a DeclarationName from the operator kind.
591
  detail::CXXOperatorIdName CXXOperatorNames[NUM_OVERLOADED_OPERATORS];
592
593
  /// Manage the uniqued CXXLiteralOperatorIdName, which contain extra
594
  /// information for the name of C++ literal operators.
595
  /// getCXXLiteralOperatorName can be used to obtain a DeclarationName
596
  /// from the corresponding IdentifierInfo.
597
  llvm::FoldingSet<detail::CXXLiteralOperatorIdName> CXXLiteralOperatorNames;
598
599
  /// Manage the uniqued CXXDeductionGuideNameExtra, which contain
600
  /// extra information for the name of a C++ deduction guide.
601
  /// getCXXDeductionGuideName can be used to obtain a DeclarationName
602
  /// from the corresponding template declaration.
603
  llvm::FoldingSet<detail::CXXDeductionGuideNameExtra> CXXDeductionGuideNames;
604
605
public:
606
  DeclarationNameTable(const ASTContext &C);
607
  DeclarationNameTable(const DeclarationNameTable &) = delete;
608
  DeclarationNameTable &operator=(const DeclarationNameTable &) = delete;
609
  DeclarationNameTable(DeclarationNameTable &&) = delete;
610
  DeclarationNameTable &operator=(DeclarationNameTable &&) = delete;
611
29.5k
  ~DeclarationNameTable() = default;
612
613
  /// Create a declaration name that is a simple identifier.
614
13.9k
  DeclarationName getIdentifier(const IdentifierInfo *ID) {
615
13.9k
    return DeclarationName(ID);
616
13.9k
  }
617
618
  /// Returns the name of a C++ constructor for the given Type.
619
  DeclarationName getCXXConstructorName(CanQualType Ty);
620
621
  /// Returns the name of a C++ destructor for the given Type.
622
  DeclarationName getCXXDestructorName(CanQualType Ty);
623
624
  /// Returns the name of a C++ deduction guide for the given template.
625
  DeclarationName getCXXDeductionGuideName(TemplateDecl *TD);
626
627
  /// Returns the name of a C++ conversion function for the given Type.
628
  DeclarationName getCXXConversionFunctionName(CanQualType Ty);
629
630
  /// Returns a declaration name for special kind of C++ name,
631
  /// e.g., for a constructor, destructor, or conversion function.
632
  /// Kind must be one of:
633
  ///   * DeclarationName::CXXConstructorName,
634
  ///   * DeclarationName::CXXDestructorName or
635
  ///   * DeclarationName::CXXConversionFunctionName
636
  DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind,
637
                                    CanQualType Ty);
638
639
  /// Get the name of the overloadable C++ operator corresponding to Op.
640
10.6M
  DeclarationName getCXXOperatorName(OverloadedOperatorKind Op) {
641
10.6M
    return DeclarationName(&CXXOperatorNames[Op]);
642
10.6M
  }
643
644
  /// Get the name of the literal operator function with II as the identifier.
645
  DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
646
};
647
648
/// DeclarationNameLoc - Additional source/type location info
649
/// for a declaration name. Needs a DeclarationName in order
650
/// to be interpreted correctly.
651
0
struct DeclarationNameLoc {
Unexecuted instantiation: clang::DeclarationNameLoc::operator=(clang::DeclarationNameLoc&&)
Unexecuted instantiation: clang::DeclarationNameLoc::operator=(clang::DeclarationNameLoc const&)
652
  // The source location for identifier stored elsewhere.
653
  // struct {} Identifier;
654
655
  // Type info for constructors, destructors and conversion functions.
656
  // Locations (if any) for the tilde (destructor) or operator keyword
657
  // (conversion) are stored elsewhere.
658
  struct NT {
659
    TypeSourceInfo *TInfo;
660
  };
661
662
  // The location (if any) of the operator keyword is stored elsewhere.
663
  struct CXXOpName {
664
    unsigned BeginOpNameLoc;
665
    unsigned EndOpNameLoc;
666
  };
667
668
  // The location (if any) of the operator keyword is stored elsewhere.
669
  struct CXXLitOpName {
670
    unsigned OpNameLoc;
671
  };
672
673
  // struct {} CXXUsingDirective;
674
  // struct {} ObjCZeroArgSelector;
675
  // struct {} ObjCOneArgSelector;
676
  // struct {} ObjCMultiArgSelector;
677
  union {
678
    struct NT NamedType;
679
    struct CXXOpName CXXOperatorName;
680
    struct CXXLitOpName CXXLiteralOperatorName;
681
  };
682
683
  DeclarationNameLoc(DeclarationName Name);
684
685
  // FIXME: this should go away once all DNLocs are properly initialized.
686
81.9M
  DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
687
};
688
689
/// DeclarationNameInfo - A collector data type for bundling together
690
/// a DeclarationName and the correspnding source/type location info.
691
0
struct DeclarationNameInfo {
Unexecuted instantiation: clang::DeclarationNameInfo::operator=(clang::DeclarationNameInfo const&)
Unexecuted instantiation: clang::DeclarationNameInfo::operator=(clang::DeclarationNameInfo&&)
692
private:
693
  /// Name - The declaration name, also encoding name kind.
694
  DeclarationName Name;
695
696
  /// Loc - The main source location for the declaration name.
697
  SourceLocation NameLoc;
698
699
  /// Info - Further source/type location info for special kinds of names.
700
  DeclarationNameLoc LocInfo;
701
702
public:
703
  // FIXME: remove it.
704
80.1M
  DeclarationNameInfo() = default;
705
706
  DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
707
89.1M
      : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
708
709
  DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc,
710
                      DeclarationNameLoc LocInfo)
711
150M
      : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
712
713
  /// getName - Returns the embedded declaration name.
714
823M
  DeclarationName getName() const { return Name; }
715
716
  /// setName - Sets the embedded declaration name.
717
58.2M
  void setName(DeclarationName N) { Name = N; }
718
719
  /// getLoc - Returns the main location of the declaration name.
720
229M
  SourceLocation getLoc() const { return NameLoc; }
721
722
  /// setLoc - Sets the main location of the declaration name.
723
57.8M
  void setLoc(SourceLocation L) { NameLoc = L; }
724
725
40.0M
  const DeclarationNameLoc &getInfo() const { return LocInfo; }
726
3.29M
  DeclarationNameLoc &getInfo() { return LocInfo; }
727
2.05k
  void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
728
729
  /// getNamedTypeInfo - Returns the source type info associated to
730
  /// the name. Assumes it is a constructor, destructor or conversion.
731
933k
  TypeSourceInfo *getNamedTypeInfo() const {
732
933k
    assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
733
933k
           Name.getNameKind() == DeclarationName::CXXDestructorName ||
734
933k
           Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
735
933k
    return LocInfo.NamedType.TInfo;
736
933k
  }
737
738
  /// setNamedTypeInfo - Sets the source type info associated to
739
  /// the name. Assumes it is a constructor, destructor or conversion.
740
2.46M
  void setNamedTypeInfo(TypeSourceInfo *TInfo) {
741
2.46M
    assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
742
2.46M
           Name.getNameKind() == DeclarationName::CXXDestructorName ||
743
2.46M
           Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
744
2.46M
    LocInfo.NamedType.TInfo = TInfo;
745
2.46M
  }
746
747
  /// getCXXOperatorNameRange - Gets the range of the operator name
748
  /// (without the operator keyword). Assumes it is a (non-literal) operator.
749
1.09k
  SourceRange getCXXOperatorNameRange() const {
750
1.09k
    assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
751
1.09k
    return SourceRange(
752
1.09k
     SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc),
753
1.09k
     SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc)
754
1.09k
                       );
755
1.09k
  }
756
757
  /// setCXXOperatorNameRange - Sets the range of the operator name
758
  /// (without the operator keyword). Assumes it is a C++ operator.
759
62.0k
  void setCXXOperatorNameRange(SourceRange R) {
760
62.0k
    assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
761
62.0k
    LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding();
762
62.0k
    LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding();
763
62.0k
  }
764
765
  /// getCXXLiteralOperatorNameLoc - Returns the location of the literal
766
  /// operator name (not the operator keyword).
767
  /// Assumes it is a literal operator.
768
177
  SourceLocation getCXXLiteralOperatorNameLoc() const {
769
177
    assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
770
177
    return SourceLocation::
771
177
      getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc);
772
177
  }
773
774
  /// setCXXLiteralOperatorNameLoc - Sets the location of the literal
775
  /// operator name (not the operator keyword).
776
  /// Assumes it is a literal operator.
777
7.32k
  void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
778
7.32k
    assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
779
7.32k
    LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
780
7.32k
  }
781
782
  /// Determine whether this name involves a template parameter.
783
  bool isInstantiationDependent() const;
784
785
  /// Determine whether this name contains an unexpanded
786
  /// parameter pack.
787
  bool containsUnexpandedParameterPack() const;
788
789
  /// getAsString - Retrieve the human-readable string for this name.
790
  std::string getAsString() const;
791
792
  /// printName - Print the human-readable name to a stream.
793
  void printName(raw_ostream &OS) const;
794
795
  /// getBeginLoc - Retrieve the location of the first token.
796
140M
  SourceLocation getBeginLoc() const { return NameLoc; }
797
798
  /// getSourceRange - The range of the declaration name.
799
34.7k
  SourceRange getSourceRange() const LLVM_READONLY {
800
34.7k
    return SourceRange(getBeginLoc(), getEndLoc());
801
34.7k
  }
802
803
22.1M
  SourceLocation getEndLoc() const LLVM_READONLY {
804
22.1M
    SourceLocation EndLoc = getEndLocPrivate();
805
22.1M
    return EndLoc.isValid() ? 
EndLoc21.9M
:
getBeginLoc()274k
;
806
22.1M
  }
807
808
private:
809
  SourceLocation getEndLocPrivate() const;
810
};
811
812
/// Insertion operator for diagnostics.  This allows sending DeclarationName's
813
/// into a diagnostic with <<.
814
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
815
189k
                                           DeclarationName N) {
816
189k
  DB.AddTaggedVal(N.getAsOpaqueInteger(),
817
189k
                  DiagnosticsEngine::ak_declarationname);
818
189k
  return DB;
819
189k
}
820
821
/// Insertion operator for partial diagnostics.  This allows binding
822
/// DeclarationName's into a partial diagnostic with <<.
823
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
824
143k
                                           DeclarationName N) {
825
143k
  PD.AddTaggedVal(N.getAsOpaqueInteger(),
826
143k
                  DiagnosticsEngine::ak_declarationname);
827
143k
  return PD;
828
143k
}
829
830
inline raw_ostream &operator<<(raw_ostream &OS,
831
31.1k
                                     DeclarationNameInfo DNInfo) {
832
31.1k
  DNInfo.printName(OS);
833
31.1k
  return OS;
834
31.1k
}
835
836
} // namespace clang
837
838
namespace llvm {
839
840
/// Define DenseMapInfo so that DeclarationNames can be used as keys
841
/// in DenseMap and DenseSets.
842
template<>
843
struct DenseMapInfo<clang::DeclarationName> {
844
269M
  static inline clang::DeclarationName getEmptyKey() {
845
269M
    return clang::DeclarationName::getEmptyMarker();
846
269M
  }
847
848
248M
  static inline clang::DeclarationName getTombstoneKey() {
849
248M
    return clang::DeclarationName::getTombstoneMarker();
850
248M
  }
851
852
245M
  static unsigned getHashValue(clang::DeclarationName Name) {
853
245M
    return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
854
245M
  }
855
856
  static inline bool
857
1.48G
  isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) {
858
1.48G
    return LHS == RHS;
859
1.48G
  }
860
};
861
862
template <>
863
struct isPodLike<clang::DeclarationName> { static const bool value = true; };
864
865
} // namespace llvm
866
867
#endif // LLVM_CLANG_AST_DECLARATIONNAME_H