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