clang  7.0.0svn
Preprocessor.cpp
Go to the documentation of this file.
1 //===- Preprocess.cpp - C Language Family Preprocessor Implementation -----===//
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 Preprocessor interface.
11 //
12 //===----------------------------------------------------------------------===//
13 //
14 // Options to support:
15 // -H - Print the name of each header file used.
16 // -d[DNI] - Dump various things.
17 // -fworking-directory - #line's with preprocessor's working dir.
18 // -fpreprocessed
19 // -dependency-file,-M,-MM,-MF,-MG,-MP,-MT,-MQ,-MD,-MMD
20 // -W*
21 // -w
22 //
23 // Messages to emit:
24 // "Multiple include guards may be useful for:\n"
25 //
26 //===----------------------------------------------------------------------===//
27 
28 #include "clang/Lex/Preprocessor.h"
32 #include "clang/Basic/LLVM.h"
34 #include "clang/Basic/Module.h"
37 #include "clang/Basic/TargetInfo.h"
40 #include "clang/Lex/HeaderSearch.h"
42 #include "clang/Lex/Lexer.h"
44 #include "clang/Lex/MacroArgs.h"
45 #include "clang/Lex/MacroInfo.h"
46 #include "clang/Lex/ModuleLoader.h"
47 #include "clang/Lex/PTHLexer.h"
48 #include "clang/Lex/PTHManager.h"
49 #include "clang/Lex/Pragma.h"
54 #include "clang/Lex/Token.h"
55 #include "clang/Lex/TokenLexer.h"
56 #include "llvm/ADT/APInt.h"
57 #include "llvm/ADT/ArrayRef.h"
58 #include "llvm/ADT/DenseMap.h"
59 #include "llvm/ADT/SmallString.h"
60 #include "llvm/ADT/SmallVector.h"
61 #include "llvm/ADT/STLExtras.h"
62 #include "llvm/ADT/StringRef.h"
63 #include "llvm/ADT/StringSwitch.h"
64 #include "llvm/Support/Capacity.h"
65 #include "llvm/Support/ErrorHandling.h"
66 #include "llvm/Support/MemoryBuffer.h"
67 #include "llvm/Support/raw_ostream.h"
68 #include <algorithm>
69 #include <cassert>
70 #include <memory>
71 #include <string>
72 #include <utility>
73 #include <vector>
74 
75 using namespace clang;
76 
77 LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
78 
80 
81 Preprocessor::Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
82  DiagnosticsEngine &diags, LangOptions &opts,
84  HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
85  IdentifierInfoLookup *IILookup, bool OwnsHeaders,
86  TranslationUnitKind TUKind)
87  : PPOpts(std::move(PPOpts)), Diags(&diags), LangOpts(opts),
88  FileMgr(Headers.getFileMgr()), SourceMgr(SM), PCMCache(PCMCache),
89  ScratchBuf(new ScratchBuffer(SourceMgr)), HeaderInfo(Headers),
90  TheModuleLoader(TheModuleLoader), ExternalSource(nullptr),
91  // As the language options may have not been loaded yet (when
92  // deserializing an ASTUnit), adding keywords to the identifier table is
93  // deferred to Preprocessor::Initialize().
94  Identifiers(IILookup), PragmaHandlers(new PragmaNamespace(StringRef())),
95  TUKind(TUKind), SkipMainFilePreamble(0, true),
96  CurSubmoduleState(&NullSubmoduleState) {
97  OwnsHeaderSearch = OwnsHeaders;
98 
99  // Default to discarding comments.
100  KeepComments = false;
101  KeepMacroComments = false;
102  SuppressIncludeNotFoundError = false;
103 
104  // Macro expansion is enabled.
105  DisableMacroExpansion = false;
106  MacroExpansionInDirectivesOverride = false;
107  InMacroArgs = false;
108  InMacroArgPreExpansion = false;
109  NumCachedTokenLexers = 0;
110  PragmasEnabled = true;
111  ParsingIfOrElifDirective = false;
112  PreprocessedOutput = false;
113 
114  // We haven't read anything from the external source.
115  ReadMacrosFromExternalSource = false;
116 
117  // "Poison" __VA_ARGS__, __VA_OPT__ which can only appear in the expansion of
118  // a macro. They get unpoisoned where it is allowed.
119  (Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned();
120  SetPoisonReason(Ident__VA_ARGS__,diag::ext_pp_bad_vaargs_use);
121  if (getLangOpts().CPlusPlus2a) {
122  (Ident__VA_OPT__ = getIdentifierInfo("__VA_OPT__"))->setIsPoisoned();
123  SetPoisonReason(Ident__VA_OPT__,diag::ext_pp_bad_vaopt_use);
124  } else {
125  Ident__VA_OPT__ = nullptr;
126  }
127 
128  // Initialize the pragma handlers.
129  RegisterBuiltinPragmas();
130 
131  // Initialize builtin macros like __LINE__ and friends.
132  RegisterBuiltinMacros();
133 
134  if(LangOpts.Borland) {
135  Ident__exception_info = getIdentifierInfo("_exception_info");
136  Ident___exception_info = getIdentifierInfo("__exception_info");
137  Ident_GetExceptionInfo = getIdentifierInfo("GetExceptionInformation");
138  Ident__exception_code = getIdentifierInfo("_exception_code");
139  Ident___exception_code = getIdentifierInfo("__exception_code");
140  Ident_GetExceptionCode = getIdentifierInfo("GetExceptionCode");
141  Ident__abnormal_termination = getIdentifierInfo("_abnormal_termination");
142  Ident___abnormal_termination = getIdentifierInfo("__abnormal_termination");
143  Ident_AbnormalTermination = getIdentifierInfo("AbnormalTermination");
144  } else {
145  Ident__exception_info = Ident__exception_code = nullptr;
146  Ident__abnormal_termination = Ident___exception_info = nullptr;
147  Ident___exception_code = Ident___abnormal_termination = nullptr;
148  Ident_GetExceptionInfo = Ident_GetExceptionCode = nullptr;
149  Ident_AbnormalTermination = nullptr;
150  }
151 
152  if (this->PPOpts->GeneratePreamble)
153  PreambleConditionalStack.startRecording();
154 }
155 
157  assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!");
158 
159  IncludeMacroStack.clear();
160 
161  // Destroy any macro definitions.
162  while (MacroInfoChain *I = MIChainHead) {
163  MIChainHead = I->Next;
164  I->~MacroInfoChain();
165  }
166 
167  // Free any cached macro expanders.
168  // This populates MacroArgCache, so all TokenLexers need to be destroyed
169  // before the code below that frees up the MacroArgCache list.
170  std::fill(TokenLexerCache, TokenLexerCache + NumCachedTokenLexers, nullptr);
171  CurTokenLexer.reset();
172 
173  // Free any cached MacroArgs.
174  for (MacroArgs *ArgList = MacroArgCache; ArgList;)
175  ArgList = ArgList->deallocate();
176 
177  // Delete the header search info, if we own it.
178  if (OwnsHeaderSearch)
179  delete &HeaderInfo;
180 }
181 
183  const TargetInfo *AuxTarget) {
184  assert((!this->Target || this->Target == &Target) &&
185  "Invalid override of target information");
186  this->Target = &Target;
187 
188  assert((!this->AuxTarget || this->AuxTarget == AuxTarget) &&
189  "Invalid override of aux target information.");
190  this->AuxTarget = AuxTarget;
191 
192  // Initialize information about built-ins.
193  BuiltinInfo.InitializeTarget(Target, AuxTarget);
194  HeaderInfo.setTarget(Target);
195 
196  // Populate the identifier table with info about keywords for the current language.
197  Identifiers.AddKeywords(LangOpts);
198 }
199 
201  NumEnteredSourceFiles = 0;
202 
203  // Reset pragmas
204  PragmaHandlersBackup = std::move(PragmaHandlers);
205  PragmaHandlers = llvm::make_unique<PragmaNamespace>(StringRef());
206  RegisterBuiltinPragmas();
207 
208  // Reset PredefinesFileID
209  PredefinesFileID = FileID();
210 }
211 
213  NumEnteredSourceFiles = 1;
214 
215  PragmaHandlers = std::move(PragmaHandlersBackup);
216 }
217 
219  PTH.reset(pm);
220  FileMgr.addStatCache(PTH->createStatCache());
221 }
222 
223 void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const {
224  llvm::errs() << tok::getTokenName(Tok.getKind()) << " '"
225  << getSpelling(Tok) << "'";
226 
227  if (!DumpFlags) return;
228 
229  llvm::errs() << "\t";
230  if (Tok.isAtStartOfLine())
231  llvm::errs() << " [StartOfLine]";
232  if (Tok.hasLeadingSpace())
233  llvm::errs() << " [LeadingSpace]";
234  if (Tok.isExpandDisabled())
235  llvm::errs() << " [ExpandDisabled]";
236  if (Tok.needsCleaning()) {
237  const char *Start = SourceMgr.getCharacterData(Tok.getLocation());
238  llvm::errs() << " [UnClean='" << StringRef(Start, Tok.getLength())
239  << "']";
240  }
241 
242  llvm::errs() << "\tLoc=<";
243  DumpLocation(Tok.getLocation());
244  llvm::errs() << ">";
245 }
246 
248  Loc.dump(SourceMgr);
249 }
250 
251 void Preprocessor::DumpMacro(const MacroInfo &MI) const {
252  llvm::errs() << "MACRO: ";
253  for (unsigned i = 0, e = MI.getNumTokens(); i != e; ++i) {
255  llvm::errs() << " ";
256  }
257  llvm::errs() << "\n";
258 }
259 
261  llvm::errs() << "\n*** Preprocessor Stats:\n";
262  llvm::errs() << NumDirectives << " directives found:\n";
263  llvm::errs() << " " << NumDefined << " #define.\n";
264  llvm::errs() << " " << NumUndefined << " #undef.\n";
265  llvm::errs() << " #include/#include_next/#import:\n";
266  llvm::errs() << " " << NumEnteredSourceFiles << " source files entered.\n";
267  llvm::errs() << " " << MaxIncludeStackDepth << " max include stack depth\n";
268  llvm::errs() << " " << NumIf << " #if/#ifndef/#ifdef.\n";
269  llvm::errs() << " " << NumElse << " #else/#elif.\n";
270  llvm::errs() << " " << NumEndif << " #endif.\n";
271  llvm::errs() << " " << NumPragma << " #pragma.\n";
272  llvm::errs() << NumSkipped << " #if/#ifndef#ifdef regions skipped\n";
273 
274  llvm::errs() << NumMacroExpanded << "/" << NumFnMacroExpanded << "/"
275  << NumBuiltinMacroExpanded << " obj/fn/builtin macros expanded, "
276  << NumFastMacroExpanded << " on the fast path.\n";
277  llvm::errs() << (NumFastTokenPaste+NumTokenPaste)
278  << " token paste (##) operations performed, "
279  << NumFastTokenPaste << " on the fast path.\n";
280 
281  llvm::errs() << "\nPreprocessor Memory: " << getTotalMemory() << "B total";
282 
283  llvm::errs() << "\n BumpPtr: " << BP.getTotalMemory();
284  llvm::errs() << "\n Macro Expanded Tokens: "
285  << llvm::capacity_in_bytes(MacroExpandedTokens);
286  llvm::errs() << "\n Predefines Buffer: " << Predefines.capacity();
287  // FIXME: List information for all submodules.
288  llvm::errs() << "\n Macros: "
289  << llvm::capacity_in_bytes(CurSubmoduleState->Macros);
290  llvm::errs() << "\n #pragma push_macro Info: "
291  << llvm::capacity_in_bytes(PragmaPushMacroInfo);
292  llvm::errs() << "\n Poison Reasons: "
293  << llvm::capacity_in_bytes(PoisonReasons);
294  llvm::errs() << "\n Comment Handlers: "
295  << llvm::capacity_in_bytes(CommentHandlers) << "\n";
296 }
297 
299 Preprocessor::macro_begin(bool IncludeExternalMacros) const {
300  if (IncludeExternalMacros && ExternalSource &&
301  !ReadMacrosFromExternalSource) {
302  ReadMacrosFromExternalSource = true;
303  ExternalSource->ReadDefinedMacros();
304  }
305 
306  // Make sure we cover all macros in visible modules.
307  for (const ModuleMacro &Macro : ModuleMacros)
308  CurSubmoduleState->Macros.insert(std::make_pair(Macro.II, MacroState()));
309 
310  return CurSubmoduleState->Macros.begin();
311 }
312 
314  return BP.getTotalMemory()
315  + llvm::capacity_in_bytes(MacroExpandedTokens)
316  + Predefines.capacity() /* Predefines buffer. */
317  // FIXME: Include sizes from all submodules, and include MacroInfo sizes,
318  // and ModuleMacros.
319  + llvm::capacity_in_bytes(CurSubmoduleState->Macros)
320  + llvm::capacity_in_bytes(PragmaPushMacroInfo)
321  + llvm::capacity_in_bytes(PoisonReasons)
322  + llvm::capacity_in_bytes(CommentHandlers);
323 }
324 
326 Preprocessor::macro_end(bool IncludeExternalMacros) const {
327  if (IncludeExternalMacros && ExternalSource &&
328  !ReadMacrosFromExternalSource) {
329  ReadMacrosFromExternalSource = true;
330  ExternalSource->ReadDefinedMacros();
331  }
332 
333  return CurSubmoduleState->Macros.end();
334 }
335 
336 /// \brief Compares macro tokens with a specified token value sequence.
337 static bool MacroDefinitionEquals(const MacroInfo *MI,
338  ArrayRef<TokenValue> Tokens) {
339  return Tokens.size() == MI->getNumTokens() &&
340  std::equal(Tokens.begin(), Tokens.end(), MI->tokens_begin());
341 }
342 
344  SourceLocation Loc,
345  ArrayRef<TokenValue> Tokens) const {
346  SourceLocation BestLocation;
347  StringRef BestSpelling;
349  I != E; ++I) {
351  Def = I->second.findDirectiveAtLoc(Loc, SourceMgr);
352  if (!Def || !Def.getMacroInfo())
353  continue;
354  if (!Def.getMacroInfo()->isObjectLike())
355  continue;
356  if (!MacroDefinitionEquals(Def.getMacroInfo(), Tokens))
357  continue;
358  SourceLocation Location = Def.getLocation();
359  // Choose the macro defined latest.
360  if (BestLocation.isInvalid() ||
361  (Location.isValid() &&
362  SourceMgr.isBeforeInTranslationUnit(BestLocation, Location))) {
363  BestLocation = Location;
364  BestSpelling = I->first->getName();
365  }
366  }
367  return BestSpelling;
368 }
369 
371  if (CurLexer)
372  CurLexerKind = CLK_Lexer;
373  else if (CurPTHLexer)
374  CurLexerKind = CLK_PTHLexer;
375  else if (CurTokenLexer)
376  CurLexerKind = CLK_TokenLexer;
377  else
378  CurLexerKind = CLK_CachingLexer;
379 }
380 
382  unsigned CompleteLine,
383  unsigned CompleteColumn) {
384  assert(File);
385  assert(CompleteLine && CompleteColumn && "Starts from 1:1");
386  assert(!CodeCompletionFile && "Already set");
387 
388  using llvm::MemoryBuffer;
389 
390  // Load the actual file's contents.
391  bool Invalid = false;
392  const MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File, &Invalid);
393  if (Invalid)
394  return true;
395 
396  // Find the byte position of the truncation point.
397  const char *Position = Buffer->getBufferStart();
398  for (unsigned Line = 1; Line < CompleteLine; ++Line) {
399  for (; *Position; ++Position) {
400  if (*Position != '\r' && *Position != '\n')
401  continue;
402 
403  // Eat \r\n or \n\r as a single line.
404  if ((Position[1] == '\r' || Position[1] == '\n') &&
405  Position[0] != Position[1])
406  ++Position;
407  ++Position;
408  break;
409  }
410  }
411 
412  Position += CompleteColumn - 1;
413 
414  // If pointing inside the preamble, adjust the position at the beginning of
415  // the file after the preamble.
416  if (SkipMainFilePreamble.first &&
417  SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()) == File) {
418  if (Position - Buffer->getBufferStart() < SkipMainFilePreamble.first)
419  Position = Buffer->getBufferStart() + SkipMainFilePreamble.first;
420  }
421 
422  if (Position > Buffer->getBufferEnd())
423  Position = Buffer->getBufferEnd();
424 
425  CodeCompletionFile = File;
426  CodeCompletionOffset = Position - Buffer->getBufferStart();
427 
428  auto NewBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
429  Buffer->getBufferSize() + 1, Buffer->getBufferIdentifier());
430  char *NewBuf = NewBuffer->getBufferStart();
431  char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
432  *NewPos = '\0';
433  std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
434  SourceMgr.overrideFileContents(File, std::move(NewBuffer));
435 
436  return false;
437 }
438 
440  if (CodeComplete)
441  CodeComplete->CodeCompleteNaturalLanguage();
443 }
444 
445 /// getSpelling - This method is used to get the spelling of a token into a
446 /// SmallVector. Note that the returned StringRef may not point to the
447 /// supplied buffer if a copy can be avoided.
449  SmallVectorImpl<char> &Buffer,
450  bool *Invalid) const {
451  // NOTE: this has to be checked *before* testing for an IdentifierInfo.
452  if (Tok.isNot(tok::raw_identifier) && !Tok.hasUCN()) {
453  // Try the fast path.
454  if (const IdentifierInfo *II = Tok.getIdentifierInfo())
455  return II->getName();
456  }
457 
458  // Resize the buffer if we need to copy into it.
459  if (Tok.needsCleaning())
460  Buffer.resize(Tok.getLength());
461 
462  const char *Ptr = Buffer.data();
463  unsigned Len = getSpelling(Tok, Ptr, Invalid);
464  return StringRef(Ptr, Len);
465 }
466 
467 /// CreateString - Plop the specified string into a scratch buffer and return a
468 /// location for it. If specified, the source location provides a source
469 /// location for the token.
470 void Preprocessor::CreateString(StringRef Str, Token &Tok,
471  SourceLocation ExpansionLocStart,
472  SourceLocation ExpansionLocEnd) {
473  Tok.setLength(Str.size());
474 
475  const char *DestPtr;
476  SourceLocation Loc = ScratchBuf->getToken(Str.data(), Str.size(), DestPtr);
477 
478  if (ExpansionLocStart.isValid())
479  Loc = SourceMgr.createExpansionLoc(Loc, ExpansionLocStart,
480  ExpansionLocEnd, Str.size());
481  Tok.setLocation(Loc);
482 
483  // If this is a raw identifier or a literal token, set the pointer data.
484  if (Tok.is(tok::raw_identifier))
485  Tok.setRawIdentifierData(DestPtr);
486  else if (Tok.isLiteral())
487  Tok.setLiteralData(DestPtr);
488 }
489 
491  if (!getLangOpts().isCompilingModule())
492  return nullptr;
493 
494  return getHeaderSearchInfo().lookupModule(getLangOpts().CurrentModule);
495 }
496 
497 //===----------------------------------------------------------------------===//
498 // Preprocessor Initialization Methods
499 //===----------------------------------------------------------------------===//
500 
501 /// EnterMainSourceFile - Enter the specified FileID as the main source file,
502 /// which implicitly adds the builtin defines etc.
504  // We do not allow the preprocessor to reenter the main file. Doing so will
505  // cause FileID's to accumulate information from both runs (e.g. #line
506  // information) and predefined macros aren't guaranteed to be set properly.
507  assert(NumEnteredSourceFiles == 0 && "Cannot reenter the main file!");
508  FileID MainFileID = SourceMgr.getMainFileID();
509 
510  // If MainFileID is loaded it means we loaded an AST file, no need to enter
511  // a main file.
512  if (!SourceMgr.isLoadedFileID(MainFileID)) {
513  // Enter the main file source buffer.
514  EnterSourceFile(MainFileID, nullptr, SourceLocation());
515 
516  // If we've been asked to skip bytes in the main file (e.g., as part of a
517  // precompiled preamble), do so now.
518  if (SkipMainFilePreamble.first > 0)
519  CurLexer->SetByteOffset(SkipMainFilePreamble.first,
520  SkipMainFilePreamble.second);
521 
522  // Tell the header info that the main file was entered. If the file is later
523  // #imported, it won't be re-entered.
524  if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID))
525  HeaderInfo.IncrementIncludeCount(FE);
526  }
527 
528  // Preprocess Predefines to populate the initial preprocessor state.
529  std::unique_ptr<llvm::MemoryBuffer> SB =
530  llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>");
531  assert(SB && "Cannot create predefined source buffer");
532  FileID FID = SourceMgr.createFileID(std::move(SB));
533  assert(FID.isValid() && "Could not create FileID for predefines?");
534  setPredefinesFileID(FID);
535 
536  // Start parsing the predefines.
537  EnterSourceFile(FID, nullptr, SourceLocation());
538 }
539 
540 void Preprocessor::replayPreambleConditionalStack() {
541  // Restore the conditional stack from the preamble, if there is one.
542  if (PreambleConditionalStack.isReplaying()) {
543  assert(CurPPLexer &&
544  "CurPPLexer is null when calling replayPreambleConditionalStack.");
545  CurPPLexer->setConditionalLevels(PreambleConditionalStack.getStack());
546  PreambleConditionalStack.doneReplaying();
547  if (PreambleConditionalStack.reachedEOFWhileSkipping())
548  SkipExcludedConditionalBlock(
549  PreambleConditionalStack.SkipInfo->HashTokenLoc,
550  PreambleConditionalStack.SkipInfo->IfTokenLoc,
551  PreambleConditionalStack.SkipInfo->FoundNonSkipPortion,
552  PreambleConditionalStack.SkipInfo->FoundElse,
553  PreambleConditionalStack.SkipInfo->ElseLoc);
554  }
555 }
556 
558  // Notify the client that we reached the end of the source file.
559  if (Callbacks)
560  Callbacks->EndOfMainFile();
561 }
562 
563 //===----------------------------------------------------------------------===//
564 // Lexer Event Handling.
565 //===----------------------------------------------------------------------===//
566 
567 /// LookUpIdentifierInfo - Given a tok::raw_identifier token, look up the
568 /// identifier information for the token and install it into the token,
569 /// updating the token kind accordingly.
571  assert(!Identifier.getRawIdentifier().empty() && "No raw identifier data!");
572 
573  // Look up this token, see if it is a macro, or if it is a language keyword.
574  IdentifierInfo *II;
575  if (!Identifier.needsCleaning() && !Identifier.hasUCN()) {
576  // No cleaning needed, just use the characters from the lexed buffer.
577  II = getIdentifierInfo(Identifier.getRawIdentifier());
578  } else {
579  // Cleaning needed, alloca a buffer, clean into it, then use the buffer.
580  SmallString<64> IdentifierBuffer;
581  StringRef CleanedStr = getSpelling(Identifier, IdentifierBuffer);
582 
583  if (Identifier.hasUCN()) {
584  SmallString<64> UCNIdentifierBuffer;
585  expandUCNs(UCNIdentifierBuffer, CleanedStr);
586  II = getIdentifierInfo(UCNIdentifierBuffer);
587  } else {
588  II = getIdentifierInfo(CleanedStr);
589  }
590  }
591 
592  // Update the token info (identifier info and appropriate token kind).
593  Identifier.setIdentifierInfo(II);
594  if (getLangOpts().MSVCCompat && II->isCPlusPlusOperatorKeyword() &&
596  Identifier.setKind(tok::identifier);
597  else
598  Identifier.setKind(II->getTokenID());
599 
600  return II;
601 }
602 
603 void Preprocessor::SetPoisonReason(IdentifierInfo *II, unsigned DiagID) {
604  PoisonReasons[II] = DiagID;
605 }
606 
608  assert(Ident__exception_code && Ident__exception_info);
609  assert(Ident___exception_code && Ident___exception_info);
610  Ident__exception_code->setIsPoisoned(Poison);
611  Ident___exception_code->setIsPoisoned(Poison);
612  Ident_GetExceptionCode->setIsPoisoned(Poison);
613  Ident__exception_info->setIsPoisoned(Poison);
614  Ident___exception_info->setIsPoisoned(Poison);
615  Ident_GetExceptionInfo->setIsPoisoned(Poison);
616  Ident__abnormal_termination->setIsPoisoned(Poison);
617  Ident___abnormal_termination->setIsPoisoned(Poison);
618  Ident_AbnormalTermination->setIsPoisoned(Poison);
619 }
620 
622  assert(Identifier.getIdentifierInfo() &&
623  "Can't handle identifiers without identifier info!");
624  llvm::DenseMap<IdentifierInfo*,unsigned>::const_iterator it =
625  PoisonReasons.find(Identifier.getIdentifierInfo());
626  if(it == PoisonReasons.end())
627  Diag(Identifier, diag::err_pp_used_poisoned_id);
628  else
629  Diag(Identifier,it->second) << Identifier.getIdentifierInfo();
630 }
631 
632 /// \brief Returns a diagnostic message kind for reporting a future keyword as
633 /// appropriate for the identifier and specified language.
635  const LangOptions &LangOpts) {
636  assert(II.isFutureCompatKeyword() && "diagnostic should not be needed");
637 
638  if (LangOpts.CPlusPlus)
639  return llvm::StringSwitch<diag::kind>(II.getName())
640 #define CXX11_KEYWORD(NAME, FLAGS) \
641  .Case(#NAME, diag::warn_cxx11_keyword)
642 #define CXX2A_KEYWORD(NAME, FLAGS) \
643  .Case(#NAME, diag::warn_cxx2a_keyword)
644 #include "clang/Basic/TokenKinds.def"
645  ;
646 
647  llvm_unreachable(
648  "Keyword not known to come from a newer Standard or proposed Standard");
649 }
650 
651 void Preprocessor::updateOutOfDateIdentifier(IdentifierInfo &II) const {
652  assert(II.isOutOfDate() && "not out of date");
654 }
655 
656 /// HandleIdentifier - This callback is invoked when the lexer reads an
657 /// identifier. This callback looks up the identifier in the map and/or
658 /// potentially macro expands it or turns it into a named token (like 'for').
659 ///
660 /// Note that callers of this method are guarded by checking the
661 /// IdentifierInfo's 'isHandleIdentifierCase' bit. If this method changes, the
662 /// IdentifierInfo methods that compute these properties will need to change to
663 /// match.
665  assert(Identifier.getIdentifierInfo() &&
666  "Can't handle identifiers without identifier info!");
667 
668  IdentifierInfo &II = *Identifier.getIdentifierInfo();
669 
670  // If the information about this identifier is out of date, update it from
671  // the external source.
672  // We have to treat __VA_ARGS__ in a special way, since it gets
673  // serialized with isPoisoned = true, but our preprocessor may have
674  // unpoisoned it if we're defining a C99 macro.
675  if (II.isOutOfDate()) {
676  bool CurrentIsPoisoned = false;
677  const bool IsSpecialVariadicMacro =
678  &II == Ident__VA_ARGS__ || &II == Ident__VA_OPT__;
679  if (IsSpecialVariadicMacro)
680  CurrentIsPoisoned = II.isPoisoned();
681 
682  updateOutOfDateIdentifier(II);
683  Identifier.setKind(II.getTokenID());
684 
685  if (IsSpecialVariadicMacro)
686  II.setIsPoisoned(CurrentIsPoisoned);
687  }
688 
689  // If this identifier was poisoned, and if it was not produced from a macro
690  // expansion, emit an error.
691  if (II.isPoisoned() && CurPPLexer) {
692  HandlePoisonedIdentifier(Identifier);
693  }
694 
695  // If this is a macro to be expanded, do it.
696  if (MacroDefinition MD = getMacroDefinition(&II)) {
697  auto *MI = MD.getMacroInfo();
698  assert(MI && "macro definition with no macro info?");
699  if (!DisableMacroExpansion) {
700  if (!Identifier.isExpandDisabled() && MI->isEnabled()) {
701  // C99 6.10.3p10: If the preprocessing token immediately after the
702  // macro name isn't a '(', this macro should not be expanded.
703  if (!MI->isFunctionLike() || isNextPPTokenLParen())
704  return HandleMacroExpandedIdentifier(Identifier, MD);
705  } else {
706  // C99 6.10.3.4p2 says that a disabled macro may never again be
707  // expanded, even if it's in a context where it could be expanded in the
708  // future.
709  Identifier.setFlag(Token::DisableExpand);
710  if (MI->isObjectLike() || isNextPPTokenLParen())
711  Diag(Identifier, diag::pp_disabled_macro_expansion);
712  }
713  }
714  }
715 
716  // If this identifier is a keyword in a newer Standard or proposed Standard,
717  // produce a warning. Don't warn if we're not considering macro expansion,
718  // since this identifier might be the name of a macro.
719  // FIXME: This warning is disabled in cases where it shouldn't be, like
720  // "#define constexpr constexpr", "int constexpr;"
721  if (II.isFutureCompatKeyword() && !DisableMacroExpansion) {
722  Diag(Identifier, getFutureCompatDiagKind(II, getLangOpts()))
723  << II.getName();
724  // Don't diagnose this keyword again in this translation unit.
725  II.setIsFutureCompatKeyword(false);
726  }
727 
728  // If this is an extension token, diagnose its use.
729  // We avoid diagnosing tokens that originate from macro definitions.
730  // FIXME: This warning is disabled in cases where it shouldn't be,
731  // like "#define TY typeof", "TY(1) x".
732  if (II.isExtensionToken() && !DisableMacroExpansion)
733  Diag(Identifier, diag::ext_token_used);
734 
735  // If this is the 'import' contextual keyword following an '@', note
736  // that the next token indicates a module name.
737  //
738  // Note that we do not treat 'import' as a contextual
739  // keyword when we're in a caching lexer, because caching lexers only get
740  // used in contexts where import declarations are disallowed.
741  //
742  // Likewise if this is the C++ Modules TS import keyword.
743  if (((LastTokenWasAt && II.isModulesImport()) ||
744  Identifier.is(tok::kw_import)) &&
745  !InMacroArgs && !DisableMacroExpansion &&
746  (getLangOpts().Modules || getLangOpts().DebuggerSupport) &&
747  CurLexerKind != CLK_CachingLexer) {
748  ModuleImportLoc = Identifier.getLocation();
749  ModuleImportPath.clear();
750  ModuleImportExpectsIdentifier = true;
751  CurLexerKind = CLK_LexAfterModuleImport;
752  }
753  return true;
754 }
755 
757  // We loop here until a lex function returns a token; this avoids recursion.
758  bool ReturnedToken;
759  do {
760  switch (CurLexerKind) {
761  case CLK_Lexer:
762  ReturnedToken = CurLexer->Lex(Result);
763  break;
764  case CLK_PTHLexer:
765  ReturnedToken = CurPTHLexer->Lex(Result);
766  break;
767  case CLK_TokenLexer:
768  ReturnedToken = CurTokenLexer->Lex(Result);
769  break;
770  case CLK_CachingLexer:
771  CachingLex(Result);
772  ReturnedToken = true;
773  break;
774  case CLK_LexAfterModuleImport:
775  LexAfterModuleImport(Result);
776  ReturnedToken = true;
777  break;
778  }
779  } while (!ReturnedToken);
780 
781  if (Result.is(tok::code_completion) && Result.getIdentifierInfo()) {
782  // Remember the identifier before code completion token.
784  // Set IdenfitierInfo to null to avoid confusing code that handles both
785  // identifiers and completion tokens.
786  Result.setIdentifierInfo(nullptr);
787  }
788 
789  LastTokenWasAt = Result.is(tok::at);
790 }
791 
792 /// \brief Lex a token following the 'import' contextual keyword.
793 ///
795  // Figure out what kind of lexer we actually have.
797 
798  // Lex the next token.
799  Lex(Result);
800 
801  // The token sequence
802  //
803  // import identifier (. identifier)*
804  //
805  // indicates a module import directive. We already saw the 'import'
806  // contextual keyword, so now we're looking for the identifiers.
807  if (ModuleImportExpectsIdentifier && Result.getKind() == tok::identifier) {
808  // We expected to see an identifier here, and we did; continue handling
809  // identifiers.
810  ModuleImportPath.push_back(std::make_pair(Result.getIdentifierInfo(),
811  Result.getLocation()));
812  ModuleImportExpectsIdentifier = false;
813  CurLexerKind = CLK_LexAfterModuleImport;
814  return;
815  }
816 
817  // If we're expecting a '.' or a ';', and we got a '.', then wait until we
818  // see the next identifier. (We can also see a '[[' that begins an
819  // attribute-specifier-seq here under the C++ Modules TS.)
820  if (!ModuleImportExpectsIdentifier && Result.getKind() == tok::period) {
821  ModuleImportExpectsIdentifier = true;
822  CurLexerKind = CLK_LexAfterModuleImport;
823  return;
824  }
825 
826  // If we have a non-empty module path, load the named module.
827  if (!ModuleImportPath.empty()) {
828  // Under the Modules TS, the dot is just part of the module name, and not
829  // a real hierarachy separator. Flatten such module names now.
830  //
831  // FIXME: Is this the right level to be performing this transformation?
832  std::string FlatModuleName;
833  if (getLangOpts().ModulesTS) {
834  for (auto &Piece : ModuleImportPath) {
835  if (!FlatModuleName.empty())
836  FlatModuleName += ".";
837  FlatModuleName += Piece.first->getName();
838  }
839  SourceLocation FirstPathLoc = ModuleImportPath[0].second;
840  ModuleImportPath.clear();
841  ModuleImportPath.push_back(
842  std::make_pair(getIdentifierInfo(FlatModuleName), FirstPathLoc));
843  }
844 
845  Module *Imported = nullptr;
846  if (getLangOpts().Modules) {
847  Imported = TheModuleLoader.loadModule(ModuleImportLoc,
848  ModuleImportPath,
850  /*IsIncludeDirective=*/false);
851  if (Imported)
852  makeModuleVisible(Imported, ModuleImportLoc);
853  }
854  if (Callbacks && (getLangOpts().Modules || getLangOpts().DebuggerSupport))
855  Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported);
856  }
857 }
858 
860  CurSubmoduleState->VisibleModules.setVisible(
861  M, Loc, [](Module *) {},
862  [&](ArrayRef<Module *> Path, Module *Conflict, StringRef Message) {
863  // FIXME: Include the path in the diagnostic.
864  // FIXME: Include the import location for the conflicting module.
865  Diag(ModuleImportLoc, diag::warn_module_conflict)
866  << Path[0]->getFullModuleName()
867  << Conflict->getFullModuleName()
868  << Message;
869  });
870 
871  // Add this module to the imports list of the currently-built submodule.
872  if (!BuildingSubmoduleStack.empty() && M != BuildingSubmoduleStack.back().M)
873  BuildingSubmoduleStack.back().M->Imports.insert(M);
874 }
875 
877  const char *DiagnosticTag,
878  bool AllowMacroExpansion) {
879  // We need at least one string literal.
880  if (Result.isNot(tok::string_literal)) {
881  Diag(Result, diag::err_expected_string_literal)
882  << /*Source='in...'*/0 << DiagnosticTag;
883  return false;
884  }
885 
886  // Lex string literal tokens, optionally with macro expansion.
887  SmallVector<Token, 4> StrToks;
888  do {
889  StrToks.push_back(Result);
890 
891  if (Result.hasUDSuffix())
892  Diag(Result, diag::err_invalid_string_udl);
893 
894  if (AllowMacroExpansion)
895  Lex(Result);
896  else
897  LexUnexpandedToken(Result);
898  } while (Result.is(tok::string_literal));
899 
900  // Concatenate and parse the strings.
901  StringLiteralParser Literal(StrToks, *this);
902  assert(Literal.isAscii() && "Didn't allow wide strings in");
903 
904  if (Literal.hadError)
905  return false;
906 
907  if (Literal.Pascal) {
908  Diag(StrToks[0].getLocation(), diag::err_expected_string_literal)
909  << /*Source='in...'*/0 << DiagnosticTag;
910  return false;
911  }
912 
913  String = Literal.GetString();
914  return true;
915 }
916 
918  assert(Tok.is(tok::numeric_constant));
919  SmallString<8> IntegerBuffer;
920  bool NumberInvalid = false;
921  StringRef Spelling = getSpelling(Tok, IntegerBuffer, &NumberInvalid);
922  if (NumberInvalid)
923  return false;
924  NumericLiteralParser Literal(Spelling, Tok.getLocation(), *this);
925  if (Literal.hadError || !Literal.isIntegerLiteral() || Literal.hasUDSuffix())
926  return false;
927  llvm::APInt APVal(64, 0);
928  if (Literal.GetIntegerValue(APVal))
929  return false;
930  Lex(Tok);
931  Value = APVal.getLimitedValue();
932  return true;
933 }
934 
936  assert(Handler && "NULL comment handler");
937  assert(std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler) ==
938  CommentHandlers.end() && "Comment handler already registered");
939  CommentHandlers.push_back(Handler);
940 }
941 
943  std::vector<CommentHandler *>::iterator Pos =
944  std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler);
945  assert(Pos != CommentHandlers.end() && "Comment handler not registered");
946  CommentHandlers.erase(Pos);
947 }
948 
950  bool AnyPendingTokens = false;
951  for (std::vector<CommentHandler *>::iterator H = CommentHandlers.begin(),
952  HEnd = CommentHandlers.end();
953  H != HEnd; ++H) {
954  if ((*H)->HandleComment(*this, Comment))
955  AnyPendingTokens = true;
956  }
957  if (!AnyPendingTokens || getCommentRetentionState())
958  return false;
959  Lex(result);
960  return true;
961 }
962 
963 ModuleLoader::~ModuleLoader() = default;
964 
966 
968 
970  if (Record)
971  return;
972 
973  Record = new PreprocessingRecord(getSourceManager());
974  addPPCallbacks(std::unique_ptr<PPCallbacks>(Record));
975 }
void AddKeywords(const LangOptions &LangOpts)
Populate the identifier table with info about the language keywords for the language specified by Lan...
void FinalizeForModelFile()
Cleanup after model file parsing.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Defines the clang::FileManager interface and associated types.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
Definition: Token.h:95
Defines the SourceManager interface.
Defines the clang::Module class, which describes a module in the source code.
Module * getCurrentModule()
Retrieves the module that we&#39;re currently building, if any.
Defines the FileSystemStatCache interface.
bool isLoadedFileID(FileID FID) const
Returns true if FID came from a PCH/Module.
void EndSourceFile()
Inform the preprocessor callbacks that processing is complete.
virtual void CodeCompleteNaturalLanguage()
Callback invoked when performing code completion in a part of the file where we expect natural langua...
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
Defines the clang::MacroInfo and clang::MacroDirective classes.
A description of the current definition of a macro.
Definition: MacroInfo.h:564
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
void LexAfterModuleImport(Token &Result)
Lex a token following the &#39;import&#39; contextual keyword.
void setFlag(TokenFlags Flag)
Set the specified flag.
Definition: Token.h:234
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
void setCodeCompletionIdentifierInfo(IdentifierInfo *Filter)
Set the code completion token for filtering purposes.
void setCodeCompletionReached()
Note that we hit the code-completion point.
void createPreprocessingRecord()
Create a new preprocessing record, which will keep track of all macro expansions, macro definitions...
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value)
Parses a simple integer literal to get its numeric value.
void setPTHManager(PTHManager *pm)
Manage memory buffers across multiple users.
tokens_iterator tokens_begin() const
Definition: MacroInfo.h:243
tok::TokenKind getKind() const
Definition: Token.h:90
bool isLiteral() const
Return true if this is a "literal", like a numeric constant, string, etc.
Definition: Token.h:113
void SetPoisonReason(IdentifierInfo *II, unsigned DiagID)
Specifies the reason for poisoning an identifier.
One of these records is kept for each identifier that is lexed.
Represents a macro directive exported by a module.
Definition: MacroInfo.h:488
void setRawIdentifierData(const char *Ptr)
Definition: Token.h:207
Definition: Format.h:2041
Preprocessor(std::shared_ptr< PreprocessorOptions > PPOpts, DiagnosticsEngine &diags, LangOptions &opts, SourceManager &SM, MemoryBufferCache &PCMCache, HeaderSearch &Headers, ModuleLoader &TheModuleLoader, IdentifierInfoLookup *IILookup=nullptr, bool OwnsHeaderSearch=false, TranslationUnitKind TUKind=TU_Complete)
void setTarget(const TargetInfo &Target)
Set the target information for the header search, if not already known.
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
void setKind(tok::TokenKind K)
Definition: Token.h:91
void removeCommentHandler(CommentHandler *Handler)
Remove the specified comment handler.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:815
Describes a module or submodule.
Definition: Module.h:65
bool SetCodeCompletionPoint(const FileEntry *File, unsigned Line, unsigned Column)
Specify the point at which code-completion will be performed.
virtual ~ModuleLoader()
llvm::Registry< PragmaHandler > PragmaHandlerRegistry
Registry of pragma handlers added by plugins.
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the &#39;spelling&#39; of the token at the given location; does not go up to the spelling location or ...
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:821
const Token & getReplacementToken(unsigned Tok) const
Definition: MacroInfo.h:236
bool hasUDSuffix() const
Return true if this token is a string or character literal which has a ud-suffix. ...
Definition: Token.h:291
const FormatToken & Tok
macro_iterator macro_begin(bool IncludeExternalMacros=true) const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void Initialize(const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
Initialize the preprocessor using information about the target.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
macro_iterator macro_end(bool IncludeExternalMacros=true) const
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
void recomputeCurLexerKind()
Recompute the current lexer kind based on the CurLexer/CurPTHLexer/ CurTokenLexer pointers...
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:148
void dump(const SourceManager &SM) const
Provides lookups to, and iteration over, IdentiferInfo objects.
bool isValid() const
Exposes information about the current target.
Definition: TargetInfo.h:54
IdentifierInfo * LookUpIdentifierInfo(Token &Identifier) const
Given a tok::raw_identifier token, look up the identifier information for the token and install it in...
Defines the clang::LangOptions interface.
void makeModuleVisible(Module *M, SourceLocation Loc)
SourceLocation getLocation() const
Definition: MacroInfo.h:462
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
const AnnotatedLine * Line
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
virtual void ReadDefinedMacros()=0
Read the set of macros defined by this external macro source.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
Definition: MacroArgs.h:30
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:124
Defines the clang::Preprocessor interface.
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
static bool MacroDefinitionEquals(const MacroInfo *MI, ArrayRef< TokenValue > Tokens)
Compares macro tokens with a specified token value sequence.
size_t getTotalMemory() const
bool getCommentRetentionState() const
Definition: Preprocessor.h:859
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
SourceLocation createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLength, int LoadedID=0, unsigned LoadedOffset=0)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
bool isObjectLike() const
Definition: MacroInfo.h:201
void IncrementIncludeCount(const FileEntry *File)
Increment the count for the number of times the specified FileEntry has been entered.
Definition: HeaderSearch.h:455
The result type of a method or function.
StringRef GetString() const
Module * lookupModule(StringRef ModuleName, bool AllowSearch=true)
Lookup a module Search for a module with the given name.
const SourceManager & SM
Definition: Format.cpp:1422
SourceManager & getSourceManager() const
Definition: Preprocessor.h:819
void DumpMacro(const MacroInfo &MI) const
void overrideFileContents(const FileEntry *SourceFile, llvm::MemoryBuffer *Buffer, bool DoNotFree)
Override the contents of the given source file by providing an already-allocated buffer.
ExternalPreprocessorSource * getExternalSource() const
Definition: Preprocessor.h:837
bool isExpandDisabled() const
Return true if this identifier token should never be expanded in the future, due to C99 6...
Definition: Token.h:274
void addStatCache(std::unique_ptr< FileSystemStatCache > statCache, bool AtBeginning=false)
Installs the provided FileSystemStatCache object within the FileManager.
Definition: FileManager.cpp:66
Encodes a location in the source.
void setLength(unsigned Len)
Definition: Token.h:133
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
Definition: Preprocessor.h:944
All of the names in this module are hidden.
Definition: Module.h:269
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:177
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:59
void setIdentifierInfo(IdentifierInfo *II)
Definition: Token.h:186
void Lex(Token &Result)
Lex the next token for this preprocessor.
llvm::MemoryBuffer * getMemoryBufferForFile(const FileEntry *File, bool *Invalid=nullptr)
Retrieve the memory buffer associated with the given file.
bool isPoisoned() const
Return true if this token has been poisoned.
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
Definition: Token.h:266
void expandUCNs(SmallVectorImpl< char > &Buf, StringRef Input)
Copy characters from Input to Buf, expanding any UCNs.
void DumpToken(const Token &Tok, bool DumpFlags=false) const
Print the token to stderr, used for debugging.
StringRef getName() const
Return the actual identifier string.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isNot(tok::TokenKind K) const
Definition: Token.h:96
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
Definition: MacroInfo.h:234
static diag::kind getFutureCompatDiagKind(const IdentifierInfo &II, const LangOptions &LangOpts)
Returns a diagnostic message kind for reporting a future keyword as appropriate for the identifier an...
void addCommentHandler(CommentHandler *Handler)
Add the specified comment handler to the preprocessor.
FileID getMainFileID() const
Returns the FileID of the main source file.
virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective)=0
Attempt to load the given module.
void CodeCompleteNaturalLanguage()
Hook used by the lexer to invoke the "natural language" code completion point.
Abstract interface for a module loader.
Definition: ModuleLoader.h:74
unsigned getLength() const
Definition: Token.h:127
void PoisonSEHIdentifiers(bool Poison=true)
void setLiteralData(const char *Ptr)
Definition: Token.h:219
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:40
PragmaNamespace - This PragmaHandler subdivides the namespace of pragmas, allowing hierarchical pragm...
Definition: Pragma.h:90
bool HandleIdentifier(Token &Identifier)
Callback invoked when the lexer reads an identifier and has filled in the tokens IdentifierInfo membe...
bool FinishLexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
Complete the lexing of a string literal where the first token has already been lexed (see LexStringLi...
void setConditionalLevels(ArrayRef< PPConditionalInfo > CL)
virtual void updateOutOfDateIdentifier(IdentifierInfo &II)=0
Update an out-of-date identifier.
void CreateString(StringRef Str, Token &Tok, SourceLocation ExpansionLocStart=SourceLocation(), SourceLocation ExpansionLocEnd=SourceLocation())
Plop the specified string into a scratch buffer and set the specified token&#39;s location and length to ...
void InitializeForModelFile()
Initialize the preprocessor to parse a model file.
void HandlePoisonedIdentifier(Token &Tok)
Display reason for poisoned identifier.
#define CXX11_KEYWORD(NAME, FLAGS)
bool HandleComment(Token &Token, SourceRange Comment)
Defines the clang::SourceLocation class and associated facilities.
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode), returns a reference to the text substring in the buffer if known.
Definition: Token.h:203
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:298
void DumpLocation(SourceLocation Loc) const
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:61
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
Definition: TokenKinds.cpp:25
Defines the clang::TargetInfo interface.
bool needsCleaning() const
Return true if this token has trigraphs or escaped newlines in it.
Definition: Token.h:283
NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber...
MacroMap::const_iterator macro_iterator
Abstract base class that describes a handler that will receive source ranges for each of the comments...
void setLocation(SourceLocation L)
Definition: Token.h:132
#define true
Definition: stdbool.h:32
A trivial tuple used to represent a source range.
bool hasUCN() const
Returns true if this token contains a universal character name.
Definition: Token.h:294
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
Defines the PreprocessorLexer interface.
ScratchBuffer - This class exposes a simple interface for the dynamic construction of tokens...
Definition: ScratchBuffer.h:25
void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget)
Perform target-specific initialization.
Definition: Builtins.cpp:43
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
Definition: Token.h:270
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
Definition: Preprocessor.h:912
This class handles loading and caching of source files into memory.
bool EnterSourceFile(FileID CurFileID, const DirectoryLookup *Dir, SourceLocation Loc)
Add a source file to the top of the include stack and start lexing tokens from it instead of the curr...