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