clang  3.8.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  RevertedTokenID = false;
46  OutOfDate = false;
47  IsModulesImport = false;
48  FETokenInfo = nullptr;
49  Entry = nullptr;
50 }
51 
52 //===----------------------------------------------------------------------===//
53 // IdentifierTable Implementation
54 //===----------------------------------------------------------------------===//
55 
57 
59 
60 namespace {
61  /// \brief A simple identifier lookup iterator that represents an
62  /// empty sequence of identifiers.
63  class EmptyLookupIterator : public IdentifierIterator
64  {
65  public:
66  StringRef Next() override { return StringRef(); }
67  };
68 }
69 
71  return new EmptyLookupIterator();
72 }
73 
75  IdentifierInfoLookup* externalLookup)
76  : HashTable(8192), // Start with space for 8K identifiers.
77  ExternalLookup(externalLookup) {
78 
79  // Populate the identifier table with info about keywords for the current
80  // language.
81  AddKeywords(LangOpts);
82 
83 
84  // Add the '_experimental_modules_import' contextual keyword.
85  get("import").setModulesImport(true);
86 }
87 
88 //===----------------------------------------------------------------------===//
89 // Language Keyword Implementation
90 //===----------------------------------------------------------------------===//
91 
92 // Constants for TokenKinds.def
93 namespace {
94  enum {
95  KEYC99 = 0x1,
96  KEYCXX = 0x2,
97  KEYCXX11 = 0x4,
98  KEYGNU = 0x8,
99  KEYMS = 0x10,
100  BOOLSUPPORT = 0x20,
101  KEYALTIVEC = 0x40,
102  KEYNOCXX = 0x80,
103  KEYBORLAND = 0x100,
104  KEYOPENCL = 0x200,
105  KEYC11 = 0x400,
106  KEYARC = 0x800,
107  KEYNOMS18 = 0x01000,
108  KEYNOOPENCL = 0x02000,
109  WCHARSUPPORT = 0x04000,
110  HALFSUPPORT = 0x08000,
111  KEYCONCEPTS = 0x10000,
112  KEYOBJC2 = 0x20000,
113  KEYZVECTOR = 0x40000,
114  KEYCOROUTINES = 0x80000,
115  KEYALL = (0xfffff & ~KEYNOMS18 &
116  ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
117  };
118 
119  /// \brief How a keyword is treated in the selected standard.
121  KS_Disabled, // Disabled
122  KS_Extension, // Is an extension
123  KS_Enabled, // Enabled
124  KS_Future // Is a keyword in future standard
125  };
126 }
127 
128 /// \brief Translates flags as specified in TokenKinds.def into keyword status
129 /// in the given language standard.
131  unsigned Flags) {
132  if (Flags == KEYALL) return KS_Enabled;
133  if (LangOpts.CPlusPlus && (Flags & KEYCXX)) return KS_Enabled;
134  if (LangOpts.CPlusPlus11 && (Flags & KEYCXX11)) return KS_Enabled;
135  if (LangOpts.C99 && (Flags & KEYC99)) return KS_Enabled;
136  if (LangOpts.GNUKeywords && (Flags & KEYGNU)) return KS_Extension;
137  if (LangOpts.MicrosoftExt && (Flags & KEYMS)) return KS_Extension;
138  if (LangOpts.Borland && (Flags & KEYBORLAND)) return KS_Extension;
139  if (LangOpts.Bool && (Flags & BOOLSUPPORT)) return KS_Enabled;
140  if (LangOpts.Half && (Flags & HALFSUPPORT)) return KS_Enabled;
141  if (LangOpts.WChar && (Flags & WCHARSUPPORT)) return KS_Enabled;
142  if (LangOpts.AltiVec && (Flags & KEYALTIVEC)) return KS_Enabled;
143  if (LangOpts.OpenCL && (Flags & KEYOPENCL)) return KS_Enabled;
144  if (!LangOpts.CPlusPlus && (Flags & KEYNOCXX)) return KS_Enabled;
145  if (LangOpts.C11 && (Flags & KEYC11)) return KS_Enabled;
146  // We treat bridge casts as objective-C keywords so we can warn on them
147  // in non-arc mode.
148  if (LangOpts.ObjC2 && (Flags & KEYARC)) return KS_Enabled;
149  if (LangOpts.ConceptsTS && (Flags & KEYCONCEPTS)) return KS_Enabled;
150  if (LangOpts.ObjC2 && (Flags & KEYOBJC2)) return KS_Enabled;
151  if (LangOpts.Coroutines && (Flags & KEYCOROUTINES)) return KS_Enabled;
152  if (LangOpts.CPlusPlus && (Flags & KEYCXX11)) return KS_Future;
153  return KS_Disabled;
154 }
155 
156 /// AddKeyword - This method is used to associate a token ID with specific
157 /// identifiers because they are language keywords. This causes the lexer to
158 /// automatically map matching identifiers to specialized token codes.
159 static void AddKeyword(StringRef Keyword,
160  tok::TokenKind TokenCode, unsigned Flags,
161  const LangOptions &LangOpts, IdentifierTable &Table) {
162  KeywordStatus AddResult = getKeywordStatus(LangOpts, Flags);
163 
164  // Don't add this keyword under MSVCCompat.
165  if (LangOpts.MSVCCompat && (Flags & KEYNOMS18) &&
167  return;
168 
169  // Don't add this keyword under OpenCL.
170  if (LangOpts.OpenCL && (Flags & KEYNOOPENCL))
171  return;
172 
173  // Don't add this keyword if disabled in this language.
174  if (AddResult == KS_Disabled) return;
175 
176  IdentifierInfo &Info =
177  Table.get(Keyword, AddResult == KS_Future ? tok::identifier : TokenCode);
178  Info.setIsExtensionToken(AddResult == KS_Extension);
179  Info.setIsFutureCompatKeyword(AddResult == KS_Future);
180 }
181 
182 /// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
183 /// representations.
184 static void AddCXXOperatorKeyword(StringRef Keyword,
185  tok::TokenKind TokenCode,
186  IdentifierTable &Table) {
187  IdentifierInfo &Info = Table.get(Keyword, TokenCode);
189 }
190 
191 /// AddObjCKeyword - Register an Objective-C \@keyword like "class" "selector"
192 /// or "property".
193 static void AddObjCKeyword(StringRef Name,
194  tok::ObjCKeywordKind ObjCID,
195  IdentifierTable &Table) {
196  Table.get(Name).setObjCKeywordID(ObjCID);
197 }
198 
199 /// AddKeywords - Add all keywords to the symbol table.
200 ///
202  // Add keywords and tokens for the current language.
203 #define KEYWORD(NAME, FLAGS) \
204  AddKeyword(StringRef(#NAME), tok::kw_ ## NAME, \
205  FLAGS, LangOpts, *this);
206 #define ALIAS(NAME, TOK, FLAGS) \
207  AddKeyword(StringRef(NAME), tok::kw_ ## TOK, \
208  FLAGS, LangOpts, *this);
209 #define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
210  if (LangOpts.CXXOperatorNames) \
211  AddCXXOperatorKeyword(StringRef(#NAME), tok::ALIAS, *this);
212 #define OBJC1_AT_KEYWORD(NAME) \
213  if (LangOpts.ObjC1) \
214  AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
215 #define OBJC2_AT_KEYWORD(NAME) \
216  if (LangOpts.ObjC2) \
217  AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
218 #define TESTING_KEYWORD(NAME, FLAGS)
219 #include "clang/Basic/TokenKinds.def"
220 
221  if (LangOpts.ParseUnknownAnytype)
222  AddKeyword("__unknown_anytype", tok::kw___unknown_anytype, KEYALL,
223  LangOpts, *this);
224 
225  if (LangOpts.DeclSpecKeyword)
226  AddKeyword("__declspec", tok::kw___declspec, KEYALL, LangOpts, *this);
227 }
228 
229 /// \brief Checks if the specified token kind represents a keyword in the
230 /// specified language.
231 /// \returns Status of the keyword in the language.
233  tok::TokenKind K) {
234  switch (K) {
235 #define KEYWORD(NAME, FLAGS) \
236  case tok::kw_##NAME: return getKeywordStatus(LangOpts, FLAGS);
237 #include "clang/Basic/TokenKinds.def"
238  default: return KS_Disabled;
239  }
240 }
241 
242 /// \brief Returns true if the identifier represents a keyword in the
243 /// specified language.
244 bool IdentifierInfo::isKeyword(const LangOptions &LangOpts) {
245  switch (getTokenKwStatus(LangOpts, getTokenID())) {
246  case KS_Enabled:
247  case KS_Extension:
248  return true;
249  default:
250  return false;
251  }
252 }
253 
255  // We use a perfect hash function here involving the length of the keyword,
256  // the first and third character. For preprocessor ID's there are no
257  // collisions (if there were, the switch below would complain about duplicate
258  // case values). Note that this depends on 'if' being null terminated.
259 
260 #define HASH(LEN, FIRST, THIRD) \
261  (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
262 #define CASE(LEN, FIRST, THIRD, NAME) \
263  case HASH(LEN, FIRST, THIRD): \
264  return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
265 
266  unsigned Len = getLength();
267  if (Len < 2) return tok::pp_not_keyword;
268  const char *Name = getNameStart();
269  switch (HASH(Len, Name[0], Name[2])) {
270  default: return tok::pp_not_keyword;
271  CASE( 2, 'i', '\0', if);
272  CASE( 4, 'e', 'i', elif);
273  CASE( 4, 'e', 's', else);
274  CASE( 4, 'l', 'n', line);
275  CASE( 4, 's', 'c', sccs);
276  CASE( 5, 'e', 'd', endif);
277  CASE( 5, 'e', 'r', error);
278  CASE( 5, 'i', 'e', ident);
279  CASE( 5, 'i', 'd', ifdef);
280  CASE( 5, 'u', 'd', undef);
281 
282  CASE( 6, 'a', 's', assert);
283  CASE( 6, 'd', 'f', define);
284  CASE( 6, 'i', 'n', ifndef);
285  CASE( 6, 'i', 'p', import);
286  CASE( 6, 'p', 'a', pragma);
287 
288  CASE( 7, 'd', 'f', defined);
289  CASE( 7, 'i', 'c', include);
290  CASE( 7, 'w', 'r', warning);
291 
292  CASE( 8, 'u', 'a', unassert);
293  CASE(12, 'i', 'c', include_next);
294 
295  CASE(14, '_', 'p', __public_macro);
296 
297  CASE(15, '_', 'p', __private_macro);
298 
299  CASE(16, '_', 'i', __include_macros);
300 #undef CASE
301 #undef HASH
302  }
303 }
304 
305 //===----------------------------------------------------------------------===//
306 // Stats Implementation
307 //===----------------------------------------------------------------------===//
308 
309 /// PrintStats - Print statistics about how well the identifier table is doing
310 /// at hashing identifiers.
312  unsigned NumBuckets = HashTable.getNumBuckets();
313  unsigned NumIdentifiers = HashTable.getNumItems();
314  unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
315  unsigned AverageIdentifierSize = 0;
316  unsigned MaxIdentifierLength = 0;
317 
318  // TODO: Figure out maximum times an identifier had to probe for -stats.
319  for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator
320  I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
321  unsigned IdLen = I->getKeyLength();
322  AverageIdentifierSize += IdLen;
323  if (MaxIdentifierLength < IdLen)
324  MaxIdentifierLength = IdLen;
325  }
326 
327  fprintf(stderr, "\n*** Identifier Table Stats:\n");
328  fprintf(stderr, "# Identifiers: %d\n", NumIdentifiers);
329  fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
330  fprintf(stderr, "Hash density (#identifiers per bucket): %f\n",
331  NumIdentifiers/(double)NumBuckets);
332  fprintf(stderr, "Ave identifier length: %f\n",
333  (AverageIdentifierSize/(double)NumIdentifiers));
334  fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength);
335 
336  // Compute statistics about the memory allocated for identifiers.
337  HashTable.getAllocator().PrintStats();
338 }
339 
340 //===----------------------------------------------------------------------===//
341 // SelectorTable Implementation
342 //===----------------------------------------------------------------------===//
343 
346 }
347 
348 namespace clang {
349 /// MultiKeywordSelector - One of these variable length records is kept for each
350 /// selector containing more than one keyword. We use a folding set
351 /// to unique aggregate names (keyword selectors in ObjC parlance). Access to
352 /// this class is provided strictly through Selector.
354  : public DeclarationNameExtra, public llvm::FoldingSetNode {
355  MultiKeywordSelector(unsigned nKeys) {
357  }
358 public:
359  // Constructor for keyword selectors.
360  MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) {
361  assert((nKeys > 1) && "not a multi-keyword selector");
363 
364  // Fill in the trailing keyword array.
365  IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1);
366  for (unsigned i = 0; i != nKeys; ++i)
367  KeyInfo[i] = IIV[i];
368  }
369 
370  // getName - Derive the full selector name and return it.
371  std::string getName() const;
372 
373  unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; }
374 
377  return reinterpret_cast<keyword_iterator>(this+1);
378  }
380  return keyword_begin()+getNumArgs();
381  }
383  assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
384  return keyword_begin()[i];
385  }
386  static void Profile(llvm::FoldingSetNodeID &ID,
387  keyword_iterator ArgTys, unsigned NumArgs) {
388  ID.AddInteger(NumArgs);
389  for (unsigned i = 0; i != NumArgs; ++i)
390  ID.AddPointer(ArgTys[i]);
391  }
392  void Profile(llvm::FoldingSetNodeID &ID) {
393  Profile(ID, keyword_begin(), getNumArgs());
394  }
395 };
396 } // end namespace clang.
397 
398 unsigned Selector::getNumArgs() const {
399  unsigned IIF = getIdentifierInfoFlag();
400  if (IIF <= ZeroArg)
401  return 0;
402  if (IIF == OneArg)
403  return 1;
404  // We point to a MultiKeywordSelector.
405  MultiKeywordSelector *SI = getMultiKeywordSelector();
406  return SI->getNumArgs();
407 }
408 
410  if (getIdentifierInfoFlag() < MultiArg) {
411  assert(argIndex == 0 && "illegal keyword index");
412  return getAsIdentifierInfo();
413  }
414  // We point to a MultiKeywordSelector.
415  MultiKeywordSelector *SI = getMultiKeywordSelector();
416  return SI->getIdentifierInfoForSlot(argIndex);
417 }
418 
419 StringRef Selector::getNameForSlot(unsigned int argIndex) const {
421  return II? II->getName() : StringRef();
422 }
423 
424 std::string MultiKeywordSelector::getName() const {
425  SmallString<256> Str;
426  llvm::raw_svector_ostream OS(Str);
427  for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
428  if (*I)
429  OS << (*I)->getName();
430  OS << ':';
431  }
432 
433  return OS.str();
434 }
435 
436 std::string Selector::getAsString() const {
437  if (InfoPtr == 0)
438  return "<null selector>";
439 
440  if (getIdentifierInfoFlag() < MultiArg) {
441  IdentifierInfo *II = getAsIdentifierInfo();
442 
443  // If the number of arguments is 0 then II is guaranteed to not be null.
444  if (getNumArgs() == 0)
445  return II->getName();
446 
447  if (!II)
448  return ":";
449 
450  return II->getName().str() + ":";
451  }
452 
453  // We have a multiple keyword selector.
454  return getMultiKeywordSelector()->getName();
455 }
456 
457 void Selector::print(llvm::raw_ostream &OS) const {
458  OS << getAsString();
459 }
460 
461 /// Interpreting the given string using the normal CamelCase
462 /// conventions, determine whether the given string starts with the
463 /// given "word", which is assumed to end in a lowercase letter.
464 static bool startsWithWord(StringRef name, StringRef word) {
465  if (name.size() < word.size()) return false;
466  return ((name.size() == word.size() || !isLowercase(name[word.size()])) &&
467  name.startswith(word));
468 }
469 
470 ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) {
472  if (!first) return OMF_None;
473 
474  StringRef name = first->getName();
475  if (sel.isUnarySelector()) {
476  if (name == "autorelease") return OMF_autorelease;
477  if (name == "dealloc") return OMF_dealloc;
478  if (name == "finalize") return OMF_finalize;
479  if (name == "release") return OMF_release;
480  if (name == "retain") return OMF_retain;
481  if (name == "retainCount") return OMF_retainCount;
482  if (name == "self") return OMF_self;
483  if (name == "initialize") return OMF_initialize;
484  }
485 
486  if (name == "performSelector") return OMF_performSelector;
487 
488  // The other method families may begin with a prefix of underscores.
489  while (!name.empty() && name.front() == '_')
490  name = name.substr(1);
491 
492  if (name.empty()) return OMF_None;
493  switch (name.front()) {
494  case 'a':
495  if (startsWithWord(name, "alloc")) return OMF_alloc;
496  break;
497  case 'c':
498  if (startsWithWord(name, "copy")) return OMF_copy;
499  break;
500  case 'i':
501  if (startsWithWord(name, "init")) return OMF_init;
502  break;
503  case 'm':
504  if (startsWithWord(name, "mutableCopy")) return OMF_mutableCopy;
505  break;
506  case 'n':
507  if (startsWithWord(name, "new")) return OMF_new;
508  break;
509  default:
510  break;
511  }
512 
513  return OMF_None;
514 }
515 
518  if (!first) return OIT_None;
519 
520  StringRef name = first->getName();
521 
522  if (name.empty()) return OIT_None;
523  switch (name.front()) {
524  case 'a':
525  if (startsWithWord(name, "array")) return OIT_Array;
526  break;
527  case 'd':
528  if (startsWithWord(name, "default")) return OIT_ReturnsSelf;
529  if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
530  break;
531  case 's':
532  if (startsWithWord(name, "shared")) return OIT_ReturnsSelf;
533  if (startsWithWord(name, "standard")) return OIT_Singleton;
534  case 'i':
535  if (startsWithWord(name, "init")) return OIT_Init;
536  default:
537  break;
538  }
539  return OIT_None;
540 }
541 
542 ObjCStringFormatFamily Selector::getStringFormatFamilyImpl(Selector sel) {
544  if (!first) return SFF_None;
545 
546  StringRef name = first->getName();
547 
548  switch (name.front()) {
549  case 'a':
550  if (name == "appendFormat") return SFF_NSString;
551  break;
552 
553  case 'i':
554  if (name == "initWithFormat") return SFF_NSString;
555  break;
556 
557  case 'l':
558  if (name == "localizedStringWithFormat") return SFF_NSString;
559  break;
560 
561  case 's':
562  if (name == "stringByAppendingFormat" ||
563  name == "stringWithFormat") return SFF_NSString;
564  break;
565  }
566  return SFF_None;
567 }
568 
569 namespace {
570  struct SelectorTableImpl {
571  llvm::FoldingSet<MultiKeywordSelector> Table;
572  llvm::BumpPtrAllocator Allocator;
573  };
574 } // end anonymous namespace.
575 
576 static SelectorTableImpl &getSelectorTableImpl(void *P) {
577  return *static_cast<SelectorTableImpl*>(P);
578 }
579 
582  SmallString<64> SetterName("set");
583  SetterName += Name;
584  SetterName[3] = toUppercase(SetterName[3]);
585  return SetterName;
586 }
587 
588 Selector
590  SelectorTable &SelTable,
591  const IdentifierInfo *Name) {
592  IdentifierInfo *SetterName =
593  &Idents.get(constructSetterName(Name->getName()));
594  return SelTable.getUnarySelector(SetterName);
595 }
596 
598  SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
599  return SelTabImpl.Allocator.getTotalMemory();
600 }
601 
603  if (nKeys < 2)
604  return Selector(IIV[0], nKeys);
605 
606  SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
607 
608  // Unique selector, to guarantee there is one per name.
609  llvm::FoldingSetNodeID ID;
610  MultiKeywordSelector::Profile(ID, IIV, nKeys);
611 
612  void *InsertPos = nullptr;
613  if (MultiKeywordSelector *SI =
614  SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
615  return Selector(SI);
616 
617  // MultiKeywordSelector objects are not allocated with new because they have a
618  // variable size array (for parameter types) at the end of them.
619  unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *);
621  (MultiKeywordSelector*)SelTabImpl.Allocator.Allocate(Size,
622  llvm::alignOf<MultiKeywordSelector>());
623  new (SI) MultiKeywordSelector(nKeys, IIV);
624  SelTabImpl.Table.InsertNode(SI, InsertPos);
625  return Selector(SI);
626 }
627 
629  Impl = new SelectorTableImpl();
630 }
631 
633  delete &getSelectorTableImpl(Impl);
634 }
635 
637  switch (Operator) {
638  case OO_None:
640  return nullptr;
641 
642 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
643  case OO_##Name: return Spelling;
644 #include "clang/Basic/OperatorKinds.def"
645  }
646 
647  llvm_unreachable("Invalid OverloadedOperatorKind!");
648 }
649 
651  bool isContextSensitive) {
652  switch (kind) {
654  return isContextSensitive ? "nonnull" : "_Nonnull";
655 
657  return isContextSensitive ? "nullable" : "_Nullable";
658 
660  return isContextSensitive ? "null_unspecified" : "_Null_unspecified";
661  }
662  llvm_unreachable("Unknown nullability kind.");
663 }
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:271
void setIsExtensionToken(bool Val)
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:4381
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
llvm::SpecificBumpPtrAllocator< FormatToken > Allocator
Definition: Format.cpp:1358
AnnotatingParser & P
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...
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
bool isUnarySelector() const
MultiKeywordSelector - One of these variable length records is kept for each selector containing more...
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:3988
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.
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:141
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.