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