clang  6.0.0svn
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  KEYMODULES = 0x100000,
117  KEYCXX2A = 0x200000,
118  KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX2A,
119  KEYALL = (0x3fffff & ~KEYNOMS18 &
120  ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
121  };
122 
123  /// \brief How a keyword is treated in the selected standard.
125  KS_Disabled, // Disabled
126  KS_Extension, // Is an extension
127  KS_Enabled, // Enabled
128  KS_Future // Is a keyword in future standard
129  };
130 }
131 
132 /// \brief Translates flags as specified in TokenKinds.def into keyword status
133 /// in the given language standard.
135  unsigned Flags) {
136  if (Flags == KEYALL) return KS_Enabled;
137  if (LangOpts.CPlusPlus && (Flags & KEYCXX)) return KS_Enabled;
138  if (LangOpts.CPlusPlus11 && (Flags & KEYCXX11)) return KS_Enabled;
139  if (LangOpts.CPlusPlus2a && (Flags & KEYCXX2A)) return KS_Enabled;
140  if (LangOpts.C99 && (Flags & KEYC99)) return KS_Enabled;
141  if (LangOpts.GNUKeywords && (Flags & KEYGNU)) return KS_Extension;
142  if (LangOpts.MicrosoftExt && (Flags & KEYMS)) return KS_Extension;
143  if (LangOpts.Borland && (Flags & KEYBORLAND)) return KS_Extension;
144  if (LangOpts.Bool && (Flags & BOOLSUPPORT)) return KS_Enabled;
145  if (LangOpts.Half && (Flags & HALFSUPPORT)) return KS_Enabled;
146  if (LangOpts.WChar && (Flags & WCHARSUPPORT)) return KS_Enabled;
147  if (LangOpts.AltiVec && (Flags & KEYALTIVEC)) return KS_Enabled;
148  if (LangOpts.OpenCL && (Flags & KEYOPENCL)) return KS_Enabled;
149  if (!LangOpts.CPlusPlus && (Flags & KEYNOCXX)) return KS_Enabled;
150  if (LangOpts.C11 && (Flags & KEYC11)) return KS_Enabled;
151  // We treat bridge casts as objective-C keywords so we can warn on them
152  // in non-arc mode.
153  if (LangOpts.ObjC2 && (Flags & KEYARC)) return KS_Enabled;
154  if (LangOpts.ObjC2 && (Flags & KEYOBJC2)) return KS_Enabled;
155  if (LangOpts.ConceptsTS && (Flags & KEYCONCEPTS)) return KS_Enabled;
156  if (LangOpts.CoroutinesTS && (Flags & KEYCOROUTINES)) return KS_Enabled;
157  if (LangOpts.ModulesTS && (Flags & KEYMODULES)) return KS_Enabled;
158  if (LangOpts.CPlusPlus && (Flags & KEYALLCXX)) return KS_Future;
159  return KS_Disabled;
160 }
161 
162 /// AddKeyword - This method is used to associate a token ID with specific
163 /// identifiers because they are language keywords. This causes the lexer to
164 /// automatically map matching identifiers to specialized token codes.
165 static void AddKeyword(StringRef Keyword,
166  tok::TokenKind TokenCode, unsigned Flags,
167  const LangOptions &LangOpts, IdentifierTable &Table) {
168  KeywordStatus AddResult = getKeywordStatus(LangOpts, Flags);
169 
170  // Don't add this keyword under MSVCCompat.
171  if (LangOpts.MSVCCompat && (Flags & KEYNOMS18) &&
173  return;
174 
175  // Don't add this keyword under OpenCL.
176  if (LangOpts.OpenCL && (Flags & KEYNOOPENCL))
177  return;
178 
179  // Don't add this keyword if disabled in this language.
180  if (AddResult == KS_Disabled) return;
181 
182  IdentifierInfo &Info =
183  Table.get(Keyword, AddResult == KS_Future ? tok::identifier : TokenCode);
184  Info.setIsExtensionToken(AddResult == KS_Extension);
185  Info.setIsFutureCompatKeyword(AddResult == KS_Future);
186 }
187 
188 /// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
189 /// representations.
190 static void AddCXXOperatorKeyword(StringRef Keyword,
191  tok::TokenKind TokenCode,
192  IdentifierTable &Table) {
193  IdentifierInfo &Info = Table.get(Keyword, TokenCode);
195 }
196 
197 /// AddObjCKeyword - Register an Objective-C \@keyword like "class" "selector"
198 /// or "property".
199 static void AddObjCKeyword(StringRef Name,
200  tok::ObjCKeywordKind ObjCID,
201  IdentifierTable &Table) {
202  Table.get(Name).setObjCKeywordID(ObjCID);
203 }
204 
205 /// AddKeywords - Add all keywords to the symbol table.
206 ///
208  // Add keywords and tokens for the current language.
209 #define KEYWORD(NAME, FLAGS) \
210  AddKeyword(StringRef(#NAME), tok::kw_ ## NAME, \
211  FLAGS, LangOpts, *this);
212 #define ALIAS(NAME, TOK, FLAGS) \
213  AddKeyword(StringRef(NAME), tok::kw_ ## TOK, \
214  FLAGS, LangOpts, *this);
215 #define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
216  if (LangOpts.CXXOperatorNames) \
217  AddCXXOperatorKeyword(StringRef(#NAME), tok::ALIAS, *this);
218 #define OBJC1_AT_KEYWORD(NAME) \
219  if (LangOpts.ObjC1) \
220  AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
221 #define OBJC2_AT_KEYWORD(NAME) \
222  if (LangOpts.ObjC2) \
223  AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
224 #define TESTING_KEYWORD(NAME, FLAGS)
225 #include "clang/Basic/TokenKinds.def"
226 
227  if (LangOpts.ParseUnknownAnytype)
228  AddKeyword("__unknown_anytype", tok::kw___unknown_anytype, KEYALL,
229  LangOpts, *this);
230 
231  if (LangOpts.DeclSpecKeyword)
232  AddKeyword("__declspec", tok::kw___declspec, KEYALL, LangOpts, *this);
233 }
234 
235 /// \brief Checks if the specified token kind represents a keyword in the
236 /// specified language.
237 /// \returns Status of the keyword in the language.
239  tok::TokenKind K) {
240  switch (K) {
241 #define KEYWORD(NAME, FLAGS) \
242  case tok::kw_##NAME: return getKeywordStatus(LangOpts, FLAGS);
243 #include "clang/Basic/TokenKinds.def"
244  default: return KS_Disabled;
245  }
246 }
247 
248 /// \brief Returns true if the identifier represents a keyword in the
249 /// specified language.
250 bool IdentifierInfo::isKeyword(const LangOptions &LangOpts) const {
251  switch (getTokenKwStatus(LangOpts, getTokenID())) {
252  case KS_Enabled:
253  case KS_Extension:
254  return true;
255  default:
256  return false;
257  }
258 }
259 
260 /// \brief Returns true if the identifier represents a C++ keyword in the
261 /// specified language.
262 bool IdentifierInfo::isCPlusPlusKeyword(const LangOptions &LangOpts) const {
263  if (!LangOpts.CPlusPlus || !isKeyword(LangOpts))
264  return false;
265  // This is a C++ keyword if this identifier is not a keyword when checked
266  // using LangOptions without C++ support.
267  LangOptions LangOptsNoCPP = LangOpts;
268  LangOptsNoCPP.CPlusPlus = false;
269  LangOptsNoCPP.CPlusPlus11 = false;
270  LangOptsNoCPP.CPlusPlus2a = false;
271  return !isKeyword(LangOptsNoCPP);
272 }
273 
275  // We use a perfect hash function here involving the length of the keyword,
276  // the first and third character. For preprocessor ID's there are no
277  // collisions (if there were, the switch below would complain about duplicate
278  // case values). Note that this depends on 'if' being null terminated.
279 
280 #define HASH(LEN, FIRST, THIRD) \
281  (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
282 #define CASE(LEN, FIRST, THIRD, NAME) \
283  case HASH(LEN, FIRST, THIRD): \
284  return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
285 
286  unsigned Len = getLength();
287  if (Len < 2) return tok::pp_not_keyword;
288  const char *Name = getNameStart();
289  switch (HASH(Len, Name[0], Name[2])) {
290  default: return tok::pp_not_keyword;
291  CASE( 2, 'i', '\0', if);
292  CASE( 4, 'e', 'i', elif);
293  CASE( 4, 'e', 's', else);
294  CASE( 4, 'l', 'n', line);
295  CASE( 4, 's', 'c', sccs);
296  CASE( 5, 'e', 'd', endif);
297  CASE( 5, 'e', 'r', error);
298  CASE( 5, 'i', 'e', ident);
299  CASE( 5, 'i', 'd', ifdef);
300  CASE( 5, 'u', 'd', undef);
301 
302  CASE( 6, 'a', 's', assert);
303  CASE( 6, 'd', 'f', define);
304  CASE( 6, 'i', 'n', ifndef);
305  CASE( 6, 'i', 'p', import);
306  CASE( 6, 'p', 'a', pragma);
307 
308  CASE( 7, 'd', 'f', defined);
309  CASE( 7, 'i', 'c', include);
310  CASE( 7, 'w', 'r', warning);
311 
312  CASE( 8, 'u', 'a', unassert);
313  CASE(12, 'i', 'c', include_next);
314 
315  CASE(14, '_', 'p', __public_macro);
316 
317  CASE(15, '_', 'p', __private_macro);
318 
319  CASE(16, '_', 'i', __include_macros);
320 #undef CASE
321 #undef HASH
322  }
323 }
324 
325 //===----------------------------------------------------------------------===//
326 // Stats Implementation
327 //===----------------------------------------------------------------------===//
328 
329 /// PrintStats - Print statistics about how well the identifier table is doing
330 /// at hashing identifiers.
332  unsigned NumBuckets = HashTable.getNumBuckets();
333  unsigned NumIdentifiers = HashTable.getNumItems();
334  unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
335  unsigned AverageIdentifierSize = 0;
336  unsigned MaxIdentifierLength = 0;
337 
338  // TODO: Figure out maximum times an identifier had to probe for -stats.
339  for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator
340  I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
341  unsigned IdLen = I->getKeyLength();
342  AverageIdentifierSize += IdLen;
343  if (MaxIdentifierLength < IdLen)
344  MaxIdentifierLength = IdLen;
345  }
346 
347  fprintf(stderr, "\n*** Identifier Table Stats:\n");
348  fprintf(stderr, "# Identifiers: %d\n", NumIdentifiers);
349  fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
350  fprintf(stderr, "Hash density (#identifiers per bucket): %f\n",
351  NumIdentifiers/(double)NumBuckets);
352  fprintf(stderr, "Ave identifier length: %f\n",
353  (AverageIdentifierSize/(double)NumIdentifiers));
354  fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength);
355 
356  // Compute statistics about the memory allocated for identifiers.
357  HashTable.getAllocator().PrintStats();
358 }
359 
360 //===----------------------------------------------------------------------===//
361 // SelectorTable Implementation
362 //===----------------------------------------------------------------------===//
363 
366 }
367 
368 namespace clang {
369 /// MultiKeywordSelector - One of these variable length records is kept for each
370 /// selector containing more than one keyword. We use a folding set
371 /// to unique aggregate names (keyword selectors in ObjC parlance). Access to
372 /// this class is provided strictly through Selector.
374  : public DeclarationNameExtra, public llvm::FoldingSetNode {
375  MultiKeywordSelector(unsigned nKeys) {
376  ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
377  }
378 public:
379  // Constructor for keyword selectors.
380  MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) {
381  assert((nKeys > 1) && "not a multi-keyword selector");
382  ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
383 
384  // Fill in the trailing keyword array.
385  IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1);
386  for (unsigned i = 0; i != nKeys; ++i)
387  KeyInfo[i] = IIV[i];
388  }
389 
390  // getName - Derive the full selector name and return it.
391  std::string getName() const;
392 
393  unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; }
394 
396  keyword_iterator keyword_begin() const {
397  return reinterpret_cast<keyword_iterator>(this+1);
398  }
399  keyword_iterator keyword_end() const {
400  return keyword_begin()+getNumArgs();
401  }
403  assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
404  return keyword_begin()[i];
405  }
406  static void Profile(llvm::FoldingSetNodeID &ID,
407  keyword_iterator ArgTys, unsigned NumArgs) {
408  ID.AddInteger(NumArgs);
409  for (unsigned i = 0; i != NumArgs; ++i)
410  ID.AddPointer(ArgTys[i]);
411  }
412  void Profile(llvm::FoldingSetNodeID &ID) {
413  Profile(ID, keyword_begin(), getNumArgs());
414  }
415 };
416 } // end namespace clang.
417 
418 unsigned Selector::getNumArgs() const {
419  unsigned IIF = getIdentifierInfoFlag();
420  if (IIF <= ZeroArg)
421  return 0;
422  if (IIF == OneArg)
423  return 1;
424  // We point to a MultiKeywordSelector.
425  MultiKeywordSelector *SI = getMultiKeywordSelector();
426  return SI->getNumArgs();
427 }
428 
430  if (getIdentifierInfoFlag() < MultiArg) {
431  assert(argIndex == 0 && "illegal keyword index");
432  return getAsIdentifierInfo();
433  }
434  // We point to a MultiKeywordSelector.
435  MultiKeywordSelector *SI = getMultiKeywordSelector();
436  return SI->getIdentifierInfoForSlot(argIndex);
437 }
438 
439 StringRef Selector::getNameForSlot(unsigned int argIndex) const {
440  IdentifierInfo *II = getIdentifierInfoForSlot(argIndex);
441  return II? II->getName() : StringRef();
442 }
443 
444 std::string MultiKeywordSelector::getName() const {
445  SmallString<256> Str;
446  llvm::raw_svector_ostream OS(Str);
447  for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
448  if (*I)
449  OS << (*I)->getName();
450  OS << ':';
451  }
452 
453  return OS.str();
454 }
455 
456 std::string Selector::getAsString() const {
457  if (InfoPtr == 0)
458  return "<null selector>";
459 
460  if (getIdentifierInfoFlag() < MultiArg) {
461  IdentifierInfo *II = getAsIdentifierInfo();
462 
463  if (getNumArgs() == 0) {
464  assert(II && "If the number of arguments is 0 then II is guaranteed to "
465  "not be null.");
466  return II->getName();
467  }
468 
469  if (!II)
470  return ":";
471 
472  return II->getName().str() + ":";
473  }
474 
475  // We have a multiple keyword selector.
476  return getMultiKeywordSelector()->getName();
477 }
478 
479 void Selector::print(llvm::raw_ostream &OS) const {
480  OS << getAsString();
481 }
482 
483 /// Interpreting the given string using the normal CamelCase
484 /// conventions, determine whether the given string starts with the
485 /// given "word", which is assumed to end in a lowercase letter.
486 static bool startsWithWord(StringRef name, StringRef word) {
487  if (name.size() < word.size()) return false;
488  return ((name.size() == word.size() || !isLowercase(name[word.size()])) &&
489  name.startswith(word));
490 }
491 
492 ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) {
494  if (!first) return OMF_None;
495 
496  StringRef name = first->getName();
497  if (sel.isUnarySelector()) {
498  if (name == "autorelease") return OMF_autorelease;
499  if (name == "dealloc") return OMF_dealloc;
500  if (name == "finalize") return OMF_finalize;
501  if (name == "release") return OMF_release;
502  if (name == "retain") return OMF_retain;
503  if (name == "retainCount") return OMF_retainCount;
504  if (name == "self") return OMF_self;
505  if (name == "initialize") return OMF_initialize;
506  }
507 
508  if (name == "performSelector" || name == "performSelectorInBackground" ||
509  name == "performSelectorOnMainThread")
510  return OMF_performSelector;
511 
512  // The other method families may begin with a prefix of underscores.
513  while (!name.empty() && name.front() == '_')
514  name = name.substr(1);
515 
516  if (name.empty()) return OMF_None;
517  switch (name.front()) {
518  case 'a':
519  if (startsWithWord(name, "alloc")) return OMF_alloc;
520  break;
521  case 'c':
522  if (startsWithWord(name, "copy")) return OMF_copy;
523  break;
524  case 'i':
525  if (startsWithWord(name, "init")) return OMF_init;
526  break;
527  case 'm':
528  if (startsWithWord(name, "mutableCopy")) return OMF_mutableCopy;
529  break;
530  case 'n':
531  if (startsWithWord(name, "new")) return OMF_new;
532  break;
533  default:
534  break;
535  }
536 
537  return OMF_None;
538 }
539 
542  if (!first) return OIT_None;
543 
544  StringRef name = first->getName();
545 
546  if (name.empty()) return OIT_None;
547  switch (name.front()) {
548  case 'a':
549  if (startsWithWord(name, "array")) return OIT_Array;
550  break;
551  case 'd':
552  if (startsWithWord(name, "default")) return OIT_ReturnsSelf;
553  if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
554  break;
555  case 's':
556  if (startsWithWord(name, "shared")) return OIT_ReturnsSelf;
557  if (startsWithWord(name, "standard")) return OIT_Singleton;
558  break;
559  case 'i':
560  if (startsWithWord(name, "init")) return OIT_Init;
561  default:
562  break;
563  }
564  return OIT_None;
565 }
566 
567 ObjCStringFormatFamily Selector::getStringFormatFamilyImpl(Selector sel) {
569  if (!first) return SFF_None;
570 
571  StringRef name = first->getName();
572 
573  switch (name.front()) {
574  case 'a':
575  if (name == "appendFormat") return SFF_NSString;
576  break;
577 
578  case 'i':
579  if (name == "initWithFormat") return SFF_NSString;
580  break;
581 
582  case 'l':
583  if (name == "localizedStringWithFormat") return SFF_NSString;
584  break;
585 
586  case 's':
587  if (name == "stringByAppendingFormat" ||
588  name == "stringWithFormat") return SFF_NSString;
589  break;
590  }
591  return SFF_None;
592 }
593 
594 namespace {
595  struct SelectorTableImpl {
596  llvm::FoldingSet<MultiKeywordSelector> Table;
597  llvm::BumpPtrAllocator Allocator;
598  };
599 } // end anonymous namespace.
600 
601 static SelectorTableImpl &getSelectorTableImpl(void *P) {
602  return *static_cast<SelectorTableImpl*>(P);
603 }
604 
607  SmallString<64> SetterName("set");
608  SetterName += Name;
609  SetterName[3] = toUppercase(SetterName[3]);
610  return SetterName;
611 }
612 
613 Selector
615  SelectorTable &SelTable,
616  const IdentifierInfo *Name) {
617  IdentifierInfo *SetterName =
618  &Idents.get(constructSetterName(Name->getName()));
619  return SelTable.getUnarySelector(SetterName);
620 }
621 
623  SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
624  return SelTabImpl.Allocator.getTotalMemory();
625 }
626 
628  if (nKeys < 2)
629  return Selector(IIV[0], nKeys);
630 
631  SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
632 
633  // Unique selector, to guarantee there is one per name.
634  llvm::FoldingSetNodeID ID;
635  MultiKeywordSelector::Profile(ID, IIV, nKeys);
636 
637  void *InsertPos = nullptr;
638  if (MultiKeywordSelector *SI =
639  SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
640  return Selector(SI);
641 
642  // MultiKeywordSelector objects are not allocated with new because they have a
643  // variable size array (for parameter types) at the end of them.
644  unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *);
646  (MultiKeywordSelector *)SelTabImpl.Allocator.Allocate(
647  Size, alignof(MultiKeywordSelector));
648  new (SI) MultiKeywordSelector(nKeys, IIV);
649  SelTabImpl.Table.InsertNode(SI, InsertPos);
650  return Selector(SI);
651 }
652 
654  Impl = new SelectorTableImpl();
655 }
656 
658  delete &getSelectorTableImpl(Impl);
659 }
660 
662  switch (Operator) {
663  case OO_None:
665  return nullptr;
666 
667 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
668  case OO_##Name: return Spelling;
669 #include "clang/Basic/OperatorKinds.def"
670  }
671 
672  llvm_unreachable("Invalid OverloadedOperatorKind!");
673 }
674 
676  bool isContextSensitive) {
677  switch (kind) {
679  return isContextSensitive ? "nonnull" : "_Nonnull";
680 
682  return isContextSensitive ? "nullable" : "_Nullable";
683 
685  return isContextSensitive ? "null_unspecified" : "_Null_unspecified";
686  }
687  llvm_unreachable("Unknown nullability kind.");
688 }
ObjCStringFormatFamily
void AddKeywords(const LangOptions &LangOpts)
AddKeywords - Add all keywords to the symbol table.
Smart pointer class that efficiently represents Objective-C method names.
void * getAsOpaquePtr() const
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:184
IdentifierInfo *const * keyword_iterator
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:282
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
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.
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.
bool isUnarySelector() const
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.
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.
Provides lookups to, and iteration over, IdentiferInfo objects.
void setIsCPlusPlusOperatorKeyword(bool Val=true)
isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether this identifier is a C++ al...
MultiKeywordSelector - One of these variable length records is kept for each selector containing more...
Defines the clang::LangOptions interface.
llvm::StringRef getAsString(SyncScope S)
Definition: SyncScope.h:51
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:33
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:41
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.
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.
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
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".
Defines various enumerations that describe declaration and type specifiers.
StringRef getName() const
Return the actual identifier string.
Dataflow Directional Tag Classes.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.
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)
No particular method family.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:61
keyword_iterator keyword_end() const
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.