clang 23.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 the 'module' contextual keyword.
235 LLVM_PREFERRED_TYPE(bool)
236 unsigned IsModulesDecl : 1;
237
238 // True if this is a mangled OpenMP variant name.
239 LLVM_PREFERRED_TYPE(bool)
240 unsigned IsMangledOpenMPVariantName : 1;
241
242 // True if this is a deprecated macro.
243 LLVM_PREFERRED_TYPE(bool)
244 unsigned IsDeprecatedMacro : 1;
245
246 // True if this macro is unsafe in headers.
247 LLVM_PREFERRED_TYPE(bool)
248 unsigned IsRestrictExpansion : 1;
249
250 // True if this macro is final.
251 LLVM_PREFERRED_TYPE(bool)
252 unsigned IsFinal : 1;
253
254 // True if this identifier would be a keyword in C++ mode.
255 LLVM_PREFERRED_TYPE(bool)
256 unsigned IsKeywordInCpp : 1;
257
258 // 21 bits left in a 64-bit word.
259
260 // Managed by the language front-end.
261 void *FETokenInfo = nullptr;
262
263 llvm::StringMapEntry<IdentifierInfo *> *Entry = nullptr;
264
265 IdentifierInfo()
266 : TokenID(tok::identifier),
267 InterestingIdentifierID(llvm::to_underlying(
269 HasMacro(false), HadMacro(false), IsExtension(false),
270 IsFutureCompatKeyword(false), IsPoisoned(false),
271 IsCPPOperatorKeyword(false), NeedsHandleIdentifier(false),
272 IsFromAST(false), ChangedAfterLoad(false), FEChangedAfterLoad(false),
273 RevertedTokenID(false), OutOfDate(false), IsModulesImport(false),
274 IsModulesDecl(false), IsMangledOpenMPVariantName(false),
275 IsDeprecatedMacro(false), IsRestrictExpansion(false), IsFinal(false),
276 IsKeywordInCpp(false) {}
277
278public:
279 IdentifierInfo(const IdentifierInfo &) = delete;
280 IdentifierInfo &operator=(const IdentifierInfo &) = delete;
281 IdentifierInfo(IdentifierInfo &&) = delete;
282 IdentifierInfo &operator=(IdentifierInfo &&) = delete;
283
284 /// Return true if this is the identifier for the specified string.
285 ///
286 /// This is intended to be used for string literals only: II->isStr("foo").
287 template <std::size_t StrLen>
288 bool isStr(const char (&Str)[StrLen]) const {
289 return getLength() == StrLen-1 &&
290 memcmp(getNameStart(), Str, StrLen-1) == 0;
291 }
292
293 /// Return true if this is the identifier for the specified StringRef.
294 bool isStr(llvm::StringRef Str) const {
295 llvm::StringRef ThisStr(getNameStart(), getLength());
296 return ThisStr == Str;
297 }
298
299 /// Return the beginning of the actual null-terminated string for this
300 /// identifier.
301 const char *getNameStart() const { return Entry->getKeyData(); }
302
303 /// Efficiently return the length of this identifier info.
304 unsigned getLength() const { return Entry->getKeyLength(); }
305
306 /// Return the actual identifier string.
307 StringRef getName() const {
308 return StringRef(getNameStart(), getLength());
309 }
310
311 /// Return true if this identifier is \#defined to some other value.
312 /// \note The current definition may be in a module and not currently visible.
313 bool hasMacroDefinition() const {
314 return HasMacro;
315 }
316 void setHasMacroDefinition(bool Val) {
317 if (HasMacro == Val) return;
318
319 HasMacro = Val;
320 if (Val) {
321 NeedsHandleIdentifier = true;
322 HadMacro = true;
323 } else {
324 // If this is a final macro, make the deprecation and header unsafe bits
325 // stick around after the undefinition so they apply to any redefinitions.
326 if (!IsFinal) {
327 // Because calling the setters of these calls recomputes, just set them
328 // manually to avoid recomputing a bunch of times.
329 IsDeprecatedMacro = false;
330 IsRestrictExpansion = false;
331 }
332 RecomputeNeedsHandleIdentifier();
333 }
334 }
335 /// Returns true if this identifier was \#defined to some value at any
336 /// moment. In this case there should be an entry for the identifier in the
337 /// macro history table in Preprocessor.
338 bool hadMacroDefinition() const {
339 return HadMacro;
340 }
341
342 bool isDeprecatedMacro() const { return IsDeprecatedMacro; }
343
344 void setIsDeprecatedMacro(bool Val) {
345 if (IsDeprecatedMacro == Val)
346 return;
347 IsDeprecatedMacro = Val;
348 if (Val)
349 NeedsHandleIdentifier = true;
350 else
351 RecomputeNeedsHandleIdentifier();
352 }
353
354 bool isRestrictExpansion() const { return IsRestrictExpansion; }
355
356 void setIsRestrictExpansion(bool Val) {
357 if (IsRestrictExpansion == Val)
358 return;
359 IsRestrictExpansion = Val;
360 if (Val)
361 NeedsHandleIdentifier = true;
362 else
363 RecomputeNeedsHandleIdentifier();
364 }
365
366 bool isFinal() const { return IsFinal; }
367
368 void setIsFinal(bool Val) { IsFinal = Val; }
369
370 /// If this is a source-language token (e.g. 'for'), this API
371 /// can be used to cause the lexer to map identifiers to source-language
372 /// tokens.
373 tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
374
375 /// True if revertTokenIDToIdentifier() was called.
376 bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
377
378 /// Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
379 /// compatibility.
380 ///
381 /// TokenID is normally read-only but there are 2 instances where we revert it
382 /// to tok::identifier for libstdc++ 4.2. Keep track of when this happens
383 /// using this method so we can inform serialization about it.
385 assert(TokenID != tok::identifier && "Already at tok::identifier");
386 TokenID = tok::identifier;
387 RevertedTokenID = true;
388 }
390 assert(TokenID == tok::identifier && "Should be at tok::identifier");
391 TokenID = TK;
392 RevertedTokenID = false;
393 }
394
395 /// Return the preprocessor keyword ID for this identifier.
396 ///
397 /// For example, "define" will return tok::pp_define.
398 tok::PPKeywordKind getPPKeywordID() const;
399
400 /// Return the Objective-C keyword ID for the this identifier.
401 ///
402 /// For example, 'class' will return tok::objc_class if ObjC is enabled.
404 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
405 auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
407 return static_cast<tok::ObjCKeywordKind>(InterestingIdentifierID);
408 return tok::objc_not_keyword;
409 }
411 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
412 InterestingIdentifierID = ID;
413 assert(getObjCKeywordID() == ID && "ID too large for field!");
414 }
415
416 /// Return a value indicating whether this is a builtin function.
417 unsigned getBuiltinID() const {
418 auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
419 if (Value >
422 auto FirstBuiltin =
423 llvm::to_underlying(InterestingIdentifier::NotBuiltin);
424 return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
425 }
427 }
428 void setBuiltinID(unsigned ID) {
429 assert(ID != Builtin::ID::NotBuiltin);
430 auto FirstBuiltin = llvm::to_underlying(InterestingIdentifier::NotBuiltin);
431 InterestingIdentifierID = ID + FirstBuiltin;
432 assert(getBuiltinID() == ID && "ID too large for field!");
433 }
435 InterestingIdentifierID =
437 }
438
440 auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
442 Value <
444 auto FirstNotableIdentifier =
445 1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
446 return static_cast<tok::NotableIdentifierKind>(InterestingIdentifierID -
447 FirstNotableIdentifier);
448 }
449 return tok::not_notable;
450 }
451 void setNotableIdentifierID(unsigned ID) {
452 assert(ID != tok::not_notable);
453 auto FirstNotableIdentifier =
454 1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
455 InterestingIdentifierID = ID + FirstNotableIdentifier;
456 assert(getNotableIdentifierID() == ID && "ID too large for field!");
457 }
458
459 unsigned getObjCOrBuiltinID() const { return InterestingIdentifierID; }
460 void setObjCOrBuiltinID(unsigned ID) { InterestingIdentifierID = ID; }
461
462 /// get/setExtension - Initialize information about whether or not this
463 /// language token is an extension. This controls extension warnings, and is
464 /// only valid if a custom token ID is set.
465 bool isExtensionToken() const { return IsExtension; }
466 void setIsExtensionToken(bool Val) {
467 IsExtension = Val;
468 if (Val)
469 NeedsHandleIdentifier = true;
470 else
471 RecomputeNeedsHandleIdentifier();
472 }
473
474 /// is/setIsFutureCompatKeyword - Initialize information about whether or not
475 /// this language token is a keyword in a newer or proposed Standard. This
476 /// controls compatibility warnings, and is only true when not parsing the
477 /// corresponding Standard. Once a compatibility problem has been diagnosed
478 /// with this keyword, the flag will be cleared.
479 bool isFutureCompatKeyword() const { return IsFutureCompatKeyword; }
481 IsFutureCompatKeyword = Val;
482 if (Val)
483 NeedsHandleIdentifier = true;
484 else
485 RecomputeNeedsHandleIdentifier();
486 }
487
488 /// setIsPoisoned - Mark this identifier as poisoned. After poisoning, the
489 /// Preprocessor will emit an error every time this token is used.
490 void setIsPoisoned(bool Value = true) {
491 IsPoisoned = Value;
492 if (Value)
493 NeedsHandleIdentifier = true;
494 else
495 RecomputeNeedsHandleIdentifier();
496 }
497
498 /// Return true if this token has been poisoned.
499 bool isPoisoned() const { return IsPoisoned; }
500
501 /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
502 /// this identifier is a C++ alternate representation of an operator.
503 void setIsCPlusPlusOperatorKeyword(bool Val = true) {
504 IsCPPOperatorKeyword = Val;
505 }
506 bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
507
508 /// Return true if this identifier would be a keyword in C++ mode.
509 bool IsKeywordInCPlusPlus() const { return IsKeywordInCpp; }
510 void setIsKeywordInCPlusPlus(bool Val = true) { IsKeywordInCpp = Val; }
511
512 /// Return true if this token is a keyword in the specified language.
513 bool isKeyword(const LangOptions &LangOpts) const;
514
515 /// Return true if this token is a C++ keyword in the specified
516 /// language.
517 bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
518
519 /// Get and set FETokenInfo. The language front-end is allowed to associate
520 /// arbitrary metadata with this token.
521 void *getFETokenInfo() const { return FETokenInfo; }
522 void setFETokenInfo(void *T) { FETokenInfo = T; }
523
524 /// Return true if the Preprocessor::HandleIdentifier must be called
525 /// on a token of this identifier.
526 ///
527 /// If this returns false, we know that HandleIdentifier will not affect
528 /// the token.
529 bool isHandleIdentifierCase() const { return NeedsHandleIdentifier; }
530 void setHandleIdentifierCase(bool Val = true) { NeedsHandleIdentifier = Val; }
531
532 /// Return true if the identifier in its current state was loaded
533 /// from an AST file.
534 bool isFromAST() const { return IsFromAST; }
535
536 void setIsFromAST() { IsFromAST = true; }
537
538 /// Determine whether this identifier has changed since it was loaded
539 /// from an AST file.
541 return ChangedAfterLoad;
542 }
543
544 /// Note that this identifier has changed since it was loaded from
545 /// an AST file.
547 ChangedAfterLoad = true;
548 }
549
550 /// Determine whether the frontend token information for this
551 /// identifier has changed since it was loaded from an AST file.
553 return FEChangedAfterLoad;
554 }
555
556 /// Note that the frontend token information for this identifier has
557 /// changed since it was loaded from an AST file.
559 FEChangedAfterLoad = true;
560 }
561
562 /// Determine whether the information for this identifier is out of
563 /// date with respect to the external source.
564 bool isOutOfDate() const { return OutOfDate; }
565
566 /// Set whether the information for this identifier is out of
567 /// date with respect to the external source.
568 void setOutOfDate(bool OOD) {
569 OutOfDate = OOD;
570 if (OOD)
571 NeedsHandleIdentifier = true;
572 else
573 RecomputeNeedsHandleIdentifier();
574 }
575
576 /// Determine whether this is the contextual keyword \c import.
577 bool isImportKeyword() const { return IsModulesImport; }
578
579 /// Set whether this identifier is the contextual keyword \c import.
580 void setKeywordImport(bool Val) {
581 IsModulesImport = Val;
582 if (Val)
583 NeedsHandleIdentifier = true;
584 else
585 RecomputeNeedsHandleIdentifier();
586 }
587
588 /// Determine whether this is the contextual keyword \c module.
589 bool isModuleKeyword() const { return IsModulesDecl; }
590
591 /// Set whether this identifier is the contextual keyword \c module.
592 void setModuleKeyword(bool Val) {
593 IsModulesDecl = Val;
594 if (Val)
595 NeedsHandleIdentifier = true;
596 else
597 RecomputeNeedsHandleIdentifier();
598 }
599
600 /// Determine whether this is the mangled name of an OpenMP variant.
601 bool isMangledOpenMPVariantName() const { return IsMangledOpenMPVariantName; }
602
603 /// Set whether this is the mangled name of an OpenMP variant.
604 void setMangledOpenMPVariantName(bool I) { IsMangledOpenMPVariantName = I; }
605
606 /// Return true if this identifier is an editor placeholder.
607 ///
608 /// Editor placeholders are produced by the code-completion engine and are
609 /// represented as characters between '<#' and '#>' in the source code. An
610 /// example of auto-completed call with a placeholder parameter is shown
611 /// below:
612 /// \code
613 /// function(<#int x#>);
614 /// \endcode
615 bool isEditorPlaceholder() const {
616 return getName().starts_with("<#") && getName().ends_with("#>");
617 }
618
619 /// Determine whether \p this is a name reserved for the implementation (C99
620 /// 7.1.3, C++ [lib.global.names]).
621 ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const;
622
623 /// Determine whether \p this is a name reserved for future standardization or
624 /// the implementation (C++ [usrlit.suffix]).
625 ReservedLiteralSuffixIdStatus isReservedLiteralSuffixId() const;
626
627 /// If the identifier is an "uglified" reserved name, return a cleaned form.
628 /// e.g. _Foo => Foo. Otherwise, just returns the name.
629 StringRef deuglifiedName() const;
630 bool isPlaceholder() const {
631 return getLength() == 1 && getNameStart()[0] == '_';
632 }
633
634 /// Provide less than operator for lexicographical sorting.
635 bool operator<(const IdentifierInfo &RHS) const {
636 return getName() < RHS.getName();
637 }
638
639private:
640 /// The Preprocessor::HandleIdentifier does several special (but rare)
641 /// things to identifiers of various sorts. For example, it changes the
642 /// \c for keyword token from tok::identifier to tok::for.
643 ///
644 /// This method is very tied to the definition of HandleIdentifier. Any
645 /// change to it should be reflected here.
646 void RecomputeNeedsHandleIdentifier() {
647 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
648 isExtensionToken() || isFutureCompatKeyword() ||
649 isOutOfDate() || isImportKeyword();
650 }
651};
652
653/// An RAII object for [un]poisoning an identifier within a scope.
654///
655/// \p II is allowed to be null, in which case objects of this type have
656/// no effect.
658 IdentifierInfo *const II;
659 const bool OldValue;
660
661public:
663 : II(II), OldValue(II ? II->isPoisoned() : false) {
664 if(II)
665 II->setIsPoisoned(NewValue);
666 }
667
669 if(II)
670 II->setIsPoisoned(OldValue);
671 }
672};
673
674/// An iterator that walks over all of the known identifiers
675/// in the lookup table.
676///
677/// Since this iterator uses an abstract interface via virtual
678/// functions, it uses an object-oriented interface rather than the
679/// more standard C++ STL iterator interface. In this OO-style
680/// iteration, the single function \c Next() provides dereference,
681/// advance, and end-of-sequence checking in a single
682/// operation. Subclasses of this iterator type will provide the
683/// actual functionality.
685protected:
687
688public:
691
693
694 /// Retrieve the next string in the identifier table and
695 /// advances the iterator for the following string.
696 ///
697 /// \returns The next string in the identifier table. If there is
698 /// no such string, returns an empty \c StringRef.
699 virtual StringRef Next() = 0;
700};
701
702/// Provides lookups to, and iteration over, IdentiferInfo objects.
704public:
706
707 /// Return the IdentifierInfo for the specified named identifier.
708 ///
709 /// Unlike the version in IdentifierTable, this returns a pointer instead
710 /// of a reference. If the pointer is null then the IdentifierInfo cannot
711 /// be found.
712 virtual IdentifierInfo* get(StringRef Name) = 0;
713
714 /// Retrieve an iterator into the set of all identifiers
715 /// known to this identifier lookup source.
716 ///
717 /// This routine provides access to all of the identifiers known to
718 /// the identifier lookup, allowing access to the contents of the
719 /// identifiers without introducing the overhead of constructing
720 /// IdentifierInfo objects for each.
721 ///
722 /// \returns A new iterator into the set of known identifiers. The
723 /// caller is responsible for deleting this iterator.
725};
726
727/// Implements an efficient mapping from strings to IdentifierInfo nodes.
728///
729/// This has no other purpose, but this is an extremely performance-critical
730/// piece of the code, as each occurrence of every identifier goes through
731/// here when lexed.
733 // Shark shows that using MallocAllocator is *much* slower than using this
734 // BumpPtrAllocator!
735 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
736 HashTableTy HashTable;
737
738 IdentifierInfoLookup* ExternalLookup;
739
740public:
741 /// Create the identifier table.
742 explicit IdentifierTable(IdentifierInfoLookup *ExternalLookup = nullptr);
743
744 /// Create the identifier table, populating it with info about the
745 /// language keywords for the language specified by \p LangOpts.
746 explicit IdentifierTable(const LangOptions &LangOpts,
747 IdentifierInfoLookup *ExternalLookup = nullptr);
748
749 /// Set the external identifier lookup mechanism.
751 ExternalLookup = IILookup;
752 }
753
754 /// Retrieve the external identifier lookup object, if any.
756 return ExternalLookup;
757 }
758
759 llvm::BumpPtrAllocator& getAllocator() {
760 return HashTable.getAllocator();
761 }
762
763 /// Return the identifier token info for the specified named
764 /// identifier.
765 IdentifierInfo &get(StringRef Name) {
766 auto &Entry = *HashTable.try_emplace(Name, nullptr).first;
767
768 IdentifierInfo *&II = Entry.second;
769 if (II) return *II;
770
771 // No entry; if we have an external lookup, look there first.
772 if (ExternalLookup) {
773 II = ExternalLookup->get(Name);
774 if (II)
775 return *II;
776 }
777
778 // Lookups failed, make a new IdentifierInfo.
779 void *Mem = getAllocator().Allocate<IdentifierInfo>();
780 II = new (Mem) IdentifierInfo();
781
782 // Make sure getName() knows how to find the IdentifierInfo
783 // contents.
784 II->Entry = &Entry;
785
786 return *II;
787 }
788
789 IdentifierInfo &get(StringRef Name, tok::TokenKind TokenCode) {
790 IdentifierInfo &II = get(Name);
791 II.TokenID = TokenCode;
792 assert(II.TokenID == (unsigned) TokenCode && "TokenCode too large");
793 return II;
794 }
795
796 /// Gets an IdentifierInfo for the given name without consulting
797 /// external sources.
798 ///
799 /// This is a version of get() meant for external sources that want to
800 /// introduce or modify an identifier. If they called get(), they would
801 /// likely end up in a recursion.
802 IdentifierInfo &getOwn(StringRef Name) {
803 auto &Entry = *HashTable.try_emplace(Name).first;
804
805 IdentifierInfo *&II = Entry.second;
806 if (II)
807 return *II;
808
809 // Lookups failed, make a new IdentifierInfo.
810 void *Mem = getAllocator().Allocate<IdentifierInfo>();
811 II = new (Mem) IdentifierInfo();
812
813 // Make sure getName() knows how to find the IdentifierInfo
814 // contents.
815 II->Entry = &Entry;
816
817 // If this is the 'import' or 'module' contextual keyword, mark it as such.
818 if (Name == "import")
819 II->setKeywordImport(true);
820 else if (Name == "module")
821 II->setModuleKeyword(true);
822 return *II;
823 }
824
825 using iterator = HashTableTy::const_iterator;
826 using const_iterator = HashTableTy::const_iterator;
827
828 iterator begin() const { return HashTable.begin(); }
829 iterator end() const { return HashTable.end(); }
830 unsigned size() const { return HashTable.size(); }
831
832 iterator find(StringRef Name) const { return HashTable.find(Name); }
833
834 /// Print some statistics to stderr that indicate how well the
835 /// hashing is doing.
836 void PrintStats() const;
837
838 /// Populate the identifier table with info about the language keywords
839 /// for the language specified by \p LangOpts.
840 void AddKeywords(const LangOptions &LangOpts);
841
842 /// Returns the correct diagnostic to issue for a future-compat diagnostic
843 /// warning. Note, this function assumes the identifier passed has already
844 /// been determined to be a future compatible keyword.
845 diag::kind getFutureCompatDiagKind(const IdentifierInfo &II,
846 const LangOptions &LangOpts);
847};
848
849/// A family of Objective-C methods.
850///
851/// These families have no inherent meaning in the language, but are
852/// nonetheless central enough in the existing implementations to
853/// merit direct AST support. While, in theory, arbitrary methods can
854/// be considered to form families, we focus here on the methods
855/// involving allocation and retain-count management, as these are the
856/// most "core" and the most likely to be useful to diverse clients
857/// without extra information.
858///
859/// Both selectors and actual method declarations may be classified
860/// into families. Method families may impose additional restrictions
861/// beyond their selector name; for example, a method called '_init'
862/// that returns void is not considered to be in the 'init' family
863/// (but would be if it returned 'id'). It is also possible to
864/// explicitly change or remove a method's family. Therefore the
865/// method's family should be considered the single source of truth.
867 /// No particular method family.
869
870 // Selectors in these families may have arbitrary arity, may be
871 // written with arbitrary leading underscores, and may have
872 // additional CamelCase "words" in their first selector chunk
873 // following the family name.
879
880 // These families are singletons consisting only of the nullary
881 // selector with the given name.
890
891 // performSelector families
893};
894
895/// Enough bits to store any enumerator in ObjCMethodFamily or
896/// InvalidObjCMethodFamily.
898
899/// An invalid value of ObjCMethodFamily.
901
902/// A family of Objective-C methods.
903///
904/// These are family of methods whose result type is initially 'id', but
905/// but are candidate for the result type to be changed to 'instancetype'.
914
920
921namespace detail {
922
923/// DeclarationNameExtra is used as a base of various uncommon special names.
924/// This class is needed since DeclarationName has not enough space to store
925/// the kind of every possible names. Therefore the kind of common names is
926/// stored directly in DeclarationName, and the kind of uncommon names is
927/// stored in DeclarationNameExtra. It is aligned to 8 bytes because
928/// DeclarationName needs the lower 3 bits to store the kind of common names.
929/// DeclarationNameExtra is tightly coupled to DeclarationName and any change
930/// here is very likely to require changes in DeclarationName(Table).
931class alignas(IdentifierInfoAlignment) DeclarationNameExtra {
934
935protected:
936 /// The kind of "extra" information stored in the DeclarationName. See
937 /// @c ExtraKindOrNumArgs for an explanation of how these enumerator values
938 /// are used. Note that DeclarationName depends on the numerical values
939 /// of the enumerators in this enum. See DeclarationName::StoredNameKind
940 /// for more info.
947
948 /// ExtraKindOrNumArgs has one of the following meaning:
949 /// * The kind of an uncommon C++ special name. This DeclarationNameExtra
950 /// is in this case in fact either a CXXDeductionGuideNameExtra or
951 /// a CXXLiteralOperatorIdName.
952 ///
953 /// * It may be also name common to C++ using-directives (CXXUsingDirective),
954 ///
955 /// * Otherwise it is ObjCMultiArgSelector+NumArgs, where NumArgs is
956 /// the number of arguments in the Objective-C selector, in which
957 /// case the DeclarationNameExtra is also a MultiKeywordSelector.
959
961 DeclarationNameExtra(unsigned NumArgs)
963
964 /// Return the corresponding ExtraKind.
971
972 /// Return the number of arguments in an ObjC selector. Only valid when this
973 /// is indeed an ObjCMultiArgSelector.
974 unsigned getNumArgs() const {
975 assert(ExtraKindOrNumArgs >= (unsigned)ObjCMultiArgSelector &&
976 "getNumArgs called but this is not an ObjC selector!");
978 }
979};
980
981} // namespace detail
982
983/// One of these variable length records is kept for each
984/// selector containing more than one keyword. We use a folding set
985/// to unique aggregate names (keyword selectors in ObjC parlance). Access to
986/// this class is provided strictly through Selector.
987class alignas(IdentifierInfoAlignment) MultiKeywordSelector
989 public llvm::FoldingSetNode {
990 MultiKeywordSelector(unsigned nKeys) : DeclarationNameExtra(nKeys) {}
991
992public:
993 // Constructor for keyword selectors.
994 MultiKeywordSelector(unsigned nKeys, const IdentifierInfo **IIV)
995 : DeclarationNameExtra(nKeys) {
996 assert((nKeys > 1) && "not a multi-keyword selector");
997
998 // Fill in the trailing keyword array.
999 const IdentifierInfo **KeyInfo =
1000 reinterpret_cast<const IdentifierInfo **>(this + 1);
1001 for (unsigned i = 0; i != nKeys; ++i)
1002 KeyInfo[i] = IIV[i];
1003 }
1004
1005 // getName - Derive the full selector name and return it.
1006 std::string getName() const;
1007
1008 using DeclarationNameExtra::getNumArgs;
1009
1010 using keyword_iterator = const IdentifierInfo *const *;
1011
1013 return reinterpret_cast<keyword_iterator>(this + 1);
1014 }
1015
1017 return keyword_begin() + getNumArgs();
1018 }
1019
1020 const IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
1021 assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
1022 return keyword_begin()[i];
1023 }
1024
1025 static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys,
1026 unsigned NumArgs) {
1027 ID.AddInteger(NumArgs);
1028 for (unsigned i = 0; i != NumArgs; ++i)
1029 ID.AddPointer(ArgTys[i]);
1030 }
1031
1032 void Profile(llvm::FoldingSetNodeID &ID) {
1034 }
1035};
1036
1037/// Smart pointer class that efficiently represents Objective-C method
1038/// names.
1039///
1040/// This class will either point to an IdentifierInfo or a
1041/// MultiKeywordSelector (which is private). This enables us to optimize
1042/// selectors that take no arguments and selectors that take 1 argument, which
1043/// accounts for 78% of all selectors in Cocoa.h.
1044class Selector {
1045 friend class Diagnostic;
1046 friend class SelectorTable; // only the SelectorTable can create these
1047 friend class DeclarationName; // and the AST's DeclarationName.
1048
1049 enum IdentifierInfoFlag {
1050 // Empty selector = 0. Note that these enumeration values must
1051 // correspond to the enumeration values of DeclarationName::StoredNameKind
1052 ZeroArg = 0x01,
1053 OneArg = 0x02,
1054 // IMPORTANT NOTE: see comments in InfoPtr (below) about this enumerator
1055 // value.
1056 MultiArg = 0x07,
1057 };
1058
1059 /// IMPORTANT NOTE: the order of the types in this PointerUnion are
1060 /// important! The DeclarationName class has bidirectional conversion
1061 /// to/from Selector through an opaque pointer (void *) which corresponds
1062 /// to this PointerIntPair. The discriminator bit from the PointerUnion
1063 /// corresponds to the high bit in the MultiArg enumerator. So while this
1064 /// PointerIntPair only has two bits for the integer (and we mask off the
1065 /// high bit in `MultiArg` when it is used), that discrimator bit is
1066 /// still necessary for the opaque conversion. The discriminator bit
1067 /// from the PointerUnion and the two integer bits from the
1068 /// PointerIntPair are also exposed via the DeclarationName::StoredNameKind
1069 /// enumeration; see the comments in DeclarationName.h for more details.
1070 /// Do not reorder or add any arguments to this template
1071 /// without thoroughly understanding how tightly coupled these classes are.
1072 llvm::PointerIntPair<
1073 llvm::PointerUnion<const IdentifierInfo *, MultiKeywordSelector *>, 2>
1074 InfoPtr;
1075
1076 Selector(const IdentifierInfo *II, unsigned nArgs) {
1077 assert(nArgs < 2 && "nArgs not equal to 0/1");
1078 InfoPtr.setPointerAndInt(II, nArgs + 1);
1079 }
1080
1081 Selector(MultiKeywordSelector *SI) {
1082 // IMPORTANT NOTE: we mask off the upper bit of this value because we only
1083 // reserve two bits for the integer in the PointerIntPair. See the comments
1084 // in `InfoPtr` for more details.
1085 InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);
1086 }
1087
1088 const IdentifierInfo *getAsIdentifierInfo() const {
1089 return dyn_cast_if_present<const IdentifierInfo *>(InfoPtr.getPointer());
1090 }
1091
1092 MultiKeywordSelector *getMultiKeywordSelector() const {
1093 return cast<MultiKeywordSelector *>(InfoPtr.getPointer());
1094 }
1095
1096 unsigned getIdentifierInfoFlag() const {
1097 unsigned new_flags = InfoPtr.getInt();
1098 // IMPORTANT NOTE: We have to reconstitute this data rather than use the
1099 // value directly from the PointerIntPair. See the comments in `InfoPtr`
1100 // for more details.
1101 if (isa<MultiKeywordSelector *>(InfoPtr.getPointer()))
1102 new_flags |= MultiArg;
1103 return new_flags;
1104 }
1105
1106 static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
1107
1108 static ObjCStringFormatFamily getStringFormatFamilyImpl(Selector sel);
1109
1110public:
1111 /// The default ctor should only be used when creating data structures that
1112 /// will contain selectors.
1113 Selector() = default;
1115 InfoPtr.setFromOpaqueValue(reinterpret_cast<void *>(V));
1116 }
1117
1118 /// operator==/!= - Indicate whether the specified selectors are identical.
1119 bool operator==(Selector RHS) const {
1120 return InfoPtr.getOpaqueValue() == RHS.InfoPtr.getOpaqueValue();
1121 }
1122 bool operator!=(Selector RHS) const {
1123 return InfoPtr.getOpaqueValue() != RHS.InfoPtr.getOpaqueValue();
1124 }
1125
1126 void *getAsOpaquePtr() const { return InfoPtr.getOpaqueValue(); }
1127
1128 /// Determine whether this is the empty selector.
1129 bool isNull() const { return InfoPtr.getOpaqueValue() == nullptr; }
1130
1131 // Predicates to identify the selector type.
1132 bool isKeywordSelector() const { return InfoPtr.getInt() != ZeroArg; }
1133
1134 bool isUnarySelector() const { return InfoPtr.getInt() == ZeroArg; }
1135
1136 /// If this selector is the specific keyword selector described by Names.
1137 bool isKeywordSelector(ArrayRef<StringRef> Names) const;
1138
1139 /// If this selector is the specific unary selector described by Name.
1140 bool isUnarySelector(StringRef Name) const;
1141
1142 unsigned getNumArgs() const;
1143
1144 /// Retrieve the identifier at a given position in the selector.
1145 ///
1146 /// Note that the identifier pointer returned may be NULL. Clients that only
1147 /// care about the text of the identifier string, and not the specific,
1148 /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
1149 /// an empty string when the identifier pointer would be NULL.
1150 ///
1151 /// \param argIndex The index for which we want to retrieve the identifier.
1152 /// This index shall be less than \c getNumArgs() unless this is a keyword
1153 /// selector, in which case 0 is the only permissible value.
1154 ///
1155 /// \returns the uniqued identifier for this slot, or NULL if this slot has
1156 /// no corresponding identifier.
1157 const IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
1158
1159 /// Retrieve the name at a given position in the selector.
1160 ///
1161 /// \param argIndex The index for which we want to retrieve the name.
1162 /// This index shall be less than \c getNumArgs() unless this is a keyword
1163 /// selector, in which case 0 is the only permissible value.
1164 ///
1165 /// \returns the name for this slot, which may be the empty string if no
1166 /// name was supplied.
1167 StringRef getNameForSlot(unsigned argIndex) const;
1168
1169 /// Derive the full selector name (e.g. "foo:bar:") and return
1170 /// it as an std::string.
1171 std::string getAsString() const;
1172
1173 /// Prints the full selector name (e.g. "foo:bar:").
1174 void print(llvm::raw_ostream &OS) const;
1175
1176 void dump() const;
1177
1178 /// Derive the conventional family of this method.
1180 return getMethodFamilyImpl(*this);
1181 }
1182
1184 return getStringFormatFamilyImpl(*this);
1185 }
1186
1187 static Selector getEmptyMarker() {
1188 return Selector(uintptr_t(-1));
1189 }
1190
1191 static Selector getTombstoneMarker() {
1192 return Selector(uintptr_t(-2));
1193 }
1194
1195 static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
1196};
1197
1198/// This table allows us to fully hide how we implement
1199/// multi-keyword caching.
1201 // Actually a SelectorTableImpl
1202 void *Impl;
1203
1204public:
1205 SelectorTable();
1206 SelectorTable(const SelectorTable &) = delete;
1209
1210 /// Can create any sort of selector.
1211 ///
1212 /// \p NumArgs indicates whether this is a no argument selector "foo", a
1213 /// single argument selector "foo:" or multi-argument "foo:bar:".
1214 Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV);
1215
1217 return Selector(ID, 1);
1218 }
1219
1221 return Selector(ID, 0);
1222 }
1223
1224 /// Return the total amount of memory allocated for managing selectors.
1225 size_t getTotalMemory() const;
1226
1227 /// Return the default setter name for the given identifier.
1228 ///
1229 /// This is "set" + \p Name where the initial character of \p Name
1230 /// has been capitalized.
1231 static SmallString<64> constructSetterName(StringRef Name);
1232
1233 /// Return the default setter selector for the given identifier.
1234 ///
1235 /// This is "set" + \p Name where the initial character of \p Name
1236 /// has been capitalized.
1237 static Selector constructSetterSelector(IdentifierTable &Idents,
1238 SelectorTable &SelTable,
1239 const IdentifierInfo *Name);
1240
1241 /// Return the property name for the given setter selector.
1242 static std::string getPropertyNameFromSetterSelector(Selector Sel);
1243};
1244
1245/// A simple pair of identifier info and location.
1247 SourceLocation Loc;
1248 IdentifierInfo *II = nullptr;
1249
1250public:
1251 IdentifierLoc() = default;
1252 IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {}
1253
1254 void setLoc(SourceLocation L) { Loc = L; }
1255 void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; }
1256 SourceLocation getLoc() const { return Loc; }
1257 IdentifierInfo *getIdentifierInfo() const { return II; }
1258
1259 bool operator==(const IdentifierLoc &X) const {
1260 return Loc == X.Loc && II == X.II;
1261 }
1262
1263 bool operator!=(const IdentifierLoc &X) const {
1264 return Loc != X.Loc || II != X.II;
1265 }
1266};
1267} // namespace clang
1268
1269namespace llvm {
1270
1271/// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
1272/// DenseSets.
1273template <>
1274struct DenseMapInfo<clang::Selector> {
1278
1282
1283 static unsigned getHashValue(clang::Selector S);
1284
1286 return LHS == RHS;
1287 }
1288};
1289
1290template<>
1291struct PointerLikeTypeTraits<clang::Selector> {
1292 static const void *getAsVoidPointer(clang::Selector P) {
1293 return P.getAsOpaquePtr();
1294 }
1295
1296 static clang::Selector getFromVoidPointer(const void *P) {
1297 return clang::Selector(reinterpret_cast<uintptr_t>(P));
1298 }
1299
1300 static constexpr int NumLowBitsAvailable = 0;
1301};
1302
1303} // namespace llvm
1304
1305#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
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.
bool isModuleKeyword() const
Determine whether this is the contextual keyword module.
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)
void setModuleKeyword(bool Val)
Set whether this identifier is the contextual keyword module.
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.
bool isImportKeyword() const
Determine whether this is the contextual keyword import.
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.
void setKeywordImport(bool Val)
Set whether this identifier is the contextual keyword import.
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)