clang 22.0.0git
IdentifierTable.h
Go to the documentation of this file.
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
20#include "clang/Basic/LLVM.h"
23#include "llvm/ADT/DenseMapInfo.h"
24#include "llvm/ADT/FoldingSet.h"
25#include "llvm/ADT/PointerIntPair.h"
26#include "llvm/ADT/PointerUnion.h"
27#include "llvm/ADT/SmallString.h"
28#include "llvm/ADT/StringMap.h"
29#include "llvm/ADT/StringRef.h"
30#include "llvm/Support/Allocator.h"
31#include "llvm/Support/PointerLikeTypeTraits.h"
32#include "llvm/Support/type_traits.h"
33#include <cassert>
34#include <cstddef>
35#include <cstdint>
36#include <cstring>
37#include <string>
38#include <utility>
39
40namespace clang {
41
42class DeclarationName;
44class IdentifierInfo;
45class LangOptions;
47class SourceLocation;
48
49/// Constants for TokenKinds.def
50enum TokenKey : unsigned {
51 KEYC99 = 0x1,
52 KEYCXX = 0x2,
53 KEYCXX11 = 0x4,
54 KEYGNU = 0x8,
55 KEYMS = 0x10,
57 KEYALTIVEC = 0x40,
58 KEYNOCXX = 0x80,
59 KEYBORLAND = 0x100,
60 KEYOPENCLC = 0x200,
61 KEYC23 = 0x400,
62 KEYNOMS18 = 0x800,
63 KEYNOOPENCL = 0x1000,
64 WCHARSUPPORT = 0x2000,
65 HALFSUPPORT = 0x4000,
66 CHAR8SUPPORT = 0x8000,
67 KEYOBJC = 0x10000,
68 KEYZVECTOR = 0x20000,
69 KEYCOROUTINES = 0x40000,
70 KEYMODULES = 0x80000,
71 KEYCXX20 = 0x100000,
72 KEYOPENCLCXX = 0x200000,
73 KEYMSCOMPAT = 0x400000,
74 KEYSYCL = 0x800000,
75 KEYCUDA = 0x1000000,
76 KEYZOS = 0x2000000,
77 KEYNOZOS = 0x4000000,
78 KEYHLSL = 0x8000000,
79 KEYFIXEDPOINT = 0x10000000,
80 KEYDEFERTS = 0x20000000,
81 KEYMAX = KEYDEFERTS, // The maximum key
84 ~KEYNOZOS // KEYNOMS18, KEYNOOPENCL, KEYNOZOS are excluded.
85};
86
87/// How a keyword is treated in the selected standard. This enum is ordered
88/// intentionally so that the value that 'wins' is the most 'permissive'.
90 KS_Unknown, // Not yet calculated. Used when figuring out the status.
91 KS_Disabled, // Disabled
92 KS_Future, // Is a keyword in future standard
93 KS_Extension, // Is an extension
94 KS_Enabled, // Enabled
95};
96
97/// Translates flags as specified in TokenKinds.def into keyword status
98/// in the given language standard.
99KeywordStatus getKeywordStatus(const LangOptions &LangOpts, unsigned Flags);
100
109
115
116/// Determine whether an identifier is reserved for use as a name at global
117/// scope. Such identifiers might be implementation-specific global functions
118/// or variables.
122
123/// Determine whether an identifier is reserved in all contexts. Such
124/// identifiers might be implementation-specific keywords or macros, for
125/// example.
131
132/// IdentifierInfo and other related classes are aligned to
133/// 8 bytes so that DeclarationName can use the lower 3 bits
134/// of a pointer to one of these classes.
136
137static constexpr int InterestingIdentifierBits = 16;
138
139/// The "layout" of InterestingIdentifier is:
140/// - ObjCKeywordKind enumerators
141/// - NotableIdentifierKind enumerators
142/// - Builtin::ID enumerators
143/// - NotInterestingIdentifier
145#define OBJC_AT_KEYWORD(X) objc_##X,
146#include "clang/Basic/TokenKinds.def"
148
149#define NOTABLE_IDENTIFIER(X) X,
150#include "clang/Basic/TokenKinds.def"
152
154#define GET_BUILTIN_ENUMERATORS
155#include "clang/Basic/Builtins.inc"
156#undef GET_BUILTIN_ENUMERATORS
158
160};
161
162/// One of these records is kept for each identifier that
163/// is lexed. This contains information about whether the token was \#define'd,
164/// is a language keyword, or if it is a front-end token of some sort (e.g. a
165/// variable or function name). The preprocessor keeps this information in a
166/// set, and all tok::identifier tokens have a pointer to one of these.
167/// It is aligned to 8 bytes because DeclarationName needs the lower 3 bits.
168class alignas(IdentifierInfoAlignment) IdentifierInfo {
169 friend class IdentifierTable;
170
171 // Front-end token ID or tok::identifier.
172 LLVM_PREFERRED_TYPE(tok::TokenKind)
173 unsigned TokenID : 9;
174
175 LLVM_PREFERRED_TYPE(InterestingIdentifier)
176 unsigned InterestingIdentifierID : InterestingIdentifierBits;
177
178 // True if there is a #define for this.
179 LLVM_PREFERRED_TYPE(bool)
180 unsigned HasMacro : 1;
181
182 // True if there was a #define for this.
183 LLVM_PREFERRED_TYPE(bool)
184 unsigned HadMacro : 1;
185
186 // True if the identifier is a language extension.
187 LLVM_PREFERRED_TYPE(bool)
188 unsigned IsExtension : 1;
189
190 // True if the identifier is a keyword in a newer or proposed Standard.
191 LLVM_PREFERRED_TYPE(bool)
192 unsigned IsFutureCompatKeyword : 1;
193
194 // True if the identifier is poisoned.
195 LLVM_PREFERRED_TYPE(bool)
196 unsigned IsPoisoned : 1;
197
198 // True if the identifier is a C++ operator keyword.
199 LLVM_PREFERRED_TYPE(bool)
200 unsigned IsCPPOperatorKeyword : 1;
201
202 // Internal bit set by the member function RecomputeNeedsHandleIdentifier.
203 // See comment about RecomputeNeedsHandleIdentifier for more info.
204 LLVM_PREFERRED_TYPE(bool)
205 unsigned NeedsHandleIdentifier : 1;
206
207 // True if the identifier was loaded (at least partially) from an AST file.
208 LLVM_PREFERRED_TYPE(bool)
209 unsigned IsFromAST : 1;
210
211 // True if the identifier has changed from the definition
212 // loaded from an AST file.
213 LLVM_PREFERRED_TYPE(bool)
214 unsigned ChangedAfterLoad : 1;
215
216 // True if the identifier's frontend information has changed from the
217 // definition loaded from an AST file.
218 LLVM_PREFERRED_TYPE(bool)
219 unsigned FEChangedAfterLoad : 1;
220
221 // True if revertTokenIDToIdentifier was called.
222 LLVM_PREFERRED_TYPE(bool)
223 unsigned RevertedTokenID : 1;
224
225 // True if there may be additional information about
226 // this identifier stored externally.
227 LLVM_PREFERRED_TYPE(bool)
228 unsigned OutOfDate : 1;
229
230 // True if this is the 'import' contextual keyword.
231 LLVM_PREFERRED_TYPE(bool)
232 unsigned IsModulesImport : 1;
233
234 // True if this is a mangled OpenMP variant name.
235 LLVM_PREFERRED_TYPE(bool)
236 unsigned IsMangledOpenMPVariantName : 1;
237
238 // True if this is a deprecated macro.
239 LLVM_PREFERRED_TYPE(bool)
240 unsigned IsDeprecatedMacro : 1;
241
242 // True if this macro is unsafe in headers.
243 LLVM_PREFERRED_TYPE(bool)
244 unsigned IsRestrictExpansion : 1;
245
246 // True if this macro is final.
247 LLVM_PREFERRED_TYPE(bool)
248 unsigned IsFinal : 1;
249
250 // True if this identifier would be a keyword in C++ mode.
251 LLVM_PREFERRED_TYPE(bool)
252 unsigned IsKeywordInCpp : 1;
253
254 // 21 bits left in a 64-bit word.
255
256 // Managed by the language front-end.
257 void *FETokenInfo = nullptr;
258
259 llvm::StringMapEntry<IdentifierInfo *> *Entry = nullptr;
260
261 IdentifierInfo()
262 : TokenID(tok::identifier),
263 InterestingIdentifierID(llvm::to_underlying(
265 HasMacro(false), HadMacro(false), IsExtension(false),
266 IsFutureCompatKeyword(false), IsPoisoned(false),
267 IsCPPOperatorKeyword(false), NeedsHandleIdentifier(false),
268 IsFromAST(false), ChangedAfterLoad(false), FEChangedAfterLoad(false),
269 RevertedTokenID(false), OutOfDate(false), IsModulesImport(false),
270 IsMangledOpenMPVariantName(false), IsDeprecatedMacro(false),
271 IsRestrictExpansion(false), IsFinal(false), IsKeywordInCpp(false) {}
272
273public:
274 IdentifierInfo(const IdentifierInfo &) = delete;
275 IdentifierInfo &operator=(const IdentifierInfo &) = delete;
276 IdentifierInfo(IdentifierInfo &&) = delete;
277 IdentifierInfo &operator=(IdentifierInfo &&) = delete;
278
279 /// Return true if this is the identifier for the specified string.
280 ///
281 /// This is intended to be used for string literals only: II->isStr("foo").
282 template <std::size_t StrLen>
283 bool isStr(const char (&Str)[StrLen]) const {
284 return getLength() == StrLen-1 &&
285 memcmp(getNameStart(), Str, StrLen-1) == 0;
286 }
287
288 /// Return true if this is the identifier for the specified StringRef.
289 bool isStr(llvm::StringRef Str) const {
290 llvm::StringRef ThisStr(getNameStart(), getLength());
291 return ThisStr == Str;
292 }
293
294 /// Return the beginning of the actual null-terminated string for this
295 /// identifier.
296 const char *getNameStart() const { return Entry->getKeyData(); }
297
298 /// Efficiently return the length of this identifier info.
299 unsigned getLength() const { return Entry->getKeyLength(); }
300
301 /// Return the actual identifier string.
302 StringRef getName() const {
303 return StringRef(getNameStart(), getLength());
304 }
305
306 /// Return true if this identifier is \#defined to some other value.
307 /// \note The current definition may be in a module and not currently visible.
308 bool hasMacroDefinition() const {
309 return HasMacro;
310 }
311 void setHasMacroDefinition(bool Val) {
312 if (HasMacro == Val) return;
313
314 HasMacro = Val;
315 if (Val) {
316 NeedsHandleIdentifier = true;
317 HadMacro = true;
318 } else {
319 // If this is a final macro, make the deprecation and header unsafe bits
320 // stick around after the undefinition so they apply to any redefinitions.
321 if (!IsFinal) {
322 // Because calling the setters of these calls recomputes, just set them
323 // manually to avoid recomputing a bunch of times.
324 IsDeprecatedMacro = false;
325 IsRestrictExpansion = false;
326 }
327 RecomputeNeedsHandleIdentifier();
328 }
329 }
330 /// Returns true if this identifier was \#defined to some value at any
331 /// moment. In this case there should be an entry for the identifier in the
332 /// macro history table in Preprocessor.
333 bool hadMacroDefinition() const {
334 return HadMacro;
335 }
336
337 bool isDeprecatedMacro() const { return IsDeprecatedMacro; }
338
339 void setIsDeprecatedMacro(bool Val) {
340 if (IsDeprecatedMacro == Val)
341 return;
342 IsDeprecatedMacro = Val;
343 if (Val)
344 NeedsHandleIdentifier = true;
345 else
346 RecomputeNeedsHandleIdentifier();
347 }
348
349 bool isRestrictExpansion() const { return IsRestrictExpansion; }
350
351 void setIsRestrictExpansion(bool Val) {
352 if (IsRestrictExpansion == Val)
353 return;
354 IsRestrictExpansion = Val;
355 if (Val)
356 NeedsHandleIdentifier = true;
357 else
358 RecomputeNeedsHandleIdentifier();
359 }
360
361 bool isFinal() const { return IsFinal; }
362
363 void setIsFinal(bool Val) { IsFinal = Val; }
364
365 /// If this is a source-language token (e.g. 'for'), this API
366 /// can be used to cause the lexer to map identifiers to source-language
367 /// tokens.
368 tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
369
370 /// True if revertTokenIDToIdentifier() was called.
371 bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
372
373 /// Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
374 /// compatibility.
375 ///
376 /// TokenID is normally read-only but there are 2 instances where we revert it
377 /// to tok::identifier for libstdc++ 4.2. Keep track of when this happens
378 /// using this method so we can inform serialization about it.
380 assert(TokenID != tok::identifier && "Already at tok::identifier");
381 TokenID = tok::identifier;
382 RevertedTokenID = true;
383 }
385 assert(TokenID == tok::identifier && "Should be at tok::identifier");
386 TokenID = TK;
387 RevertedTokenID = false;
388 }
389
390 /// Return the preprocessor keyword ID for this identifier.
391 ///
392 /// For example, "define" will return tok::pp_define.
393 tok::PPKeywordKind getPPKeywordID() const;
394
395 /// Return the Objective-C keyword ID for the this identifier.
396 ///
397 /// For example, 'class' will return tok::objc_class if ObjC is enabled.
399 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
400 auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
402 return static_cast<tok::ObjCKeywordKind>(InterestingIdentifierID);
403 return tok::objc_not_keyword;
404 }
406 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
407 InterestingIdentifierID = ID;
408 assert(getObjCKeywordID() == ID && "ID too large for field!");
409 }
410
411 /// Return a value indicating whether this is a builtin function.
412 unsigned getBuiltinID() const {
413 auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
414 if (Value >
417 auto FirstBuiltin =
418 llvm::to_underlying(InterestingIdentifier::NotBuiltin);
419 return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
420 }
422 }
423 void setBuiltinID(unsigned ID) {
424 assert(ID != Builtin::ID::NotBuiltin);
425 auto FirstBuiltin = llvm::to_underlying(InterestingIdentifier::NotBuiltin);
426 InterestingIdentifierID = ID + FirstBuiltin;
427 assert(getBuiltinID() == ID && "ID too large for field!");
428 }
430 InterestingIdentifierID =
432 }
433
435 auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
437 Value <
439 auto FirstNotableIdentifier =
440 1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
441 return static_cast<tok::NotableIdentifierKind>(InterestingIdentifierID -
442 FirstNotableIdentifier);
443 }
444 return tok::not_notable;
445 }
446 void setNotableIdentifierID(unsigned ID) {
447 assert(ID != tok::not_notable);
448 auto FirstNotableIdentifier =
449 1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
450 InterestingIdentifierID = ID + FirstNotableIdentifier;
451 assert(getNotableIdentifierID() == ID && "ID too large for field!");
452 }
453
454 unsigned getObjCOrBuiltinID() const { return InterestingIdentifierID; }
455 void setObjCOrBuiltinID(unsigned ID) { InterestingIdentifierID = ID; }
456
457 /// get/setExtension - Initialize information about whether or not this
458 /// language token is an extension. This controls extension warnings, and is
459 /// only valid if a custom token ID is set.
460 bool isExtensionToken() const { return IsExtension; }
461 void setIsExtensionToken(bool Val) {
462 IsExtension = Val;
463 if (Val)
464 NeedsHandleIdentifier = true;
465 else
466 RecomputeNeedsHandleIdentifier();
467 }
468
469 /// is/setIsFutureCompatKeyword - Initialize information about whether or not
470 /// this language token is a keyword in a newer or proposed Standard. This
471 /// controls compatibility warnings, and is only true when not parsing the
472 /// corresponding Standard. Once a compatibility problem has been diagnosed
473 /// with this keyword, the flag will be cleared.
474 bool isFutureCompatKeyword() const { return IsFutureCompatKeyword; }
476 IsFutureCompatKeyword = Val;
477 if (Val)
478 NeedsHandleIdentifier = true;
479 else
480 RecomputeNeedsHandleIdentifier();
481 }
482
483 /// setIsPoisoned - Mark this identifier as poisoned. After poisoning, the
484 /// Preprocessor will emit an error every time this token is used.
485 void setIsPoisoned(bool Value = true) {
486 IsPoisoned = Value;
487 if (Value)
488 NeedsHandleIdentifier = true;
489 else
490 RecomputeNeedsHandleIdentifier();
491 }
492
493 /// Return true if this token has been poisoned.
494 bool isPoisoned() const { return IsPoisoned; }
495
496 /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
497 /// this identifier is a C++ alternate representation of an operator.
498 void setIsCPlusPlusOperatorKeyword(bool Val = true) {
499 IsCPPOperatorKeyword = Val;
500 }
501 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
502
503 /// Return true if this identifier would be a keyword in C++ mode.
504 bool IsKeywordInCPlusPlus() const { return IsKeywordInCpp; }
505 void setIsKeywordInCPlusPlus(bool Val = true) { IsKeywordInCpp = Val; }
506
507 /// Return true if this token is a keyword in the specified language.
508 bool isKeyword(const LangOptions &LangOpts) const;
509
510 /// Return true if this token is a C++ keyword in the specified
511 /// language.
512 bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
513
514 /// Get and set FETokenInfo. The language front-end is allowed to associate
515 /// arbitrary metadata with this token.
516 void *getFETokenInfo() const { return FETokenInfo; }
517 void setFETokenInfo(void *T) { FETokenInfo = T; }
518
519 /// Return true if the Preprocessor::HandleIdentifier must be called
520 /// on a token of this identifier.
521 ///
522 /// If this returns false, we know that HandleIdentifier will not affect
523 /// the token.
524 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
525 void setHandleIdentifierCase(bool Val = true) { NeedsHandleIdentifier = Val; }
526
527 /// Return true if the identifier in its current state was loaded
528 /// from an AST file.
529 bool isFromAST() const { return IsFromAST; }
530
531 void setIsFromAST() { IsFromAST = true; }
532
533 /// Determine whether this identifier has changed since it was loaded
534 /// from an AST file.
536 return ChangedAfterLoad;
537 }
538
539 /// Note that this identifier has changed since it was loaded from
540 /// an AST file.
542 ChangedAfterLoad = true;
543 }
544
545 /// Determine whether the frontend token information for this
546 /// identifier has changed since it was loaded from an AST file.
548 return FEChangedAfterLoad;
549 }
550
551 /// Note that the frontend token information for this identifier has
552 /// changed since it was loaded from an AST file.
554 FEChangedAfterLoad = true;
555 }
556
557 /// Determine whether the information for this identifier is out of
558 /// date with respect to the external source.
559 bool isOutOfDate() const { return OutOfDate; }
560
561 /// Set whether the information for this identifier is out of
562 /// date with respect to the external source.
563 void setOutOfDate(bool OOD) {
564 OutOfDate = OOD;
565 if (OOD)
566 NeedsHandleIdentifier = true;
567 else
568 RecomputeNeedsHandleIdentifier();
569 }
570
571 /// Determine whether this is the contextual keyword \c import.
572 bool isModulesImport() const { return IsModulesImport; }
573
574 /// Set whether this identifier is the contextual keyword \c import.
575 void setModulesImport(bool I) {
576 IsModulesImport = I;
577 if (I)
578 NeedsHandleIdentifier = true;
579 else
580 RecomputeNeedsHandleIdentifier();
581 }
582
583 /// Determine whether this is the mangled name of an OpenMP variant.
584 bool isMangledOpenMPVariantName() const { return IsMangledOpenMPVariantName; }
585
586 /// Set whether this is the mangled name of an OpenMP variant.
587 void setMangledOpenMPVariantName(bool I) { IsMangledOpenMPVariantName = I; }
588
589 /// Return true if this identifier is an editor placeholder.
590 ///
591 /// Editor placeholders are produced by the code-completion engine and are
592 /// represented as characters between '<#' and '#>' in the source code. An
593 /// example of auto-completed call with a placeholder parameter is shown
594 /// below:
595 /// \code
596 /// function(<#int x#>);
597 /// \endcode
598 bool isEditorPlaceholder() const {
599 return getName().starts_with("<#") && getName().ends_with("#>");
600 }
601
602 /// Determine whether \p this is a name reserved for the implementation (C99
603 /// 7.1.3, C++ [lib.global.names]).
604 ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const;
605
606 /// Determine whether \p this is a name reserved for future standardization or
607 /// the implementation (C++ [usrlit.suffix]).
608 ReservedLiteralSuffixIdStatus isReservedLiteralSuffixId() const;
609
610 /// If the identifier is an "uglified" reserved name, return a cleaned form.
611 /// e.g. _Foo => Foo. Otherwise, just returns the name.
612 StringRef deuglifiedName() const;
613 bool isPlaceholder() const {
614 return getLength() == 1 && getNameStart()[0] == '_';
615 }
616
617 /// Provide less than operator for lexicographical sorting.
618 bool operator<(const IdentifierInfo &RHS) const {
619 return getName() < RHS.getName();
620 }
621
622private:
623 /// The Preprocessor::HandleIdentifier does several special (but rare)
624 /// things to identifiers of various sorts. For example, it changes the
625 /// \c for keyword token from tok::identifier to tok::for.
626 ///
627 /// This method is very tied to the definition of HandleIdentifier. Any
628 /// change to it should be reflected here.
629 void RecomputeNeedsHandleIdentifier() {
630 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
631 isExtensionToken() || isFutureCompatKeyword() ||
632 isOutOfDate() || isModulesImport();
633 }
634};
635
636/// An RAII object for [un]poisoning an identifier within a scope.
637///
638/// \p II is allowed to be null, in which case objects of this type have
639/// no effect.
641 IdentifierInfo *const II;
642 const bool OldValue;
643
644public:
646 : II(II), OldValue(II ? II->isPoisoned() : false) {
647 if(II)
648 II->setIsPoisoned(NewValue);
649 }
650
652 if(II)
653 II->setIsPoisoned(OldValue);
654 }
655};
656
657/// An iterator that walks over all of the known identifiers
658/// in the lookup table.
659///
660/// Since this iterator uses an abstract interface via virtual
661/// functions, it uses an object-oriented interface rather than the
662/// more standard C++ STL iterator interface. In this OO-style
663/// iteration, the single function \c Next() provides dereference,
664/// advance, and end-of-sequence checking in a single
665/// operation. Subclasses of this iterator type will provide the
666/// actual functionality.
668protected:
670
671public:
674
676
677 /// Retrieve the next string in the identifier table and
678 /// advances the iterator for the following string.
679 ///
680 /// \returns The next string in the identifier table. If there is
681 /// no such string, returns an empty \c StringRef.
682 virtual StringRef Next() = 0;
683};
684
685/// Provides lookups to, and iteration over, IdentiferInfo objects.
687public:
689
690 /// Return the IdentifierInfo for the specified named identifier.
691 ///
692 /// Unlike the version in IdentifierTable, this returns a pointer instead
693 /// of a reference. If the pointer is null then the IdentifierInfo cannot
694 /// be found.
695 virtual IdentifierInfo* get(StringRef Name) = 0;
696
697 /// Retrieve an iterator into the set of all identifiers
698 /// known to this identifier lookup source.
699 ///
700 /// This routine provides access to all of the identifiers known to
701 /// the identifier lookup, allowing access to the contents of the
702 /// identifiers without introducing the overhead of constructing
703 /// IdentifierInfo objects for each.
704 ///
705 /// \returns A new iterator into the set of known identifiers. The
706 /// caller is responsible for deleting this iterator.
708};
709
710/// Implements an efficient mapping from strings to IdentifierInfo nodes.
711///
712/// This has no other purpose, but this is an extremely performance-critical
713/// piece of the code, as each occurrence of every identifier goes through
714/// here when lexed.
716 // Shark shows that using MallocAllocator is *much* slower than using this
717 // BumpPtrAllocator!
718 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
719 HashTableTy HashTable;
720
721 IdentifierInfoLookup* ExternalLookup;
722
723public:
724 /// Create the identifier table.
725 explicit IdentifierTable(IdentifierInfoLookup *ExternalLookup = nullptr);
726
727 /// Create the identifier table, populating it with info about the
728 /// language keywords for the language specified by \p LangOpts.
729 explicit IdentifierTable(const LangOptions &LangOpts,
730 IdentifierInfoLookup *ExternalLookup = nullptr);
731
732 /// Set the external identifier lookup mechanism.
734 ExternalLookup = IILookup;
735 }
736
737 /// Retrieve the external identifier lookup object, if any.
739 return ExternalLookup;
740 }
741
742 llvm::BumpPtrAllocator& getAllocator() {
743 return HashTable.getAllocator();
744 }
745
746 /// Return the identifier token info for the specified named
747 /// identifier.
748 IdentifierInfo &get(StringRef Name) {
749 auto &Entry = *HashTable.try_emplace(Name, nullptr).first;
750
751 IdentifierInfo *&II = Entry.second;
752 if (II) return *II;
753
754 // No entry; if we have an external lookup, look there first.
755 if (ExternalLookup) {
756 II = ExternalLookup->get(Name);
757 if (II)
758 return *II;
759 }
760
761 // Lookups failed, make a new IdentifierInfo.
762 void *Mem = getAllocator().Allocate<IdentifierInfo>();
763 II = new (Mem) IdentifierInfo();
764
765 // Make sure getName() knows how to find the IdentifierInfo
766 // contents.
767 II->Entry = &Entry;
768
769 return *II;
770 }
771
772 IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
773 IdentifierInfo &II = get(Name);
774 II.TokenID = TokenCode;
775 assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
776 return II;
777 }
778
779 /// Gets an IdentifierInfo for the given name without consulting
780 /// external sources.
781 ///
782 /// This is a version of get() meant for external sources that want to
783 /// introduce or modify an identifier. If they called get(), they would
784 /// likely end up in a recursion.
785 IdentifierInfo &getOwn(StringRef Name) {
786 auto &Entry = *HashTable.try_emplace(Name).first;
787
788 IdentifierInfo *&II = Entry.second;
789 if (II)
790 return *II;
791
792 // Lookups failed, make a new IdentifierInfo.
793 void *Mem = getAllocator().Allocate<IdentifierInfo>();
794 II = new (Mem) IdentifierInfo();
795
796 // Make sure getName() knows how to find the IdentifierInfo
797 // contents.
798 II->Entry = &Entry;
799
800 // If this is the 'import' contextual keyword, mark it as such.
801 if (Name == "import")
802 II->setModulesImport(true);
803
804 return *II;
805 }
806
807 using iterator = HashTableTy::const_iterator;
808 using const_iterator = HashTableTy::const_iterator;
809
810 iterator begin() const { return HashTable.begin(); }
811 iterator end() const { return HashTable.end(); }
812 unsigned size() const { return HashTable.size(); }
813
814 iterator find(StringRef Name) const { return HashTable.find(Name); }
815
816 /// Print some statistics to stderr that indicate how well the
817 /// hashing is doing.
818 void PrintStats() const;
819
820 /// Populate the identifier table with info about the language keywords
821 /// for the language specified by \p LangOpts.
822 void AddKeywords(const LangOptions &LangOpts);
823
824 /// Returns the correct diagnostic to issue for a future-compat diagnostic
825 /// warning. Note, this function assumes the identifier passed has already
826 /// been determined to be a future compatible keyword.
827 diag::kind getFutureCompatDiagKind(const IdentifierInfo &II,
828 const LangOptions &LangOpts);
829};
830
831/// A family of Objective-C methods.
832///
833/// These families have no inherent meaning in the language, but are
834/// nonetheless central enough in the existing implementations to
835/// merit direct AST support. While, in theory, arbitrary methods can
836/// be considered to form families, we focus here on the methods
837/// involving allocation and retain-count management, as these are the
838/// most "core" and the most likely to be useful to diverse clients
839/// without extra information.
840///
841/// Both selectors and actual method declarations may be classified
842/// into families. Method families may impose additional restrictions
843/// beyond their selector name; for example, a method called '_init'
844/// that returns void is not considered to be in the 'init' family
845/// (but would be if it returned 'id'). It is also possible to
846/// explicitly change or remove a method's family. Therefore the
847/// method's family should be considered the single source of truth.
849 /// No particular method family.
851
852 // Selectors in these families may have arbitrary arity, may be
853 // written with arbitrary leading underscores, and may have
854 // additional CamelCase "words" in their first selector chunk
855 // following the family name.
861
862 // These families are singletons consisting only of the nullary
863 // selector with the given name.
872
873 // performSelector families
875};
876
877/// Enough bits to store any enumerator in ObjCMethodFamily or
878/// InvalidObjCMethodFamily.
880
881/// An invalid value of ObjCMethodFamily.
883
884/// A family of Objective-C methods.
885///
886/// These are family of methods whose result type is initially 'id', but
887/// but are candidate for the result type to be changed to 'instancetype'.
896
902
903namespace detail {
904
905/// DeclarationNameExtra is used as a base of various uncommon special names.
906/// This class is needed since DeclarationName has not enough space to store
907/// the kind of every possible names. Therefore the kind of common names is
908/// stored directly in DeclarationName, and the kind of uncommon names is
909/// stored in DeclarationNameExtra. It is aligned to 8 bytes because
910/// DeclarationName needs the lower 3 bits to store the kind of common names.
911/// DeclarationNameExtra is tightly coupled to DeclarationName and any change
912/// here is very likely to require changes in DeclarationName(Table).
913class alignas(IdentifierInfoAlignment) DeclarationNameExtra {
916
917protected:
918 /// The kind of "extra" information stored in the DeclarationName. See
919 /// @c ExtraKindOrNumArgs for an explanation of how these enumerator values
920 /// are used. Note that DeclarationName depends on the numerical values
921 /// of the enumerators in this enum. See DeclarationName::StoredNameKind
922 /// for more info.
929
930 /// ExtraKindOrNumArgs has one of the following meaning:
931 /// * The kind of an uncommon C++ special name. This DeclarationNameExtra
932 /// is in this case in fact either a CXXDeductionGuideNameExtra or
933 /// a CXXLiteralOperatorIdName.
934 ///
935 /// * It may be also name common to C++ using-directives (CXXUsingDirective),
936 ///
937 /// * Otherwise it is ObjCMultiArgSelector+NumArgs, where NumArgs is
938 /// the number of arguments in the Objective-C selector, in which
939 /// case the DeclarationNameExtra is also a MultiKeywordSelector.
941
943 DeclarationNameExtra(unsigned NumArgs)
945
946 /// Return the corresponding ExtraKind.
953
954 /// Return the number of arguments in an ObjC selector. Only valid when this
955 /// is indeed an ObjCMultiArgSelector.
956 unsigned getNumArgs() const {
957 assert(ExtraKindOrNumArgs >= (unsigned)ObjCMultiArgSelector &&
958 "getNumArgs called but this is not an ObjC selector!");
960 }
961};
962
963} // namespace detail
964
965/// One of these variable length records is kept for each
966/// selector containing more than one keyword. We use a folding set
967/// to unique aggregate names (keyword selectors in ObjC parlance). Access to
968/// this class is provided strictly through Selector.
969class alignas(IdentifierInfoAlignment) MultiKeywordSelector
971 public llvm::FoldingSetNode {
972 MultiKeywordSelector(unsigned nKeys) : DeclarationNameExtra(nKeys) {}
973
974public:
975 // Constructor for keyword selectors.
976 MultiKeywordSelector(unsigned nKeys, const IdentifierInfo **IIV)
977 : DeclarationNameExtra(nKeys) {
978 assert((nKeys > 1) && "not a multi-keyword selector");
979
980 // Fill in the trailing keyword array.
981 const IdentifierInfo **KeyInfo =
982 reinterpret_cast<const IdentifierInfo **>(this + 1);
983 for (unsigned i = 0; i != nKeys; ++i)
984 KeyInfo[i] = IIV[i];
985 }
986
987 // getName - Derive the full selector name and return it.
988 std::string getName() const;
989
990 using DeclarationNameExtra::getNumArgs;
991
992 using keyword_iterator = const IdentifierInfo *const *;
993
995 return reinterpret_cast<keyword_iterator>(this + 1);
996 }
997
999 return keyword_begin() + getNumArgs();
1000 }
1001
1002 const IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
1003 assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
1004 return keyword_begin()[i];
1005 }
1006
1007 static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys,
1008 unsigned NumArgs) {
1009 ID.AddInteger(NumArgs);
1010 for (unsigned i = 0; i != NumArgs; ++i)
1011 ID.AddPointer(ArgTys[i]);
1012 }
1013
1014 void Profile(llvm::FoldingSetNodeID &ID) {
1016 }
1017};
1018
1019/// Smart pointer class that efficiently represents Objective-C method
1020/// names.
1021///
1022/// This class will either point to an IdentifierInfo or a
1023/// MultiKeywordSelector (which is private). This enables us to optimize
1024/// selectors that take no arguments and selectors that take 1 argument, which
1025/// accounts for 78% of all selectors in Cocoa.h.
1026class Selector {
1027 friend class Diagnostic;
1028 friend class SelectorTable; // only the SelectorTable can create these
1029 friend class DeclarationName; // and the AST's DeclarationName.
1030
1031 enum IdentifierInfoFlag {
1032 // Empty selector = 0. Note that these enumeration values must
1033 // correspond to the enumeration values of DeclarationName::StoredNameKind
1034 ZeroArg = 0x01,
1035 OneArg = 0x02,
1036 // IMPORTANT NOTE: see comments in InfoPtr (below) about this enumerator
1037 // value.
1038 MultiArg = 0x07,
1039 };
1040
1041 /// IMPORTANT NOTE: the order of the types in this PointerUnion are
1042 /// important! The DeclarationName class has bidirectional conversion
1043 /// to/from Selector through an opaque pointer (void *) which corresponds
1044 /// to this PointerIntPair. The discriminator bit from the PointerUnion
1045 /// corresponds to the high bit in the MultiArg enumerator. So while this
1046 /// PointerIntPair only has two bits for the integer (and we mask off the
1047 /// high bit in `MultiArg` when it is used), that discrimator bit is
1048 /// still necessary for the opaque conversion. The discriminator bit
1049 /// from the PointerUnion and the two integer bits from the
1050 /// PointerIntPair are also exposed via the DeclarationName::StoredNameKind
1051 /// enumeration; see the comments in DeclarationName.h for more details.
1052 /// Do not reorder or add any arguments to this template
1053 /// without thoroughly understanding how tightly coupled these classes are.
1054 llvm::PointerIntPair<
1055 llvm::PointerUnion<const IdentifierInfo *, MultiKeywordSelector *>, 2>
1056 InfoPtr;
1057
1058 Selector(const IdentifierInfo *II, unsigned nArgs) {
1059 assert(nArgs < 2 && "nArgs not equal to 0/1");
1060 InfoPtr.setPointerAndInt(II, nArgs + 1);
1061 }
1062
1063 Selector(MultiKeywordSelector *SI) {
1064 // IMPORTANT NOTE: we mask off the upper bit of this value because we only
1065 // reserve two bits for the integer in the PointerIntPair. See the comments
1066 // in `InfoPtr` for more details.
1067 InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);
1068 }
1069
1070 const IdentifierInfo *getAsIdentifierInfo() const {
1071 return dyn_cast_if_present<const IdentifierInfo *>(InfoPtr.getPointer());
1072 }
1073
1074 MultiKeywordSelector *getMultiKeywordSelector() const {
1075 return cast<MultiKeywordSelector *>(InfoPtr.getPointer());
1076 }
1077
1078 unsigned getIdentifierInfoFlag() const {
1079 unsigned new_flags = InfoPtr.getInt();
1080 // IMPORTANT NOTE: We have to reconstitute this data rather than use the
1081 // value directly from the PointerIntPair. See the comments in `InfoPtr`
1082 // for more details.
1083 if (isa<MultiKeywordSelector *>(InfoPtr.getPointer()))
1084 new_flags |= MultiArg;
1085 return new_flags;
1086 }
1087
1088 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
1089
1090 static ObjCStringFormatFamily getStringFormatFamilyImpl(Selector sel);
1091
1092public:
1093 /// The default ctor should only be used when creating data structures that
1094 /// will contain selectors.
1095 Selector() = default;
1097 InfoPtr.setFromOpaqueValue(reinterpret_cast<void *>(V));
1098 }
1099
1100 /// operator==/!= - Indicate whether the specified selectors are identical.
1101 bool operator==(Selector RHS) const {
1102 return InfoPtr.getOpaqueValue() == RHS.InfoPtr.getOpaqueValue();
1103 }
1104 bool operator!=(Selector RHS) const {
1105 return InfoPtr.getOpaqueValue() != RHS.InfoPtr.getOpaqueValue();
1106 }
1107
1108 void *getAsOpaquePtr() const { return InfoPtr.getOpaqueValue(); }
1109
1110 /// Determine whether this is the empty selector.
1111 bool isNull() const { return InfoPtr.getOpaqueValue() == nullptr; }
1112
1113 // Predicates to identify the selector type.
1114 bool isKeywordSelector() const { return InfoPtr.getInt() != ZeroArg; }
1115
1116 bool isUnarySelector() const { return InfoPtr.getInt() == ZeroArg; }
1117
1118 /// If this selector is the specific keyword selector described by Names.
1119 bool isKeywordSelector(ArrayRef<StringRef> Names) const;
1120
1121 /// If this selector is the specific unary selector described by Name.
1122 bool isUnarySelector(StringRef Name) const;
1123
1124 unsigned getNumArgs() const;
1125
1126 /// Retrieve the identifier at a given position in the selector.
1127 ///
1128 /// Note that the identifier pointer returned may be NULL. Clients that only
1129 /// care about the text of the identifier string, and not the specific,
1130 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
1131 /// an empty string when the identifier pointer would be NULL.
1132 ///
1133 /// \param argIndex The index for which we want to retrieve the identifier.
1134 /// This index shall be less than \c getNumArgs() unless this is a keyword
1135 /// selector, in which case 0 is the only permissible value.
1136 ///
1137 /// \returns the uniqued identifier for this slot, or NULL if this slot has
1138 /// no corresponding identifier.
1139 const IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
1140
1141 /// Retrieve the name at a given position in the selector.
1142 ///
1143 /// \param argIndex The index for which we want to retrieve the name.
1144 /// This index shall be less than \c getNumArgs() unless this is a keyword
1145 /// selector, in which case 0 is the only permissible value.
1146 ///
1147 /// \returns the name for this slot, which may be the empty string if no
1148 /// name was supplied.
1149 StringRef getNameForSlot(unsigned argIndex) const;
1150
1151 /// Derive the full selector name (e.g. "foo:bar:") and return
1152 /// it as an std::string.
1153 std::string getAsString() const;
1154
1155 /// Prints the full selector name (e.g. "foo:bar:").
1156 void print(llvm::raw_ostream &OS) const;
1157
1158 void dump() const;
1159
1160 /// Derive the conventional family of this method.
1162 return getMethodFamilyImpl(*this);
1163 }
1164
1166 return getStringFormatFamilyImpl(*this);
1167 }
1168
1169 static Selector getEmptyMarker() {
1170 return Selector(uintptr_t(-1));
1171 }
1172
1173 static Selector getTombstoneMarker() {
1174 return Selector(uintptr_t(-2));
1175 }
1176
1177 static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
1178};
1179
1180/// This table allows us to fully hide how we implement
1181/// multi-keyword caching.
1183 // Actually a SelectorTableImpl
1184 void *Impl;
1185
1186public:
1187 SelectorTable();
1188 SelectorTable(const SelectorTable &) = delete;
1191
1192 /// Can create any sort of selector.
1193 ///
1194 /// \p NumArgs indicates whether this is a no argument selector "foo", a
1195 /// single argument selector "foo:" or multi-argument "foo:bar:".
1196 Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV);
1197
1199 return Selector(ID, 1);
1200 }
1201
1203 return Selector(ID, 0);
1204 }
1205
1206 /// Return the total amount of memory allocated for managing selectors.
1207 size_t getTotalMemory() const;
1208
1209 /// Return the default setter name for the given identifier.
1210 ///
1211 /// This is "set" + \p Name where the initial character of \p Name
1212 /// has been capitalized.
1213 static SmallString<64> constructSetterName(StringRef Name);
1214
1215 /// Return the default setter selector for the given identifier.
1216 ///
1217 /// This is "set" + \p Name where the initial character of \p Name
1218 /// has been capitalized.
1219 static Selector constructSetterSelector(IdentifierTable &Idents,
1220 SelectorTable &SelTable,
1221 const IdentifierInfo *Name);
1222
1223 /// Return the property name for the given setter selector.
1224 static std::string getPropertyNameFromSetterSelector(Selector Sel);
1225};
1226
1227/// A simple pair of identifier info and location.
1229 SourceLocation Loc;
1230 IdentifierInfo *II = nullptr;
1231
1232public:
1233 IdentifierLoc() = default;
1234 IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {}
1235
1236 void setLoc(SourceLocation L) { Loc = L; }
1237 void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; }
1238 SourceLocation getLoc() const { return Loc; }
1239 IdentifierInfo *getIdentifierInfo() const { return II; }
1240
1241 bool operator==(const IdentifierLoc &X) const {
1242 return Loc == X.Loc && II == X.II;
1243 }
1244
1245 bool operator!=(const IdentifierLoc &X) const {
1246 return Loc != X.Loc || II != X.II;
1247 }
1248};
1249} // namespace clang
1250
1251namespace llvm {
1252
1253/// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
1254/// DenseSets.
1255template <>
1256struct DenseMapInfo<clang::Selector> {
1260
1264
1265 static unsigned getHashValue(clang::Selector S);
1266
1268 return LHS == RHS;
1269 }
1270};
1271
1272template<>
1273struct PointerLikeTypeTraits<clang::Selector> {
1274 static const void *getAsVoidPointer(clang::Selector P) {
1275 return P.getAsOpaquePtr();
1276 }
1277
1278 static clang::Selector getFromVoidPointer(const void *P) {
1279 return clang::Selector(reinterpret_cast<uintptr_t>(P));
1280 }
1281
1282 static constexpr int NumLowBitsAvailable = 0;
1283};
1284
1285} // namespace llvm
1286
1287#endif // LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
#define V(N, I)
Defines enum values for all the target-independent builtin functions.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Defines the Diagnostic IDs-related interfaces.
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, QualType Ty)
#define X(type, name)
Definition Value.h:97
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::SourceLocation class and associated facilities.
Defines the clang::TokenKind enum and support functions.
DeclarationNameTable is used to store and retrieve DeclarationName instances for the various kinds of...
The name of a declaration.
Provides lookups to, and iteration over, IdentiferInfo objects.
virtual IdentifierInfo * get(StringRef Name)=0
Return the IdentifierInfo for the specified named identifier.
virtual IdentifierIterator * getIdentifiers()
Retrieve an iterator into the set of all identifiers known to this identifier lookup source.
One of these records is kept for each identifier that is lexed.
bool isHandleIdentifierCase() const
Return true if the Preprocessor::HandleIdentifier must be called on a token of this identifier.
IdentifierInfo(const IdentifierInfo &)=delete
IdentifierInfo(IdentifierInfo &&)=delete
bool isModulesImport() const
Determine whether this is the contextual keyword import.
void revertIdentifierToTokenID(tok::TokenKind TK)
unsigned getLength() const
Efficiently return the length of this identifier info.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
bool IsKeywordInCPlusPlus() const
Return true if this identifier would be a keyword in C++ mode.
void setModulesImport(bool I)
Set whether this identifier is the contextual keyword import.
void setNotableIdentifierID(unsigned ID)
void setIsExtensionToken(bool Val)
void setIsRestrictExpansion(bool Val)
void setFETokenInfo(void *T)
bool hasChangedSinceDeserialization() const
Determine whether this identifier has changed since it was loaded from an AST file.
bool isCPlusPlusOperatorKeyword() const
IdentifierInfo & operator=(const IdentifierInfo &)=delete
void setIsDeprecatedMacro(bool Val)
bool hasFETokenInfoChangedSinceDeserialization() const
Determine whether the frontend token information for this identifier has changed since it was loaded ...
void setMangledOpenMPVariantName(bool I)
Set whether this is the mangled name of an OpenMP variant.
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
void setObjCKeywordID(tok::ObjCKeywordKind ID)
void setIsFinal(bool Val)
IdentifierInfo & operator=(IdentifierInfo &&)=delete
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
void setHandleIdentifierCase(bool Val=true)
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
void setIsKeywordInCPlusPlus(bool Val=true)
bool isPoisoned() const
Return true if this token has been poisoned.
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
tok::NotableIdentifierKind getNotableIdentifierID() const
bool isMangledOpenMPVariantName() const
Determine whether this is the mangled name of an OpenMP variant.
void setOutOfDate(bool OOD)
Set whether the information for this identifier is out of date with respect to the external source.
void setHasMacroDefinition(bool Val)
bool isStr(llvm::StringRef Str) const
Return true if this is the identifier for the specified StringRef.
unsigned getObjCOrBuiltinID() const
tok::ObjCKeywordKind getObjCKeywordID() const
Return the Objective-C keyword ID for the this identifier.
void setObjCOrBuiltinID(unsigned ID)
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
void setIsCPlusPlusOperatorKeyword(bool Val=true)
isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether this identifier is a C++ al...
void setBuiltinID(unsigned ID)
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
bool operator<(const IdentifierInfo &RHS) const
Provide less than operator for lexicographical sorting.
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
bool isDeprecatedMacro() const
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
void setIsFutureCompatKeyword(bool Val)
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
void * getFETokenInfo() const
Get and set FETokenInfo.
StringRef getName() const
Return the actual identifier string.
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension.
bool isRestrictExpansion() const
An iterator that walks over all of the known identifiers in the lookup table.
virtual StringRef Next()=0
Retrieve the next string in the identifier table and advances the iterator for the following string.
IdentifierIterator & operator=(const IdentifierIterator &)=delete
IdentifierIterator(const IdentifierIterator &)=delete
bool operator!=(const IdentifierLoc &X) const
SourceLocation getLoc() const
bool operator==(const IdentifierLoc &X) const
void setIdentifierInfo(IdentifierInfo *Ident)
void setLoc(SourceLocation L)
IdentifierInfo * getIdentifierInfo() const
IdentifierLoc(SourceLocation L, IdentifierInfo *Ident)
Implements an efficient mapping from strings to IdentifierInfo nodes.
IdentifierTable(IdentifierInfoLookup *ExternalLookup=nullptr)
Create the identifier table.
IdentifierInfo & getOwn(StringRef Name)
Gets an IdentifierInfo for the given name without consulting external sources.
iterator find(StringRef Name) const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IdentifierInfo & get(StringRef Name, tok::TokenKind TokenCode)
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
HashTableTy::const_iterator iterator
HashTableTy::const_iterator const_iterator
llvm::BumpPtrAllocator & getAllocator()
void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup)
Set the external identifier lookup mechanism.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
One of these variable length records is kept for each selector containing more than one keyword.
keyword_iterator keyword_end() const
const IdentifierInfo *const * keyword_iterator
MultiKeywordSelector(unsigned nKeys, const IdentifierInfo **IIV)
void Profile(llvm::FoldingSetNodeID &ID)
static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys, unsigned NumArgs)
keyword_iterator keyword_begin() const
const IdentifierInfo * getIdentifierInfoForSlot(unsigned i) const
PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
This table allows us to fully hide how we implement multi-keyword caching.
SelectorTable(const SelectorTable &)=delete
Selector getNullarySelector(const IdentifierInfo *ID)
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Selector getUnarySelector(const IdentifierInfo *ID)
SelectorTable & operator=(const SelectorTable &)=delete
Smart pointer class that efficiently represents Objective-C method names.
friend class DeclarationName
friend class SelectorTable
Selector()=default
The default ctor should only be used when creating data structures that will contain selectors.
friend class Diagnostic
static Selector getEmptyMarker()
static Selector getTombstoneMarker()
void * getAsOpaquePtr() const
bool isKeywordSelector() const
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
bool operator==(Selector RHS) const
operator==/!= - Indicate whether the specified selectors are identical.
bool isUnarySelector() const
bool operator!=(Selector RHS) const
bool isNull() const
Determine whether this is the empty selector.
Selector(uintptr_t V)
ObjCStringFormatFamily getStringFormatFamily() const
Encodes a location in the source.
DeclarationNameExtra is used as a base of various uncommon special names.
ExtraKind
The kind of "extra" information stored in the DeclarationName.
ExtraKind getKind() const
Return the corresponding ExtraKind.
unsigned ExtraKindOrNumArgs
ExtraKindOrNumArgs has one of the following meaning:
unsigned getNumArgs() const
Return the number of arguments in an ObjC selector.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
NotableIdentifierKind
Provides a namespace for notable identifers such as float_t and double_t.
Definition TokenKinds.h:49
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
Definition TokenKinds.h:41
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition TokenKinds.h:25
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
Definition TokenKinds.h:33
The JSON file list parser is used to communicate input to InstallAPI.
TokenKey
Constants for TokenKinds.def.
@ ObjCMethodFamilyBitWidth
KeywordStatus getKeywordStatus(const LangOptions &LangOpts, unsigned Flags)
Translates flags as specified in TokenKinds.def into keyword status in the given language standard.
bool isReservedInAllContexts(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved in all contexts.
@ InvalidObjCMethodFamily
InterestingIdentifier
The "layout" of InterestingIdentifier is:
ObjCMethodFamily
A family of Objective-C methods.
@ OMF_performSelector
@ OMF_None
No particular method family.
const FunctionProtoType * T
ObjCInstanceTypeFamily
A family of Objective-C methods.
ReservedLiteralSuffixIdStatus
static constexpr int InterestingIdentifierBits
KeywordStatus
How a keyword is treated in the selected standard.
bool isReservedAtGlobalScope(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved for use as a name at global scope.
llvm::StringRef getAsString(SyncScope S)
Definition SyncScope.h:62
@ IdentifierInfoAlignment
ReservedIdentifierStatus
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define false
Definition stdbool.h:26
static bool isEqual(clang::Selector LHS, clang::Selector RHS)
static clang::Selector getTombstoneKey()
static clang::Selector getFromVoidPointer(const void *P)
static const void * getAsVoidPointer(clang::Selector P)