Coverage Report

Created: 2018-11-16 02:38

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