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