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