clang  16.0.0git
PPLexerChange.cpp
Go to the documentation of this file.
1 //===--- PPLexerChange.cpp - Handle changing lexers in the preprocessor ---===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements pieces of the Preprocessor interface that manage the
10 // current lexer stack.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "clang/Lex/HeaderSearch.h"
18 #include "clang/Lex/MacroInfo.h"
19 #include "clang/Lex/Preprocessor.h"
21 #include "llvm/ADT/StringSwitch.h"
22 #include "llvm/Support/FileSystem.h"
23 #include "llvm/Support/MemoryBufferRef.h"
24 #include "llvm/Support/Path.h"
25 
26 using namespace clang;
27 
28 //===----------------------------------------------------------------------===//
29 // Miscellaneous Methods.
30 //===----------------------------------------------------------------------===//
31 
32 /// isInPrimaryFile - Return true if we're in the top-level file, not in a
33 /// \#include. This looks through macro expansions and active _Pragma lexers.
35  if (IsFileLexer())
36  return IncludeMacroStack.empty();
37 
38  // If there are any stacked lexers, we're in a #include.
39  assert(IsFileLexer(IncludeMacroStack[0]) &&
40  "Top level include stack isn't our primary lexer?");
41  return llvm::none_of(
42  llvm::drop_begin(IncludeMacroStack),
43  [&](const IncludeStackInfo &ISI) -> bool { return IsFileLexer(ISI); });
44 }
45 
46 /// getCurrentLexer - Return the current file lexer being lexed from. Note
47 /// that this ignores any potentially active macro expansions and _Pragma
48 /// expansions going on at the time.
50  if (IsFileLexer())
51  return CurPPLexer;
52 
53  // Look for a stacked lexer.
54  for (const IncludeStackInfo &ISI : llvm::reverse(IncludeMacroStack)) {
55  if (IsFileLexer(ISI))
56  return ISI.ThePPLexer;
57  }
58  return nullptr;
59 }
60 
61 
62 //===----------------------------------------------------------------------===//
63 // Methods for Entering and Callbacks for leaving various contexts
64 //===----------------------------------------------------------------------===//
65 
66 /// EnterSourceFile - Add a source file to the top of the include stack and
67 /// start lexing tokens from it instead of the current buffer.
69  SourceLocation Loc,
70  bool IsFirstIncludeOfFile) {
71  assert(!CurTokenLexer && "Cannot #include a file inside a macro!");
72  ++NumEnteredSourceFiles;
73 
74  if (MaxIncludeStackDepth < IncludeMacroStack.size())
75  MaxIncludeStackDepth = IncludeMacroStack.size();
76 
77  // Get the MemoryBuffer for this FID, if it fails, we fail.
80  if (!InputFile) {
81  SourceLocation FileStart = SourceMgr.getLocForStartOfFile(FID);
82  Diag(Loc, diag::err_pp_error_opening_file)
83  << std::string(SourceMgr.getBufferName(FileStart)) << "";
84  return true;
85  }
86 
88  SourceMgr.getFileEntryForID(FID) == CodeCompletionFile) {
89  CodeCompletionFileLoc = SourceMgr.getLocForStartOfFile(FID);
90  CodeCompletionLoc =
91  CodeCompletionFileLoc.getLocWithOffset(CodeCompletionOffset);
92  }
93 
94  Lexer *TheLexer = new Lexer(FID, *InputFile, *this, IsFirstIncludeOfFile);
95  if (getPreprocessorOpts().DependencyDirectivesForFile &&
96  FID != PredefinesFileID) {
97  if (Optional<FileEntryRef> File = SourceMgr.getFileEntryRefForID(FID)) {
99  DepDirectives =
100  getPreprocessorOpts().DependencyDirectivesForFile(*File)) {
101  TheLexer->DepDirectives = *DepDirectives;
102  }
103  }
104  }
105 
106  EnterSourceFileWithLexer(TheLexer, CurDir);
107  return false;
108 }
109 
110 /// EnterSourceFileWithLexer - Add a source file to the top of the include stack
111 /// and start lexing tokens from it instead of the current buffer.
112 void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
113  ConstSearchDirIterator CurDir) {
114  PreprocessorLexer *PrevPPLexer = CurPPLexer;
115 
116  // Add the current lexer to the include stack.
117  if (CurPPLexer || CurTokenLexer)
118  PushIncludeMacroStack();
119 
120  CurLexer.reset(TheLexer);
121  CurPPLexer = TheLexer;
122  CurDirLookup = CurDir;
123  CurLexerSubmodule = nullptr;
124  if (CurLexerKind != CLK_LexAfterModuleImport)
125  CurLexerKind = TheLexer->isDependencyDirectivesLexer()
126  ? CLK_DependencyDirectivesLexer
127  : CLK_Lexer;
128 
129  // Notify the client, if desired, that we are in a new source file.
130  if (Callbacks && !CurLexer->Is_PragmaLexer) {
131  SrcMgr::CharacteristicKind FileType =
132  SourceMgr.getFileCharacteristic(CurLexer->getFileLoc());
133 
134  FileID PrevFID;
135  SourceLocation EnterLoc;
136  if (PrevPPLexer) {
137  PrevFID = PrevPPLexer->getFileID();
138  EnterLoc = PrevPPLexer->getSourceLocation();
139  }
140  Callbacks->FileChanged(CurLexer->getFileLoc(), PPCallbacks::EnterFile,
141  FileType, PrevFID);
142  Callbacks->LexedFileChanged(CurLexer->getFileID(),
144  FileType, PrevFID, EnterLoc);
145  }
146 }
147 
148 /// EnterMacro - Add a Macro to the top of the include stack and start lexing
149 /// tokens from it instead of the current buffer.
151  MacroInfo *Macro, MacroArgs *Args) {
152  std::unique_ptr<TokenLexer> TokLexer;
153  if (NumCachedTokenLexers == 0) {
154  TokLexer = std::make_unique<TokenLexer>(Tok, ILEnd, Macro, Args, *this);
155  } else {
156  TokLexer = std::move(TokenLexerCache[--NumCachedTokenLexers]);
157  TokLexer->Init(Tok, ILEnd, Macro, Args);
158  }
159 
160  PushIncludeMacroStack();
161  CurDirLookup = nullptr;
162  CurTokenLexer = std::move(TokLexer);
163  if (CurLexerKind != CLK_LexAfterModuleImport)
164  CurLexerKind = CLK_TokenLexer;
165 }
166 
167 /// EnterTokenStream - Add a "macro" context to the top of the include stack,
168 /// which will cause the lexer to start returning the specified tokens.
169 ///
170 /// If DisableMacroExpansion is true, tokens lexed from the token stream will
171 /// not be subject to further macro expansion. Otherwise, these tokens will
172 /// be re-macro-expanded when/if expansion is enabled.
173 ///
174 /// If OwnsTokens is false, this method assumes that the specified stream of
175 /// tokens has a permanent owner somewhere, so they do not need to be copied.
176 /// If it is true, it assumes the array of tokens is allocated with new[] and
177 /// must be freed.
178 ///
179 void Preprocessor::EnterTokenStream(const Token *Toks, unsigned NumToks,
180  bool DisableMacroExpansion, bool OwnsTokens,
181  bool IsReinject) {
182  if (CurLexerKind == CLK_CachingLexer) {
183  if (CachedLexPos < CachedTokens.size()) {
184  assert(IsReinject && "new tokens in the middle of cached stream");
185  // We're entering tokens into the middle of our cached token stream. We
186  // can't represent that, so just insert the tokens into the buffer.
187  CachedTokens.insert(CachedTokens.begin() + CachedLexPos,
188  Toks, Toks + NumToks);
189  if (OwnsTokens)
190  delete [] Toks;
191  return;
192  }
193 
194  // New tokens are at the end of the cached token sequnece; insert the
195  // token stream underneath the caching lexer.
196  ExitCachingLexMode();
197  EnterTokenStream(Toks, NumToks, DisableMacroExpansion, OwnsTokens,
198  IsReinject);
199  EnterCachingLexMode();
200  return;
201  }
202 
203  // Create a macro expander to expand from the specified token stream.
204  std::unique_ptr<TokenLexer> TokLexer;
205  if (NumCachedTokenLexers == 0) {
206  TokLexer = std::make_unique<TokenLexer>(
207  Toks, NumToks, DisableMacroExpansion, OwnsTokens, IsReinject, *this);
208  } else {
209  TokLexer = std::move(TokenLexerCache[--NumCachedTokenLexers]);
210  TokLexer->Init(Toks, NumToks, DisableMacroExpansion, OwnsTokens,
211  IsReinject);
212  }
213 
214  // Save our current state.
215  PushIncludeMacroStack();
216  CurDirLookup = nullptr;
217  CurTokenLexer = std::move(TokLexer);
218  if (CurLexerKind != CLK_LexAfterModuleImport)
219  CurLexerKind = CLK_TokenLexer;
220 }
221 
222 /// Compute the relative path that names the given file relative to
223 /// the given directory.
224 static void computeRelativePath(FileManager &FM, const DirectoryEntry *Dir,
225  const FileEntry *File,
226  SmallString<128> &Result) {
227  Result.clear();
228 
229  StringRef FilePath = File->getDir()->getName();
230  StringRef Path = FilePath;
231  while (!Path.empty()) {
232  if (auto CurDir = FM.getDirectory(Path)) {
233  if (*CurDir == Dir) {
234  Result = FilePath.substr(Path.size());
235  llvm::sys::path::append(Result,
236  llvm::sys::path::filename(File->getName()));
237  return;
238  }
239  }
240 
241  Path = llvm::sys::path::parent_path(Path);
242  }
243 
244  Result = File->getName();
245 }
246 
247 void Preprocessor::PropagateLineStartLeadingSpaceInfo(Token &Result) {
248  if (CurTokenLexer) {
249  CurTokenLexer->PropagateLineStartLeadingSpaceInfo(Result);
250  return;
251  }
252  if (CurLexer) {
253  CurLexer->PropagateLineStartLeadingSpaceInfo(Result);
254  return;
255  }
256  // FIXME: Handle other kinds of lexers? It generally shouldn't matter,
257  // but it might if they're empty?
258 }
259 
260 /// Determine the location to use as the end of the buffer for a lexer.
261 ///
262 /// If the file ends with a newline, form the EOF token on the newline itself,
263 /// rather than "on the line following it", which doesn't exist. This makes
264 /// diagnostics relating to the end of file include the last file that the user
265 /// actually typed, which is goodness.
266 const char *Preprocessor::getCurLexerEndPos() {
267  const char *EndPos = CurLexer->BufferEnd;
268  if (EndPos != CurLexer->BufferStart &&
269  (EndPos[-1] == '\n' || EndPos[-1] == '\r')) {
270  --EndPos;
271 
272  // Handle \n\r and \r\n:
273  if (EndPos != CurLexer->BufferStart &&
274  (EndPos[-1] == '\n' || EndPos[-1] == '\r') &&
275  EndPos[-1] != EndPos[0])
276  --EndPos;
277  }
278 
279  return EndPos;
280 }
281 
283  const Module &Mod, SmallVectorImpl<const Module *> &SubMods) {
284  if (Mod.getUmbrellaHeader())
285  SubMods.push_back(&Mod);
286  for (auto *M : Mod.submodules())
288 }
289 
290 void Preprocessor::diagnoseMissingHeaderInUmbrellaDir(const Module &Mod) {
291  const Module::Header &UmbrellaHeader = Mod.getUmbrellaHeader();
292  assert(UmbrellaHeader.Entry && "Module must use umbrella header");
293  const FileID &File = SourceMgr.translateFile(UmbrellaHeader.Entry);
294  SourceLocation ExpectedHeadersLoc = SourceMgr.getLocForEndOfFile(File);
295  if (getDiagnostics().isIgnored(diag::warn_uncovered_module_header,
296  ExpectedHeadersLoc))
297  return;
298 
300  const DirectoryEntry *Dir = Mod.getUmbrellaDir().Entry;
301  llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
302  std::error_code EC;
303  for (llvm::vfs::recursive_directory_iterator Entry(FS, Dir->getName(), EC),
304  End;
305  Entry != End && !EC; Entry.increment(EC)) {
306  using llvm::StringSwitch;
307 
308  // Check whether this entry has an extension typically associated with
309  // headers.
310  if (!StringSwitch<bool>(llvm::sys::path::extension(Entry->path()))
311  .Cases(".h", ".H", ".hh", ".hpp", true)
312  .Default(false))
313  continue;
314 
315  if (auto Header = getFileManager().getFile(Entry->path()))
316  if (!getSourceManager().hasFileInfo(*Header)) {
317  if (!ModMap.isHeaderInUnavailableModule(*Header)) {
318  // Find the relative path that would access this header.
319  SmallString<128> RelativePath;
320  computeRelativePath(FileMgr, Dir, *Header, RelativePath);
321  Diag(ExpectedHeadersLoc, diag::warn_uncovered_module_header)
322  << Mod.getFullModuleName() << RelativePath;
323  }
324  }
325  }
326 }
327 
328 /// HandleEndOfFile - This callback is invoked when the lexer hits the end of
329 /// the current file. This either returns the EOF token or pops a level off
330 /// the include stack and keeps going.
331 bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
332  assert(!CurTokenLexer &&
333  "Ending a file when currently in a macro!");
334 
335  // If we have an unclosed module region from a pragma at the end of a
336  // module, complain and close it now.
337  const bool LeavingSubmodule = CurLexer && CurLexerSubmodule;
338  if ((LeavingSubmodule || IncludeMacroStack.empty()) &&
339  !BuildingSubmoduleStack.empty() &&
340  BuildingSubmoduleStack.back().IsPragma) {
341  Diag(BuildingSubmoduleStack.back().ImportLoc,
342  diag::err_pp_module_begin_without_module_end);
343  Module *M = LeaveSubmodule(/*ForPragma*/true);
344 
345  Result.startToken();
346  const char *EndPos = getCurLexerEndPos();
347  CurLexer->BufferPtr = EndPos;
348  CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_module_end);
349  Result.setAnnotationEndLoc(Result.getLocation());
350  Result.setAnnotationValue(M);
351  return true;
352  }
353 
354  // See if this file had a controlling macro.
355  if (CurPPLexer) { // Not ending a macro, ignore it.
356  if (const IdentifierInfo *ControllingMacro =
357  CurPPLexer->MIOpt.GetControllingMacroAtEndOfFile()) {
358  // Okay, this has a controlling macro, remember in HeaderFileInfo.
359  if (const FileEntry *FE = CurPPLexer->getFileEntry()) {
360  HeaderInfo.SetFileControllingMacro(FE, ControllingMacro);
361  if (MacroInfo *MI =
362  getMacroInfo(const_cast<IdentifierInfo*>(ControllingMacro)))
363  MI->setUsedForHeaderGuard(true);
364  if (const IdentifierInfo *DefinedMacro =
365  CurPPLexer->MIOpt.GetDefinedMacro()) {
366  if (!isMacroDefined(ControllingMacro) &&
367  DefinedMacro != ControllingMacro &&
368  CurLexer->isFirstTimeLexingFile()) {
369 
370  // If the edit distance between the two macros is more than 50%,
371  // DefinedMacro may not be header guard, or can be header guard of
372  // another header file. Therefore, it maybe defining something
373  // completely different. This can be observed in the wild when
374  // handling feature macros or header guards in different files.
375 
376  const StringRef ControllingMacroName = ControllingMacro->getName();
377  const StringRef DefinedMacroName = DefinedMacro->getName();
378  const size_t MaxHalfLength = std::max(ControllingMacroName.size(),
379  DefinedMacroName.size()) / 2;
380  const unsigned ED = ControllingMacroName.edit_distance(
381  DefinedMacroName, true, MaxHalfLength);
382  if (ED <= MaxHalfLength) {
383  // Emit a warning for a bad header guard.
384  Diag(CurPPLexer->MIOpt.GetMacroLocation(),
385  diag::warn_header_guard)
386  << CurPPLexer->MIOpt.GetMacroLocation() << ControllingMacro;
387  Diag(CurPPLexer->MIOpt.GetDefinedLocation(),
388  diag::note_header_guard)
389  << CurPPLexer->MIOpt.GetDefinedLocation() << DefinedMacro
390  << ControllingMacro
392  CurPPLexer->MIOpt.GetDefinedLocation(),
393  ControllingMacro->getName());
394  }
395  }
396  }
397  }
398  }
399  }
400 
401  // Complain about reaching a true EOF within arc_cf_code_audited.
402  // We don't want to complain about reaching the end of a macro
403  // instantiation or a _Pragma.
404  if (PragmaARCCFCodeAuditedInfo.second.isValid() && !isEndOfMacro &&
405  !(CurLexer && CurLexer->Is_PragmaLexer)) {
406  Diag(PragmaARCCFCodeAuditedInfo.second,
407  diag::err_pp_eof_in_arc_cf_code_audited);
408 
409  // Recover by leaving immediately.
410  PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()};
411  }
412 
413  // Complain about reaching a true EOF within assume_nonnull.
414  // We don't want to complain about reaching the end of a macro
415  // instantiation or a _Pragma.
416  if (PragmaAssumeNonNullLoc.isValid() &&
417  !isEndOfMacro && !(CurLexer && CurLexer->Is_PragmaLexer)) {
418  // If we're at the end of generating a preamble, we should record the
419  // unterminated \#pragma clang assume_nonnull so we can restore it later
420  // when the preamble is loaded into the main file.
422  PreambleRecordedPragmaAssumeNonNullLoc = PragmaAssumeNonNullLoc;
423  else
424  Diag(PragmaAssumeNonNullLoc, diag::err_pp_eof_in_assume_nonnull);
425  // Recover by leaving immediately.
426  PragmaAssumeNonNullLoc = SourceLocation();
427  }
428 
429  bool LeavingPCHThroughHeader = false;
430 
431  // If this is a #include'd file, pop it off the include stack and continue
432  // lexing the #includer file.
433  if (!IncludeMacroStack.empty()) {
434 
435  // If we lexed the code-completion file, act as if we reached EOF.
436  if (isCodeCompletionEnabled() && CurPPLexer &&
437  SourceMgr.getLocForStartOfFile(CurPPLexer->getFileID()) ==
438  CodeCompletionFileLoc) {
439  assert(CurLexer && "Got EOF but no current lexer set!");
440  Result.startToken();
441  CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
442  CurLexer.reset();
443 
444  CurPPLexer = nullptr;
446  return true;
447  }
448 
449  if (!isEndOfMacro && CurPPLexer &&
450  (SourceMgr.getIncludeLoc(CurPPLexer->getFileID()).isValid() ||
451  // Predefines file doesn't have a valid include location.
452  (PredefinesFileID.isValid() &&
453  CurPPLexer->getFileID() == PredefinesFileID))) {
454  // Notify SourceManager to record the number of FileIDs that were created
455  // during lexing of the #include'd file.
456  unsigned NumFIDs =
457  SourceMgr.local_sloc_entry_size() -
458  CurPPLexer->getInitialNumSLocEntries() + 1/*#include'd file*/;
459  SourceMgr.setNumCreatedFIDsForFileID(CurPPLexer->getFileID(), NumFIDs);
460  }
461 
462  bool ExitedFromPredefinesFile = false;
463  FileID ExitedFID;
464  if (!isEndOfMacro && CurPPLexer) {
465  ExitedFID = CurPPLexer->getFileID();
466 
467  assert(PredefinesFileID.isValid() &&
468  "HandleEndOfFile is called before PredefinesFileId is set");
469  ExitedFromPredefinesFile = (PredefinesFileID == ExitedFID);
470  }
471 
472  if (LeavingSubmodule) {
473  // We're done with this submodule.
474  Module *M = LeaveSubmodule(/*ForPragma*/false);
475 
476  // Notify the parser that we've left the module.
477  const char *EndPos = getCurLexerEndPos();
478  Result.startToken();
479  CurLexer->BufferPtr = EndPos;
480  CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_module_end);
481  Result.setAnnotationEndLoc(Result.getLocation());
482  Result.setAnnotationValue(M);
483  }
484 
485  bool FoundPCHThroughHeader = false;
486  if (CurPPLexer && creatingPCHWithThroughHeader() &&
488  SourceMgr.getFileEntryForID(CurPPLexer->getFileID())))
489  FoundPCHThroughHeader = true;
490 
491  // We're done with the #included file.
493 
494  // Propagate info about start-of-line/leading white-space/etc.
495  PropagateLineStartLeadingSpaceInfo(Result);
496 
497  // Notify the client, if desired, that we are in a new source file.
498  if (Callbacks && !isEndOfMacro && CurPPLexer) {
499  SourceLocation Loc = CurPPLexer->getSourceLocation();
500  SrcMgr::CharacteristicKind FileType =
501  SourceMgr.getFileCharacteristic(Loc);
502  Callbacks->FileChanged(Loc, PPCallbacks::ExitFile, FileType, ExitedFID);
503  Callbacks->LexedFileChanged(CurPPLexer->getFileID(),
505  FileType, ExitedFID, Loc);
506  }
507 
508  // Restore conditional stack as well as the recorded
509  // \#pragma clang assume_nonnull from the preamble right after exiting
510  // from the predefines file.
511  if (ExitedFromPredefinesFile) {
512  replayPreambleConditionalStack();
513  if (PreambleRecordedPragmaAssumeNonNullLoc.isValid())
514  PragmaAssumeNonNullLoc = PreambleRecordedPragmaAssumeNonNullLoc;
515  }
516 
517  if (!isEndOfMacro && CurPPLexer && FoundPCHThroughHeader &&
518  (isInPrimaryFile() ||
519  CurPPLexer->getFileID() == getPredefinesFileID())) {
520  // Leaving the through header. Continue directly to end of main file
521  // processing.
522  LeavingPCHThroughHeader = true;
523  } else {
524  // Client should lex another token unless we generated an EOM.
525  return LeavingSubmodule;
526  }
527  }
528 
529  // If this is the end of the main file, form an EOF token.
530  assert(CurLexer && "Got EOF but no current lexer set!");
531  const char *EndPos = getCurLexerEndPos();
532  Result.startToken();
533  CurLexer->BufferPtr = EndPos;
534  CurLexer->FormTokenWithChars(Result, EndPos, tok::eof);
535 
536  if (isCodeCompletionEnabled()) {
537  // Inserting the code-completion point increases the source buffer by 1,
538  // but the main FileID was created before inserting the point.
539  // Compensate by reducing the EOF location by 1, otherwise the location
540  // will point to the next FileID.
541  // FIXME: This is hacky, the code-completion point should probably be
542  // inserted before the main FileID is created.
543  if (CurLexer->getFileLoc() == CodeCompletionFileLoc)
544  Result.setLocation(Result.getLocation().getLocWithOffset(-1));
545  }
546 
547  if (creatingPCHWithThroughHeader() && !LeavingPCHThroughHeader) {
548  // Reached the end of the compilation without finding the through header.
549  Diag(CurLexer->getFileLoc(), diag::err_pp_through_header_not_seen)
550  << PPOpts->PCHThroughHeader << 0;
551  }
552 
554  // We're done with lexing.
555  CurLexer.reset();
556 
558  CurPPLexer = nullptr;
559 
560  if (TUKind == TU_Complete) {
561  // This is the end of the top-level file. 'WarnUnusedMacroLocs' has
562  // collected all macro locations that we need to warn because they are not
563  // used.
564  for (WarnUnusedMacroLocsTy::iterator
565  I=WarnUnusedMacroLocs.begin(), E=WarnUnusedMacroLocs.end();
566  I!=E; ++I)
567  Diag(*I, diag::pp_macro_not_used);
568  }
569 
570  // If we are building a module that has an umbrella header, make sure that
571  // each of the headers within the directory, including all submodules, is
572  // covered by the umbrella header was actually included by the umbrella
573  // header.
574  if (Module *Mod = getCurrentModule()) {
577  for (auto *M : AllMods)
578  diagnoseMissingHeaderInUmbrellaDir(*M);
579  }
580 
581  return true;
582 }
583 
584 /// HandleEndOfTokenLexer - This callback is invoked when the current TokenLexer
585 /// hits the end of its token stream.
587  assert(CurTokenLexer && !CurPPLexer &&
588  "Ending a macro when currently in a #include file!");
589 
590  if (!MacroExpandingLexersStack.empty() &&
591  MacroExpandingLexersStack.back().first == CurTokenLexer.get())
592  removeCachedMacroExpandedTokensOfLastLexer();
593 
594  // Delete or cache the now-dead macro expander.
595  if (NumCachedTokenLexers == TokenLexerCacheSize)
596  CurTokenLexer.reset();
597  else
598  TokenLexerCache[NumCachedTokenLexers++] = std::move(CurTokenLexer);
599 
600  // Handle this like a #include file being popped off the stack.
601  return HandleEndOfFile(Result, true);
602 }
603 
604 /// RemoveTopOfLexerStack - Pop the current lexer/macro exp off the top of the
605 /// lexer stack. This should only be used in situations where the current
606 /// state of the top-of-stack lexer is unknown.
608  assert(!IncludeMacroStack.empty() && "Ran out of stack entries to load");
609 
610  if (CurTokenLexer) {
611  // Delete or cache the now-dead macro expander.
612  if (NumCachedTokenLexers == TokenLexerCacheSize)
613  CurTokenLexer.reset();
614  else
615  TokenLexerCache[NumCachedTokenLexers++] = std::move(CurTokenLexer);
616  }
617 
618  PopIncludeMacroStack();
619 }
620 
621 /// HandleMicrosoftCommentPaste - When the macro expander pastes together a
622 /// comment (/##/) in microsoft mode, this method handles updating the current
623 /// state, returning the token on the next source line.
625  assert(CurTokenLexer && !CurPPLexer &&
626  "Pasted comment can only be formed from macro");
627  // We handle this by scanning for the closest real lexer, switching it to
628  // raw mode and preprocessor mode. This will cause it to return \n as an
629  // explicit EOD token.
630  PreprocessorLexer *FoundLexer = nullptr;
631  bool LexerWasInPPMode = false;
632  for (const IncludeStackInfo &ISI : llvm::reverse(IncludeMacroStack)) {
633  if (ISI.ThePPLexer == nullptr) continue; // Scan for a real lexer.
634 
635  // Once we find a real lexer, mark it as raw mode (disabling macro
636  // expansions) and preprocessor mode (return EOD). We know that the lexer
637  // was *not* in raw mode before, because the macro that the comment came
638  // from was expanded. However, it could have already been in preprocessor
639  // mode (#if COMMENT) in which case we have to return it to that mode and
640  // return EOD.
641  FoundLexer = ISI.ThePPLexer;
642  FoundLexer->LexingRawMode = true;
643  LexerWasInPPMode = FoundLexer->ParsingPreprocessorDirective;
644  FoundLexer->ParsingPreprocessorDirective = true;
645  break;
646  }
647 
648  // Okay, we either found and switched over the lexer, or we didn't find a
649  // lexer. In either case, finish off the macro the comment came from, getting
650  // the next token.
651  if (!HandleEndOfTokenLexer(Tok)) Lex(Tok);
652 
653  // Discarding comments as long as we don't have EOF or EOD. This 'comments
654  // out' the rest of the line, including any tokens that came from other macros
655  // that were active, as in:
656  // #define submacro a COMMENT b
657  // submacro c
658  // which should lex to 'a' only: 'b' and 'c' should be removed.
659  while (Tok.isNot(tok::eod) && Tok.isNot(tok::eof))
660  Lex(Tok);
661 
662  // If we got an eod token, then we successfully found the end of the line.
663  if (Tok.is(tok::eod)) {
664  assert(FoundLexer && "Can't get end of line without an active lexer");
665  // Restore the lexer back to normal mode instead of raw mode.
666  FoundLexer->LexingRawMode = false;
667 
668  // If the lexer was already in preprocessor mode, just return the EOD token
669  // to finish the preprocessor line.
670  if (LexerWasInPPMode) return;
671 
672  // Otherwise, switch out of PP mode and return the next lexed token.
673  FoundLexer->ParsingPreprocessorDirective = false;
674  return Lex(Tok);
675  }
676 
677  // If we got an EOF token, then we reached the end of the token stream but
678  // didn't find an explicit \n. This can only happen if there was no lexer
679  // active (an active lexer would return EOD at EOF if there was no \n in
680  // preprocessor directive mode), so just return EOF as our token.
681  assert(!FoundLexer && "Lexer should return EOD before EOF in PP mode");
682 }
683 
685  bool ForPragma) {
686  if (!getLangOpts().ModulesLocalVisibility) {
687  // Just track that we entered this submodule.
688  BuildingSubmoduleStack.push_back(
689  BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
690  PendingModuleMacroNames.size()));
691  if (Callbacks)
692  Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma);
693  return;
694  }
695 
696  // Resolve as much of the module definition as we can now, before we enter
697  // one of its headers.
698  // FIXME: Can we enable Complain here?
699  // FIXME: Can we do this when local visibility is disabled?
701  ModMap.resolveExports(M, /*Complain=*/false);
702  ModMap.resolveUses(M, /*Complain=*/false);
703  ModMap.resolveConflicts(M, /*Complain=*/false);
704 
705  // If this is the first time we've entered this module, set up its state.
706  auto R = Submodules.insert(std::make_pair(M, SubmoduleState()));
707  auto &State = R.first->second;
708  bool FirstTime = R.second;
709  if (FirstTime) {
710  // Determine the set of starting macros for this submodule; take these
711  // from the "null" module (the predefines buffer).
712  //
713  // FIXME: If we have local visibility but not modules enabled, the
714  // NullSubmoduleState is polluted by #defines in the top-level source
715  // file.
716  auto &StartingMacros = NullSubmoduleState.Macros;
717 
718  // Restore to the starting state.
719  // FIXME: Do this lazily, when each macro name is first referenced.
720  for (auto &Macro : StartingMacros) {
721  // Skip uninteresting macros.
722  if (!Macro.second.getLatest() &&
723  Macro.second.getOverriddenMacros().empty())
724  continue;
725 
726  MacroState MS(Macro.second.getLatest());
727  MS.setOverriddenMacros(*this, Macro.second.getOverriddenMacros());
728  State.Macros.insert(std::make_pair(Macro.first, std::move(MS)));
729  }
730  }
731 
732  // Track that we entered this module.
733  BuildingSubmoduleStack.push_back(
734  BuildingSubmoduleInfo(M, ImportLoc, ForPragma, CurSubmoduleState,
735  PendingModuleMacroNames.size()));
736 
737  if (Callbacks)
738  Callbacks->EnteredSubmodule(M, ImportLoc, ForPragma);
739 
740  // Switch to this submodule as the current submodule.
741  CurSubmoduleState = &State;
742 
743  // This module is visible to itself.
744  if (FirstTime)
745  makeModuleVisible(M, ImportLoc);
746 }
747 
748 bool Preprocessor::needModuleMacros() const {
749  // If we're not within a submodule, we never need to create ModuleMacros.
750  if (BuildingSubmoduleStack.empty())
751  return false;
752  // If we are tracking module macro visibility even for textually-included
753  // headers, we need ModuleMacros.
754  if (getLangOpts().ModulesLocalVisibility)
755  return true;
756  // Otherwise, we only need module macros if we're actually compiling a module
757  // interface.
758  return getLangOpts().isCompilingModule();
759 }
760 
762  if (BuildingSubmoduleStack.empty() ||
763  BuildingSubmoduleStack.back().IsPragma != ForPragma) {
764  assert(ForPragma && "non-pragma module enter/leave mismatch");
765  return nullptr;
766  }
767 
768  auto &Info = BuildingSubmoduleStack.back();
769 
770  Module *LeavingMod = Info.M;
771  SourceLocation ImportLoc = Info.ImportLoc;
772 
773  if (!needModuleMacros() ||
774  (!getLangOpts().ModulesLocalVisibility &&
775  LeavingMod->getTopLevelModuleName() != getLangOpts().CurrentModule)) {
776  // If we don't need module macros, or this is not a module for which we
777  // are tracking macro visibility, don't build any, and preserve the list
778  // of pending names for the surrounding submodule.
779  BuildingSubmoduleStack.pop_back();
780 
781  if (Callbacks)
782  Callbacks->LeftSubmodule(LeavingMod, ImportLoc, ForPragma);
783 
784  makeModuleVisible(LeavingMod, ImportLoc);
785  return LeavingMod;
786  }
787 
788  // Create ModuleMacros for any macros defined in this submodule.
790  for (unsigned I = Info.OuterPendingModuleMacroNames;
791  I != PendingModuleMacroNames.size(); ++I) {
792  auto *II = const_cast<IdentifierInfo*>(PendingModuleMacroNames[I]);
793  if (!VisitedMacros.insert(II).second)
794  continue;
795 
796  auto MacroIt = CurSubmoduleState->Macros.find(II);
797  if (MacroIt == CurSubmoduleState->Macros.end())
798  continue;
799  auto &Macro = MacroIt->second;
800 
801  // Find the starting point for the MacroDirective chain in this submodule.
802  MacroDirective *OldMD = nullptr;
803  auto *OldState = Info.OuterSubmoduleState;
804  if (getLangOpts().ModulesLocalVisibility)
805  OldState = &NullSubmoduleState;
806  if (OldState && OldState != CurSubmoduleState) {
807  // FIXME: It'd be better to start at the state from when we most recently
808  // entered this submodule, but it doesn't really matter.
809  auto &OldMacros = OldState->Macros;
810  auto OldMacroIt = OldMacros.find(II);
811  if (OldMacroIt == OldMacros.end())
812  OldMD = nullptr;
813  else
814  OldMD = OldMacroIt->second.getLatest();
815  }
816 
817  // This module may have exported a new macro. If so, create a ModuleMacro
818  // representing that fact.
819  bool ExplicitlyPublic = false;
820  for (auto *MD = Macro.getLatest(); MD != OldMD; MD = MD->getPrevious()) {
821  assert(MD && "broken macro directive chain");
822 
823  if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) {
824  // The latest visibility directive for a name in a submodule affects
825  // all the directives that come before it.
826  if (VisMD->isPublic())
827  ExplicitlyPublic = true;
828  else if (!ExplicitlyPublic)
829  // Private with no following public directive: not exported.
830  break;
831  } else {
832  MacroInfo *Def = nullptr;
833  if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD))
834  Def = DefMD->getInfo();
835 
836  // FIXME: Issue a warning if multiple headers for the same submodule
837  // define a macro, rather than silently ignoring all but the first.
838  bool IsNew;
839  // Don't bother creating a module macro if it would represent a #undef
840  // that doesn't override anything.
841  if (Def || !Macro.getOverriddenMacros().empty())
842  addModuleMacro(LeavingMod, II, Def,
843  Macro.getOverriddenMacros(), IsNew);
844 
845  if (!getLangOpts().ModulesLocalVisibility) {
846  // This macro is exposed to the rest of this compilation as a
847  // ModuleMacro; we don't need to track its MacroDirective any more.
848  Macro.setLatest(nullptr);
849  Macro.setOverriddenMacros(*this, {});
850  }
851  break;
852  }
853  }
854  }
855  PendingModuleMacroNames.resize(Info.OuterPendingModuleMacroNames);
856 
857  // FIXME: Before we leave this submodule, we should parse all the other
858  // headers within it. Otherwise, we're left with an inconsistent state
859  // where we've made the module visible but don't yet have its complete
860  // contents.
861 
862  // Put back the outer module's state, if we're tracking it.
863  if (getLangOpts().ModulesLocalVisibility)
864  CurSubmoduleState = Info.OuterSubmoduleState;
865 
866  BuildingSubmoduleStack.pop_back();
867 
868  if (Callbacks)
869  Callbacks->LeftSubmodule(LeavingMod, ImportLoc, ForPragma);
870 
871  // A nested #include makes the included submodule visible.
872  makeModuleVisible(LeavingMod, ImportLoc);
873  return LeavingMod;
874 }
clang::PPCallbacks::LexedFileChangeReason::ExitFile
@ ExitFile
clang::ModuleMap::resolveConflicts
bool resolveConflicts(Module *Mod, bool Complain)
Resolve all of the unresolved conflicts in the given module.
Definition: ModuleMap.cpp:1375
max
__DEVICE__ int max(int __a, int __b)
Definition: __clang_cuda_math.h:196
clang::PreprocessorLexer::getFileEntry
OptionalFileEntryRefDegradesToFileEntryPtr getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
Definition: PreprocessorLexer.cpp:51
clang::ModuleMap::resolveUses
bool resolveUses(Module *Mod, bool Complain)
Resolve all of the unresolved uses in the given module.
Definition: ModuleMap.cpp:1362
clang::SourceManager::getFileCharacteristic
SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const
Return the file characteristic of the specified source location, indicating whether this is a normal ...
Definition: SourceManager.cpp:1475
clang::DeclaratorContext::File
@ File
clang::Module::getUmbrellaDir
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
Definition: Module.cpp:244
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::Preprocessor::addModuleMacro
ModuleMacro * addModuleMacro(Module *Mod, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides, bool &IsNew)
Register an exported macro for a module and identifier.
Definition: PPMacroExpansion.cpp:133
clang::Preprocessor::HandleEndOfTokenLexer
bool HandleEndOfTokenLexer(Token &Result)
Callback invoked when the current TokenLexer hits the end of its token stream.
Definition: PPLexerChange.cpp:586
clang::Preprocessor::isIncrementalProcessingEnabled
bool isIncrementalProcessingEnabled() const
Returns true if incremental processing is enabled.
Definition: Preprocessor.h:1781
clang::Preprocessor::Lex
void Lex(Token &Result)
Lex the next token for this preprocessor.
Definition: Preprocessor.cpp:881
llvm::SmallVector< Token, 4 >
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::LangOptions::isCompilingModule
bool isCompilingModule() const
Are we compiling a module?
Definition: LangOptions.h:511
clang::Preprocessor::TUKind
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
Definition: Preprocessor.h:292
clang::Module::getFullModuleName
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition: Module.cpp:219
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:134
clang::Preprocessor::RemoveTopOfLexerStack
void RemoveTopOfLexerStack()
Pop the current lexer/macro exp off the top of the lexer stack.
Definition: PPLexerChange.cpp:607
clang::DirectoryEntry::getName
StringRef getName() const
Definition: DirectoryEntry.h:47
clang::PreprocessorLexer
Definition: PreprocessorLexer.h:30
clang::SourceManager::getBufferOrNone
llvm::Optional< llvm::MemoryBufferRef > getBufferOrNone(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
Definition: SourceManager.h:1024
clang::Module::DirectoryName::Entry
const DirectoryEntry * Entry
Definition: Module.h:227
clang::MacroArgs
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
Definition: MacroArgs.h:29
clang::PreprocessorLexer::MIOpt
MultipleIncludeOpt MIOpt
A state machine that detects the #ifndef-wrapping a file idiom for the multiple-include optimization.
Definition: PreprocessorLexer.h:72
clang::HeaderSearch::SetFileControllingMacro
void SetFileControllingMacro(const FileEntry *File, const IdentifierInfo *ControllingMacro)
Mark the specified file as having a controlling macro.
Definition: HeaderSearch.h:546
clang::PreprocessorLexer::getInitialNumSLocEntries
unsigned getInitialNumSLocEntries() const
Number of SLocEntries before lexing the file.
Definition: PreprocessorLexer.h:154
clang::PPCallbacks::EnterFile
@ EnterFile
Definition: PPCallbacks.h:40
computeRelativePath
static void computeRelativePath(FileManager &FM, const DirectoryEntry *Dir, const FileEntry *File, SmallString< 128 > &Result)
Compute the relative path that names the given file relative to the given directory.
Definition: PPLexerChange.cpp:224
llvm::Optional< llvm::MemoryBufferRef >
llvm::SmallPtrSet
Definition: ASTContext.h:82
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
SourceManager.h
clang::SourceManager::getIncludeLoc
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include'd file otherwise it returns an invalid location.
Definition: SourceManager.h:1142
clang::SrcMgr::CharacteristicKind
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:79
clang::Preprocessor::HandleMicrosoftCommentPaste
void HandleMicrosoftCommentPaste(Token &Tok)
When the macro expander pastes together a comment (/##/) in Microsoft mode, this method handles updat...
Definition: PPLexerChange.cpp:624
clang::PreprocessorLexer::LexingRawMode
bool LexingRawMode
True if in raw mode.
Definition: PreprocessorLexer.h:68
clang::Preprocessor::getCurrentFileLexer
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
Definition: PPLexerChange.cpp:49
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::Preprocessor::getLangOpts
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:1065
Preprocessor.h
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
Definition: Lexer.h:78
clang::MacroDirective::getPrevious
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
Definition: MacroInfo.h:351
clang::Module
Describes a module or submodule.
Definition: Module.h:98
clang::Preprocessor::EnterSourceFile
bool EnterSourceFile(FileID FID, ConstSearchDirIterator Dir, SourceLocation Loc, bool IsFirstIncludeOfFile=true)
Add a source file to the top of the include stack and start lexing tokens from it instead of the curr...
Definition: PPLexerChange.cpp:68
clang::FileManager::getVirtualFileSystem
llvm::vfs::FileSystem & getVirtualFileSystem() const
Definition: FileManager.h:245
clang::DirectoryEntry
Cached information about one directory (either on disk or in the virtual file system).
Definition: DirectoryEntry.h:36
clang::Module::getTopLevelModuleName
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
Definition: Module.h:603
clang::FileID::isValid
bool isValid() const
Definition: SourceLocation.h:44
clang::Preprocessor::isPCHThroughHeader
bool isPCHThroughHeader(const FileEntry *FE)
Returns true if the FileEntry is the PCH through header.
Definition: Preprocessor.cpp:610
LexDiagnostic.h
clang::Preprocessor::Diag
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
Definition: Preprocessor.h:1899
clang::MultipleIncludeOpt::GetDefinedMacro
const IdentifierInfo * GetDefinedMacro() const
If the ControllingMacro is followed by a macro definition, return the macro that was defined.
Definition: MultipleIncludeOpt.h:173
clang::Token::is
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:97
clang::SourceManager::getBufferName
StringRef getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const
Return the filename or buffer identifier of the buffer the location is in.
Definition: SourceManager.cpp:1504
clang::Preprocessor::isMacroDefined
bool isMacroDefined(StringRef Id)
Definition: Preprocessor.h:1193
clang::Preprocessor::EnterSubmodule
void EnterSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Definition: PPLexerChange.cpp:684
llvm::SmallString< 128 >
clang::PreprocessorLexer::ParsingPreprocessorDirective
bool ParsingPreprocessorDirective
True when parsing #XXX; turns '\n' into a tok::eod token.
Definition: PreprocessorLexer.h:50
clang::Preprocessor::getMacroInfo
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
Definition: Preprocessor.h:1258
clang::SourceManager::getLocForEndOfFile
SourceLocation getLocForEndOfFile(FileID FID) const
Return the source location corresponding to the last byte of the specified file.
Definition: SourceManager.h:1133
clang::PPCallbacks::LexedFileChangeReason::EnterFile
@ EnterFile
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:98
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:366
clang::ModuleMap
Definition: ModuleMap.h:75
clang::DefMacroDirective
A directive for a defined macro or a macro imported from a module.
Definition: MacroInfo.h:429
clang::SourceManager::getLocForStartOfFile
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
Definition: SourceManager.h:1125
clang::Module::submodules
llvm::iterator_range< submodule_iterator > submodules()
Definition: Module.h:713
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition: Preprocessor.h:1069
clang::PPCallbacks::ExitFile
@ ExitFile
Definition: PPCallbacks.h:40
clang::Decl::setLocation
void setLocation(SourceLocation L)
Definition: DeclBase.h:433
clang::PreprocessorLexer::getFileID
FileID getFileID() const
Definition: PreprocessorLexer.h:147
clang::detail::SearchDirIteratorImpl< true >
clang::MultipleIncludeOpt::GetDefinedLocation
SourceLocation GetDefinedLocation() const
Definition: MultipleIncludeOpt.h:70
collectAllSubModulesWithUmbrellaHeader
static void collectAllSubModulesWithUmbrellaHeader(const Module &Mod, SmallVectorImpl< const Module * > &SubMods)
Definition: PPLexerChange.cpp:282
clang::Preprocessor::isCodeCompletionEnabled
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
Definition: Preprocessor.h:1806
llvm::ArrayRef
Definition: LLVM.h:34
HeaderSearch.h
State
LineState State
Definition: UnwrappedLineFormatter.cpp:1147
clang::MultipleIncludeOpt::GetControllingMacroAtEndOfFile
const IdentifierInfo * GetControllingMacroAtEndOfFile() const
Once the entire file has been lexed, if there is a controlling macro, return it.
Definition: MultipleIncludeOpt.h:163
clang::Preprocessor::getFileManager
FileManager & getFileManager() const
Definition: Preprocessor.h:1068
clang::Preprocessor::getCurrentModule
Module * getCurrentModule()
Retrieves the module that we're currently building, if any.
Definition: Preprocessor.cpp:524
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::Preprocessor::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
Definition: Preprocessor.h:1060
clang::ModuleMap::resolveExports
bool resolveExports(Module *Mod, bool Complain)
Resolve all of the unresolved exports in the given module.
Definition: ModuleMap.cpp:1349
clang::Preprocessor::EnterMacro
void EnterMacro(Token &Tok, SourceLocation ILEnd, MacroInfo *Macro, MacroArgs *Args)
Add a Macro to the top of the include stack and start lexing tokens from it instead of the current bu...
Definition: PPLexerChange.cpp:150
clang::PreprocessorLexer::getSourceLocation
virtual SourceLocation getSourceLocation()=0
Return the source location for the next observable location.
clang
Definition: CalledOnceCheck.h:17
clang::FileManager
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
clang::SourceManager::setNumCreatedFIDsForFileID
void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs, bool Force=false) const
Set the number of FileIDs (files and macros) that were created during preprocessing of FID,...
Definition: SourceManager.h:1097
clang::Preprocessor::creatingPCHWithThroughHeader
bool creatingPCHWithThroughHeader()
True if creating a PCH with a through header.
Definition: Preprocessor.cpp:616
clang::MultipleIncludeOpt::GetMacroLocation
SourceLocation GetMacroLocation() const
Definition: MultipleIncludeOpt.h:66
MacroInfo.h
clang::MacroDirective
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
clang::Preprocessor::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: Preprocessor.h:1062
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang::Module::getUmbrellaHeader
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Definition: Module.h:624
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::SourceManager::getFileEntryForID
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Definition: SourceManager.h:1043
clang::Preprocessor::isInPrimaryFile
bool isInPrimaryFile() const
Return true if we're in the top-level file, not in a #include.
Definition: PPLexerChange.cpp:34
clang::Preprocessor::makeModuleVisible
void makeModuleVisible(Module *M, SourceLocation Loc)
Definition: Preprocessor.cpp:1316
clang::FileManager::getDirectory
llvm::ErrorOr< const DirectoryEntry * > getDirectory(StringRef DirName, bool CacheFailure=true)
Lookup, cache, and verify the specified directory (real or virtual).
Definition: FileManager.cpp:189
clang::Preprocessor::recomputeCurLexerKind
void recomputeCurLexerKind()
Recompute the current lexer kind based on the CurLexer/ CurTokenLexer pointers.
Definition: Preprocessor.cpp:383
clang::SourceManager::local_sloc_entry_size
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
Definition: SourceManager.h:1699
clang::TU_Complete
@ TU_Complete
The translation unit is a complete translation unit.
Definition: LangOptions.h:916
clang::SourceManager::getFileEntryRefForID
Optional< FileEntryRef > getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
Definition: SourceManager.h:1050
clang::Preprocessor::LeaveSubmodule
Module * LeaveSubmodule(bool ForPragma)
Definition: PPLexerChange.cpp:761
clang::comments::tok::eof
@ eof
Definition: CommentLexer.h:33
llvm::SmallVectorImpl
Definition: Randstruct.h:18
FileManager.h
PreprocessorOptions.h
clang::Preprocessor::isRecordingPreamble
bool isRecordingPreamble() const
Definition: Preprocessor.h:2569
clang::Preprocessor::getHeaderSearchInfo
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:1070
clang::SourceManager::translateFile
FileID translateFile(const FileEntry *SourceFile) const
Get the FileID for the given file.
Definition: SourceManager.cpp:1660
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:432
clang::ModuleMap::isHeaderInUnavailableModule
bool isHeaderInUnavailableModule(const FileEntry *Header) const
Determine whether the given header is part of a module marked 'unavailable'.
Definition: ModuleMap.cpp:706
clang::Preprocessor::getPredefinesFileID
FileID getPredefinesFileID() const
Returns the FileID for the preprocessor predefines.
Definition: Preprocessor.h:1155
clang::HeaderSearch::getModuleMap
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:791
clang::FixItHint::CreateReplacement
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Definition: Diagnostic.h:134
clang::Preprocessor::HandleEndOfFile
bool HandleEndOfFile(Token &Result, bool isEndOfMacro=false)
Callback invoked when the lexer hits the end of the current file.
Definition: PPLexerChange.cpp:331