clang  3.9.0
IdentifierTable.cpp
Go to the documentation of this file.
1 //===--- IdentifierTable.cpp - Hash table for identifier lookup -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the IdentifierInfo, IdentifierVisitor, and
11 // IdentifierTable interfaces.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "clang/Basic/CharInfo.h"
19 #include "clang/Basic/Specifiers.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/FoldingSet.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include <cstdio>
26 
27 using namespace clang;
28 
29 //===----------------------------------------------------------------------===//
30 // IdentifierInfo Implementation
31 //===----------------------------------------------------------------------===//
32 
34  TokenID = tok::identifier;
35  ObjCOrBuiltinID = 0;
36  HasMacro = false;
37  HadMacro = false;
38  IsExtension = false;
39  IsFutureCompatKeyword = false;
40  IsPoisoned = false;
41  IsCPPOperatorKeyword = false;
42  NeedsHandleIdentifier = false;
43  IsFromAST = false;
44  ChangedAfterLoad = false;
45  FEChangedAfterLoad = false;
46  RevertedTokenID = false;
47  OutOfDate = false;
48  IsModulesImport = false;
49  FETokenInfo = nullptr;
50  Entry = nullptr;
51 }
52 
53 //===----------------------------------------------------------------------===//
54 // IdentifierTable Implementation
55 //===----------------------------------------------------------------------===//
56 
58 
60 
61 namespace {
62  /// \brief A simple identifier lookup iterator that represents an
63  /// empty sequence of identifiers.
64  class EmptyLookupIterator : public IdentifierIterator
65  {
66  public:
67  StringRef Next() override { return StringRef(); }
68  };
69 }
70 
72  return new EmptyLookupIterator();
73 }
74 
76  IdentifierInfoLookup* externalLookup)
77  : HashTable(8192), // Start with space for 8K identifiers.
78  ExternalLookup(externalLookup) {
79 
80  // Populate the identifier table with info about keywords for the current
81  // language.
82  AddKeywords(LangOpts);
83 
84 
85  // Add the '_experimental_modules_import' contextual keyword.
86  get("import").setModulesImport(true);
87 }
88 
89 //===----------------------------------------------------------------------===//
90 // Language Keyword Implementation
91 //===----------------------------------------------------------------------===//
92 
93 // Constants for TokenKinds.def
94 namespace {
95  enum {
96  KEYC99 = 0x1,
97  KEYCXX = 0x2,
98  KEYCXX11 = 0x4,
99  KEYGNU = 0x8,
100  KEYMS = 0x10,
101  BOOLSUPPORT = 0x20,
102  KEYALTIVEC = 0x40,
103  KEYNOCXX = 0x80,
104  KEYBORLAND = 0x100,
105  KEYOPENCL = 0x200,
106  KEYC11 = 0x400,
107  KEYARC = 0x800,
108  KEYNOMS18 = 0x01000,
109  KEYNOOPENCL = 0x02000,
110  WCHARSUPPORT = 0x04000,
111  HALFSUPPORT = 0x08000,
112  KEYCONCEPTS = 0x10000,
113  KEYOBJC2 = 0x20000,
114  KEYZVECTOR = 0x40000,
115  KEYCOROUTINES = 0x80000,
116  KEYALL = (0xfffff & ~KEYNOMS18 &
117  ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
118  };
119 
120  /// \brief How a keyword is treated in the selected standard.
122  KS_Disabled, // Disabled
123  KS_Extension, // Is an extension
124  KS_Enabled, // Enabled
125  KS_Future // Is a keyword in future standard
126  };
127 }
128 
129 /// \brief Translates flags as specified in TokenKinds.def into keyword status
130 /// in the given language standard.
132  unsigned Flags) {
133  if (Flags == KEYALL) return KS_Enabled;
134  if (LangOpts.CPlusPlus && (Flags & KEYCXX)) return KS_Enabled;
135  if (LangOpts.CPlusPlus11 && (Flags & KEYCXX11)) return KS_Enabled;
136  if (LangOpts.C99 && (Flags & KEYC99)) return KS_Enabled;
137  if (LangOpts.GNUKeywords && (Flags & KEYGNU)) return KS_Extension;
138  if (LangOpts.MicrosoftExt && (Flags & KEYMS)) return KS_Extension;
139  if (LangOpts.Borland && (Flags & KEYBORLAND)) return KS_Extension;
140  if (LangOpts.Bool && (Flags & BOOLSUPPORT)) return KS_Enabled;
141  if (LangOpts.Half && (Flags & HALFSUPPORT)) return KS_Enabled;
142  if (LangOpts.WChar && (Flags & WCHARSUPPORT)) return KS_Enabled;
143  if (LangOpts.AltiVec && (Flags & KEYALTIVEC)) return KS_Enabled;
144  if (LangOpts.OpenCL && (Flags & KEYOPENCL)) return KS_Enabled;
145  if (!LangOpts.CPlusPlus && (Flags & KEYNOCXX)) return KS_Enabled;
146  if (LangOpts.C11 && (Flags & KEYC11)) return KS_Enabled;
147  // We treat bridge casts as objective-C keywords so we can warn on them
148  // in non-arc mode.
149  if (LangOpts.ObjC2 && (Flags & KEYARC)) return KS_Enabled;
150  if (LangOpts.ConceptsTS && (Flags & KEYCONCEPTS)) return KS_Enabled;
151  if (LangOpts.ObjC2 && (Flags & KEYOBJC2)) return KS_Enabled;
152  if (LangOpts.Coroutines && (Flags & KEYCOROUTINES)) return KS_Enabled;
153  if (LangOpts.CPlusPlus && (Flags & KEYCXX11)) return KS_Future;
154  return KS_Disabled;
155 }
156 
157 /// AddKeyword - This method is used to associate a token ID with specific
158 /// identifiers because they are language keywords. This causes the lexer to
159 /// automatically map matching identifiers to specialized token codes.
160 static void AddKeyword(StringRef Keyword,
161  tok::TokenKind TokenCode, unsigned Flags,
162  const LangOptions &LangOpts, IdentifierTable &Table) {
163  KeywordStatus AddResult = getKeywordStatus(LangOpts, Flags);
164 
165  // Don't add this keyword under MSVCCompat.
166  if (LangOpts.MSVCCompat && (Flags & KEYNOMS18) &&
168  return;
169 
170  // Don't add this keyword under OpenCL.
171  if (LangOpts.OpenCL && (Flags & KEYNOOPENCL))
172  return;
173 
174  // Don't add this keyword if disabled in this language.
175  if (AddResult == KS_Disabled) return;
176 
177  IdentifierInfo &Info =
178  Table.get(Keyword, AddResult == KS_Future ? tok::identifier : TokenCode);
179  Info.setIsExtensionToken(AddResult == KS_Extension);
180  Info.setIsFutureCompatKeyword(AddResult == KS_Future);
181 }
182 
183 /// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
184 /// representations.
185 static void AddCXXOperatorKeyword(StringRef Keyword,
186  tok::TokenKind TokenCode,
187  IdentifierTable &Table) {
188  IdentifierInfo &Info = Table.get(Keyword, TokenCode);
190 }
191 
192 /// AddObjCKeyword - Register an Objective-C \@keyword like "class" "selector"
193 /// or "property".
194 static void AddObjCKeyword(StringRef Name,
195  tok::ObjCKeywordKind ObjCID,
196  IdentifierTable &Table) {
197  Table.get(Name).setObjCKeywordID(ObjCID);
198 }
199 
200 /// AddKeywords - Add all keywords to the symbol table.
201 ///
203  // Add keywords and tokens for the current language.
204 #define KEYWORD(NAME, FLAGS) \
205  AddKeyword(StringRef(#NAME), tok::kw_ ## NAME, \
206  FLAGS, LangOpts, *this);
207 #define ALIAS(NAME, TOK, FLAGS) \
208  AddKeyword(StringRef(NAME), tok::kw_ ## TOK, \
209  FLAGS, LangOpts, *this);
210 #define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
211  if (LangOpts.CXXOperatorNames) \
212  AddCXXOperatorKeyword(StringRef(#NAME), tok::ALIAS, *this);
213 #define OBJC1_AT_KEYWORD(NAME) \
214  if (LangOpts.ObjC1) \
215  AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
216 #define OBJC2_AT_KEYWORD(NAME) \
217  if (LangOpts.ObjC2) \
218  AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
219 #define TESTING_KEYWORD(NAME, FLAGS)
220 #include "clang/Basic/TokenKinds.def"
221 
222  if (LangOpts.ParseUnknownAnytype)
223  AddKeyword("__unknown_anytype", tok::kw___unknown_anytype, KEYALL,
224  LangOpts, *this);
225 
226  if (LangOpts.DeclSpecKeyword)
227  AddKeyword("__declspec", tok::kw___declspec, KEYALL, LangOpts, *this);
228 }
229 
230 /// \brief Checks if the specified token kind represents a keyword in the
231 /// specified language.
232 /// \returns Status of the keyword in the language.
234  tok::TokenKind K) {
235  switch (K) {
236 #define KEYWORD(NAME, FLAGS) \
237  case tok::kw_##NAME: return getKeywordStatus(LangOpts, FLAGS);
238 #include "clang/Basic/TokenKinds.def"
239  default: return KS_Disabled;
240  }
241 }
242 
243 /// \brief Returns true if the identifier represents a keyword in the
244 /// specified language.
245 bool IdentifierInfo::isKeyword(const LangOptions &LangOpts) {
246  switch (getTokenKwStatus(LangOpts, getTokenID())) {
247  case KS_Enabled:
248  case KS_Extension:
249  return true;
250  default:
251  return false;
252  }
253 }
254 
256  // We use a perfect hash function here involving the length of the keyword,
257  // the first and third character. For preprocessor ID's there are no
258  // collisions (if there were, the switch below would complain about duplicate
259  // case values). Note that this depends on 'if' being null terminated.
260 
261 #define HASH(LEN, FIRST, THIRD) \
262  (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
263 #define CASE(LEN, FIRST, THIRD, NAME) \
264  case HASH(LEN, FIRST, THIRD): \
265  return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
266 
267  unsigned Len = getLength();
268  if (Len < 2) return tok::pp_not_keyword;
269  const char *Name = getNameStart();
270  switch (HASH(Len, Name[0], Name[2])) {
271  default: return tok::pp_not_keyword;
272  CASE( 2, 'i', '\0', if);
273  CASE( 4, 'e', 'i', elif);
274  CASE( 4, 'e', 's', else);
275  CASE( 4, 'l', 'n', line);
276  CASE( 4, 's', 'c', sccs);
277  CASE( 5, 'e', 'd', endif);
278  CASE( 5, 'e', 'r', error);
279  CASE( 5, 'i', 'e', ident);
280  CASE( 5, 'i', 'd', ifdef);
281  CASE( 5, 'u', 'd', undef);
282 
283  CASE( 6, 'a', 's', assert);
284  CASE( 6, 'd', 'f', define);
285  CASE( 6, 'i', 'n', ifndef);
286  CASE( 6, 'i', 'p', import);
287  CASE( 6, 'p', 'a', pragma);
288 
289  CASE( 7, 'd', 'f', defined);
290  CASE( 7, 'i', 'c', include);
291  CASE( 7, 'w', 'r', warning);
292 
293  CASE( 8, 'u', 'a', unassert);
294  CASE(12, 'i', 'c', include_next);
295 
296  CASE(14, '_', 'p', __public_macro);
297 
298  CASE(15, '_', 'p', __private_macro);
299 
300  CASE(16, '_', 'i', __include_macros);
301 #undef CASE
302 #undef HASH
303  }
304 }
305 
306 //===----------------------------------------------------------------------===//
307 // Stats Implementation
308 //===----------------------------------------------------------------------===//
309 
310 /// PrintStats - Print statistics about how well the identifier table is doing
311 /// at hashing identifiers.
313  unsigned NumBuckets = HashTable.getNumBuckets();
314  unsigned NumIdentifiers = HashTable.getNumItems();
315  unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
316  unsigned AverageIdentifierSize = 0;
317  unsigned MaxIdentifierLength = 0;
318 
319  // TODO: Figure out maximum times an identifier had to probe for -stats.
320  for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator
321  I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
322  unsigned IdLen = I->getKeyLength();
323  AverageIdentifierSize += IdLen;
324  if (MaxIdentifierLength < IdLen)
325  MaxIdentifierLength = IdLen;
326  }
327 
328  fprintf(stderr, "\n*** Identifier Table Stats:\n");
329  fprintf(stderr, "# Identifiers: %d\n", NumIdentifiers);
330  fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
331  fprintf(stderr, "Hash density (#identifiers per bucket): %f\n",
332  NumIdentifiers/(double)NumBuckets);
333  fprintf(stderr, "Ave identifier length: %f\n",
334  (AverageIdentifierSize/(double)NumIdentifiers));
335  fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength);
336 
337  // Compute statistics about the memory allocated for identifiers.
338  HashTable.getAllocator().PrintStats();
339 }
340 
341 //===----------------------------------------------------------------------===//
342 // SelectorTable Implementation
343 //===----------------------------------------------------------------------===//
344 
347 }
348 
349 namespace clang {
350 /// MultiKeywordSelector - One of these variable length records is kept for each
351 /// selector containing more than one keyword. We use a folding set
352 /// to unique aggregate names (keyword selectors in ObjC parlance). Access to
353 /// this class is provided strictly through Selector.
355  : public DeclarationNameExtra, public llvm::FoldingSetNode {
356  MultiKeywordSelector(unsigned nKeys) {
358  }
359 public:
360  // Constructor for keyword selectors.
361  MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) {
362  assert((nKeys > 1) && "not a multi-keyword selector");
364 
365  // Fill in the trailing keyword array.
366  IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1);
367  for (unsigned i = 0; i != nKeys; ++i)
368  KeyInfo[i] = IIV[i];
369  }
370 
371  // getName - Derive the full selector name and return it.
372  std::string getName() const;
373 
374  unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; }
375 
378  return reinterpret_cast<keyword_iterator>(this+1);
379  }
381  return keyword_begin()+getNumArgs();
382  }
384  assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
385  return keyword_begin()[i];
386  }
387  static void Profile(llvm::FoldingSetNodeID &ID,
388  keyword_iterator ArgTys, unsigned NumArgs) {
389  ID.AddInteger(NumArgs);
390  for (unsigned i = 0; i != NumArgs; ++i)
391  ID.AddPointer(ArgTys[i]);
392  }
393  void Profile(llvm::FoldingSetNodeID &ID) {
394  Profile(ID, keyword_begin(), getNumArgs());
395  }
396 };
397 } // end namespace clang.
398 
399 unsigned Selector::getNumArgs() const {
400  unsigned IIF = getIdentifierInfoFlag();
401  if (IIF <= ZeroArg)
402  return 0;
403  if (IIF == OneArg)
404  return 1;
405  // We point to a MultiKeywordSelector.
406  MultiKeywordSelector *SI = getMultiKeywordSelector();
407  return SI->getNumArgs();
408 }
409 
411  if (getIdentifierInfoFlag() < MultiArg) {
412  assert(argIndex == 0 && "illegal keyword index");
413  return getAsIdentifierInfo();
414  }
415  // We point to a MultiKeywordSelector.
416  MultiKeywordSelector *SI = getMultiKeywordSelector();
417  return SI->getIdentifierInfoForSlot(argIndex);
418 }
419 
420 StringRef Selector::getNameForSlot(unsigned int argIndex) const {
422  return II? II->getName() : StringRef();
423 }
424 
425 std::string MultiKeywordSelector::getName() const {
426  SmallString<256> Str;
427  llvm::raw_svector_ostream OS(Str);
428  for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
429  if (*I)
430  OS << (*I)->getName();
431  OS << ':';
432  }
433 
434  return OS.str();
435 }
436 
437 std::string Selector::getAsString() const {
438  if (InfoPtr == 0)
439  return "<null selector>";
440 
441  if (getIdentifierInfoFlag() < MultiArg) {
442  IdentifierInfo *II = getAsIdentifierInfo();
443 
444  // If the number of arguments is 0 then II is guaranteed to not be null.
445  if (getNumArgs() == 0)
446  return II->getName();
447 
448  if (!II)
449  return ":";
450 
451  return II->getName().str() + ":";
452  }
453 
454  // We have a multiple keyword selector.
455  return getMultiKeywordSelector()->getName();
456 }
457 
458 void Selector::print(llvm::raw_ostream &OS) const {
459  OS << getAsString();
460 }
461 
462 /// Interpreting the given string using the normal CamelCase
463 /// conventions, determine whether the given string starts with the
464 /// given "word", which is assumed to end in a lowercase letter.
465 static bool startsWithWord(StringRef name, StringRef word) {
466  if (name.size() < word.size()) return false;
467  return ((name.size() == word.size() || !isLowercase(name[word.size()])) &&
468  name.startswith(word));
469 }
470 
471 ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) {
473  if (!first) return OMF_None;
474 
475  StringRef name = first->getName();
476  if (sel.isUnarySelector()) {
477  if (name == "autorelease") return OMF_autorelease;
478  if (name == "dealloc") return OMF_dealloc;
479  if (name == "finalize") return OMF_finalize;
480  if (name == "release") return OMF_release;
481  if (name == "retain") return OMF_retain;
482  if (name == "retainCount") return OMF_retainCount;
483  if (name == "self") return OMF_self;
484  if (name == "initialize") return OMF_initialize;
485  }
486 
487  if (name == "performSelector") return OMF_performSelector;
488 
489  // The other method families may begin with a prefix of underscores.
490  while (!name.empty() && name.front() == '_')
491  name = name.substr(1);
492 
493  if (name.empty()) return OMF_None;
494  switch (name.front()) {
495  case 'a':
496  if (startsWithWord(name, "alloc")) return OMF_alloc;
497  break;
498  case 'c':
499  if (startsWithWord(name, "copy")) return OMF_copy;
500  break;
501  case 'i':
502  if (startsWithWord(name, "init")) return OMF_init;
503  break;
504  case 'm':
505  if (startsWithWord(name, "mutableCopy")) return OMF_mutableCopy;
506  break;
507  case 'n':
508  if (startsWithWord(name, "new")) return OMF_new;
509  break;
510  default:
511  break;
512  }
513 
514  return OMF_None;
515 }
516 
519  if (!first) return OIT_None;
520 
521  StringRef name = first->getName();
522 
523  if (name.empty()) return OIT_None;
524  switch (name.front()) {
525  case 'a':
526  if (startsWithWord(name, "array")) return OIT_Array;
527  break;
528  case 'd':
529  if (startsWithWord(name, "default")) return OIT_ReturnsSelf;
530  if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
531  break;
532  case 's':
533  if (startsWithWord(name, "shared")) return OIT_ReturnsSelf;
534  if (startsWithWord(name, "standard")) return OIT_Singleton;
535  case 'i':
536  if (startsWithWord(name, "init")) return OIT_Init;
537  default:
538  break;
539  }
540  return OIT_None;
541 }
542 
543 ObjCStringFormatFamily Selector::getStringFormatFamilyImpl(Selector sel) {
545  if (!first) return SFF_None;
546 
547  StringRef name = first->getName();
548 
549  switch (name.front()) {
550  case 'a':
551  if (name == "appendFormat") return SFF_NSString;
552  break;
553 
554  case 'i':
555  if (name == "initWithFormat") return SFF_NSString;
556  break;
557 
558  case 'l':
559  if (name == "localizedStringWithFormat") return SFF_NSString;
560  break;
561 
562  case 's':
563  if (name == "stringByAppendingFormat" ||
564  name == "stringWithFormat") return SFF_NSString;
565  break;
566  }
567  return SFF_None;
568 }
569 
570 namespace {
571  struct SelectorTableImpl {
572  llvm::FoldingSet<MultiKeywordSelector> Table;
573  llvm::BumpPtrAllocator Allocator;
574  };
575 } // end anonymous namespace.
576 
577 static SelectorTableImpl &getSelectorTableImpl(void *P) {
578  return *static_cast<SelectorTableImpl*>(P);
579 }
580 
583  SmallString<64> SetterName("set");
584  SetterName += Name;
585  SetterName[3] = toUppercase(SetterName[3]);
586  return SetterName;
587 }
588 
589 Selector
591  SelectorTable &SelTable,
592  const IdentifierInfo *Name) {
593  IdentifierInfo *SetterName =
594  &Idents.get(constructSetterName(Name->getName()));
595  return SelTable.getUnarySelector(SetterName);
596 }
597 
599  SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
600  return SelTabImpl.Allocator.getTotalMemory();
601 }
602 
604  if (nKeys < 2)
605  return Selector(IIV[0], nKeys);
606 
607  SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
608 
609  // Unique selector, to guarantee there is one per name.
610  llvm::FoldingSetNodeID ID;
611  MultiKeywordSelector::Profile(ID, IIV, nKeys);
612 
613  void *InsertPos = nullptr;
614  if (MultiKeywordSelector *SI =
615  SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
616  return Selector(SI);
617 
618  // MultiKeywordSelector objects are not allocated with new because they have a
619  // variable size array (for parameter types) at the end of them.
620  unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *);
622  (MultiKeywordSelector*)SelTabImpl.Allocator.Allocate(Size,
623  llvm::alignOf<MultiKeywordSelector>());
624  new (SI) MultiKeywordSelector(nKeys, IIV);
625  SelTabImpl.Table.InsertNode(SI, InsertPos);
626  return Selector(SI);
627 }
628 
630  Impl = new SelectorTableImpl();
631 }
632 
634  delete &getSelectorTableImpl(Impl);
635 }
636 
638  switch (Operator) {
639  case OO_None:
641  return nullptr;
642 
643 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
644  case OO_##Name: return Spelling;
645 #include "clang/Basic/OperatorKinds.def"
646  }
647 
648  llvm_unreachable("Invalid OverloadedOperatorKind!");
649 }
650 
652  bool isContextSensitive) {
653  switch (kind) {
655  return isContextSensitive ? "nonnull" : "_Nonnull";
656 
658  return isContextSensitive ? "nullable" : "_Nullable";
659 
661  return isContextSensitive ? "null_unspecified" : "_Null_unspecified";
662  }
663  llvm_unreachable("Unknown nullability kind.");
664 }
ObjCStringFormatFamily
void AddKeywords(const LangOptions &LangOpts)
AddKeywords - Add all keywords to the symbol table.
Smart pointer class that efficiently represents Objective-C method names.
IdentifierInfo *const * keyword_iterator
NullabilityKind
Describes the nullability of a particular type.
Definition: Specifiers.h:278
void setIsExtensionToken(bool Val)
StringRef P
size_t getTotalMemory() const
Return the total amount of memory allocated for managing selectors.
unsigned getLength() const
Efficiently return the length of this identifier info.
static SelectorTableImpl & getSelectorTableImpl(void *P)
void * getAsOpaquePtr() const
virtual IdentifierIterator * getIdentifiers()
Retrieve an iterator into the set of all identifiers known to this identifier lookup source...
KeywordStatus
How a keyword is treated in the selected standard.
static void AddKeyword(StringRef Keyword, tok::TokenKind TokenCode, unsigned Flags, const LangOptions &LangOpts, IdentifierTable &Table)
AddKeyword - This method is used to associate a token ID with specific identifiers because they are l...
keyword_iterator keyword_end() const
Selector getUnarySelector(IdentifierInfo *ID)
One of these records is kept for each identifier that is lexed.
static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel)
This table allows us to fully hide how we implement multi-keyword caching.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
ObjCMethodFamily
A family of Objective-C methods.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
static KeywordStatus getTokenKwStatus(const LangOptions &LangOpts, tok::TokenKind K)
Checks if the specified token kind represents a keyword in the specified language.
Values of this type can be null.
void setIsFutureCompatKeyword(bool Val)
DeclarationNameExtra - Common base of the MultiKeywordSelector, CXXSpecialName, and CXXOperatorIdName...
static SmallString< 64 > constructSetterName(StringRef Name)
Return the default setter name for the given identifier.
static Selector constructSetterSelector(IdentifierTable &Idents, SelectorTable &SelTable, const IdentifierInfo *Name)
Return the default setter selector for the given identifier.
void Profile(llvm::FoldingSetNodeID &ID)
Whether values of this type can be null is (explicitly) unspecified.
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
Values of this type can never be null.
static void AddCXXOperatorKeyword(StringRef Keyword, tok::TokenKind TokenCode, IdentifierTable &Table)
AddCXXOperatorKeyword - Register a C++ operator keyword alternative representations.
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
detail::InMemoryDirectory::const_iterator I
unsigned ExtraKindOrNumArgs
ExtraKindOrNumArgs - Either the kind of C++ special name or operator-id (if the value is one of the C...
Provides lookups to, and iteration over, IdentiferInfo objects.
void setIsCPlusPlusOperatorKeyword(bool Val=true)
isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether this identifier is a C++ al...
bool isUnarySelector() const
MultiKeywordSelector - One of these variable length records is kept for each selector containing more...
llvm::SpecificBumpPtrAllocator< StateNode > Allocator
Defines the clang::LangOptions interface.
std::string getName() const
StringRef getName() const
Return the actual identifier string.
unsigned getNumArgs() const
Implements an efficient mapping from strings to IdentifierInfo nodes.
Defines an enumeration for C++ overloaded operators.
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line...
Definition: TokenKinds.h:33
#define CASE(LEN, FIRST, THIRD, NAME)
ObjCInstanceTypeFamily
A family of Objective-C methods.
static KeywordStatus getKeywordStatus(const LangOptions &LangOpts, unsigned Flags)
Translates flags as specified in TokenKinds.def into keyword status in the given language standard...
An iterator that walks over all of the known identifiers in the lookup table.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4154
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
Definition: TokenKinds.h:41
void setObjCKeywordID(tok::ObjCKeywordKind ID)
static bool startsWithWord(StringRef name, StringRef word)
Interpreting the given string using the normal CamelCase conventions, determine whether the given str...
static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys, unsigned NumArgs)
SmallVectorImpl< AnnotatedLine * >::const_iterator Next
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
const std::string ID
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
bool isKeyword(const LangOptions &LangOpts)
Return true if this token is a keyword in the specified language.
IdentifierTable(const LangOptions &LangOpts, IdentifierInfoLookup *externalLookup=nullptr)
Create the identifier table, populating it with info about the language keywords for the language spe...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
std::string getAsString() const
Derive the full selector name (e.g.
static void AddObjCKeyword(StringRef Name, tok::ObjCKeywordKind ObjCID, IdentifierTable &Table)
AddObjCKeyword - Register an Objective-C @keyword like "class" "selector" or "property".
Defines various enumerations that describe declaration and type specifiers.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
keyword_iterator keyword_begin() const
detail::InMemoryDirectory::const_iterator E
static LLVM_READONLY bool isLowercase(unsigned char c)
Return true if this character is a lowercase ASCII letter: [a-z].
Definition: CharInfo.h:100
Not an overloaded operator.
Definition: OperatorKinds.h:23
MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV)
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword...
#define HASH(LEN, FIRST, THIRD)
void PrintStats() const
Print some statistics to stderr that indicate how well the hashing is doing.
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:147
No particular method family.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:43
static LLVM_READONLY char toUppercase(char c)
Converts the given ASCII character to its uppercase equivalent.
Definition: CharInfo.h:174
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
IdentifierInfo * getIdentifierInfoForSlot(unsigned i) const
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.