Coverage Report

Created: 2022-01-22 13:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Basic/IdentifierTable.h
Line
Count
Source (jump to first uncovered line)
1
//===- IdentifierTable.h - Hash table for identifier lookup -----*- 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
/// \file
10
/// Defines the clang::IdentifierInfo, clang::IdentifierTable, and
11
/// clang::Selector interfaces.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
16
#define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
17
18
#include "clang/Basic/LLVM.h"
19
#include "clang/Basic/TokenKinds.h"
20
#include "llvm/ADT/DenseMapInfo.h"
21
#include "llvm/ADT/SmallString.h"
22
#include "llvm/ADT/StringMap.h"
23
#include "llvm/ADT/StringRef.h"
24
#include "llvm/Support/Allocator.h"
25
#include "llvm/Support/PointerLikeTypeTraits.h"
26
#include "llvm/Support/type_traits.h"
27
#include <cassert>
28
#include <cstddef>
29
#include <cstdint>
30
#include <cstring>
31
#include <string>
32
#include <utility>
33
34
namespace clang {
35
36
class DeclarationName;
37
class DeclarationNameTable;
38
class IdentifierInfo;
39
class LangOptions;
40
class MultiKeywordSelector;
41
class SourceLocation;
42
43
enum class ReservedIdentifierStatus {
44
  NotReserved = 0,
45
  StartsWithUnderscoreAtGlobalScope,
46
  StartsWithUnderscoreAndIsExternC,
47
  StartsWithDoubleUnderscore,
48
  StartsWithUnderscoreFollowedByCapitalLetter,
49
  ContainsDoubleUnderscore,
50
};
51
52
/// Determine whether an identifier is reserved for use as a name at global
53
/// scope. Such identifiers might be implementation-specific global functions
54
/// or variables.
55
47.8M
inline bool isReservedAtGlobalScope(ReservedIdentifierStatus Status) {
56
47.8M
  return Status != ReservedIdentifierStatus::NotReserved;
57
47.8M
}
58
59
/// Determine whether an identifier is reserved in all contexts. Such
60
/// identifiers might be implementation-specific keywords or macros, for
61
/// example.
62
15.8M
inline bool isReservedInAllContexts(ReservedIdentifierStatus Status) {
63
15.8M
  return Status != ReservedIdentifierStatus::NotReserved &&
64
15.8M
         
Status != ReservedIdentifierStatus::StartsWithUnderscoreAtGlobalScope12.8M
&&
65
15.8M
         
Status != ReservedIdentifierStatus::StartsWithUnderscoreAndIsExternC11.5M
;
66
15.8M
}
67
68
/// A simple pair of identifier info and location.
69
using IdentifierLocPair = std::pair<IdentifierInfo *, SourceLocation>;
70
71
/// IdentifierInfo and other related classes are aligned to
72
/// 8 bytes so that DeclarationName can use the lower 3 bits
73
/// of a pointer to one of these classes.
74
enum { IdentifierInfoAlignment = 8 };
75
76
static constexpr int ObjCOrBuiltinIDBits = 16;
77
78
/// One of these records is kept for each identifier that
79
/// is lexed.  This contains information about whether the token was \#define'd,
80
/// is a language keyword, or if it is a front-end token of some sort (e.g. a
81
/// variable or function name).  The preprocessor keeps this information in a
82
/// set, and all tok::identifier tokens have a pointer to one of these.
83
/// It is aligned to 8 bytes because DeclarationName needs the lower 3 bits.
84
class alignas(IdentifierInfoAlignment) IdentifierInfo {
85
  friend class IdentifierTable;
86
87
  // Front-end token ID or tok::identifier.
88
  unsigned TokenID : 9;
89
90
  // ObjC keyword ('protocol' in '@protocol') or builtin (__builtin_inf).
91
  // First NUM_OBJC_KEYWORDS values are for Objective-C,
92
  // the remaining values are for builtins.
93
  unsigned ObjCOrBuiltinID : ObjCOrBuiltinIDBits;
94
95
  // True if there is a #define for this.
96
  unsigned HasMacro : 1;
97
98
  // True if there was a #define for this.
99
  unsigned HadMacro : 1;
100
101
  // True if the identifier is a language extension.
102
  unsigned IsExtension : 1;
103
104
  // True if the identifier is a keyword in a newer or proposed Standard.
105
  unsigned IsFutureCompatKeyword : 1;
106
107
  // True if the identifier is poisoned.
108
  unsigned IsPoisoned : 1;
109
110
  // True if the identifier is a C++ operator keyword.
111
  unsigned IsCPPOperatorKeyword : 1;
112
113
  // Internal bit set by the member function RecomputeNeedsHandleIdentifier.
114
  // See comment about RecomputeNeedsHandleIdentifier for more info.
115
  unsigned NeedsHandleIdentifier : 1;
116
117
  // True if the identifier was loaded (at least partially) from an AST file.
118
  unsigned IsFromAST : 1;
119
120
  // True if the identifier has changed from the definition
121
  // loaded from an AST file.
122
  unsigned ChangedAfterLoad : 1;
123
124
  // True if the identifier's frontend information has changed from the
125
  // definition loaded from an AST file.
126
  unsigned FEChangedAfterLoad : 1;
127
128
  // True if revertTokenIDToIdentifier was called.
129
  unsigned RevertedTokenID : 1;
130
131
  // True if there may be additional information about
132
  // this identifier stored externally.
133
  unsigned OutOfDate : 1;
134
135
  // True if this is the 'import' contextual keyword.
136
  unsigned IsModulesImport : 1;
137
138
  // True if this is a mangled OpenMP variant name.
139
  unsigned IsMangledOpenMPVariantName : 1;
140
141
  // True if this is a deprecated macro.
142
  unsigned IsDeprecatedMacro : 1;
143
144
  // True if this macro is unsafe in headers.
145
  unsigned IsRestrictExpansion : 1;
146
147
  // True if this macro is final.
148
  unsigned IsFinal : 1;
149
150
  // 22 bits left in a 64-bit word.
151
152
  // Managed by the language front-end.
153
  void *FETokenInfo = nullptr;
154
155
  llvm::StringMapEntry<IdentifierInfo *> *Entry = nullptr;
156
157
  IdentifierInfo()
158
      : TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(false),
159
        HadMacro(false), IsExtension(false), IsFutureCompatKeyword(false),
160
        IsPoisoned(false), IsCPPOperatorKeyword(false),
161
        NeedsHandleIdentifier(false), IsFromAST(false), ChangedAfterLoad(false),
162
        FEChangedAfterLoad(false), RevertedTokenID(false), OutOfDate(false),
163
        IsModulesImport(false), IsMangledOpenMPVariantName(false),
164
406M
        IsDeprecatedMacro(false), IsRestrictExpansion(false), IsFinal(false) {}
165
166
public:
167
  IdentifierInfo(const IdentifierInfo &) = delete;
168
  IdentifierInfo &operator=(const IdentifierInfo &) = delete;
169
  IdentifierInfo(IdentifierInfo &&) = delete;
170
  IdentifierInfo &operator=(IdentifierInfo &&) = delete;
171
172
  /// Return true if this is the identifier for the specified string.
173
  ///
174
  /// This is intended to be used for string literals only: II->isStr("foo").
175
  template <std::size_t StrLen>
176
255M
  bool isStr(const char (&Str)[StrLen]) const {
177
255M
    return getLength() == StrLen-1 &&
178
255M
           
memcmp(getNameStart(), Str, StrLen-1) == 014.3M
;
179
255M
  }
bool clang::IdentifierInfo::isStr<5ul>(char const (&) [5ul]) const
Line
Count
Source
176
122M
  bool isStr(const char (&Str)[StrLen]) const {
177
122M
    return getLength() == StrLen-1 &&
178
122M
           
memcmp(getNameStart(), Str, StrLen-1) == 01.41M
;
179
122M
  }
bool clang::IdentifierInfo::isStr<20ul>(char const (&) [20ul]) const
Line
Count
Source
176
24.9k
  bool isStr(const char (&Str)[StrLen]) const {
177
24.9k
    return getLength() == StrLen-1 &&
178
24.9k
           
memcmp(getNameStart(), Str, StrLen-1) == 01.17k
;
179
24.9k
  }
bool clang::IdentifierInfo::isStr<7ul>(char const (&) [7ul]) const
Line
Count
Source
176
9.31M
  bool isStr(const char (&Str)[StrLen]) const {
177
9.31M
    return getLength() == StrLen-1 &&
178
9.31M
           
memcmp(getNameStart(), Str, StrLen-1) == 0556k
;
179
9.31M
  }
bool clang::IdentifierInfo::isStr<8ul>(char const (&) [8ul]) const
Line
Count
Source
176
22.7M
  bool isStr(const char (&Str)[StrLen]) const {
177
22.7M
    return getLength() == StrLen-1 &&
178
22.7M
           
memcmp(getNameStart(), Str, StrLen-1) == 02.80M
;
179
22.7M
  }
bool clang::IdentifierInfo::isStr<6ul>(char const (&) [6ul]) const
Line
Count
Source
176
9.00M
  bool isStr(const char (&Str)[StrLen]) const {
177
9.00M
    return getLength() == StrLen-1 &&
178
9.00M
           
memcmp(getNameStart(), Str, StrLen-1) == 03.27M
;
179
9.00M
  }
bool clang::IdentifierInfo::isStr<4ul>(char const (&) [4ul]) const
Line
Count
Source
176
3.81M
  bool isStr(const char (&Str)[StrLen]) const {
177
3.81M
    return getLength() == StrLen-1 &&
178
3.81M
           
memcmp(getNameStart(), Str, StrLen-1) == 01.86M
;
179
3.81M
  }
bool clang::IdentifierInfo::isStr<22ul>(char const (&) [22ul]) const
Line
Count
Source
176
34
  bool isStr(const char (&Str)[StrLen]) const {
177
34
    return getLength() == StrLen-1 &&
178
34
           
memcmp(getNameStart(), Str, StrLen-1) == 022
;
179
34
  }
bool clang::IdentifierInfo::isStr<13ul>(char const (&) [13ul]) const
Line
Count
Source
176
14.0k
  bool isStr(const char (&Str)[StrLen]) const {
177
14.0k
    return getLength() == StrLen-1 &&
178
14.0k
           
memcmp(getNameStart(), Str, StrLen-1) == 067
;
179
14.0k
  }
bool clang::IdentifierInfo::isStr<14ul>(char const (&) [14ul]) const
Line
Count
Source
176
15.7k
  bool isStr(const char (&Str)[StrLen]) const {
177
15.7k
    return getLength() == StrLen-1 &&
178
15.7k
           
memcmp(getNameStart(), Str, StrLen-1) == 01.15k
;
179
15.7k
  }
bool clang::IdentifierInfo::isStr<15ul>(char const (&) [15ul]) const
Line
Count
Source
176
31.2k
  bool isStr(const char (&Str)[StrLen]) const {
177
31.2k
    return getLength() == StrLen-1 &&
178
31.2k
           
memcmp(getNameStart(), Str, StrLen-1) == 0184
;
179
31.2k
  }
bool clang::IdentifierInfo::isStr<10ul>(char const (&) [10ul]) const
Line
Count
Source
176
27.4M
  bool isStr(const char (&Str)[StrLen]) const {
177
27.4M
    return getLength() == StrLen-1 &&
178
27.4M
           
memcmp(getNameStart(), Str, StrLen-1) == 01.54M
;
179
27.4M
  }
bool clang::IdentifierInfo::isStr<12ul>(char const (&) [12ul]) const
Line
Count
Source
176
1.78M
  bool isStr(const char (&Str)[StrLen]) const {
177
1.78M
    return getLength() == StrLen-1 &&
178
1.78M
           
memcmp(getNameStart(), Str, StrLen-1) == 017.6k
;
179
1.78M
  }
bool clang::IdentifierInfo::isStr<9ul>(char const (&) [9ul]) const
Line
Count
Source
176
27.9M
  bool isStr(const char (&Str)[StrLen]) const {
177
27.9M
    return getLength() == StrLen-1 &&
178
27.9M
           
memcmp(getNameStart(), Str, StrLen-1) == 02.32M
;
179
27.9M
  }
bool clang::IdentifierInfo::isStr<16ul>(char const (&) [16ul]) const
Line
Count
Source
176
78.3k
  bool isStr(const char (&Str)[StrLen]) const {
177
78.3k
    return getLength() == StrLen-1 &&
178
78.3k
           
memcmp(getNameStart(), Str, StrLen-1) == 013.6k
;
179
78.3k
  }
bool clang::IdentifierInfo::isStr<17ul>(char const (&) [17ul]) const
Line
Count
Source
176
78.2k
  bool isStr(const char (&Str)[StrLen]) const {
177
78.2k
    return getLength() == StrLen-1 &&
178
78.2k
           
memcmp(getNameStart(), Str, StrLen-1) == 022
;
179
78.2k
  }
bool clang::IdentifierInfo::isStr<11ul>(char const (&) [11ul]) const
Line
Count
Source
176
3.24M
  bool isStr(const char (&Str)[StrLen]) const {
177
3.24M
    return getLength() == StrLen-1 &&
178
3.24M
           
memcmp(getNameStart(), Str, StrLen-1) == 0132k
;
179
3.24M
  }
bool clang::IdentifierInfo::isStr<3ul>(char const (&) [3ul]) const
Line
Count
Source
176
1.31k
  bool isStr(const char (&Str)[StrLen]) const {
177
1.31k
    return getLength() == StrLen-1 &&
178
1.31k
           
memcmp(getNameStart(), Str, StrLen-1) == 0905
;
179
1.31k
  }
bool clang::IdentifierInfo::isStr<2ul>(char const (&) [2ul]) const
Line
Count
Source
176
240k
  bool isStr(const char (&Str)[StrLen]) const {
177
240k
    return getLength() == StrLen-1 &&
178
240k
           
memcmp(getNameStart(), Str, StrLen-1) == 01.44k
;
179
240k
  }
bool clang::IdentifierInfo::isStr<18ul>(char const (&) [18ul]) const
Line
Count
Source
176
423k
  bool isStr(const char (&Str)[StrLen]) const {
177
423k
    return getLength() == StrLen-1 &&
178
423k
           
memcmp(getNameStart(), Str, StrLen-1) == 0155
;
179
423k
  }
bool clang::IdentifierInfo::isStr<19ul>(char const (&) [19ul]) const
Line
Count
Source
176
2.17k
  bool isStr(const char (&Str)[StrLen]) const {
177
2.17k
    return getLength() == StrLen-1 &&
178
2.17k
           
memcmp(getNameStart(), Str, StrLen-1) == 019
;
179
2.17k
  }
bool clang::IdentifierInfo::isStr<21ul>(char const (&) [21ul]) const
Line
Count
Source
176
85
  bool isStr(const char (&Str)[StrLen]) const {
177
85
    return getLength() == StrLen-1 &&
178
85
           
memcmp(getNameStart(), Str, StrLen-1) == 010
;
179
85
  }
bool clang::IdentifierInfo::isStr<29ul>(char const (&) [29ul]) const
Line
Count
Source
176
26.7M
  bool isStr(const char (&Str)[StrLen]) const {
177
26.7M
    return getLength() == StrLen-1 &&
178
26.7M
           
memcmp(getNameStart(), Str, StrLen-1) == 0344k
;
179
26.7M
  }
bool clang::IdentifierInfo::isStr<27ul>(char const (&) [27ul]) const
Line
Count
Source
176
23.9k
  bool isStr(const char (&Str)[StrLen]) const {
177
23.9k
    return getLength() == StrLen-1 &&
178
23.9k
           
memcmp(getNameStart(), Str, StrLen-1) == 031
;
179
23.9k
  }
bool clang::IdentifierInfo::isStr<30ul>(char const (&) [30ul]) const
Line
Count
Source
176
73
  bool isStr(const char (&Str)[StrLen]) const {
177
73
    return getLength() == StrLen-1 &&
178
73
           
memcmp(getNameStart(), Str, StrLen-1) == 03
;
179
73
  }
bool clang::IdentifierInfo::isStr<24ul>(char const (&) [24ul]) const
Line
Count
Source
176
1.63k
  bool isStr(const char (&Str)[StrLen]) const {
177
1.63k
    return getLength() == StrLen-1 &&
178
1.63k
           
memcmp(getNameStart(), Str, StrLen-1) == 016
;
179
1.63k
  }
180
181
  /// Return true if this is the identifier for the specified StringRef.
182
2.14k
  bool isStr(llvm::StringRef Str) const {
183
2.14k
    llvm::StringRef ThisStr(getNameStart(), getLength());
184
2.14k
    return ThisStr == Str;
185
2.14k
  }
186
187
  /// Return the beginning of the actual null-terminated string for this
188
  /// identifier.
189
1.87G
  const char *getNameStart() const { return Entry->getKeyData(); }
190
191
  /// Efficiently return the length of this identifier info.
192
2.11G
  unsigned getLength() const { return Entry->getKeyLength(); }
193
194
  /// Return the actual identifier string.
195
1.72G
  StringRef getName() const {
196
1.72G
    return StringRef(getNameStart(), getLength());
197
1.72G
  }
198
199
  /// Return true if this identifier is \#defined to some other value.
200
  /// \note The current definition may be in a module and not currently visible.
201
859M
  bool hasMacroDefinition() const {
202
859M
    return HasMacro;
203
859M
  }
204
46.1M
  void setHasMacroDefinition(bool Val) {
205
46.1M
    if (HasMacro == Val) 
return864k
;
206
207
45.2M
    HasMacro = Val;
208
45.2M
    if (Val) {
209
45.2M
      NeedsHandleIdentifier = true;
210
45.2M
      HadMacro = true;
211
45.2M
    } else {
212
      // If this is a final macro, make the deprecation and header unsafe bits
213
      // stick around after the undefinition so they apply to any redefinitions.
214
75.4k
      if (
!IsFinal75.3k
) {
215
        // Because calling the setters of these calls recomputes, just set them
216
        // manually to avoid recomputing a bunch of times.
217
75.4k
        IsDeprecatedMacro = false;
218
75.4k
        IsRestrictExpansion = false;
219
75.4k
      }
220
75.3k
      RecomputeNeedsHandleIdentifier();
221
75.3k
    }
222
45.2M
  }
223
  /// Returns true if this identifier was \#defined to some value at any
224
  /// moment. In this case there should be an entry for the identifier in the
225
  /// macro history table in Preprocessor.
226
82.0M
  bool hadMacroDefinition() const {
227
82.0M
    return HadMacro;
228
82.0M
  }
229
230
66.3M
  bool isDeprecatedMacro() const { return IsDeprecatedMacro; }
231
232
26
  void setIsDeprecatedMacro(bool Val) {
233
26
    if (IsDeprecatedMacro == Val)
234
1
      return;
235
25
    IsDeprecatedMacro = Val;
236
25
    if (Val)
237
25
      NeedsHandleIdentifier = true;
238
0
    else
239
0
      RecomputeNeedsHandleIdentifier();
240
25
  }
241
242
66.3M
  bool isRestrictExpansion() const { return IsRestrictExpansion; }
243
244
7
  void setIsRestrictExpansion(bool Val) {
245
7
    if (IsRestrictExpansion == Val)
246
1
      return;
247
6
    IsRestrictExpansion = Val;
248
6
    if (Val)
249
6
      NeedsHandleIdentifier = true;
250
0
    else
251
0
      RecomputeNeedsHandleIdentifier();
252
6
  }
253
254
634k
  bool isFinal() const { return IsFinal; }
255
256
3
  void setIsFinal(bool Val) { IsFinal = Val; }
257
258
  /// If this is a source-language token (e.g. 'for'), this API
259
  /// can be used to cause the lexer to map identifiers to source-language
260
  /// tokens.
261
724M
  tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
262
263
  /// True if revertTokenIDToIdentifier() was called.
264
43.2M
  bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
265
266
  /// Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
267
  /// compatibility.
268
  ///
269
  /// TokenID is normally read-only but there are 2 instances where we revert it
270
  /// to tok::identifier for libstdc++ 4.2. Keep track of when this happens
271
  /// using this method so we can inform serialization about it.
272
127k
  void revertTokenIDToIdentifier() {
273
127k
    assert(TokenID != tok::identifier && "Already at tok::identifier");
274
0
    TokenID = tok::identifier;
275
127k
    RevertedTokenID = true;
276
127k
  }
277
5
  void revertIdentifierToTokenID(tok::TokenKind TK) {
278
5
    assert(TokenID == tok::identifier && "Should be at tok::identifier");
279
0
    TokenID = TK;
280
5
    RevertedTokenID = false;
281
5
  }
282
283
  /// Return the preprocessor keyword ID for this identifier.
284
  ///
285
  /// For example, "define" will return tok::pp_define.
286
  tok::PPKeywordKind getPPKeywordID() const;
287
288
  /// Return the Objective-C keyword ID for the this identifier.
289
  ///
290
  /// For example, 'class' will return tok::objc_class if ObjC is enabled.
291
1.28M
  tok::ObjCKeywordKind getObjCKeywordID() const {
292
1.28M
    if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
293
1.28M
      return tok::ObjCKeywordKind(ObjCOrBuiltinID);
294
6
    else
295
6
      return tok::objc_not_keyword;
296
1.28M
  }
297
2.18M
  void setObjCKeywordID(tok::ObjCKeywordKind ID) { ObjCOrBuiltinID = ID; }
298
299
  /// Return a value indicating whether this is a builtin function.
300
  ///
301
  /// 0 is not-built-in. 1+ are specific builtin functions.
302
340M
  unsigned getBuiltinID() const {
303
340M
    if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
304
102M
      return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
305
237M
    else
306
237M
      return 0;
307
340M
  }
308
269M
  void setBuiltinID(unsigned ID) {
309
269M
    ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS;
310
269M
    assert(ObjCOrBuiltinID - unsigned(tok::NUM_OBJC_KEYWORDS) == ID
311
269M
           && "ID too large for field!");
312
269M
  }
313
314
55.9M
  unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
315
627k
  void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
316
317
  /// get/setExtension - Initialize information about whether or not this
318
  /// language token is an extension.  This controls extension warnings, and is
319
  /// only valid if a custom token ID is set.
320
113M
  bool isExtensionToken() const { return IsExtension; }
321
36.0M
  void setIsExtensionToken(bool Val) {
322
36.0M
    IsExtension = Val;
323
36.0M
    if (Val)
324
3.02M
      NeedsHandleIdentifier = true;
325
33.0M
    else
326
33.0M
      RecomputeNeedsHandleIdentifier();
327
36.0M
  }
328
329
  /// is/setIsFutureCompatKeyword - Initialize information about whether or not
330
  /// this language token is a keyword in a newer or proposed Standard. This
331
  /// controls compatibility warnings, and is only true when not parsing the
332
  /// corresponding Standard. Once a compatibility problem has been diagnosed
333
  /// with this keyword, the flag will be cleared.
334
97.3M
  bool isFutureCompatKeyword() const { return IsFutureCompatKeyword; }
335
36.0M
  void setIsFutureCompatKeyword(bool Val) {
336
36.0M
    IsFutureCompatKeyword = Val;
337
36.0M
    if (Val)
338
761k
      NeedsHandleIdentifier = true;
339
35.3M
    else
340
35.3M
      RecomputeNeedsHandleIdentifier();
341
36.0M
  }
342
343
  /// setIsPoisoned - Mark this identifier as poisoned.  After poisoning, the
344
  /// Preprocessor will emit an error every time this token is used.
345
84.4M
  void setIsPoisoned(bool Value = true) {
346
84.4M
    IsPoisoned = Value;
347
84.4M
    if (Value)
348
83.6M
      NeedsHandleIdentifier = true;
349
795k
    else
350
795k
      RecomputeNeedsHandleIdentifier();
351
84.4M
  }
352
353
  /// Return true if this token has been poisoned.
354
541M
  bool isPoisoned() const { return IsPoisoned; }
355
356
  /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
357
  /// this identifier is a C++ alternate representation of an operator.
358
1.12M
  void setIsCPlusPlusOperatorKeyword(bool Val = true) {
359
1.12M
    IsCPPOperatorKeyword = Val;
360
1.12M
  }
361
62.9M
  bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
362
363
  /// Return true if this token is a keyword in the specified language.
364
  bool isKeyword(const LangOptions &LangOpts) const;
365
366
  /// Return true if this token is a C++ keyword in the specified
367
  /// language.
368
  bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
369
370
  /// Get and set FETokenInfo. The language front-end is allowed to associate
371
  /// arbitrary metadata with this token.
372
519M
  void *getFETokenInfo() const { return FETokenInfo; }
373
81.7M
  void setFETokenInfo(void *T) { FETokenInfo = T; }
374
375
  /// Return true if the Preprocessor::HandleIdentifier must be called
376
  /// on a token of this identifier.
377
  ///
378
  /// If this returns false, we know that HandleIdentifier will not affect
379
  /// the token.
380
709M
  bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
381
382
  /// Return true if the identifier in its current state was loaded
383
  /// from an AST file.
384
161M
  bool isFromAST() const { return IsFromAST; }
385
386
16.7M
  void setIsFromAST() { IsFromAST = true; }
387
388
  /// Determine whether this identifier has changed since it was loaded
389
  /// from an AST file.
390
1.92M
  bool hasChangedSinceDeserialization() const {
391
1.92M
    return ChangedAfterLoad;
392
1.92M
  }
393
394
  /// Note that this identifier has changed since it was loaded from
395
  /// an AST file.
396
82.3k
  void setChangedSinceDeserialization() {
397
82.3k
    ChangedAfterLoad = true;
398
82.3k
  }
399
400
  /// Determine whether the frontend token information for this
401
  /// identifier has changed since it was loaded from an AST file.
402
83.9k
  bool hasFETokenInfoChangedSinceDeserialization() const {
403
83.9k
    return FEChangedAfterLoad;
404
83.9k
  }
405
406
  /// Note that the frontend token information for this identifier has
407
  /// changed since it was loaded from an AST file.
408
412k
  void setFETokenInfoChangedSinceDeserialization() {
409
412k
    FEChangedAfterLoad = true;
410
412k
  }
411
412
  /// Determine whether the information for this identifier is out of
413
  /// date with respect to the external source.
414
921M
  bool isOutOfDate() const { return OutOfDate; }
415
416
  /// Set whether the information for this identifier is out of
417
  /// date with respect to the external source.
418
27.4M
  void setOutOfDate(bool OOD) {
419
27.4M
    OutOfDate = OOD;
420
27.4M
    if (OOD)
421
21.1M
      NeedsHandleIdentifier = true;
422
6.30M
    else
423
6.30M
      RecomputeNeedsHandleIdentifier();
424
27.4M
  }
425
426
  /// Determine whether this is the contextual keyword \c import.
427
72.5M
  bool isModulesImport() const { return IsModulesImport; }
428
429
  /// Set whether this identifier is the contextual keyword \c import.
430
152k
  void setModulesImport(bool I) {
431
152k
    IsModulesImport = I;
432
152k
    if (I)
433
152k
      NeedsHandleIdentifier = true;
434
0
    else
435
0
      RecomputeNeedsHandleIdentifier();
436
152k
  }
437
438
  /// Determine whether this is the mangled name of an OpenMP variant.
439
3.28M
  bool isMangledOpenMPVariantName() const { return IsMangledOpenMPVariantName; }
440
441
  /// Set whether this is the mangled name of an OpenMP variant.
442
7.20k
  void setMangledOpenMPVariantName(bool I) { IsMangledOpenMPVariantName = I; }
443
444
  /// Return true if this identifier is an editor placeholder.
445
  ///
446
  /// Editor placeholders are produced by the code-completion engine and are
447
  /// represented as characters between '<#' and '#>' in the source code. An
448
  /// example of auto-completed call with a placeholder parameter is shown
449
  /// below:
450
  /// \code
451
  ///   function(<#int x#>);
452
  /// \endcode
453
16.1M
  bool isEditorPlaceholder() const {
454
16.1M
    return getName().startswith("<#") && 
getName().endswith("#>")27
;
455
16.1M
  }
456
457
  /// Determine whether \p this is a name reserved for the implementation (C99
458
  /// 7.1.3, C++ [lib.global.names]).
459
  ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const;
460
461
  /// Provide less than operator for lexicographical sorting.
462
558M
  bool operator<(const IdentifierInfo &RHS) const {
463
558M
    return getName() < RHS.getName();
464
558M
  }
465
466
private:
467
  /// The Preprocessor::HandleIdentifier does several special (but rare)
468
  /// things to identifiers of various sorts.  For example, it changes the
469
  /// \c for keyword token from tok::identifier to tok::for.
470
  ///
471
  /// This method is very tied to the definition of HandleIdentifier.  Any
472
  /// change to it should be reflected here.
473
75.5M
  void RecomputeNeedsHandleIdentifier() {
474
75.5M
    NeedsHandleIdentifier = isPoisoned() || 
hasMacroDefinition()75.5M
||
475
75.5M
                            
isExtensionToken()75.3M
||
isFutureCompatKeyword()72.3M
||
476
75.5M
                            
isOutOfDate()72.3M
||
isModulesImport()72.3M
;
477
75.5M
  }
478
};
479
480
/// An RAII object for [un]poisoning an identifier within a scope.
481
///
482
/// \p II is allowed to be null, in which case objects of this type have
483
/// no effect.
484
class PoisonIdentifierRAIIObject {
485
  IdentifierInfo *const II;
486
  const bool OldValue;
487
488
public:
489
  PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
490
26.7M
    : II(II), OldValue(II ? II->isPoisoned() : false) {
491
26.7M
    if(II)
492
432
      II->setIsPoisoned(NewValue);
493
26.7M
  }
494
495
26.7M
  ~PoisonIdentifierRAIIObject() {
496
26.7M
    if(II)
497
432
      II->setIsPoisoned(OldValue);
498
26.7M
  }
499
};
500
501
/// An iterator that walks over all of the known identifiers
502
/// in the lookup table.
503
///
504
/// Since this iterator uses an abstract interface via virtual
505
/// functions, it uses an object-oriented interface rather than the
506
/// more standard C++ STL iterator interface. In this OO-style
507
/// iteration, the single function \c Next() provides dereference,
508
/// advance, and end-of-sequence checking in a single
509
/// operation. Subclasses of this iterator type will provide the
510
/// actual functionality.
511
class IdentifierIterator {
512
protected:
513
374
  IdentifierIterator() = default;
514
515
public:
516
  IdentifierIterator(const IdentifierIterator &) = delete;
517
  IdentifierIterator &operator=(const IdentifierIterator &) = delete;
518
519
  virtual ~IdentifierIterator();
520
521
  /// Retrieve the next string in the identifier table and
522
  /// advances the iterator for the following string.
523
  ///
524
  /// \returns The next string in the identifier table. If there is
525
  /// no such string, returns an empty \c StringRef.
526
  virtual StringRef Next() = 0;
527
};
528
529
/// Provides lookups to, and iteration over, IdentiferInfo objects.
530
class IdentifierInfoLookup {
531
public:
532
  virtual ~IdentifierInfoLookup();
533
534
  /// Return the IdentifierInfo for the specified named identifier.
535
  ///
536
  /// Unlike the version in IdentifierTable, this returns a pointer instead
537
  /// of a reference.  If the pointer is null then the IdentifierInfo cannot
538
  /// be found.
539
  virtual IdentifierInfo* get(StringRef Name) = 0;
540
541
  /// Retrieve an iterator into the set of all identifiers
542
  /// known to this identifier lookup source.
543
  ///
544
  /// This routine provides access to all of the identifiers known to
545
  /// the identifier lookup, allowing access to the contents of the
546
  /// identifiers without introducing the overhead of constructing
547
  /// IdentifierInfo objects for each.
548
  ///
549
  /// \returns A new iterator into the set of known identifiers. The
550
  /// caller is responsible for deleting this iterator.
551
  virtual IdentifierIterator *getIdentifiers();
552
};
553
554
/// Implements an efficient mapping from strings to IdentifierInfo nodes.
555
///
556
/// This has no other purpose, but this is an extremely performance-critical
557
/// piece of the code, as each occurrence of every identifier goes through
558
/// here when lexed.
559
class IdentifierTable {
560
  // Shark shows that using MallocAllocator is *much* slower than using this
561
  // BumpPtrAllocator!
562
  using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
563
  HashTableTy HashTable;
564
565
  IdentifierInfoLookup* ExternalLookup;
566
567
public:
568
  /// Create the identifier table.
569
  explicit IdentifierTable(IdentifierInfoLookup *ExternalLookup = nullptr);
570
571
  /// Create the identifier table, populating it with info about the
572
  /// language keywords for the language specified by \p LangOpts.
573
  explicit IdentifierTable(const LangOptions &LangOpts,
574
                           IdentifierInfoLookup *ExternalLookup = nullptr);
575
576
  /// Set the external identifier lookup mechanism.
577
17.9k
  void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup) {
578
17.9k
    ExternalLookup = IILookup;
579
17.9k
  }
580
581
  /// Retrieve the external identifier lookup object, if any.
582
5.08M
  IdentifierInfoLookup *getExternalIdentifierLookup() const {
583
5.08M
    return ExternalLookup;
584
5.08M
  }
585
586
406M
  llvm::BumpPtrAllocator& getAllocator() {
587
406M
    return HashTable.getAllocator();
588
406M
  }
589
590
  /// Return the identifier token info for the specified named
591
  /// identifier.
592
831M
  IdentifierInfo &get(StringRef Name) {
593
831M
    auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
594
595
831M
    IdentifierInfo *&II = Entry.second;
596
831M
    if (II) 
return *II439M
;
597
598
    // No entry; if we have an external lookup, look there first.
599
391M
    if (ExternalLookup) {
600
3.08M
      II = ExternalLookup->get(Name);
601
3.08M
      if (II)
602
722k
        return *II;
603
3.08M
    }
604
605
    // Lookups failed, make a new IdentifierInfo.
606
391M
    void *Mem = getAllocator().Allocate<IdentifierInfo>();
607
391M
    II = new (Mem) IdentifierInfo();
608
609
    // Make sure getName() knows how to find the IdentifierInfo
610
    // contents.
611
391M
    II->Entry = &Entry;
612
613
391M
    return *II;
614
391M
  }
615
616
37.2M
  IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
617
37.2M
    IdentifierInfo &II = get(Name);
618
37.2M
    II.TokenID = TokenCode;
619
37.2M
    assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
620
0
    return II;
621
37.2M
  }
622
623
  /// Gets an IdentifierInfo for the given name without consulting
624
  ///        external sources.
625
  ///
626
  /// This is a version of get() meant for external sources that want to
627
  /// introduce or modify an identifier. If they called get(), they would
628
  /// likely end up in a recursion.
629
17.0M
  IdentifierInfo &getOwn(StringRef Name) {
630
17.0M
    auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
631
632
17.0M
    IdentifierInfo *&II = Entry.second;
633
17.0M
    if (II)
634
1.80M
      return *II;
635
636
    // Lookups failed, make a new IdentifierInfo.
637
15.2M
    void *Mem = getAllocator().Allocate<IdentifierInfo>();
638
15.2M
    II = new (Mem) IdentifierInfo();
639
640
    // Make sure getName() knows how to find the IdentifierInfo
641
    // contents.
642
15.2M
    II->Entry = &Entry;
643
644
    // If this is the 'import' contextual keyword, mark it as such.
645
15.2M
    if (Name.equals("import"))
646
0
      II->setModulesImport(true);
647
648
15.2M
    return *II;
649
17.0M
  }
650
651
  using iterator = HashTableTy::const_iterator;
652
  using const_iterator = HashTableTy::const_iterator;
653
654
26.0k
  iterator begin() const { return HashTable.begin(); }
655
26.0k
  iterator end() const   { return HashTable.end(); }
656
0
  unsigned size() const  { return HashTable.size(); }
657
658
0
  iterator find(StringRef Name) const { return HashTable.find(Name); }
659
660
  /// Print some statistics to stderr that indicate how well the
661
  /// hashing is doing.
662
  void PrintStats() const;
663
664
  /// Populate the identifier table with info about the language keywords
665
  /// for the language specified by \p LangOpts.
666
  void AddKeywords(const LangOptions &LangOpts);
667
};
668
669
/// A family of Objective-C methods.
670
///
671
/// These families have no inherent meaning in the language, but are
672
/// nonetheless central enough in the existing implementations to
673
/// merit direct AST support.  While, in theory, arbitrary methods can
674
/// be considered to form families, we focus here on the methods
675
/// involving allocation and retain-count management, as these are the
676
/// most "core" and the most likely to be useful to diverse clients
677
/// without extra information.
678
///
679
/// Both selectors and actual method declarations may be classified
680
/// into families.  Method families may impose additional restrictions
681
/// beyond their selector name; for example, a method called '_init'
682
/// that returns void is not considered to be in the 'init' family
683
/// (but would be if it returned 'id').  It is also possible to
684
/// explicitly change or remove a method's family.  Therefore the
685
/// method's family should be considered the single source of truth.
686
enum ObjCMethodFamily {
687
  /// No particular method family.
688
  OMF_None,
689
690
  // Selectors in these families may have arbitrary arity, may be
691
  // written with arbitrary leading underscores, and may have
692
  // additional CamelCase "words" in their first selector chunk
693
  // following the family name.
694
  OMF_alloc,
695
  OMF_copy,
696
  OMF_init,
697
  OMF_mutableCopy,
698
  OMF_new,
699
700
  // These families are singletons consisting only of the nullary
701
  // selector with the given name.
702
  OMF_autorelease,
703
  OMF_dealloc,
704
  OMF_finalize,
705
  OMF_release,
706
  OMF_retain,
707
  OMF_retainCount,
708
  OMF_self,
709
  OMF_initialize,
710
711
  // performSelector families
712
  OMF_performSelector
713
};
714
715
/// Enough bits to store any enumerator in ObjCMethodFamily or
716
/// InvalidObjCMethodFamily.
717
enum { ObjCMethodFamilyBitWidth = 4 };
718
719
/// An invalid value of ObjCMethodFamily.
720
enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
721
722
/// A family of Objective-C methods.
723
///
724
/// These are family of methods whose result type is initially 'id', but
725
/// but are candidate for the result type to be changed to 'instancetype'.
726
enum ObjCInstanceTypeFamily {
727
  OIT_None,
728
  OIT_Array,
729
  OIT_Dictionary,
730
  OIT_Singleton,
731
  OIT_Init,
732
  OIT_ReturnsSelf
733
};
734
735
enum ObjCStringFormatFamily {
736
  SFF_None,
737
  SFF_NSString,
738
  SFF_CFString
739
};
740
741
/// Smart pointer class that efficiently represents Objective-C method
742
/// names.
743
///
744
/// This class will either point to an IdentifierInfo or a
745
/// MultiKeywordSelector (which is private). This enables us to optimize
746
/// selectors that take no arguments and selectors that take 1 argument, which
747
/// accounts for 78% of all selectors in Cocoa.h.
748
class Selector {
749
  friend class Diagnostic;
750
  friend class SelectorTable; // only the SelectorTable can create these
751
  friend class DeclarationName; // and the AST's DeclarationName.
752
753
  enum IdentifierInfoFlag {
754
    // Empty selector = 0. Note that these enumeration values must
755
    // correspond to the enumeration values of DeclarationName::StoredNameKind
756
    ZeroArg  = 0x01,
757
    OneArg   = 0x02,
758
    MultiArg = 0x07,
759
    ArgFlags = 0x07
760
  };
761
762
  /// A pointer to the MultiKeywordSelector or IdentifierInfo. We use the low
763
  /// three bits of InfoPtr to store an IdentifierInfoFlag. Note that in any
764
  /// case IdentifierInfo and MultiKeywordSelector are already aligned to
765
  /// 8 bytes even on 32 bits archs because of DeclarationName.
766
  uintptr_t InfoPtr = 0;
767
768
1.20M
  Selector(IdentifierInfo *II, unsigned nArgs) {
769
1.20M
    InfoPtr = reinterpret_cast<uintptr_t>(II);
770
1.20M
    assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
771
0
    assert(nArgs < 2 && "nArgs not equal to 0/1");
772
0
    InfoPtr |= nArgs+1;
773
1.20M
  }
774
775
318k
  Selector(MultiKeywordSelector *SI) {
776
318k
    InfoPtr = reinterpret_cast<uintptr_t>(SI);
777
318k
    assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
778
0
    InfoPtr |= MultiArg;
779
318k
  }
780
781
1.74M
  IdentifierInfo *getAsIdentifierInfo() const {
782
1.74M
    if (getIdentifierInfoFlag() < MultiArg)
783
1.74M
      return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
784
0
    return nullptr;
785
1.74M
  }
786
787
2.15M
  MultiKeywordSelector *getMultiKeywordSelector() const {
788
2.15M
    return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags);
789
2.15M
  }
790
791
7.70M
  unsigned getIdentifierInfoFlag() const {
792
7.70M
    return InfoPtr & ArgFlags;
793
7.70M
  }
794
795
  static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
796
797
  static ObjCStringFormatFamily getStringFormatFamilyImpl(Selector sel);
798
799
public:
800
  /// The default ctor should only be used when creating data structures that
801
  ///  will contain selectors.
802
4.14M
  Selector() = default;
803
33.3M
  explicit Selector(uintptr_t V) : InfoPtr(V) {}
804
805
  /// operator==/!= - Indicate whether the specified selectors are identical.
806
80.5M
  bool operator==(Selector RHS) const {
807
80.5M
    return InfoPtr == RHS.InfoPtr;
808
80.5M
  }
809
57.9k
  bool operator!=(Selector RHS) const {
810
57.9k
    return InfoPtr != RHS.InfoPtr;
811
57.9k
  }
812
813
7.32M
  void *getAsOpaquePtr() const {
814
7.32M
    return reinterpret_cast<void*>(InfoPtr);
815
7.32M
  }
816
817
  /// Determine whether this is the empty selector.
818
66.7k
  bool isNull() const { return InfoPtr == 0; }
819
820
  // Predicates to identify the selector type.
821
935
  bool isKeywordSelector() const {
822
935
    return getIdentifierInfoFlag() != ZeroArg;
823
935
  }
824
825
265k
  bool isUnarySelector() const {
826
265k
    return getIdentifierInfoFlag() == ZeroArg;
827
265k
  }
828
829
  /// If this selector is the specific keyword selector described by Names.
830
  bool isKeywordSelector(ArrayRef<StringRef> Names) const;
831
832
  /// If this selector is the specific unary selector described by Name.
833
  bool isUnarySelector(StringRef Name) const;
834
835
  unsigned getNumArgs() const;
836
837
  /// Retrieve the identifier at a given position in the selector.
838
  ///
839
  /// Note that the identifier pointer returned may be NULL. Clients that only
840
  /// care about the text of the identifier string, and not the specific,
841
  /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
842
  /// an empty string when the identifier pointer would be NULL.
843
  ///
844
  /// \param argIndex The index for which we want to retrieve the identifier.
845
  /// This index shall be less than \c getNumArgs() unless this is a keyword
846
  /// selector, in which case 0 is the only permissible value.
847
  ///
848
  /// \returns the uniqued identifier for this slot, or NULL if this slot has
849
  /// no corresponding identifier.
850
  IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
851
852
  /// Retrieve the name at a given position in the selector.
853
  ///
854
  /// \param argIndex The index for which we want to retrieve the name.
855
  /// This index shall be less than \c getNumArgs() unless this is a keyword
856
  /// selector, in which case 0 is the only permissible value.
857
  ///
858
  /// \returns the name for this slot, which may be the empty string if no
859
  /// name was supplied.
860
  StringRef getNameForSlot(unsigned argIndex) const;
861
862
  /// Derive the full selector name (e.g. "foo:bar:") and return
863
  /// it as an std::string.
864
  std::string getAsString() const;
865
866
  /// Prints the full selector name (e.g. "foo:bar:").
867
  void print(llvm::raw_ostream &OS) const;
868
869
  void dump() const;
870
871
  /// Derive the conventional family of this method.
872
241k
  ObjCMethodFamily getMethodFamily() const {
873
241k
    return getMethodFamilyImpl(*this);
874
241k
  }
875
876
25.3k
  ObjCStringFormatFamily getStringFormatFamily() const {
877
25.3k
    return getStringFormatFamilyImpl(*this);
878
25.3k
  }
879
880
8.81M
  static Selector getEmptyMarker() {
881
8.81M
    return Selector(uintptr_t(-1));
882
8.81M
  }
883
884
6.97M
  static Selector getTombstoneMarker() {
885
6.97M
    return Selector(uintptr_t(-2));
886
6.97M
  }
887
888
  static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
889
};
890
891
/// This table allows us to fully hide how we implement
892
/// multi-keyword caching.
893
class SelectorTable {
894
  // Actually a SelectorTableImpl
895
  void *Impl;
896
897
public:
898
  SelectorTable();
899
  SelectorTable(const SelectorTable &) = delete;
900
  SelectorTable &operator=(const SelectorTable &) = delete;
901
  ~SelectorTable();
902
903
  /// Can create any sort of selector.
904
  ///
905
  /// \p NumArgs indicates whether this is a no argument selector "foo", a
906
  /// single argument selector "foo:" or multi-argument "foo:bar:".
907
  Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
908
909
365k
  Selector getUnarySelector(IdentifierInfo *ID) {
910
365k
    return Selector(ID, 1);
911
365k
  }
912
913
474k
  Selector getNullarySelector(IdentifierInfo *ID) {
914
474k
    return Selector(ID, 0);
915
474k
  }
916
917
  /// Return the total amount of memory allocated for managing selectors.
918
  size_t getTotalMemory() const;
919
920
  /// Return the default setter name for the given identifier.
921
  ///
922
  /// This is "set" + \p Name where the initial character of \p Name
923
  /// has been capitalized.
924
  static SmallString<64> constructSetterName(StringRef Name);
925
926
  /// Return the default setter selector for the given identifier.
927
  ///
928
  /// This is "set" + \p Name where the initial character of \p Name
929
  /// has been capitalized.
930
  static Selector constructSetterSelector(IdentifierTable &Idents,
931
                                          SelectorTable &SelTable,
932
                                          const IdentifierInfo *Name);
933
934
  /// Return the property name for the given setter selector.
935
  static std::string getPropertyNameFromSetterSelector(Selector Sel);
936
};
937
938
namespace detail {
939
940
/// DeclarationNameExtra is used as a base of various uncommon special names.
941
/// This class is needed since DeclarationName has not enough space to store
942
/// the kind of every possible names. Therefore the kind of common names is
943
/// stored directly in DeclarationName, and the kind of uncommon names is
944
/// stored in DeclarationNameExtra. It is aligned to 8 bytes because
945
/// DeclarationName needs the lower 3 bits to store the kind of common names.
946
/// DeclarationNameExtra is tightly coupled to DeclarationName and any change
947
/// here is very likely to require changes in DeclarationName(Table).
948
class alignas(IdentifierInfoAlignment) DeclarationNameExtra {
949
  friend class clang::DeclarationName;
950
  friend class clang::DeclarationNameTable;
951
952
protected:
953
  /// The kind of "extra" information stored in the DeclarationName. See
954
  /// @c ExtraKindOrNumArgs for an explanation of how these enumerator values
955
  /// are used. Note that DeclarationName depends on the numerical values
956
  /// of the enumerators in this enum. See DeclarationName::StoredNameKind
957
  /// for more info.
958
  enum ExtraKind {
959
    CXXDeductionGuideName,
960
    CXXLiteralOperatorName,
961
    CXXUsingDirective,
962
    ObjCMultiArgSelector
963
  };
964
965
  /// ExtraKindOrNumArgs has one of the following meaning:
966
  ///  * The kind of an uncommon C++ special name. This DeclarationNameExtra
967
  ///    is in this case in fact either a CXXDeductionGuideNameExtra or
968
  ///    a CXXLiteralOperatorIdName.
969
  ///
970
  ///  * It may be also name common to C++ using-directives (CXXUsingDirective),
971
  ///
972
  ///  * Otherwise it is ObjCMultiArgSelector+NumArgs, where NumArgs is
973
  ///    the number of arguments in the Objective-C selector, in which
974
  ///    case the DeclarationNameExtra is also a MultiKeywordSelector.
975
  unsigned ExtraKindOrNumArgs;
976
977
33.1k
  DeclarationNameExtra(ExtraKind Kind) : ExtraKindOrNumArgs(Kind) {}
978
  DeclarationNameExtra(unsigned NumArgs)
979
240k
      : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {}
980
981
  /// Return the corresponding ExtraKind.
982
7.59M
  ExtraKind getKind() const {
983
7.59M
    return static_cast<ExtraKind>(ExtraKindOrNumArgs >
984
7.59M
                                          (unsigned)ObjCMultiArgSelector
985
7.59M
                                      ? 
(unsigned)ObjCMultiArgSelector7.46M
986
7.59M
                                      : 
ExtraKindOrNumArgs131k
);
987
7.59M
  }
988
989
  /// Return the number of arguments in an ObjC selector. Only valid when this
990
  /// is indeed an ObjCMultiArgSelector.
991
2.78M
  unsigned getNumArgs() const {
992
2.78M
    assert(ExtraKindOrNumArgs >= (unsigned)ObjCMultiArgSelector &&
993
2.78M
           "getNumArgs called but this is not an ObjC selector!");
994
0
    return ExtraKindOrNumArgs - (unsigned)ObjCMultiArgSelector;
995
2.78M
  }
996
};
997
998
} // namespace detail
999
1000
}  // namespace clang
1001
1002
namespace llvm {
1003
1004
/// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
1005
/// DenseSets.
1006
template <>
1007
struct DenseMapInfo<clang::Selector> {
1008
8.81M
  static clang::Selector getEmptyKey() {
1009
8.81M
    return clang::Selector::getEmptyMarker();
1010
8.81M
  }
1011
1012
6.97M
  static clang::Selector getTombstoneKey() {
1013
6.97M
    return clang::Selector::getTombstoneMarker();
1014
6.97M
  }
1015
1016
  static unsigned getHashValue(clang::Selector S);
1017
1018
80.4M
  static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
1019
80.4M
    return LHS == RHS;
1020
80.4M
  }
1021
};
1022
1023
template<>
1024
struct PointerLikeTypeTraits<clang::Selector> {
1025
168k
  static const void *getAsVoidPointer(clang::Selector P) {
1026
168k
    return P.getAsOpaquePtr();
1027
168k
  }
1028
1029
0
  static clang::Selector getFromVoidPointer(const void *P) {
1030
0
    return clang::Selector(reinterpret_cast<uintptr_t>(P));
1031
0
  }
1032
1033
  static constexpr int NumLowBitsAvailable = 0;
1034
};
1035
1036
// Provide PointerLikeTypeTraits for IdentifierInfo pointers, which
1037
// are not guaranteed to be 8-byte aligned.
1038
template<>
1039
struct PointerLikeTypeTraits<clang::IdentifierInfo*> {
1040
2.21k
  static void *getAsVoidPointer(clang::IdentifierInfo* P) {
1041
2.21k
    return P;
1042
2.21k
  }
1043
1044
22
  static clang::IdentifierInfo *getFromVoidPointer(void *P) {
1045
22
    return static_cast<clang::IdentifierInfo*>(P);
1046
22
  }
1047
1048
  static constexpr int NumLowBitsAvailable = 1;
1049
};
1050
1051
template<>
1052
struct PointerLikeTypeTraits<const clang::IdentifierInfo*> {
1053
344k
  static const void *getAsVoidPointer(const clang::IdentifierInfo* P) {
1054
344k
    return P;
1055
344k
  }
1056
1057
0
  static const clang::IdentifierInfo *getFromVoidPointer(const void *P) {
1058
0
    return static_cast<const clang::IdentifierInfo*>(P);
1059
0
  }
1060
1061
  static constexpr int NumLowBitsAvailable = 1;
1062
};
1063
1064
} // namespace llvm
1065
1066
#endif // LLVM_CLANG_BASIC_IDENTIFIERTABLE_H