clang  14.0.0git
Preprocessor.h
Go to the documentation of this file.
1 //===- Preprocessor.h - C Language Family Preprocessor ----------*- C++ -*-===//
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 /// \file
10 /// Defines the clang::Preprocessor interface.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LEX_PREPROCESSOR_H
15 #define LLVM_CLANG_LEX_PREPROCESSOR_H
16 
17 #include "clang/Basic/Diagnostic.h"
20 #include "clang/Basic/LLVM.h"
22 #include "clang/Basic/Module.h"
25 #include "clang/Basic/TokenKinds.h"
26 #include "clang/Lex/Lexer.h"
27 #include "clang/Lex/MacroInfo.h"
28 #include "clang/Lex/ModuleLoader.h"
29 #include "clang/Lex/ModuleMap.h"
30 #include "clang/Lex/PPCallbacks.h"
32 #include "clang/Lex/Token.h"
33 #include "clang/Lex/TokenLexer.h"
34 #include "llvm/ADT/ArrayRef.h"
35 #include "llvm/ADT/DenseMap.h"
36 #include "llvm/ADT/FoldingSet.h"
37 #include "llvm/ADT/FunctionExtras.h"
38 #include "llvm/ADT/None.h"
39 #include "llvm/ADT/Optional.h"
40 #include "llvm/ADT/PointerUnion.h"
41 #include "llvm/ADT/STLExtras.h"
42 #include "llvm/ADT/SmallPtrSet.h"
43 #include "llvm/ADT/SmallVector.h"
44 #include "llvm/ADT/StringRef.h"
45 #include "llvm/ADT/TinyPtrVector.h"
46 #include "llvm/ADT/iterator_range.h"
47 #include "llvm/Support/Allocator.h"
48 #include "llvm/Support/Casting.h"
49 #include "llvm/Support/Registry.h"
50 #include <cassert>
51 #include <cstddef>
52 #include <cstdint>
53 #include <map>
54 #include <memory>
55 #include <string>
56 #include <utility>
57 #include <vector>
58 
59 namespace llvm {
60 
61 template<unsigned InternalLen> class SmallString;
62 
63 } // namespace llvm
64 
65 namespace clang {
66 
67 class CodeCompletionHandler;
68 class CommentHandler;
69 class DirectoryEntry;
70 class DirectoryLookup;
71 class EmptylineHandler;
72 class ExternalPreprocessorSource;
73 class FileEntry;
74 class FileManager;
75 class HeaderSearch;
76 class MacroArgs;
77 class PragmaHandler;
78 class PragmaNamespace;
79 class PreprocessingRecord;
80 class PreprocessorLexer;
81 class PreprocessorOptions;
82 class ScratchBuffer;
83 class TargetInfo;
84 
85 namespace Builtin {
86 class Context;
87 }
88 
89 /// Stores token information for comparing actual tokens with
90 /// predefined values. Only handles simple tokens and identifiers.
91 class TokenValue {
92  tok::TokenKind Kind;
93  IdentifierInfo *II;
94 
95 public:
96  TokenValue(tok::TokenKind Kind) : Kind(Kind), II(nullptr) {
97  assert(Kind != tok::raw_identifier && "Raw identifiers are not supported.");
98  assert(Kind != tok::identifier &&
99  "Identifiers should be created by TokenValue(IdentifierInfo *)");
100  assert(!tok::isLiteral(Kind) && "Literals are not supported.");
101  assert(!tok::isAnnotation(Kind) && "Annotations are not supported.");
102  }
103 
104  TokenValue(IdentifierInfo *II) : Kind(tok::identifier), II(II) {}
105 
106  bool operator==(const Token &Tok) const {
107  return Tok.getKind() == Kind &&
108  (!II || II == Tok.getIdentifierInfo());
109  }
110 };
111 
112 /// Context in which macro name is used.
113 enum MacroUse {
114  // other than #define or #undef
115  MU_Other = 0,
116 
117  // macro name specified in #define
119 
120  // macro name specified in #undef
122 };
123 
124 /// Engages in a tight little dance with the lexer to efficiently
125 /// preprocess tokens.
126 ///
127 /// Lexers know only about tokens within a single source file, and don't
128 /// know anything about preprocessor-level issues like the \#include stack,
129 /// token expansion, etc.
133 
134  llvm::unique_function<void(const clang::Token &)> OnToken;
135  std::shared_ptr<PreprocessorOptions> PPOpts;
136  DiagnosticsEngine *Diags;
137  LangOptions &LangOpts;
138  const TargetInfo *Target = nullptr;
139  const TargetInfo *AuxTarget = nullptr;
140  FileManager &FileMgr;
141  SourceManager &SourceMgr;
142  std::unique_ptr<ScratchBuffer> ScratchBuf;
143  HeaderSearch &HeaderInfo;
144  ModuleLoader &TheModuleLoader;
145 
146  /// External source of macros.
147  ExternalPreprocessorSource *ExternalSource;
148 
149  /// A BumpPtrAllocator object used to quickly allocate and release
150  /// objects internal to the Preprocessor.
151  llvm::BumpPtrAllocator BP;
152 
153  /// Identifiers for builtin macros and other builtins.
154  IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__
155  IdentifierInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__
156  IdentifierInfo *Ident__INCLUDE_LEVEL__; // __INCLUDE_LEVEL__
157  IdentifierInfo *Ident__BASE_FILE__; // __BASE_FILE__
158  IdentifierInfo *Ident__FILE_NAME__; // __FILE_NAME__
159  IdentifierInfo *Ident__TIMESTAMP__; // __TIMESTAMP__
160  IdentifierInfo *Ident__COUNTER__; // __COUNTER__
161  IdentifierInfo *Ident_Pragma, *Ident__pragma; // _Pragma, __pragma
162  IdentifierInfo *Ident__identifier; // __identifier
163  IdentifierInfo *Ident__VA_ARGS__; // __VA_ARGS__
164  IdentifierInfo *Ident__VA_OPT__; // __VA_OPT__
165  IdentifierInfo *Ident__has_feature; // __has_feature
166  IdentifierInfo *Ident__has_extension; // __has_extension
167  IdentifierInfo *Ident__has_builtin; // __has_builtin
168  IdentifierInfo *Ident__has_attribute; // __has_attribute
169  IdentifierInfo *Ident__has_include; // __has_include
170  IdentifierInfo *Ident__has_include_next; // __has_include_next
171  IdentifierInfo *Ident__has_warning; // __has_warning
172  IdentifierInfo *Ident__is_identifier; // __is_identifier
173  IdentifierInfo *Ident__building_module; // __building_module
174  IdentifierInfo *Ident__MODULE__; // __MODULE__
175  IdentifierInfo *Ident__has_cpp_attribute; // __has_cpp_attribute
176  IdentifierInfo *Ident__has_c_attribute; // __has_c_attribute
177  IdentifierInfo *Ident__has_declspec; // __has_declspec_attribute
178  IdentifierInfo *Ident__is_target_arch; // __is_target_arch
179  IdentifierInfo *Ident__is_target_vendor; // __is_target_vendor
180  IdentifierInfo *Ident__is_target_os; // __is_target_os
181  IdentifierInfo *Ident__is_target_environment; // __is_target_environment
182 
183  // Weak, only valid (and set) while InMacroArgs is true.
184  Token* ArgMacro;
185 
186  SourceLocation DATELoc, TIMELoc;
187 
188  // Next __COUNTER__ value, starts at 0.
189  unsigned CounterValue = 0;
190 
191  enum {
192  /// Maximum depth of \#includes.
193  MaxAllowedIncludeStackDepth = 200
194  };
195 
196  // State that is set before the preprocessor begins.
197  bool KeepComments : 1;
198  bool KeepMacroComments : 1;
199  bool SuppressIncludeNotFoundError : 1;
200 
201  // State that changes while the preprocessor runs:
202  bool InMacroArgs : 1; // True if parsing fn macro invocation args.
203 
204  /// Whether the preprocessor owns the header search object.
205  bool OwnsHeaderSearch : 1;
206 
207  /// True if macro expansion is disabled.
208  bool DisableMacroExpansion : 1;
209 
210  /// Temporarily disables DisableMacroExpansion (i.e. enables expansion)
211  /// when parsing preprocessor directives.
212  bool MacroExpansionInDirectivesOverride : 1;
213 
214  class ResetMacroExpansionHelper;
215 
216  /// Whether we have already loaded macros from the external source.
217  mutable bool ReadMacrosFromExternalSource : 1;
218 
219  /// True if pragmas are enabled.
220  bool PragmasEnabled : 1;
221 
222  /// True if the current build action is a preprocessing action.
223  bool PreprocessedOutput : 1;
224 
225  /// True if we are currently preprocessing a #if or #elif directive
226  bool ParsingIfOrElifDirective;
227 
228  /// True if we are pre-expanding macro arguments.
229  bool InMacroArgPreExpansion;
230 
231  /// Mapping/lookup information for all identifiers in
232  /// the program, including program keywords.
233  mutable IdentifierTable Identifiers;
234 
235  /// This table contains all the selectors in the program.
236  ///
237  /// Unlike IdentifierTable above, this table *isn't* populated by the
238  /// preprocessor. It is declared/expanded here because its role/lifetime is
239  /// conceptually similar to the IdentifierTable. In addition, the current
240  /// control flow (in clang::ParseAST()), make it convenient to put here.
241  ///
242  /// FIXME: Make sure the lifetime of Identifiers/Selectors *isn't* tied to
243  /// the lifetime of the preprocessor.
244  SelectorTable Selectors;
245 
246  /// Information about builtins.
247  std::unique_ptr<Builtin::Context> BuiltinInfo;
248 
249  /// Tracks all of the pragmas that the client registered
250  /// with this preprocessor.
251  std::unique_ptr<PragmaNamespace> PragmaHandlers;
252 
253  /// Pragma handlers of the original source is stored here during the
254  /// parsing of a model file.
255  std::unique_ptr<PragmaNamespace> PragmaHandlersBackup;
256 
257  /// Tracks all of the comment handlers that the client registered
258  /// with this preprocessor.
259  std::vector<CommentHandler *> CommentHandlers;
260 
261  /// Empty line handler.
262  EmptylineHandler *Emptyline = nullptr;
263 
264  /// True if we want to ignore EOF token and continue later on (thus
265  /// avoid tearing the Lexer and etc. down).
266  bool IncrementalProcessing = false;
267 
268 public:
269  /// The kind of translation unit we are processing.
271 
272 private:
273  /// The code-completion handler.
274  CodeCompletionHandler *CodeComplete = nullptr;
275 
276  /// The file that we're performing code-completion for, if any.
277  const FileEntry *CodeCompletionFile = nullptr;
278 
279  /// The offset in file for the code-completion point.
280  unsigned CodeCompletionOffset = 0;
281 
282  /// The location for the code-completion point. This gets instantiated
283  /// when the CodeCompletionFile gets \#include'ed for preprocessing.
284  SourceLocation CodeCompletionLoc;
285 
286  /// The start location for the file of the code-completion point.
287  ///
288  /// This gets instantiated when the CodeCompletionFile gets \#include'ed
289  /// for preprocessing.
290  SourceLocation CodeCompletionFileLoc;
291 
292  /// The source location of the \c import contextual keyword we just
293  /// lexed, if any.
294  SourceLocation ModuleImportLoc;
295 
296  /// The module import path that we're currently processing.
298 
299  /// Whether the last token we lexed was an '@'.
300  bool LastTokenWasAt = false;
301 
302  /// A position within a C++20 import-seq.
303  class ImportSeq {
304  public:
305  enum State : int {
306  // Positive values represent a number of unclosed brackets.
307  AtTopLevel = 0,
308  AfterTopLevelTokenSeq = -1,
309  AfterExport = -2,
310  AfterImportSeq = -3,
311  };
312 
313  ImportSeq(State S) : S(S) {}
314 
315  /// Saw any kind of open bracket.
316  void handleOpenBracket() {
317  S = static_cast<State>(std::max<int>(S, 0) + 1);
318  }
319  /// Saw any kind of close bracket other than '}'.
320  void handleCloseBracket() {
321  S = static_cast<State>(std::max<int>(S, 1) - 1);
322  }
323  /// Saw a close brace.
324  void handleCloseBrace() {
325  handleCloseBracket();
326  if (S == AtTopLevel && !AfterHeaderName)
327  S = AfterTopLevelTokenSeq;
328  }
329  /// Saw a semicolon.
330  void handleSemi() {
331  if (atTopLevel()) {
332  S = AfterTopLevelTokenSeq;
333  AfterHeaderName = false;
334  }
335  }
336 
337  /// Saw an 'export' identifier.
338  void handleExport() {
339  if (S == AfterTopLevelTokenSeq)
340  S = AfterExport;
341  else if (S <= 0)
342  S = AtTopLevel;
343  }
344  /// Saw an 'import' identifier.
345  void handleImport() {
346  if (S == AfterTopLevelTokenSeq || S == AfterExport)
347  S = AfterImportSeq;
348  else if (S <= 0)
349  S = AtTopLevel;
350  }
351 
352  /// Saw a 'header-name' token; do not recognize any more 'import' tokens
353  /// until we reach a top-level semicolon.
354  void handleHeaderName() {
355  if (S == AfterImportSeq)
356  AfterHeaderName = true;
357  handleMisc();
358  }
359 
360  /// Saw any other token.
361  void handleMisc() {
362  if (S <= 0)
363  S = AtTopLevel;
364  }
365 
366  bool atTopLevel() { return S <= 0; }
367  bool afterImportSeq() { return S == AfterImportSeq; }
368 
369  private:
370  State S;
371  /// Whether we're in the pp-import-suffix following the header-name in a
372  /// pp-import. If so, a close-brace is not sufficient to end the
373  /// top-level-token-seq of an import-seq.
374  bool AfterHeaderName = false;
375  };
376 
377  /// Our current position within a C++20 import-seq.
378  ImportSeq ImportSeqState = ImportSeq::AfterTopLevelTokenSeq;
379 
380  /// Whether the module import expects an identifier next. Otherwise,
381  /// it expects a '.' or ';'.
382  bool ModuleImportExpectsIdentifier = false;
383 
384  /// The identifier and source location of the currently-active
385  /// \#pragma clang arc_cf_code_audited begin.
386  std::pair<IdentifierInfo *, SourceLocation> PragmaARCCFCodeAuditedInfo;
387 
388  /// The source location of the currently-active
389  /// \#pragma clang assume_nonnull begin.
390  SourceLocation PragmaAssumeNonNullLoc;
391 
392  /// True if we hit the code-completion point.
393  bool CodeCompletionReached = false;
394 
395  /// The code completion token containing the information
396  /// on the stem that is to be code completed.
397  IdentifierInfo *CodeCompletionII = nullptr;
398 
399  /// Range for the code completion token.
400  SourceRange CodeCompletionTokenRange;
401 
402  /// The directory that the main file should be considered to occupy,
403  /// if it does not correspond to a real file (as happens when building a
404  /// module).
405  const DirectoryEntry *MainFileDir = nullptr;
406 
407  /// The number of bytes that we will initially skip when entering the
408  /// main file, along with a flag that indicates whether skipping this number
409  /// of bytes will place the lexer at the start of a line.
410  ///
411  /// This is used when loading a precompiled preamble.
412  std::pair<int, bool> SkipMainFilePreamble;
413 
414  /// Whether we hit an error due to reaching max allowed include depth. Allows
415  /// to avoid hitting the same error over and over again.
416  bool HasReachedMaxIncludeDepth = false;
417 
418  /// The number of currently-active calls to Lex.
419  ///
420  /// Lex is reentrant, and asking for an (end-of-phase-4) token can often
421  /// require asking for multiple additional tokens. This counter makes it
422  /// possible for Lex to detect whether it's producing a token for the end
423  /// of phase 4 of translation or for some other situation.
424  unsigned LexLevel = 0;
425 
426  /// The number of (LexLevel 0) preprocessor tokens.
427  unsigned TokenCount = 0;
428 
429  /// Preprocess every token regardless of LexLevel.
430  bool PreprocessToken = false;
431 
432  /// The maximum number of (LexLevel 0) tokens before issuing a -Wmax-tokens
433  /// warning, or zero for unlimited.
434  unsigned MaxTokens = 0;
435  SourceLocation MaxTokensOverrideLoc;
436 
437 public:
442  bool FoundElse;
444 
446  bool FoundNonSkipPortion, bool FoundElse,
450  ElseLoc(ElseLoc) {}
451  };
452 
453 private:
454  friend class ASTReader;
455  friend class MacroArgs;
456 
457  class PreambleConditionalStackStore {
458  enum State {
459  Off = 0,
460  Recording = 1,
461  Replaying = 2,
462  };
463 
464  public:
465  PreambleConditionalStackStore() = default;
466 
467  void startRecording() { ConditionalStackState = Recording; }
468  void startReplaying() { ConditionalStackState = Replaying; }
469  bool isRecording() const { return ConditionalStackState == Recording; }
470  bool isReplaying() const { return ConditionalStackState == Replaying; }
471 
472  ArrayRef<PPConditionalInfo> getStack() const {
473  return ConditionalStack;
474  }
475 
476  void doneReplaying() {
477  ConditionalStack.clear();
478  ConditionalStackState = Off;
479  }
480 
481  void setStack(ArrayRef<PPConditionalInfo> s) {
482  if (!isRecording() && !isReplaying())
483  return;
484  ConditionalStack.clear();
485  ConditionalStack.append(s.begin(), s.end());
486  }
487 
488  bool hasRecordedPreamble() const { return !ConditionalStack.empty(); }
489 
490  bool reachedEOFWhileSkipping() const { return SkipInfo.hasValue(); }
491 
492  void clearSkipInfo() { SkipInfo.reset(); }
493 
495 
496  private:
497  SmallVector<PPConditionalInfo, 4> ConditionalStack;
498  State ConditionalStackState = Off;
499  } PreambleConditionalStack;
500 
501  /// The current top of the stack that we're lexing from if
502  /// not expanding a macro and we are lexing directly from source code.
503  ///
504  /// Only one of CurLexer, or CurTokenLexer will be non-null.
505  std::unique_ptr<Lexer> CurLexer;
506 
507  /// The current top of the stack what we're lexing from
508  /// if not expanding a macro.
509  ///
510  /// This is an alias for CurLexer.
511  PreprocessorLexer *CurPPLexer = nullptr;
512 
513  /// Used to find the current FileEntry, if CurLexer is non-null
514  /// and if applicable.
515  ///
516  /// This allows us to implement \#include_next and find directory-specific
517  /// properties.
518  const DirectoryLookup *CurDirLookup = nullptr;
519 
520  /// The current macro we are expanding, if we are expanding a macro.
521  ///
522  /// One of CurLexer and CurTokenLexer must be null.
523  std::unique_ptr<TokenLexer> CurTokenLexer;
524 
525  /// The kind of lexer we're currently working with.
526  enum CurLexerKind {
527  CLK_Lexer,
528  CLK_TokenLexer,
529  CLK_CachingLexer,
530  CLK_LexAfterModuleImport
531  } CurLexerKind = CLK_Lexer;
532 
533  /// If the current lexer is for a submodule that is being built, this
534  /// is that submodule.
535  Module *CurLexerSubmodule = nullptr;
536 
537  /// Keeps track of the stack of files currently
538  /// \#included, and macros currently being expanded from, not counting
539  /// CurLexer/CurTokenLexer.
540  struct IncludeStackInfo {
541  enum CurLexerKind CurLexerKind;
542  Module *TheSubmodule;
543  std::unique_ptr<Lexer> TheLexer;
544  PreprocessorLexer *ThePPLexer;
545  std::unique_ptr<TokenLexer> TheTokenLexer;
546  const DirectoryLookup *TheDirLookup;
547 
548  // The following constructors are completely useless copies of the default
549  // versions, only needed to pacify MSVC.
550  IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
551  std::unique_ptr<Lexer> &&TheLexer,
552  PreprocessorLexer *ThePPLexer,
553  std::unique_ptr<TokenLexer> &&TheTokenLexer,
554  const DirectoryLookup *TheDirLookup)
555  : CurLexerKind(std::move(CurLexerKind)),
556  TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
557  ThePPLexer(std::move(ThePPLexer)),
558  TheTokenLexer(std::move(TheTokenLexer)),
559  TheDirLookup(std::move(TheDirLookup)) {}
560  };
561  std::vector<IncludeStackInfo> IncludeMacroStack;
562 
563  /// Actions invoked when some preprocessor activity is
564  /// encountered (e.g. a file is \#included, etc).
565  std::unique_ptr<PPCallbacks> Callbacks;
566 
567  struct MacroExpandsInfo {
568  Token Tok;
569  MacroDefinition MD;
570  SourceRange Range;
571 
572  MacroExpandsInfo(Token Tok, MacroDefinition MD, SourceRange Range)
573  : Tok(Tok), MD(MD), Range(Range) {}
574  };
575  SmallVector<MacroExpandsInfo, 2> DelayedMacroExpandsCallbacks;
576 
577  /// Information about a name that has been used to define a module macro.
578  struct ModuleMacroInfo {
579  /// The most recent macro directive for this identifier.
580  MacroDirective *MD;
581 
582  /// The active module macros for this identifier.
583  llvm::TinyPtrVector<ModuleMacro *> ActiveModuleMacros;
584 
585  /// The generation number at which we last updated ActiveModuleMacros.
586  /// \see Preprocessor::VisibleModules.
587  unsigned ActiveModuleMacrosGeneration = 0;
588 
589  /// Whether this macro name is ambiguous.
590  bool IsAmbiguous = false;
591 
592  /// The module macros that are overridden by this macro.
593  llvm::TinyPtrVector<ModuleMacro *> OverriddenMacros;
594 
595  ModuleMacroInfo(MacroDirective *MD) : MD(MD) {}
596  };
597 
598  /// The state of a macro for an identifier.
599  class MacroState {
600  mutable llvm::PointerUnion<MacroDirective *, ModuleMacroInfo *> State;
601 
602  ModuleMacroInfo *getModuleInfo(Preprocessor &PP,
603  const IdentifierInfo *II) const {
604  if (II->isOutOfDate())
605  PP.updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
606  // FIXME: Find a spare bit on IdentifierInfo and store a
607  // HasModuleMacros flag.
608  if (!II->hasMacroDefinition() ||
609  (!PP.getLangOpts().Modules &&
610  !PP.getLangOpts().ModulesLocalVisibility) ||
611  !PP.CurSubmoduleState->VisibleModules.getGeneration())
612  return nullptr;
613 
614  auto *Info = State.dyn_cast<ModuleMacroInfo*>();
615  if (!Info) {
616  Info = new (PP.getPreprocessorAllocator())
617  ModuleMacroInfo(State.get<MacroDirective *>());
618  State = Info;
619  }
620 
621  if (PP.CurSubmoduleState->VisibleModules.getGeneration() !=
622  Info->ActiveModuleMacrosGeneration)
623  PP.updateModuleMacroInfo(II, *Info);
624  return Info;
625  }
626 
627  public:
628  MacroState() : MacroState(nullptr) {}
629  MacroState(MacroDirective *MD) : State(MD) {}
630 
631  MacroState(MacroState &&O) noexcept : State(O.State) {
632  O.State = (MacroDirective *)nullptr;
633  }
634 
635  MacroState &operator=(MacroState &&O) noexcept {
636  auto S = O.State;
637  O.State = (MacroDirective *)nullptr;
638  State = S;
639  return *this;
640  }
641 
642  ~MacroState() {
643  if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
644  Info->~ModuleMacroInfo();
645  }
646 
647  MacroDirective *getLatest() const {
648  if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
649  return Info->MD;
650  return State.get<MacroDirective*>();
651  }
652 
653  void setLatest(MacroDirective *MD) {
654  if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
655  Info->MD = MD;
656  else
657  State = MD;
658  }
659 
660  bool isAmbiguous(Preprocessor &PP, const IdentifierInfo *II) const {
661  auto *Info = getModuleInfo(PP, II);
662  return Info ? Info->IsAmbiguous : false;
663  }
664 
665  ArrayRef<ModuleMacro *>
666  getActiveModuleMacros(Preprocessor &PP, const IdentifierInfo *II) const {
667  if (auto *Info = getModuleInfo(PP, II))
668  return Info->ActiveModuleMacros;
669  return None;
670  }
671 
672  MacroDirective::DefInfo findDirectiveAtLoc(SourceLocation Loc,
673  SourceManager &SourceMgr) const {
674  // FIXME: Incorporate module macros into the result of this.
675  if (auto *Latest = getLatest())
676  return Latest->findDirectiveAtLoc(Loc, SourceMgr);
677  return {};
678  }
679 
680  void overrideActiveModuleMacros(Preprocessor &PP, IdentifierInfo *II) {
681  if (auto *Info = getModuleInfo(PP, II)) {
682  Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
683  Info->ActiveModuleMacros.begin(),
684  Info->ActiveModuleMacros.end());
685  Info->ActiveModuleMacros.clear();
686  Info->IsAmbiguous = false;
687  }
688  }
689 
690  ArrayRef<ModuleMacro*> getOverriddenMacros() const {
691  if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
692  return Info->OverriddenMacros;
693  return None;
694  }
695 
696  void setOverriddenMacros(Preprocessor &PP,
697  ArrayRef<ModuleMacro *> Overrides) {
698  auto *Info = State.dyn_cast<ModuleMacroInfo*>();
699  if (!Info) {
700  if (Overrides.empty())
701  return;
702  Info = new (PP.getPreprocessorAllocator())
703  ModuleMacroInfo(State.get<MacroDirective *>());
704  State = Info;
705  }
706  Info->OverriddenMacros.clear();
707  Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
708  Overrides.begin(), Overrides.end());
709  Info->ActiveModuleMacrosGeneration = 0;
710  }
711  };
712 
713  /// For each IdentifierInfo that was associated with a macro, we
714  /// keep a mapping to the history of all macro definitions and #undefs in
715  /// the reverse order (the latest one is in the head of the list).
716  ///
717  /// This mapping lives within the \p CurSubmoduleState.
718  using MacroMap = llvm::DenseMap<const IdentifierInfo *, MacroState>;
719 
720  struct SubmoduleState;
721 
722  /// Information about a submodule that we're currently building.
723  struct BuildingSubmoduleInfo {
724  /// The module that we are building.
725  Module *M;
726 
727  /// The location at which the module was included.
728  SourceLocation ImportLoc;
729 
730  /// Whether we entered this submodule via a pragma.
731  bool IsPragma;
732 
733  /// The previous SubmoduleState.
734  SubmoduleState *OuterSubmoduleState;
735 
736  /// The number of pending module macro names when we started building this.
737  unsigned OuterPendingModuleMacroNames;
738 
739  BuildingSubmoduleInfo(Module *M, SourceLocation ImportLoc, bool IsPragma,
740  SubmoduleState *OuterSubmoduleState,
741  unsigned OuterPendingModuleMacroNames)
742  : M(M), ImportLoc(ImportLoc), IsPragma(IsPragma),
743  OuterSubmoduleState(OuterSubmoduleState),
744  OuterPendingModuleMacroNames(OuterPendingModuleMacroNames) {}
745  };
746  SmallVector<BuildingSubmoduleInfo, 8> BuildingSubmoduleStack;
747 
748  /// Information about a submodule's preprocessor state.
749  struct SubmoduleState {
750  /// The macros for the submodule.
751  MacroMap Macros;
752 
753  /// The set of modules that are visible within the submodule.
754  VisibleModuleSet VisibleModules;
755 
756  // FIXME: CounterValue?
757  // FIXME: PragmaPushMacroInfo?
758  };
759  std::map<Module *, SubmoduleState> Submodules;
760 
761  /// The preprocessor state for preprocessing outside of any submodule.
762  SubmoduleState NullSubmoduleState;
763 
764  /// The current submodule state. Will be \p NullSubmoduleState if we're not
765  /// in a submodule.
766  SubmoduleState *CurSubmoduleState;
767 
768  /// The set of known macros exported from modules.
769  llvm::FoldingSet<ModuleMacro> ModuleMacros;
770 
771  /// The names of potential module macros that we've not yet processed.
772  llvm::SmallVector<const IdentifierInfo *, 32> PendingModuleMacroNames;
773 
774  /// The list of module macros, for each identifier, that are not overridden by
775  /// any other module macro.
776  llvm::DenseMap<const IdentifierInfo *, llvm::TinyPtrVector<ModuleMacro *>>
777  LeafModuleMacros;
778 
779  /// Macros that we want to warn because they are not used at the end
780  /// of the translation unit.
781  ///
782  /// We store just their SourceLocations instead of
783  /// something like MacroInfo*. The benefit of this is that when we are
784  /// deserializing from PCH, we don't need to deserialize identifier & macros
785  /// just so that we can report that they are unused, we just warn using
786  /// the SourceLocations of this set (that will be filled by the ASTReader).
787  using WarnUnusedMacroLocsTy = llvm::SmallDenseSet<SourceLocation, 32>;
788  WarnUnusedMacroLocsTy WarnUnusedMacroLocs;
789 
790  /// This is a pair of an optional message and source location used for pragmas
791  /// that annotate macros like pragma clang restrict_expansion and pragma clang
792  /// deprecated. This pair stores the optional message and the location of the
793  /// annotation pragma for use producing diagnostics and notes.
794  using MsgLocationPair = std::pair<std::string, SourceLocation>;
795 
796  /// Deprecation messages for macros provided in #pragma clang deprecated.
797  llvm::DenseMap<const IdentifierInfo *, std::string> MacroDeprecationMsgs;
798 
799  /// Usage warning for macros marked by #pragma clang restrict_expansion.
800  llvm::DenseMap<const IdentifierInfo *, MsgLocationPair>
801  RestrictExpansionMacroMsgs;
802 
803  /// A "freelist" of MacroArg objects that can be
804  /// reused for quick allocation.
805  MacroArgs *MacroArgCache = nullptr;
806 
807  /// For each IdentifierInfo used in a \#pragma push_macro directive,
808  /// we keep a MacroInfo stack used to restore the previous macro value.
809  llvm::DenseMap<IdentifierInfo *, std::vector<MacroInfo *>>
810  PragmaPushMacroInfo;
811 
812  // Various statistics we track for performance analysis.
813  unsigned NumDirectives = 0;
814  unsigned NumDefined = 0;
815  unsigned NumUndefined = 0;
816  unsigned NumPragma = 0;
817  unsigned NumIf = 0;
818  unsigned NumElse = 0;
819  unsigned NumEndif = 0;
820  unsigned NumEnteredSourceFiles = 0;
821  unsigned MaxIncludeStackDepth = 0;
822  unsigned NumMacroExpanded = 0;
823  unsigned NumFnMacroExpanded = 0;
824  unsigned NumBuiltinMacroExpanded = 0;
825  unsigned NumFastMacroExpanded = 0;
826  unsigned NumTokenPaste = 0;
827  unsigned NumFastTokenPaste = 0;
828  unsigned NumSkipped = 0;
829 
830  /// The predefined macros that preprocessor should use from the
831  /// command line etc.
832  std::string Predefines;
833 
834  /// The file ID for the preprocessor predefines.
835  FileID PredefinesFileID;
836 
837  /// The file ID for the PCH through header.
838  FileID PCHThroughHeaderFileID;
839 
840  /// Whether tokens are being skipped until a #pragma hdrstop is seen.
841  bool SkippingUntilPragmaHdrStop = false;
842 
843  /// Whether tokens are being skipped until the through header is seen.
844  bool SkippingUntilPCHThroughHeader = false;
845 
846  /// \{
847  /// Cache of macro expanders to reduce malloc traffic.
848  enum { TokenLexerCacheSize = 8 };
849  unsigned NumCachedTokenLexers;
850  std::unique_ptr<TokenLexer> TokenLexerCache[TokenLexerCacheSize];
851  /// \}
852 
853  /// Keeps macro expanded tokens for TokenLexers.
854  //
855  /// Works like a stack; a TokenLexer adds the macro expanded tokens that is
856  /// going to lex in the cache and when it finishes the tokens are removed
857  /// from the end of the cache.
858  SmallVector<Token, 16> MacroExpandedTokens;
859  std::vector<std::pair<TokenLexer *, size_t>> MacroExpandingLexersStack;
860 
861  /// A record of the macro definitions and expansions that
862  /// occurred during preprocessing.
863  ///
864  /// This is an optional side structure that can be enabled with
865  /// \c createPreprocessingRecord() prior to preprocessing.
866  PreprocessingRecord *Record = nullptr;
867 
868  /// Cached tokens state.
869  using CachedTokensTy = SmallVector<Token, 1>;
870 
871  /// Cached tokens are stored here when we do backtracking or
872  /// lookahead. They are "lexed" by the CachingLex() method.
873  CachedTokensTy CachedTokens;
874 
875  /// The position of the cached token that CachingLex() should
876  /// "lex" next.
877  ///
878  /// If it points beyond the CachedTokens vector, it means that a normal
879  /// Lex() should be invoked.
880  CachedTokensTy::size_type CachedLexPos = 0;
881 
882  /// Stack of backtrack positions, allowing nested backtracks.
883  ///
884  /// The EnableBacktrackAtThisPos() method pushes a position to
885  /// indicate where CachedLexPos should be set when the BackTrack() method is
886  /// invoked (at which point the last position is popped).
887  std::vector<CachedTokensTy::size_type> BacktrackPositions;
888 
889  struct MacroInfoChain {
890  MacroInfo MI;
891  MacroInfoChain *Next;
892  };
893 
894  /// MacroInfos are managed as a chain for easy disposal. This is the head
895  /// of that list.
896  MacroInfoChain *MIChainHead = nullptr;
897 
898  void updateOutOfDateIdentifier(IdentifierInfo &II) const;
899 
900 public:
901  Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
902  DiagnosticsEngine &diags, LangOptions &opts, SourceManager &SM,
903  HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
904  IdentifierInfoLookup *IILookup = nullptr,
905  bool OwnsHeaderSearch = false,
907 
908  ~Preprocessor();
909 
910  /// Initialize the preprocessor using information about the target.
911  ///
912  /// \param Target is owned by the caller and must remain valid for the
913  /// lifetime of the preprocessor.
914  /// \param AuxTarget is owned by the caller and must remain valid for
915  /// the lifetime of the preprocessor.
916  void Initialize(const TargetInfo &Target,
917  const TargetInfo *AuxTarget = nullptr);
918 
919  /// Initialize the preprocessor to parse a model file
920  ///
921  /// To parse model files the preprocessor of the original source is reused to
922  /// preserver the identifier table. However to avoid some duplicate
923  /// information in the preprocessor some cleanup is needed before it is used
924  /// to parse model files. This method does that cleanup.
925  void InitializeForModelFile();
926 
927  /// Cleanup after model file parsing
928  void FinalizeForModelFile();
929 
930  /// Retrieve the preprocessor options used to initialize this
931  /// preprocessor.
932  PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
933 
934  DiagnosticsEngine &getDiagnostics() const { return *Diags; }
935  void setDiagnostics(DiagnosticsEngine &D) { Diags = &D; }
936 
937  const LangOptions &getLangOpts() const { return LangOpts; }
938  const TargetInfo &getTargetInfo() const { return *Target; }
939  const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
940  FileManager &getFileManager() const { return FileMgr; }
941  SourceManager &getSourceManager() const { return SourceMgr; }
942  HeaderSearch &getHeaderSearchInfo() const { return HeaderInfo; }
943 
944  IdentifierTable &getIdentifierTable() { return Identifiers; }
945  const IdentifierTable &getIdentifierTable() const { return Identifiers; }
946  SelectorTable &getSelectorTable() { return Selectors; }
947  Builtin::Context &getBuiltinInfo() { return *BuiltinInfo; }
948  llvm::BumpPtrAllocator &getPreprocessorAllocator() { return BP; }
949 
951  ExternalSource = Source;
952  }
953 
955  return ExternalSource;
956  }
957 
958  /// Retrieve the module loader associated with this preprocessor.
959  ModuleLoader &getModuleLoader() const { return TheModuleLoader; }
960 
962  return TheModuleLoader.HadFatalFailure;
963  }
964 
965  /// Retrieve the number of Directives that have been processed by the
966  /// Preprocessor.
967  unsigned getNumDirectives() const {
968  return NumDirectives;
969  }
970 
971  /// True if we are currently preprocessing a #if or #elif directive
973  return ParsingIfOrElifDirective;
974  }
975 
976  /// Control whether the preprocessor retains comments in output.
977  void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments) {
978  this->KeepComments = KeepComments | KeepMacroComments;
979  this->KeepMacroComments = KeepMacroComments;
980  }
981 
982  bool getCommentRetentionState() const { return KeepComments; }
983 
984  void setPragmasEnabled(bool Enabled) { PragmasEnabled = Enabled; }
985  bool getPragmasEnabled() const { return PragmasEnabled; }
986 
987  void SetSuppressIncludeNotFoundError(bool Suppress) {
988  SuppressIncludeNotFoundError = Suppress;
989  }
990 
992  return SuppressIncludeNotFoundError;
993  }
994 
995  /// Sets whether the preprocessor is responsible for producing output or if
996  /// it is producing tokens to be consumed by Parse and Sema.
997  void setPreprocessedOutput(bool IsPreprocessedOutput) {
998  PreprocessedOutput = IsPreprocessedOutput;
999  }
1000 
1001  /// Returns true if the preprocessor is responsible for generating output,
1002  /// false if it is producing tokens to be consumed by Parse and Sema.
1003  bool isPreprocessedOutput() const { return PreprocessedOutput; }
1004 
1005  /// Return true if we are lexing directly from the specified lexer.
1006  bool isCurrentLexer(const PreprocessorLexer *L) const {
1007  return CurPPLexer == L;
1008  }
1009 
1010  /// Return the current lexer being lexed from.
1011  ///
1012  /// Note that this ignores any potentially active macro expansions and _Pragma
1013  /// expansions going on at the time.
1014  PreprocessorLexer *getCurrentLexer() const { return CurPPLexer; }
1015 
1016  /// Return the current file lexer being lexed from.
1017  ///
1018  /// Note that this ignores any potentially active macro expansions and _Pragma
1019  /// expansions going on at the time.
1021 
1022  /// Return the submodule owning the file being lexed. This may not be
1023  /// the current module if we have changed modules since entering the file.
1024  Module *getCurrentLexerSubmodule() const { return CurLexerSubmodule; }
1025 
1026  /// Returns the FileID for the preprocessor predefines.
1027  FileID getPredefinesFileID() const { return PredefinesFileID; }
1028 
1029  /// \{
1030  /// Accessors for preprocessor callbacks.
1031  ///
1032  /// Note that this class takes ownership of any PPCallbacks object given to
1033  /// it.
1034  PPCallbacks *getPPCallbacks() const { return Callbacks.get(); }
1035  void addPPCallbacks(std::unique_ptr<PPCallbacks> C) {
1036  if (Callbacks)
1037  C = std::make_unique<PPChainedCallbacks>(std::move(C),
1038  std::move(Callbacks));
1039  Callbacks = std::move(C);
1040  }
1041  /// \}
1042 
1043  /// Get the number of tokens processed so far.
1044  unsigned getTokenCount() const { return TokenCount; }
1045 
1046  /// Get the max number of tokens before issuing a -Wmax-tokens warning.
1047  unsigned getMaxTokens() const { return MaxTokens; }
1048 
1050  MaxTokens = Value;
1051  MaxTokensOverrideLoc = Loc;
1052  };
1053 
1054  SourceLocation getMaxTokensOverrideLoc() const { return MaxTokensOverrideLoc; }
1055 
1056  /// Register a function that would be called on each token in the final
1057  /// expanded token stream.
1058  /// This also reports annotation tokens produced by the parser.
1059  void setTokenWatcher(llvm::unique_function<void(const clang::Token &)> F) {
1060  OnToken = std::move(F);
1061  }
1062 
1063  void setPreprocessToken(bool Preprocess) { PreprocessToken = Preprocess; }
1064 
1065  bool isMacroDefined(StringRef Id) {
1066  return isMacroDefined(&Identifiers.get(Id));
1067  }
1068  bool isMacroDefined(const IdentifierInfo *II) {
1069  return II->hasMacroDefinition() &&
1070  (!getLangOpts().Modules || (bool)getMacroDefinition(II));
1071  }
1072 
1073  /// Determine whether II is defined as a macro within the module M,
1074  /// if that is a module that we've already preprocessed. Does not check for
1075  /// macros imported into M.
1077  if (!II->hasMacroDefinition())
1078  return false;
1079  auto I = Submodules.find(M);
1080  if (I == Submodules.end())
1081  return false;
1082  auto J = I->second.Macros.find(II);
1083  if (J == I->second.Macros.end())
1084  return false;
1085  auto *MD = J->second.getLatest();
1086  return MD && MD->isDefined();
1087  }
1088 
1090  if (!II->hasMacroDefinition())
1091  return {};
1092 
1093  MacroState &S = CurSubmoduleState->Macros[II];
1094  auto *MD = S.getLatest();
1095  while (MD && isa<VisibilityMacroDirective>(MD))
1096  MD = MD->getPrevious();
1097  return MacroDefinition(dyn_cast_or_null<DefMacroDirective>(MD),
1098  S.getActiveModuleMacros(*this, II),
1099  S.isAmbiguous(*this, II));
1100  }
1101 
1103  SourceLocation Loc) {
1104  if (!II->hadMacroDefinition())
1105  return {};
1106 
1107  MacroState &S = CurSubmoduleState->Macros[II];
1109  if (auto *MD = S.getLatest())
1110  DI = MD->findDirectiveAtLoc(Loc, getSourceManager());
1111  // FIXME: Compute the set of active module macros at the specified location.
1112  return MacroDefinition(DI.getDirective(),
1113  S.getActiveModuleMacros(*this, II),
1114  S.isAmbiguous(*this, II));
1115  }
1116 
1117  /// Given an identifier, return its latest non-imported MacroDirective
1118  /// if it is \#define'd and not \#undef'd, or null if it isn't \#define'd.
1120  if (!II->hasMacroDefinition())
1121  return nullptr;
1122 
1123  auto *MD = getLocalMacroDirectiveHistory(II);
1124  if (!MD || MD->getDefinition().isUndefined())
1125  return nullptr;
1126 
1127  return MD;
1128  }
1129 
1130  const MacroInfo *getMacroInfo(const IdentifierInfo *II) const {
1131  return const_cast<Preprocessor*>(this)->getMacroInfo(II);
1132  }
1133 
1135  if (!II->hasMacroDefinition())
1136  return nullptr;
1137  if (auto MD = getMacroDefinition(II))
1138  return MD.getMacroInfo();
1139  return nullptr;
1140  }
1141 
1142  /// Given an identifier, return the latest non-imported macro
1143  /// directive for that identifier.
1144  ///
1145  /// One can iterate over all previous macro directives from the most recent
1146  /// one.
1148 
1149  /// Add a directive to the macro directive history for this identifier.
1152  SourceLocation Loc) {
1153  DefMacroDirective *MD = AllocateDefMacroDirective(MI, Loc);
1154  appendMacroDirective(II, MD);
1155  return MD;
1156  }
1158  MacroInfo *MI) {
1159  return appendDefMacroDirective(II, MI, MI->getDefinitionLoc());
1160  }
1161 
1162  /// Set a MacroDirective that was loaded from a PCH file.
1164  MacroDirective *MD);
1165 
1166  /// Register an exported macro for a module and identifier.
1168  ArrayRef<ModuleMacro *> Overrides, bool &IsNew);
1169  ModuleMacro *getModuleMacro(Module *Mod, const IdentifierInfo *II);
1170 
1171  /// Get the list of leaf (non-overridden) module macros for a name.
1173  if (II->isOutOfDate())
1174  updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
1175  auto I = LeafModuleMacros.find(II);
1176  if (I != LeafModuleMacros.end())
1177  return I->second;
1178  return None;
1179  }
1180 
1181  /// Get the list of submodules that we're currently building.
1183  return BuildingSubmoduleStack;
1184  }
1185 
1186  /// \{
1187  /// Iterators for the macro history table. Currently defined macros have
1188  /// IdentifierInfo::hasMacroDefinition() set and an empty
1189  /// MacroInfo::getUndefLoc() at the head of the list.
1190  using macro_iterator = MacroMap::const_iterator;
1191 
1192  macro_iterator macro_begin(bool IncludeExternalMacros = true) const;
1193  macro_iterator macro_end(bool IncludeExternalMacros = true) const;
1194 
1195  llvm::iterator_range<macro_iterator>
1196  macros(bool IncludeExternalMacros = true) const {
1197  macro_iterator begin = macro_begin(IncludeExternalMacros);
1198  macro_iterator end = macro_end(IncludeExternalMacros);
1199  return llvm::make_range(begin, end);
1200  }
1201 
1202  /// \}
1203 
1204  /// Return the name of the macro defined before \p Loc that has
1205  /// spelling \p Tokens. If there are multiple macros with same spelling,
1206  /// return the last one defined.
1208  ArrayRef<TokenValue> Tokens) const;
1209 
1210  const std::string &getPredefines() const { return Predefines; }
1211 
1212  /// Set the predefines for this Preprocessor.
1213  ///
1214  /// These predefines are automatically injected when parsing the main file.
1215  void setPredefines(const char *P) { Predefines = P; }
1216  void setPredefines(StringRef P) { Predefines = std::string(P); }
1217 
1218  /// Return information about the specified preprocessor
1219  /// identifier token.
1220  IdentifierInfo *getIdentifierInfo(StringRef Name) const {
1221  return &Identifiers.get(Name);
1222  }
1223 
1224  /// Add the specified pragma handler to this preprocessor.
1225  ///
1226  /// If \p Namespace is non-null, then it is a token required to exist on the
1227  /// pragma line before the pragma string starts, e.g. "STDC" or "GCC".
1228  void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler);
1230  AddPragmaHandler(StringRef(), Handler);
1231  }
1232 
1233  /// Remove the specific pragma handler from this preprocessor.
1234  ///
1235  /// If \p Namespace is non-null, then it should be the namespace that
1236  /// \p Handler was added to. It is an error to remove a handler that
1237  /// has not been registered.
1238  void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler);
1240  RemovePragmaHandler(StringRef(), Handler);
1241  }
1242 
1243  /// Install empty handlers for all pragmas (making them ignored).
1244  void IgnorePragmas();
1245 
1246  /// Set empty line handler.
1247  void setEmptylineHandler(EmptylineHandler *Handler) { Emptyline = Handler; }
1248 
1249  EmptylineHandler *getEmptylineHandler() const { return Emptyline; }
1250 
1251  /// Add the specified comment handler to the preprocessor.
1252  void addCommentHandler(CommentHandler *Handler);
1253 
1254  /// Remove the specified comment handler.
1255  ///
1256  /// It is an error to remove a handler that has not been registered.
1257  void removeCommentHandler(CommentHandler *Handler);
1258 
1259  /// Set the code completion handler to the given object.
1261  CodeComplete = &Handler;
1262  }
1263 
1264  /// Retrieve the current code-completion handler.
1266  return CodeComplete;
1267  }
1268 
1269  /// Clear out the code completion handler.
1271  CodeComplete = nullptr;
1272  }
1273 
1274  /// Hook used by the lexer to invoke the "included file" code
1275  /// completion point.
1276  void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled);
1277 
1278  /// Hook used by the lexer to invoke the "natural language" code
1279  /// completion point.
1281 
1282  /// Set the code completion token for filtering purposes.
1284  CodeCompletionII = Filter;
1285  }
1286 
1287  /// Set the code completion token range for detecting replacement range later
1288  /// on.
1290  const SourceLocation End) {
1291  CodeCompletionTokenRange = {Start, End};
1292  }
1294  return CodeCompletionTokenRange;
1295  }
1296 
1297  /// Get the code completion token for filtering purposes.
1299  if (CodeCompletionII)
1300  return CodeCompletionII->getName();
1301  return {};
1302  }
1303 
1304  /// Retrieve the preprocessing record, or NULL if there is no
1305  /// preprocessing record.
1306  PreprocessingRecord *getPreprocessingRecord() const { return Record; }
1307 
1308  /// Create a new preprocessing record, which will keep track of
1309  /// all macro expansions, macro definitions, etc.
1311 
1312  /// Returns true if the FileEntry is the PCH through header.
1313  bool isPCHThroughHeader(const FileEntry *FE);
1314 
1315  /// True if creating a PCH with a through header.
1317 
1318  /// True if using a PCH with a through header.
1320 
1321  /// True if creating a PCH with a #pragma hdrstop.
1323 
1324  /// True if using a PCH with a #pragma hdrstop.
1326 
1327  /// Skip tokens until after the #include of the through header or
1328  /// until after a #pragma hdrstop.
1329  void SkipTokensWhileUsingPCH();
1330 
1331  /// Process directives while skipping until the through header or
1332  /// #pragma hdrstop is found.
1334  SourceLocation HashLoc);
1335 
1336  /// Enter the specified FileID as the main source file,
1337  /// which implicitly adds the builtin defines etc.
1338  void EnterMainSourceFile();
1339 
1340  /// Inform the preprocessor callbacks that processing is complete.
1341  void EndSourceFile();
1342 
1343  /// Add a source file to the top of the include stack and
1344  /// start lexing tokens from it instead of the current buffer.
1345  ///
1346  /// Emits a diagnostic, doesn't enter the file, and returns true on error.
1347  bool EnterSourceFile(FileID FID, const DirectoryLookup *Dir,
1348  SourceLocation Loc);
1349 
1350  /// Add a Macro to the top of the include stack and start lexing
1351  /// tokens from it instead of the current buffer.
1352  ///
1353  /// \param Args specifies the tokens input to a function-like macro.
1354  /// \param ILEnd specifies the location of the ')' for a function-like macro
1355  /// or the identifier for an object-like macro.
1356  void EnterMacro(Token &Tok, SourceLocation ILEnd, MacroInfo *Macro,
1357  MacroArgs *Args);
1358 
1359 private:
1360  /// Add a "macro" context to the top of the include stack,
1361  /// which will cause the lexer to start returning the specified tokens.
1362  ///
1363  /// If \p DisableMacroExpansion is true, tokens lexed from the token stream
1364  /// will not be subject to further macro expansion. Otherwise, these tokens
1365  /// will be re-macro-expanded when/if expansion is enabled.
1366  ///
1367  /// If \p OwnsTokens is false, this method assumes that the specified stream
1368  /// of tokens has a permanent owner somewhere, so they do not need to be
1369  /// copied. If it is true, it assumes the array of tokens is allocated with
1370  /// \c new[] and the Preprocessor will delete[] it.
1371  ///
1372  /// If \p IsReinject the resulting tokens will have Token::IsReinjected flag
1373  /// set, see the flag documentation for details.
1374  void EnterTokenStream(const Token *Toks, unsigned NumToks,
1375  bool DisableMacroExpansion, bool OwnsTokens,
1376  bool IsReinject);
1377 
1378 public:
1379  void EnterTokenStream(std::unique_ptr<Token[]> Toks, unsigned NumToks,
1380  bool DisableMacroExpansion, bool IsReinject) {
1381  EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion, true,
1382  IsReinject);
1383  }
1384 
1385  void EnterTokenStream(ArrayRef<Token> Toks, bool DisableMacroExpansion,
1386  bool IsReinject) {
1387  EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion, false,
1388  IsReinject);
1389  }
1390 
1391  /// Pop the current lexer/macro exp off the top of the lexer stack.
1392  ///
1393  /// This should only be used in situations where the current state of the
1394  /// top-of-stack lexer is known.
1395  void RemoveTopOfLexerStack();
1396 
1397  /// From the point that this method is called, and until
1398  /// CommitBacktrackedTokens() or Backtrack() is called, the Preprocessor
1399  /// keeps track of the lexed tokens so that a subsequent Backtrack() call will
1400  /// make the Preprocessor re-lex the same tokens.
1401  ///
1402  /// Nested backtracks are allowed, meaning that EnableBacktrackAtThisPos can
1403  /// be called multiple times and CommitBacktrackedTokens/Backtrack calls will
1404  /// be combined with the EnableBacktrackAtThisPos calls in reverse order.
1405  ///
1406  /// NOTE: *DO NOT* forget to call either CommitBacktrackedTokens or Backtrack
1407  /// at some point after EnableBacktrackAtThisPos. If you don't, caching of
1408  /// tokens will continue indefinitely.
1409  ///
1410  void EnableBacktrackAtThisPos();
1411 
1412  /// Disable the last EnableBacktrackAtThisPos call.
1413  void CommitBacktrackedTokens();
1414 
1415  /// Make Preprocessor re-lex the tokens that were lexed since
1416  /// EnableBacktrackAtThisPos() was previously called.
1417  void Backtrack();
1418 
1419  /// True if EnableBacktrackAtThisPos() was called and
1420  /// caching of tokens is on.
1421  bool isBacktrackEnabled() const { return !BacktrackPositions.empty(); }
1422 
1423  /// Lex the next token for this preprocessor.
1424  void Lex(Token &Result);
1425 
1426  /// Lex a token, forming a header-name token if possible.
1427  bool LexHeaderName(Token &Result, bool AllowMacroExpansion = true);
1428 
1429  bool LexAfterModuleImport(Token &Result);
1431 
1432  void makeModuleVisible(Module *M, SourceLocation Loc);
1433 
1435  return CurSubmoduleState->VisibleModules.getImportLoc(M);
1436  }
1437 
1438  /// Lex a string literal, which may be the concatenation of multiple
1439  /// string literals and may even come from macro expansion.
1440  /// \returns true on success, false if a error diagnostic has been generated.
1441  bool LexStringLiteral(Token &Result, std::string &String,
1442  const char *DiagnosticTag, bool AllowMacroExpansion) {
1443  if (AllowMacroExpansion)
1444  Lex(Result);
1445  else
1446  LexUnexpandedToken(Result);
1447  return FinishLexStringLiteral(Result, String, DiagnosticTag,
1448  AllowMacroExpansion);
1449  }
1450 
1451  /// Complete the lexing of a string literal where the first token has
1452  /// already been lexed (see LexStringLiteral).
1453  bool FinishLexStringLiteral(Token &Result, std::string &String,
1454  const char *DiagnosticTag,
1455  bool AllowMacroExpansion);
1456 
1457  /// Lex a token. If it's a comment, keep lexing until we get
1458  /// something not a comment.
1459  ///
1460  /// This is useful in -E -C mode where comments would foul up preprocessor
1461  /// directive handling.
1462  void LexNonComment(Token &Result) {
1463  do
1464  Lex(Result);
1465  while (Result.getKind() == tok::comment);
1466  }
1467 
1468  /// Just like Lex, but disables macro expansion of identifier tokens.
1469  void LexUnexpandedToken(Token &Result) {
1470  // Disable macro expansion.
1471  bool OldVal = DisableMacroExpansion;
1472  DisableMacroExpansion = true;
1473  // Lex the token.
1474  Lex(Result);
1475 
1476  // Reenable it.
1477  DisableMacroExpansion = OldVal;
1478  }
1479 
1480  /// Like LexNonComment, but this disables macro expansion of
1481  /// identifier tokens.
1483  do
1484  LexUnexpandedToken(Result);
1485  while (Result.getKind() == tok::comment);
1486  }
1487 
1488  /// Parses a simple integer literal to get its numeric value. Floating
1489  /// point literals and user defined literals are rejected. Used primarily to
1490  /// handle pragmas that accept integer arguments.
1491  bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value);
1492 
1493  /// Disables macro expansion everywhere except for preprocessor directives.
1495  DisableMacroExpansion = true;
1496  MacroExpansionInDirectivesOverride = true;
1497  }
1498 
1499  /// Peeks ahead N tokens and returns that token without consuming any
1500  /// tokens.
1501  ///
1502  /// LookAhead(0) returns the next token that would be returned by Lex(),
1503  /// LookAhead(1) returns the token after it, etc. This returns normal
1504  /// tokens after phase 5. As such, it is equivalent to using
1505  /// 'Lex', not 'LexUnexpandedToken'.
1506  const Token &LookAhead(unsigned N) {
1507  assert(LexLevel == 0 && "cannot use lookahead while lexing");
1508  if (CachedLexPos + N < CachedTokens.size())
1509  return CachedTokens[CachedLexPos+N];
1510  else
1511  return PeekAhead(N+1);
1512  }
1513 
1514  /// When backtracking is enabled and tokens are cached,
1515  /// this allows to revert a specific number of tokens.
1516  ///
1517  /// Note that the number of tokens being reverted should be up to the last
1518  /// backtrack position, not more.
1519  void RevertCachedTokens(unsigned N) {
1520  assert(isBacktrackEnabled() &&
1521  "Should only be called when tokens are cached for backtracking");
1522  assert(signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back())
1523  && "Should revert tokens up to the last backtrack position, not more");
1524  assert(signed(CachedLexPos) - signed(N) >= 0 &&
1525  "Corrupted backtrack positions ?");
1526  CachedLexPos -= N;
1527  }
1528 
1529  /// Enters a token in the token stream to be lexed next.
1530  ///
1531  /// If BackTrack() is called afterwards, the token will remain at the
1532  /// insertion point.
1533  /// If \p IsReinject is true, resulting token will have Token::IsReinjected
1534  /// flag set. See the flag documentation for details.
1535  void EnterToken(const Token &Tok, bool IsReinject) {
1536  if (LexLevel) {
1537  // It's not correct in general to enter caching lex mode while in the
1538  // middle of a nested lexing action.
1539  auto TokCopy = std::make_unique<Token[]>(1);
1540  TokCopy[0] = Tok;
1541  EnterTokenStream(std::move(TokCopy), 1, true, IsReinject);
1542  } else {
1543  EnterCachingLexMode();
1544  assert(IsReinject && "new tokens in the middle of cached stream");
1545  CachedTokens.insert(CachedTokens.begin()+CachedLexPos, Tok);
1546  }
1547  }
1548 
1549  /// We notify the Preprocessor that if it is caching tokens (because
1550  /// backtrack is enabled) it should replace the most recent cached tokens
1551  /// with the given annotation token. This function has no effect if
1552  /// backtracking is not enabled.
1553  ///
1554  /// Note that the use of this function is just for optimization, so that the
1555  /// cached tokens doesn't get re-parsed and re-resolved after a backtrack is
1556  /// invoked.
1557  void AnnotateCachedTokens(const Token &Tok) {
1558  assert(Tok.isAnnotation() && "Expected annotation token");
1559  if (CachedLexPos != 0 && isBacktrackEnabled())
1560  AnnotatePreviousCachedTokens(Tok);
1561  }
1562 
1563  /// Get the location of the last cached token, suitable for setting the end
1564  /// location of an annotation token.
1566  assert(CachedLexPos != 0);
1567  return CachedTokens[CachedLexPos-1].getLastLoc();
1568  }
1569 
1570  /// Whether \p Tok is the most recent token (`CachedLexPos - 1`) in
1571  /// CachedTokens.
1572  bool IsPreviousCachedToken(const Token &Tok) const;
1573 
1574  /// Replace token in `CachedLexPos - 1` in CachedTokens by the tokens
1575  /// in \p NewToks.
1576  ///
1577  /// Useful when a token needs to be split in smaller ones and CachedTokens
1578  /// most recent token must to be updated to reflect that.
1580 
1581  /// Replace the last token with an annotation token.
1582  ///
1583  /// Like AnnotateCachedTokens(), this routine replaces an
1584  /// already-parsed (and resolved) token with an annotation
1585  /// token. However, this routine only replaces the last token with
1586  /// the annotation token; it does not affect any other cached
1587  /// tokens. This function has no effect if backtracking is not
1588  /// enabled.
1590  assert(Tok.isAnnotation() && "Expected annotation token");
1591  if (CachedLexPos != 0 && isBacktrackEnabled())
1592  CachedTokens[CachedLexPos-1] = Tok;
1593  }
1594 
1595  /// Enter an annotation token into the token stream.
1597  void *AnnotationVal);
1598 
1599  /// Determine whether it's possible for a future call to Lex to produce an
1600  /// annotation token created by a previous call to EnterAnnotationToken.
1602  return CurLexerKind != CLK_Lexer;
1603  }
1604 
1605  /// Update the current token to represent the provided
1606  /// identifier, in order to cache an action performed by typo correction.
1607  void TypoCorrectToken(const Token &Tok) {
1608  assert(Tok.getIdentifierInfo() && "Expected identifier token");
1609  if (CachedLexPos != 0 && isBacktrackEnabled())
1610  CachedTokens[CachedLexPos-1] = Tok;
1611  }
1612 
1613  /// Recompute the current lexer kind based on the CurLexer/
1614  /// CurTokenLexer pointers.
1615  void recomputeCurLexerKind();
1616 
1617  /// Returns true if incremental processing is enabled
1618  bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
1619 
1620  /// Enables the incremental processing
1621  void enableIncrementalProcessing(bool value = true) {
1622  IncrementalProcessing = value;
1623  }
1624 
1625  /// Specify the point at which code-completion will be performed.
1626  ///
1627  /// \param File the file in which code completion should occur. If
1628  /// this file is included multiple times, code-completion will
1629  /// perform completion the first time it is included. If NULL, this
1630  /// function clears out the code-completion point.
1631  ///
1632  /// \param Line the line at which code completion should occur
1633  /// (1-based).
1634  ///
1635  /// \param Column the column at which code completion should occur
1636  /// (1-based).
1637  ///
1638  /// \returns true if an error occurred, false otherwise.
1639  bool SetCodeCompletionPoint(const FileEntry *File,
1640  unsigned Line, unsigned Column);
1641 
1642  /// Determine if we are performing code completion.
1643  bool isCodeCompletionEnabled() const { return CodeCompletionFile != nullptr; }
1644 
1645  /// Returns the location of the code-completion point.
1646  ///
1647  /// Returns an invalid location if code-completion is not enabled or the file
1648  /// containing the code-completion point has not been lexed yet.
1649  SourceLocation getCodeCompletionLoc() const { return CodeCompletionLoc; }
1650 
1651  /// Returns the start location of the file of code-completion point.
1652  ///
1653  /// Returns an invalid location if code-completion is not enabled or the file
1654  /// containing the code-completion point has not been lexed yet.
1656  return CodeCompletionFileLoc;
1657  }
1658 
1659  /// Returns true if code-completion is enabled and we have hit the
1660  /// code-completion point.
1661  bool isCodeCompletionReached() const { return CodeCompletionReached; }
1662 
1663  /// Note that we hit the code-completion point.
1665  assert(isCodeCompletionEnabled() && "Code-completion not enabled!");
1666  CodeCompletionReached = true;
1667  // Silence any diagnostics that occur after we hit the code-completion.
1669  }
1670 
1671  /// The location of the currently-active \#pragma clang
1672  /// arc_cf_code_audited begin.
1673  ///
1674  /// Returns an invalid location if there is no such pragma active.
1675  std::pair<IdentifierInfo *, SourceLocation>
1677  return PragmaARCCFCodeAuditedInfo;
1678  }
1679 
1680  /// Set the location of the currently-active \#pragma clang
1681  /// arc_cf_code_audited begin. An invalid location ends the pragma.
1683  SourceLocation Loc) {
1684  PragmaARCCFCodeAuditedInfo = {Ident, Loc};
1685  }
1686 
1687  /// The location of the currently-active \#pragma clang
1688  /// assume_nonnull begin.
1689  ///
1690  /// Returns an invalid location if there is no such pragma active.
1692  return PragmaAssumeNonNullLoc;
1693  }
1694 
1695  /// Set the location of the currently-active \#pragma clang
1696  /// assume_nonnull begin. An invalid location ends the pragma.
1698  PragmaAssumeNonNullLoc = Loc;
1699  }
1700 
1701  /// Set the directory in which the main file should be considered
1702  /// to have been found, if it is not a real file.
1703  void setMainFileDir(const DirectoryEntry *Dir) {
1704  MainFileDir = Dir;
1705  }
1706 
1707  /// Instruct the preprocessor to skip part of the main source file.
1708  ///
1709  /// \param Bytes The number of bytes in the preamble to skip.
1710  ///
1711  /// \param StartOfLine Whether skipping these bytes puts the lexer at the
1712  /// start of a line.
1713  void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine) {
1714  SkipMainFilePreamble.first = Bytes;
1715  SkipMainFilePreamble.second = StartOfLine;
1716  }
1717 
1718  /// Forwarding function for diagnostics. This emits a diagnostic at
1719  /// the specified Token's location, translating the token's start
1720  /// position in the current buffer into a SourcePosition object for rendering.
1721  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const {
1722  return Diags->Report(Loc, DiagID);
1723  }
1724 
1725  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) const {
1726  return Diags->Report(Tok.getLocation(), DiagID);
1727  }
1728 
1729  /// Return the 'spelling' of the token at the given
1730  /// location; does not go up to the spelling location or down to the
1731  /// expansion location.
1732  ///
1733  /// \param buffer A buffer which will be used only if the token requires
1734  /// "cleaning", e.g. if it contains trigraphs or escaped newlines
1735  /// \param invalid If non-null, will be set \c true if an error occurs.
1737  SmallVectorImpl<char> &buffer,
1738  bool *invalid = nullptr) const {
1739  return Lexer::getSpelling(loc, buffer, SourceMgr, LangOpts, invalid);
1740  }
1741 
1742  /// Return the 'spelling' of the Tok token.
1743  ///
1744  /// The spelling of a token is the characters used to represent the token in
1745  /// the source file after trigraph expansion and escaped-newline folding. In
1746  /// particular, this wants to get the true, uncanonicalized, spelling of
1747  /// things like digraphs, UCNs, etc.
1748  ///
1749  /// \param Invalid If non-null, will be set \c true if an error occurs.
1750  std::string getSpelling(const Token &Tok, bool *Invalid = nullptr) const {
1751  return Lexer::getSpelling(Tok, SourceMgr, LangOpts, Invalid);
1752  }
1753 
1754  /// Get the spelling of a token into a preallocated buffer, instead
1755  /// of as an std::string.
1756  ///
1757  /// The caller is required to allocate enough space for the token, which is
1758  /// guaranteed to be at least Tok.getLength() bytes long. The length of the
1759  /// actual result is returned.
1760  ///
1761  /// Note that this method may do two possible things: it may either fill in
1762  /// the buffer specified with characters, or it may *change the input pointer*
1763  /// to point to a constant buffer with the data already in it (avoiding a
1764  /// copy). The caller is not allowed to modify the returned buffer pointer
1765  /// if an internal buffer is returned.
1766  unsigned getSpelling(const Token &Tok, const char *&Buffer,
1767  bool *Invalid = nullptr) const {
1768  return Lexer::getSpelling(Tok, Buffer, SourceMgr, LangOpts, Invalid);
1769  }
1770 
1771  /// Get the spelling of a token into a SmallVector.
1772  ///
1773  /// Note that the returned StringRef may not point to the
1774  /// supplied buffer if a copy can be avoided.
1775  StringRef getSpelling(const Token &Tok,
1776  SmallVectorImpl<char> &Buffer,
1777  bool *Invalid = nullptr) const;
1778 
1779  /// Relex the token at the specified location.
1780  /// \returns true if there was a failure, false on success.
1781  bool getRawToken(SourceLocation Loc, Token &Result,
1782  bool IgnoreWhiteSpace = false) {
1783  return Lexer::getRawToken(Loc, Result, SourceMgr, LangOpts, IgnoreWhiteSpace);
1784  }
1785 
1786  /// Given a Token \p Tok that is a numeric constant with length 1,
1787  /// return the character.
1788  char
1790  bool *Invalid = nullptr) const {
1791  assert(Tok.is(tok::numeric_constant) &&
1792  Tok.getLength() == 1 && "Called on unsupported token");
1793  assert(!Tok.needsCleaning() && "Token can't need cleaning with length 1");
1794 
1795  // If the token is carrying a literal data pointer, just use it.
1796  if (const char *D = Tok.getLiteralData())
1797  return *D;
1798 
1799  // Otherwise, fall back on getCharacterData, which is slower, but always
1800  // works.
1801  return *SourceMgr.getCharacterData(Tok.getLocation(), Invalid);
1802  }
1803 
1804  /// Retrieve the name of the immediate macro expansion.
1805  ///
1806  /// This routine starts from a source location, and finds the name of the
1807  /// macro responsible for its immediate expansion. It looks through any
1808  /// intervening macro argument expansions to compute this. It returns a
1809  /// StringRef that refers to the SourceManager-owned buffer of the source
1810  /// where that macro name is spelled. Thus, the result shouldn't out-live
1811  /// the SourceManager.
1813  return Lexer::getImmediateMacroName(Loc, SourceMgr, getLangOpts());
1814  }
1815 
1816  /// Plop the specified string into a scratch buffer and set the
1817  /// specified token's location and length to it.
1818  ///
1819  /// If specified, the source location provides a location of the expansion
1820  /// point of the token.
1821  void CreateString(StringRef Str, Token &Tok,
1822  SourceLocation ExpansionLocStart = SourceLocation(),
1823  SourceLocation ExpansionLocEnd = SourceLocation());
1824 
1825  /// Split the first Length characters out of the token starting at TokLoc
1826  /// and return a location pointing to the split token. Re-lexing from the
1827  /// split token will return the split token rather than the original.
1828  SourceLocation SplitToken(SourceLocation TokLoc, unsigned Length);
1829 
1830  /// Computes the source location just past the end of the
1831  /// token at this source location.
1832  ///
1833  /// This routine can be used to produce a source location that
1834  /// points just past the end of the token referenced by \p Loc, and
1835  /// is generally used when a diagnostic needs to point just after a
1836  /// token where it expected something different that it received. If
1837  /// the returned source location would not be meaningful (e.g., if
1838  /// it points into a macro), this routine returns an invalid
1839  /// source location.
1840  ///
1841  /// \param Offset an offset from the end of the token, where the source
1842  /// location should refer to. The default offset (0) produces a source
1843  /// location pointing just past the end of the token; an offset of 1 produces
1844  /// a source location pointing to the last character in the token, etc.
1846  return Lexer::getLocForEndOfToken(Loc, Offset, SourceMgr, LangOpts);
1847  }
1848 
1849  /// Returns true if the given MacroID location points at the first
1850  /// token of the macro expansion.
1851  ///
1852  /// \param MacroBegin If non-null and function returns true, it is set to
1853  /// begin location of the macro.
1855  SourceLocation *MacroBegin = nullptr) const {
1856  return Lexer::isAtStartOfMacroExpansion(loc, SourceMgr, LangOpts,
1857  MacroBegin);
1858  }
1859 
1860  /// Returns true if the given MacroID location points at the last
1861  /// token of the macro expansion.
1862  ///
1863  /// \param MacroEnd If non-null and function returns true, it is set to
1864  /// end location of the macro.
1866  SourceLocation *MacroEnd = nullptr) const {
1867  return Lexer::isAtEndOfMacroExpansion(loc, SourceMgr, LangOpts, MacroEnd);
1868  }
1869 
1870  /// Print the token to stderr, used for debugging.
1871  void DumpToken(const Token &Tok, bool DumpFlags = false) const;
1872  void DumpLocation(SourceLocation Loc) const;
1873  void DumpMacro(const MacroInfo &MI) const;
1874  void dumpMacroInfo(const IdentifierInfo *II);
1875 
1876  /// Given a location that specifies the start of a
1877  /// token, return a new location that specifies a character within the token.
1879  unsigned Char) const {
1880  return Lexer::AdvanceToTokenCharacter(TokStart, Char, SourceMgr, LangOpts);
1881  }
1882 
1883  /// Increment the counters for the number of token paste operations
1884  /// performed.
1885  ///
1886  /// If fast was specified, this is a 'fast paste' case we handled.
1887  void IncrementPasteCounter(bool isFast) {
1888  if (isFast)
1889  ++NumFastTokenPaste;
1890  else
1891  ++NumTokenPaste;
1892  }
1893 
1894  void PrintStats();
1895 
1896  size_t getTotalMemory() const;
1897 
1898  /// When the macro expander pastes together a comment (/##/) in Microsoft
1899  /// mode, this method handles updating the current state, returning the
1900  /// token on the next source line.
1902 
1903  //===--------------------------------------------------------------------===//
1904  // Preprocessor callback methods. These are invoked by a lexer as various
1905  // directives and events are found.
1906 
1907  /// Given a tok::raw_identifier token, look up the
1908  /// identifier information for the token and install it into the token,
1909  /// updating the token kind accordingly.
1911 
1912 private:
1913  llvm::DenseMap<IdentifierInfo*,unsigned> PoisonReasons;
1914 
1915 public:
1916  /// Specifies the reason for poisoning an identifier.
1917  ///
1918  /// If that identifier is accessed while poisoned, then this reason will be
1919  /// used instead of the default "poisoned" diagnostic.
1920  void SetPoisonReason(IdentifierInfo *II, unsigned DiagID);
1921 
1922  /// Display reason for poisoned identifier.
1924 
1926  if(IdentifierInfo * II = Identifier.getIdentifierInfo()) {
1927  if(II->isPoisoned()) {
1929  }
1930  }
1931  }
1932 
1933 private:
1934  /// Identifiers used for SEH handling in Borland. These are only
1935  /// allowed in particular circumstances
1936  // __except block
1937  IdentifierInfo *Ident__exception_code,
1938  *Ident___exception_code,
1939  *Ident_GetExceptionCode;
1940  // __except filter expression
1941  IdentifierInfo *Ident__exception_info,
1942  *Ident___exception_info,
1943  *Ident_GetExceptionInfo;
1944  // __finally
1945  IdentifierInfo *Ident__abnormal_termination,
1946  *Ident___abnormal_termination,
1947  *Ident_AbnormalTermination;
1948 
1949  const char *getCurLexerEndPos();
1950  void diagnoseMissingHeaderInUmbrellaDir(const Module &Mod);
1951 
1952 public:
1953  void PoisonSEHIdentifiers(bool Poison = true); // Borland
1954 
1955  /// Callback invoked when the lexer reads an identifier and has
1956  /// filled in the tokens IdentifierInfo member.
1957  ///
1958  /// This callback potentially macro expands it or turns it into a named
1959  /// token (like 'for').
1960  ///
1961  /// \returns true if we actually computed a token, false if we need to
1962  /// lex again.
1964 
1965  /// Callback invoked when the lexer hits the end of the current file.
1966  ///
1967  /// This either returns the EOF token and returns true, or
1968  /// pops a level off the include stack and returns false, at which point the
1969  /// client should call lex again.
1970  bool HandleEndOfFile(Token &Result, SourceLocation Loc,
1971  bool isEndOfMacro = false);
1972 
1973  /// Callback invoked when the current TokenLexer hits the end of its
1974  /// token stream.
1975  bool HandleEndOfTokenLexer(Token &Result);
1976 
1977  /// Callback invoked when the lexer sees a # token at the start of a
1978  /// line.
1979  ///
1980  /// This consumes the directive, modifies the lexer/preprocessor state, and
1981  /// advances the lexer(s) so that the next token read is the correct one.
1982  void HandleDirective(Token &Result);
1983 
1984  /// Ensure that the next token is a tok::eod token.
1985  ///
1986  /// If not, emit a diagnostic and consume up until the eod.
1987  /// If \p EnableMacros is true, then we consider macros that expand to zero
1988  /// tokens as being ok.
1989  ///
1990  /// \return The location of the end of the directive (the terminating
1991  /// newline).
1992  SourceLocation CheckEndOfDirective(const char *DirType,
1993  bool EnableMacros = false);
1994 
1995  /// Read and discard all tokens remaining on the current line until
1996  /// the tok::eod token is found. Returns the range of the skipped tokens.
1998 
1999  /// Returns true if the preprocessor has seen a use of
2000  /// __DATE__ or __TIME__ in the file so far.
2001  bool SawDateOrTime() const {
2002  return DATELoc != SourceLocation() || TIMELoc != SourceLocation();
2003  }
2004  unsigned getCounterValue() const { return CounterValue; }
2005  void setCounterValue(unsigned V) { CounterValue = V; }
2006 
2007  /// Retrieves the module that we're currently building, if any.
2009 
2010  /// Allocate a new MacroInfo object with the provided SourceLocation.
2012 
2013  /// Turn the specified lexer token into a fully checked and spelled
2014  /// filename, e.g. as an operand of \#include.
2015  ///
2016  /// The caller is expected to provide a buffer that is large enough to hold
2017  /// the spelling of the filename, but is also expected to handle the case
2018  /// when this method decides to use a different buffer.
2019  ///
2020  /// \returns true if the input filename was in <>'s or false if it was
2021  /// in ""'s.
2022  bool GetIncludeFilenameSpelling(SourceLocation Loc,StringRef &Buffer);
2023 
2024  /// Given a "foo" or <foo> reference, look up the indicated file.
2025  ///
2026  /// Returns None on failure. \p isAngled indicates whether the file
2027  /// reference is for system \#include's or not (i.e. using <> instead of "").
2029  LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled,
2030  const DirectoryLookup *FromDir, const FileEntry *FromFile,
2031  const DirectoryLookup *&CurDir, SmallVectorImpl<char> *SearchPath,
2032  SmallVectorImpl<char> *RelativePath,
2033  ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped,
2034  bool *IsFrameworkFound, bool SkipCache = false);
2035 
2036  /// Get the DirectoryLookup structure used to find the current
2037  /// FileEntry, if CurLexer is non-null and if applicable.
2038  ///
2039  /// This allows us to implement \#include_next and find directory-specific
2040  /// properties.
2041  const DirectoryLookup *GetCurDirLookup() { return CurDirLookup; }
2042 
2043  /// Return true if we're in the top-level file, not in a \#include.
2044  bool isInPrimaryFile() const;
2045 
2046  /// Lex an on-off-switch (C99 6.10.6p2) and verify that it is
2047  /// followed by EOD. Return true if the token is not a valid on-off-switch.
2048  bool LexOnOffSwitch(tok::OnOffSwitch &Result);
2049 
2050  bool CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
2051  bool *ShadowFlag = nullptr);
2052 
2053  void EnterSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma);
2054  Module *LeaveSubmodule(bool ForPragma);
2055 
2056 private:
2057  friend void TokenLexer::ExpandFunctionArguments();
2058 
2059  void PushIncludeMacroStack() {
2060  assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
2061  IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
2062  std::move(CurLexer), CurPPLexer,
2063  std::move(CurTokenLexer), CurDirLookup);
2064  CurPPLexer = nullptr;
2065  }
2066 
2067  void PopIncludeMacroStack() {
2068  CurLexer = std::move(IncludeMacroStack.back().TheLexer);
2069  CurPPLexer = IncludeMacroStack.back().ThePPLexer;
2070  CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
2071  CurDirLookup = IncludeMacroStack.back().TheDirLookup;
2072  CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
2073  CurLexerKind = IncludeMacroStack.back().CurLexerKind;
2074  IncludeMacroStack.pop_back();
2075  }
2076 
2077  void PropagateLineStartLeadingSpaceInfo(Token &Result);
2078 
2079  /// Determine whether we need to create module macros for #defines in the
2080  /// current context.
2081  bool needModuleMacros() const;
2082 
2083  /// Update the set of active module macros and ambiguity flag for a module
2084  /// macro name.
2085  void updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info);
2086 
2087  DefMacroDirective *AllocateDefMacroDirective(MacroInfo *MI,
2088  SourceLocation Loc);
2089  UndefMacroDirective *AllocateUndefMacroDirective(SourceLocation UndefLoc);
2090  VisibilityMacroDirective *AllocateVisibilityMacroDirective(SourceLocation Loc,
2091  bool isPublic);
2092 
2093  /// Lex and validate a macro name, which occurs after a
2094  /// \#define or \#undef.
2095  ///
2096  /// \param MacroNameTok Token that represents the name defined or undefined.
2097  /// \param IsDefineUndef Kind if preprocessor directive.
2098  /// \param ShadowFlag Points to flag that is set if macro name shadows
2099  /// a keyword.
2100  ///
2101  /// This emits a diagnostic, sets the token kind to eod,
2102  /// and discards the rest of the macro line if the macro name is invalid.
2103  void ReadMacroName(Token &MacroNameTok, MacroUse IsDefineUndef = MU_Other,
2104  bool *ShadowFlag = nullptr);
2105 
2106  /// ReadOptionalMacroParameterListAndBody - This consumes all (i.e. the
2107  /// entire line) of the macro's tokens and adds them to MacroInfo, and while
2108  /// doing so performs certain validity checks including (but not limited to):
2109  /// - # (stringization) is followed by a macro parameter
2110  /// \param MacroNameTok - Token that represents the macro name
2111  /// \param ImmediatelyAfterHeaderGuard - Macro follows an #ifdef header guard
2112  ///
2113  /// Either returns a pointer to a MacroInfo object OR emits a diagnostic and
2114  /// returns a nullptr if an invalid sequence of tokens is encountered.
2115  MacroInfo *ReadOptionalMacroParameterListAndBody(
2116  const Token &MacroNameTok, bool ImmediatelyAfterHeaderGuard);
2117 
2118  /// The ( starting an argument list of a macro definition has just been read.
2119  /// Lex the rest of the parameters and the closing ), updating \p MI with
2120  /// what we learn and saving in \p LastTok the last token read.
2121  /// Return true if an error occurs parsing the arg list.
2122  bool ReadMacroParameterList(MacroInfo *MI, Token& LastTok);
2123 
2124  /// We just read a \#if or related directive and decided that the
2125  /// subsequent tokens are in the \#if'd out portion of the
2126  /// file. Lex the rest of the file, until we see an \#endif. If \p
2127  /// FoundNonSkipPortion is true, then we have already emitted code for part of
2128  /// this \#if directive, so \#else/\#elif blocks should never be entered. If
2129  /// \p FoundElse is false, then \#else directives are ok, if not, then we have
2130  /// already seen one so a \#else directive is a duplicate. When this returns,
2131  /// the caller can lex the first valid token.
2132  void SkipExcludedConditionalBlock(SourceLocation HashTokenLoc,
2133  SourceLocation IfTokenLoc,
2134  bool FoundNonSkipPortion, bool FoundElse,
2135  SourceLocation ElseLoc = SourceLocation());
2136 
2137  /// Information about the result for evaluating an expression for a
2138  /// preprocessor directive.
2139  struct DirectiveEvalResult {
2140  /// Whether the expression was evaluated as true or not.
2141  bool Conditional;
2142 
2143  /// True if the expression contained identifiers that were undefined.
2144  bool IncludedUndefinedIds;
2145 
2146  /// The source range for the expression.
2147  SourceRange ExprRange;
2148  };
2149 
2150  /// Evaluate an integer constant expression that may occur after a
2151  /// \#if or \#elif directive and return a \p DirectiveEvalResult object.
2152  ///
2153  /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro.
2154  DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro);
2155 
2156  /// Install the standard preprocessor pragmas:
2157  /// \#pragma GCC poison/system_header/dependency and \#pragma once.
2158  void RegisterBuiltinPragmas();
2159 
2160  /// Register builtin macros such as __LINE__ with the identifier table.
2161  void RegisterBuiltinMacros();
2162 
2163  /// If an identifier token is read that is to be expanded as a macro, handle
2164  /// it and return the next token as 'Tok'. If we lexed a token, return true;
2165  /// otherwise the caller should lex again.
2166  bool HandleMacroExpandedIdentifier(Token &Identifier, const MacroDefinition &MD);
2167 
2168  /// Cache macro expanded tokens for TokenLexers.
2169  //
2170  /// Works like a stack; a TokenLexer adds the macro expanded tokens that is
2171  /// going to lex in the cache and when it finishes the tokens are removed
2172  /// from the end of the cache.
2173  Token *cacheMacroExpandedTokens(TokenLexer *tokLexer,
2174  ArrayRef<Token> tokens);
2175 
2176  void removeCachedMacroExpandedTokensOfLastLexer();
2177 
2178  /// Determine whether the next preprocessor token to be
2179  /// lexed is a '('. If so, consume the token and return true, if not, this
2180  /// method should have no observable side-effect on the lexed tokens.
2181  bool isNextPPTokenLParen();
2182 
2183  /// After reading "MACRO(", this method is invoked to read all of the formal
2184  /// arguments specified for the macro invocation. Returns null on error.
2185  MacroArgs *ReadMacroCallArgumentList(Token &MacroName, MacroInfo *MI,
2186  SourceLocation &MacroEnd);
2187 
2188  /// If an identifier token is read that is to be expanded
2189  /// as a builtin macro, handle it and return the next token as 'Tok'.
2190  void ExpandBuiltinMacro(Token &Tok);
2191 
2192  /// Read a \c _Pragma directive, slice it up, process it, then
2193  /// return the first token after the directive.
2194  /// This assumes that the \c _Pragma token has just been read into \p Tok.
2195  void Handle_Pragma(Token &Tok);
2196 
2197  /// Like Handle_Pragma except the pragma text is not enclosed within
2198  /// a string literal.
2199  void HandleMicrosoft__pragma(Token &Tok);
2200 
2201  /// Add a lexer to the top of the include stack and
2202  /// start lexing tokens from it instead of the current buffer.
2203  void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir);
2204 
2205  /// Set the FileID for the preprocessor predefines.
2206  void setPredefinesFileID(FileID FID) {
2207  assert(PredefinesFileID.isInvalid() && "PredefinesFileID already set!");
2208  PredefinesFileID = FID;
2209  }
2210 
2211  /// Set the FileID for the PCH through header.
2212  void setPCHThroughHeaderFileID(FileID FID);
2213 
2214  /// Returns true if we are lexing from a file and not a
2215  /// pragma or a macro.
2216  static bool IsFileLexer(const Lexer* L, const PreprocessorLexer* P) {
2217  return L ? !L->isPragmaLexer() : P != nullptr;
2218  }
2219 
2220  static bool IsFileLexer(const IncludeStackInfo& I) {
2221  return IsFileLexer(I.TheLexer.get(), I.ThePPLexer);
2222  }
2223 
2224  bool IsFileLexer() const {
2225  return IsFileLexer(CurLexer.get(), CurPPLexer);
2226  }
2227 
2228  //===--------------------------------------------------------------------===//
2229  // Caching stuff.
2230  void CachingLex(Token &Result);
2231 
2232  bool InCachingLexMode() const {
2233  // If the Lexer pointers are 0 and IncludeMacroStack is empty, it means
2234  // that we are past EOF, not that we are in CachingLex mode.
2235  return !CurPPLexer && !CurTokenLexer && !IncludeMacroStack.empty();
2236  }
2237 
2238  void EnterCachingLexMode();
2239  void EnterCachingLexModeUnchecked();
2240 
2241  void ExitCachingLexMode() {
2242  if (InCachingLexMode())
2244  }
2245 
2246  const Token &PeekAhead(unsigned N);
2247  void AnnotatePreviousCachedTokens(const Token &Tok);
2248 
2249  //===--------------------------------------------------------------------===//
2250  /// Handle*Directive - implement the various preprocessor directives. These
2251  /// should side-effect the current preprocessor object so that the next call
2252  /// to Lex() will return the appropriate token next.
2253  void HandleLineDirective();
2254  void HandleDigitDirective(Token &Tok);
2255  void HandleUserDiagnosticDirective(Token &Tok, bool isWarning);
2256  void HandleIdentSCCSDirective(Token &Tok);
2257  void HandleMacroPublicDirective(Token &Tok);
2258  void HandleMacroPrivateDirective();
2259 
2260  /// An additional notification that can be produced by a header inclusion or
2261  /// import to tell the parser what happened.
2262  struct ImportAction {
2263  enum ActionKind {
2264  None,
2265  ModuleBegin,
2266  ModuleImport,
2267  SkippedModuleImport,
2268  Failure,
2269  } Kind;
2270  Module *ModuleForHeader = nullptr;
2271 
2272  ImportAction(ActionKind AK, Module *Mod = nullptr)
2273  : Kind(AK), ModuleForHeader(Mod) {
2274  assert((AK == None || Mod || AK == Failure) &&
2275  "no module for module action");
2276  }
2277  };
2278 
2279  Optional<FileEntryRef> LookupHeaderIncludeOrImport(
2280  const DirectoryLookup *&CurDir, StringRef &Filename,
2281  SourceLocation FilenameLoc, CharSourceRange FilenameRange,
2282  const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl,
2283  bool &IsMapped, const DirectoryLookup *LookupFrom,
2284  const FileEntry *LookupFromFile, StringRef &LookupFilename,
2285  SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath,
2286  ModuleMap::KnownHeader &SuggestedModule, bool isAngled);
2287 
2288  // File inclusion.
2289  void HandleIncludeDirective(SourceLocation HashLoc, Token &Tok,
2290  const DirectoryLookup *LookupFrom = nullptr,
2291  const FileEntry *LookupFromFile = nullptr);
2292  ImportAction
2293  HandleHeaderIncludeOrImport(SourceLocation HashLoc, Token &IncludeTok,
2294  Token &FilenameTok, SourceLocation EndLoc,
2295  const DirectoryLookup *LookupFrom = nullptr,
2296  const FileEntry *LookupFromFile = nullptr);
2297  void HandleIncludeNextDirective(SourceLocation HashLoc, Token &Tok);
2298  void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok);
2299  void HandleImportDirective(SourceLocation HashLoc, Token &Tok);
2300  void HandleMicrosoftImportDirective(Token &Tok);
2301 
2302 public:
2303  /// Check that the given module is available, producing a diagnostic if not.
2304  /// \return \c true if the check failed (because the module is not available).
2305  /// \c false if the module appears to be usable.
2306  static bool checkModuleIsAvailable(const LangOptions &LangOpts,
2307  const TargetInfo &TargetInfo,
2308  DiagnosticsEngine &Diags, Module *M);
2309 
2310  // Module inclusion testing.
2311  /// Find the module that owns the source or header file that
2312  /// \p Loc points to. If the location is in a file that was included
2313  /// into a module, or is outside any module, returns nullptr.
2314  Module *getModuleForLocation(SourceLocation Loc);
2315 
2316  /// We want to produce a diagnostic at location IncLoc concerning an
2317  /// unreachable effect at location MLoc (eg, where a desired entity was
2318  /// declared or defined). Determine whether the right way to make MLoc
2319  /// reachable is by #include, and if so, what header should be included.
2320  ///
2321  /// This is not necessarily fast, and might load unexpected module maps, so
2322  /// should only be called by code that intends to produce an error.
2323  ///
2324  /// \param IncLoc The location at which the missing effect was detected.
2325  /// \param MLoc A location within an unimported module at which the desired
2326  /// effect occurred.
2327  /// \return A file that can be #included to provide the desired effect. Null
2328  /// if no such file could be determined or if a #include is not
2329  /// appropriate (eg, if a module should be imported instead).
2330  const FileEntry *getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
2331  SourceLocation MLoc);
2332 
2333  bool isRecordingPreamble() const {
2334  return PreambleConditionalStack.isRecording();
2335  }
2336 
2337  bool hasRecordedPreamble() const {
2338  return PreambleConditionalStack.hasRecordedPreamble();
2339  }
2340 
2342  return PreambleConditionalStack.getStack();
2343  }
2344 
2346  PreambleConditionalStack.setStack(s);
2347  }
2348 
2351  PreambleConditionalStack.startReplaying();
2352  PreambleConditionalStack.setStack(s);
2353  PreambleConditionalStack.SkipInfo = SkipInfo;
2354  }
2355 
2357  return PreambleConditionalStack.SkipInfo;
2358  }
2359 
2360 private:
2361  /// After processing predefined file, initialize the conditional stack from
2362  /// the preamble.
2363  void replayPreambleConditionalStack();
2364 
2365  // Macro handling.
2366  void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterHeaderGuard);
2367  void HandleUndefDirective();
2368 
2369  // Conditional Inclusion.
2370  void HandleIfdefDirective(Token &Result, const Token &HashToken,
2371  bool isIfndef, bool ReadAnyTokensBeforeDirective);
2372  void HandleIfDirective(Token &IfToken, const Token &HashToken,
2373  bool ReadAnyTokensBeforeDirective);
2374  void HandleEndifDirective(Token &EndifToken);
2375  void HandleElseDirective(Token &Result, const Token &HashToken);
2376  void HandleElifFamilyDirective(Token &ElifToken, const Token &HashToken,
2378 
2379  // Pragmas.
2380  void HandlePragmaDirective(PragmaIntroducer Introducer);
2381  void ResolvePragmaIncludeInstead(SourceLocation Location) const;
2382 
2383 public:
2384  void HandlePragmaOnce(Token &OnceTok);
2385  void HandlePragmaMark(Token &MarkTok);
2386  void HandlePragmaPoison();
2387  void HandlePragmaSystemHeader(Token &SysHeaderTok);
2388  void HandlePragmaIncludeInstead(Token &Tok);
2389  void HandlePragmaDependency(Token &DependencyTok);
2390  void HandlePragmaPushMacro(Token &Tok);
2391  void HandlePragmaPopMacro(Token &Tok);
2392  void HandlePragmaIncludeAlias(Token &Tok);
2393  void HandlePragmaModuleBuild(Token &Tok);
2394  void HandlePragmaHdrstop(Token &Tok);
2396 
2397  // Return true and store the first token only if any CommentHandler
2398  // has inserted some tokens and getCommentRetentionState() is false.
2399  bool HandleComment(Token &result, SourceRange Comment);
2400 
2401  /// A macro is used, update information about macros that need unused
2402  /// warnings.
2403  void markMacroAsUsed(MacroInfo *MI);
2404 
2406  MacroDeprecationMsgs.insert(std::make_pair(II, Msg));
2407  }
2408 
2410  auto MsgEntry = MacroDeprecationMsgs.find(II);
2411  if (MsgEntry == MacroDeprecationMsgs.end())
2412  return llvm::None;
2413  return MsgEntry->second;
2414  }
2415 
2417  SourceLocation AnnotationLoc) {
2418  RestrictExpansionMacroMsgs.insert(
2419  std::make_pair(II, std::make_pair(std::move(Msg), AnnotationLoc)));
2420  }
2421 
2422  MsgLocationPair getRestrictExpansionMsg(const IdentifierInfo *II) {
2423  return RestrictExpansionMacroMsgs.find(II)->second;
2424  }
2425 
2427  if (Identifier.getIdentifierInfo()->isDeprecatedMacro())
2428  emitMacroDeprecationWarning(Identifier);
2429 
2430  if (Identifier.getIdentifierInfo()->isRestrictExpansion() &&
2431  !SourceMgr.isInMainFile(Identifier.getLocation()))
2432  emitMacroUnsafeHeaderWarning(Identifier);
2433  }
2434 
2435 private:
2436  void emitMacroDeprecationWarning(const Token &Identifier);
2437  void emitMacroUnsafeHeaderWarning(const Token &Identifier);
2438 
2440  getSkippedRangeForExcludedConditionalBlock(SourceLocation HashLoc);
2441 
2442  /// Contains the currently active skipped range mappings for skipping excluded
2443  /// conditional directives.
2445  *ExcludedConditionalDirectiveSkipMappings;
2446 };
2447 
2448 /// Abstract base class that describes a handler that will receive
2449 /// source ranges for each of the comments encountered in the source file.
2451 public:
2452  virtual ~CommentHandler();
2453 
2454  // The handler shall return true if it has pushed any tokens
2455  // to be read using e.g. EnterToken or EnterTokenStream.
2456  virtual bool HandleComment(Preprocessor &PP, SourceRange Comment) = 0;
2457 };
2458 
2459 /// Abstract base class that describes a handler that will receive
2460 /// source ranges for empty lines encountered in the source file.
2462 public:
2463  virtual ~EmptylineHandler();
2464 
2465  // The handler handles empty lines.
2466  virtual void HandleEmptyline(SourceRange Range) = 0;
2467 };
2468 
2469 /// Registry of pragma handlers added by plugins
2470 using PragmaHandlerRegistry = llvm::Registry<PragmaHandler>;
2471 
2472 } // namespace clang
2473 
2474 #endif // LLVM_CLANG_LEX_PREPROCESSOR_H
clang::MacroDirective::DefInfo::getDirective
const DefMacroDirective * getDirective() const
Definition: MacroInfo.h:349
clang::Preprocessor::isParsingIfOrElifDirective
bool isParsingIfOrElifDirective() const
True if we are currently preprocessing a if or #elif directive.
Definition: Preprocessor.h:972
clang::Preprocessor::PreambleSkipInfo::ElseLoc
SourceLocation ElseLoc
Definition: Preprocessor.h:443
clang::Preprocessor::MaybeHandlePoisonedIdentifier
void MaybeHandlePoisonedIdentifier(Token &Identifier)
Definition: Preprocessor.h:1925
clang::VariadicMacroScopeGuard
An RAII class that tracks when the Preprocessor starts and stops lexing the definition of a (ISO C/C+...
Definition: VariadicMacroSupport.h:30
clang::Lexer::isAtEndOfMacroExpansion
static bool isAtEndOfMacroExpansion(SourceLocation loc, const SourceManager &SM, const LangOptions &LangOpts, SourceLocation *MacroEnd=nullptr)
Returns true if the given MacroID location points at the last token of the macro expansion.
Definition: Lexer.cpp:827
clang::Preprocessor::HandlePragmaPopMacro
void HandlePragmaPopMacro(Token &Tok)
Handle #pragma pop_macro.
Definition: Pragma.cpp:681
clang::IdentifierInfo::hasMacroDefinition
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
Definition: IdentifierTable.h:181
clang::Preprocessor::HandlePragmaSystemHeader
void HandlePragmaSystemHeader(Token &SysHeaderTok)
HandlePragmaSystemHeader - Implement #pragma GCC system_header.
Definition: Pragma.cpp:469
clang::TokenValue
Stores token information for comparing actual tokens with predefined values.
Definition: Preprocessor.h:91
clang::Preprocessor::setSkipMainFilePreamble
void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine)
Instruct the preprocessor to skip part of the main source file.
Definition: Preprocessor.h:1713
clang::prec::Conditional
@ Conditional
Definition: OperatorPrecedence.h:30
clang::Preprocessor::CreateString
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's location and length to ...
Definition: Preprocessor.cpp:481
clang::Preprocessor::enableIncrementalProcessing
void enableIncrementalProcessing(bool value=true)
Enables the incremental processing.
Definition: Preprocessor.h:1621
clang::Preprocessor::RemovePragmaHandler
void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Remove the specific pragma handler from this preprocessor.
Definition: Pragma.cpp:977
clang::Preprocessor::getSpelling
std::string getSpelling(const Token &Tok, bool *Invalid=nullptr) const
Return the 'spelling' of the Tok token.
Definition: Preprocessor.h:1750
llvm
Definition: Dominators.h:30
clang::Preprocessor::AdvanceToTokenCharacter
SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Char) const
Given a location that specifies the start of a token, return a new location that specifies a characte...
Definition: Preprocessor.h:1878
clang::Preprocessor::CheckMacroName
bool CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef, bool *ShadowFlag=nullptr)
Definition: PPDirectives.cpp:269
clang::Preprocessor::getPreprocessorAllocator
llvm::BumpPtrAllocator & getPreprocessorAllocator()
Definition: Preprocessor.h:948
clang::ExternalPreprocessorSource
Abstract interface for external sources of preprocessor information.
Definition: ExternalPreprocessorSource.h:26
clang::Preprocessor::PrintStats
void PrintStats()
Definition: Preprocessor.cpp:268
clang::Preprocessor::FinalizeForModelFile
void FinalizeForModelFile()
Cleanup after model file parsing.
Definition: Preprocessor.cpp:225
clang::TokenValue::TokenValue
TokenValue(tok::TokenKind Kind)
Definition: Preprocessor.h:96
clang::DiagnosticBuilder
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1261
clang::Preprocessor::setPragmaAssumeNonNullLoc
void setPragmaAssumeNonNullLoc(SourceLocation Loc)
Set the location of the currently-active #pragma clang assume_nonnull begin.
Definition: Preprocessor.h:1697
clang::Preprocessor::FinishLexStringLiteral
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...
Definition: Preprocessor.cpp:1323
clang::Preprocessor::setCodeCompletionReached
void setCodeCompletionReached()
Note that we hit the code-completion point.
Definition: Preprocessor.h:1664
clang::ModuleMap::KnownHeader
A header that is known to reside within a given module, whether it was included or excluded.
Definition: ModuleMap.h:155
clang::Preprocessor::EnterTokenStream
void EnterTokenStream(ArrayRef< Token > Toks, bool DisableMacroExpansion, bool IsReinject)
Definition: Preprocessor.h:1385
clang::Preprocessor::LookAhead
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
Definition: Preprocessor.h:1506
clang::Preprocessor::addMacroDeprecationMsg
void addMacroDeprecationMsg(const IdentifierInfo *II, std::string Msg)
Definition: Preprocessor.h:2405
clang::Preprocessor::setRecordedPreambleConditionalStack
void setRecordedPreambleConditionalStack(ArrayRef< PPConditionalInfo > s)
Definition: Preprocessor.h:2345
clang::Preprocessor::getMacroDefinition
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
Definition: Preprocessor.h:1089
clang::Preprocessor::SetCodeCompletionPoint
bool SetCodeCompletionPoint(const FileEntry *File, unsigned Line, unsigned Column)
Specify the point at which code-completion will be performed.
Definition: Preprocessor.cpp:387
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:212
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::PreprocessorOptions
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Definition: PreprocessorOptions.h:64
clang::Preprocessor::getModuleMacro
ModuleMacro * getModuleMacro(Module *Mod, const IdentifierInfo *II)
Definition: PPMacroExpansion.cpp:174
clang::Preprocessor::HandlePragmaMark
void HandlePragmaMark(Token &MarkTok)
Definition: Pragma.cpp:417
clang::Preprocessor::setCodeCompletionHandler
void setCodeCompletionHandler(CodeCompletionHandler &Handler)
Set the code completion handler to the given object.
Definition: Preprocessor.h:1260
clang::Preprocessor::HandleEndOfTokenLexer
bool HandleEndOfTokenLexer(Token &Result)
Callback invoked when the current TokenLexer hits the end of its token stream.
Definition: PPLexerChange.cpp:589
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:132
clang::Preprocessor::getLastMacroWithSpelling
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
Definition: Preprocessor.cpp:351
clang::Lexer::getRawToken
static bool getRawToken(SourceLocation Loc, Token &Result, const SourceManager &SM, const LangOptions &LangOpts, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
Definition: Lexer.cpp:458
clang::Preprocessor::getPPCallbacks
PPCallbacks * getPPCallbacks() const
Definition: Preprocessor.h:1034
clang::Preprocessor::setCodeCompletionTokenRange
void setCodeCompletionTokenRange(const SourceLocation Start, const SourceLocation End)
Set the code completion token range for detecting replacement range later on.
Definition: Preprocessor.h:1289
clang::Preprocessor::isIncrementalProcessingEnabled
bool isIncrementalProcessingEnabled() const
Returns true if incremental processing is enabled.
Definition: Preprocessor.h:1618
clang::Preprocessor::Lex
void Lex(Token &Result)
Lex the next token for this preprocessor.
Definition: Preprocessor.cpp:888
clang::Preprocessor::HandleIdentifier
bool HandleIdentifier(Token &Identifier)
Callback invoked when the lexer reads an identifier and has filled in the tokens IdentifierInfo membe...
Definition: Preprocessor.cpp:796
clang::Preprocessor::getLocalMacroDirectiveHistory
MacroDirective * getLocalMacroDirectiveHistory(const IdentifierInfo *II) const
Given an identifier, return the latest non-imported macro directive for that identifier.
Definition: PPMacroExpansion.cpp:63
ModuleMap.h
clang::Preprocessor::isAtEndOfMacroExpansion
bool isAtEndOfMacroExpansion(SourceLocation loc, SourceLocation *MacroEnd=nullptr) const
Returns true if the given MacroID location points at the last token of the macro expansion.
Definition: Preprocessor.h:1865
clang::Preprocessor::getCodeCompletionTokenRange
SourceRange getCodeCompletionTokenRange() const
Definition: Preprocessor.h:1293
clang::Preprocessor::macro_iterator
MacroMap::const_iterator macro_iterator
Definition: Preprocessor.h:1190
clang::Token::getLiteralData
const char * getLiteralData() const
getLiteralData - For a literal token (numeric constant, string, etc), this returns a pointer to the s...
Definition: Token.h:217
clang::Preprocessor::LookupFile
Optional< FileEntryRef > LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const FileEntry *FromFile, const DirectoryLookup *&CurDir, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache=false)
Given a "foo" or <foo> reference, look up the indicated file.
Definition: PPDirectives.cpp:818
clang::Lexer::getSpelling
static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, const LangOptions &LangOpts, bool *Invalid=nullptr)
getSpelling - This method is used to get the spelling of a token into a preallocated buffer,...
Definition: Lexer.cpp:400
clang::MacroDefinition
A description of the current definition of a macro.
Definition: MacroInfo.h:564
clang::Preprocessor::LexHeaderName
bool LexHeaderName(Token &Result, bool AllowMacroExpansion=true)
Lex a token, forming a header-name token if possible.
Definition: Preprocessor.cpp:988
clang::CommentHandler::HandleComment
virtual bool HandleComment(Preprocessor &PP, SourceRange Comment)=0
llvm::SmallVector
Definition: LLVM.h:38
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:564
clang::Preprocessor::getMaxTokens
unsigned getMaxTokens() const
Get the max number of tokens before issuing a -Wmax-tokens warning.
Definition: Preprocessor.h:1047
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::Preprocessor::TUKind
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
Definition: Preprocessor.h:270
clang::PPCallbacks
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition: PPCallbacks.h:35
clang::Preprocessor::getCommentRetentionState
bool getCommentRetentionState() const
Definition: Preprocessor.h:982
clang::driver::phases::Preprocess
@ Preprocess
Definition: Phases.h:18
clang::Preprocessor::RemoveTopOfLexerStack
void RemoveTopOfLexerStack()
Pop the current lexer/macro exp off the top of the lexer stack.
Definition: PPLexerChange.cpp:610
clang::Preprocessor::IgnorePragmas
void IgnorePragmas()
Install empty handlers for all pragmas (making them ignored).
Definition: Pragma.cpp:2119
clang::MultiVersionKind::Target
@ Target
clang::Preprocessor::getModuleForLocation
Module * getModuleForLocation(SourceLocation Loc)
Find the module that owns the source or header file that Loc points to.
Definition: PPDirectives.cpp:731
clang::PreprocessorLexer
Definition: PreprocessorLexer.h:31
clang::tooling::Filter
llvm::cl::opt< std::string > Filter
clang::Token::getIdentifierInfo
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:179
clang::MacroArgs
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
Definition: MacroArgs.h:29
Filename
StringRef Filename
Definition: Format.cpp:2333
clang::Preprocessor::setExternalSource
void setExternalSource(ExternalPreprocessorSource *Source)
Definition: Preprocessor.h:950
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::PreprocessingRecord
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
Definition: PreprocessingRecord.h:308
Module.h
clang::IdentifierInfo::isOutOfDate
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
Definition: IdentifierTable.h:386
clang::Preprocessor::CodeCompleteIncludedFile
void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled)
Hook used by the lexer to invoke the "included file" code completion point.
Definition: Preprocessor.cpp:443
llvm::Optional
Definition: LLVM.h:40
clang::Preprocessor::macro_end
macro_iterator macro_end(bool IncludeExternalMacros=true) const
Definition: Preprocessor.cpp:334
clang::ModuleLoader::HadFatalFailure
bool HadFatalFailure
Definition: ModuleLoader.h:157
clang::Preprocessor::getMacroDeprecationMsg
llvm::Optional< std::string > getMacroDeprecationMsg(const IdentifierInfo *II)
Definition: Preprocessor.h:2409
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
SourceManager.h
clang::Preprocessor::getCurrentLexer
PreprocessorLexer * getCurrentLexer() const
Return the current lexer being lexed from.
Definition: Preprocessor.h:1014
clang::Preprocessor::appendDefMacroDirective
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI)
Definition: Preprocessor.h:1157
clang::Preprocessor::setReplayablePreambleConditionalStack
void setReplayablePreambleConditionalStack(ArrayRef< PPConditionalInfo > s, llvm::Optional< PreambleSkipInfo > SkipInfo)
Definition: Preprocessor.h:2349
clang::TokenValue::operator==
bool operator==(const Token &Tok) const
Definition: Preprocessor.h:106
clang::Preprocessor::EnterToken
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
Definition: Preprocessor.h:1535
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:627
clang::DiagnosticsEngine::setSuppressAllDiagnostics
void setSuppressAllDiagnostics(bool Val)
Suppress all diagnostics, to silence the front end when we know that we don't want any more diagnosti...
Definition: Diagnostic.h:690
DiagnosticIDs.h
clang::Preprocessor::getCurrentFileLexer
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
Definition: PPLexerChange.cpp:50
clang::Preprocessor::IncrementPasteCounter
void IncrementPasteCounter(bool isFast)
Increment the counters for the number of token paste operations performed.
Definition: Preprocessor.h:1887
clang::Preprocessor::MacroArgs
friend class MacroArgs
Definition: Preprocessor.h:455
clang::ExcludedPreprocessorDirectiveSkipMapping
llvm::DenseMap< const char *, const PreprocessorSkippedRangeMapping * > ExcludedPreprocessorDirectiveSkipMapping
The datastructure that holds the mapping between the active memory buffers and the individual skip ma...
Definition: PreprocessorExcludedConditionalDirectiveSkipMapping.h:26
Identifier
StringRef Identifier
Definition: Format.cpp:2341
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::CommentHandler
Abstract base class that describes a handler that will receive source ranges for each of the comments...
Definition: Preprocessor.h:2450
clang::Preprocessor::AddPragmaHandler
void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Add the specified pragma handler to this preprocessor.
Definition: Pragma.cpp:946
clang::Preprocessor::ReplaceLastTokenWithAnnotation
void ReplaceLastTokenWithAnnotation(const Token &Tok)
Replace the last token with an annotation token.
Definition: Preprocessor.h:1589
End
SourceLocation End
Definition: USRLocFinder.cpp:167
TokenLexer.h
clang::Preprocessor::ReplacePreviousCachedToken
void ReplacePreviousCachedToken(ArrayRef< Token > NewToks)
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
Definition: PPCaching.cpp:157
clang::Preprocessor::isCodeCompletionReached
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
Definition: Preprocessor.h:1661
clang::CodeCompletionHandler
Callback handler that receives notifications when performing code completion within the preprocessor.
Definition: CodeCompletionHandler.h:25
clang::Preprocessor::getIdentifierTable
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:944
clang::Preprocessor::PreambleSkipInfo::PreambleSkipInfo
PreambleSkipInfo(SourceLocation HashTokenLoc, SourceLocation IfTokenLoc, bool FoundNonSkipPortion, bool FoundElse, SourceLocation ElseLoc)
Definition: Preprocessor.h:445
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
clang::Preprocessor::setPragmasEnabled
void setPragmasEnabled(bool Enabled)
Definition: Preprocessor.h:984
clang::Preprocessor::getLangOpts
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:937
clang::Preprocessor::getImmediateMacroName
StringRef getImmediateMacroName(SourceLocation Loc)
Retrieve the name of the immediate macro expansion.
Definition: Preprocessor.h:1812
clang::HeaderSearch
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
Definition: HeaderSearch.h:169
clang::Preprocessor::creatingPCHWithPragmaHdrStop
bool creatingPCHWithPragmaHdrStop()
True if creating a PCH with a #pragma hdrstop.
Definition: Preprocessor.cpp:613
clang::Preprocessor::AnnotateCachedTokens
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
Definition: Preprocessor.h:1557
Offset
unsigned Offset
Definition: Format.cpp:2335
clang::Preprocessor::getPragmasEnabled
bool getPragmasEnabled() const
Definition: Preprocessor.h:985
clang::Preprocessor::usingPCHWithThroughHeader
bool usingPCHWithThroughHeader()
True if using a PCH with a through header.
Definition: Preprocessor.cpp:608
BuiltinInfo
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:20
TokenKinds.h
clang::Preprocessor::GetIncludeFilenameSpelling
bool GetIncludeFilenameSpelling(SourceLocation Loc, StringRef &Buffer)
Turn the specified lexer token into a fully checked and spelled filename, e.g.
Definition: PPDirectives.cpp:1601
clang::Preprocessor::getMacroDefinitionAtLoc
MacroDefinition getMacroDefinitionAtLoc(const IdentifierInfo *II, SourceLocation Loc)
Definition: Preprocessor.h:1102
clang::Preprocessor::PreambleSkipInfo::HashTokenLoc
SourceLocation HashTokenLoc
Definition: Preprocessor.h:439
V
#define V(N, I)
Definition: ASTContext.h:3113
clang::Preprocessor::HandlePragmaOnce
void HandlePragmaOnce(Token &OnceTok)
HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'.
Definition: Pragma.cpp:402
clang::Preprocessor::AllocateMacroInfo
MacroInfo * AllocateMacroInfo(SourceLocation L)
Allocate a new MacroInfo object with the provided SourceLocation.
Definition: PPDirectives.cpp:58
clang::Preprocessor::SetPoisonReason
void SetPoisonReason(IdentifierInfo *II, unsigned DiagID)
Specifies the reason for poisoning an identifier.
Definition: Preprocessor.cpp:731
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::Preprocessor::TypoCorrectToken
void TypoCorrectToken(const Token &Tok)
Update the current token to represent the provided identifier, in order to cache an action performed ...
Definition: Preprocessor.h:1607
clang::Preprocessor::getBuildingSubmodules
ArrayRef< BuildingSubmoduleInfo > getBuildingSubmodules() const
Get the list of submodules that we're currently building.
Definition: Preprocessor.h:1182
clang::Preprocessor::getPreambleSkipInfo
llvm::Optional< PreambleSkipInfo > getPreambleSkipInfo() const
Definition: Preprocessor.h:2356
clang::Preprocessor::SetCommentRetentionState
void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments)
Control whether the preprocessor retains comments in output.
Definition: Preprocessor.h:977
clang::Preprocessor::getIdentifierTable
const IdentifierTable & getIdentifierTable() const
Definition: Preprocessor.h:945
clang::frontend::ActionKind
ActionKind
Definition: FrontendOptions.h:35
clang::Preprocessor::EndSourceFile
void EndSourceFile()
Inform the preprocessor callbacks that processing is complete.
Definition: Preprocessor.cpp:683
clang::Preprocessor::ParsePragmaPushOrPopMacro
IdentifierInfo * ParsePragmaPushOrPopMacro(Token &Tok)
ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
Definition: Pragma.cpp:603
clang::Preprocessor::getCounterValue
unsigned getCounterValue() const
Definition: Preprocessor.h:2004
clang::Preprocessor::setLoadedMacroDirective
void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD)
Set a MacroDirective that was loaded from a PCH file.
Definition: PPMacroExpansion.cpp:96
clang::DirectoryEntry
Cached information about one directory (either on disk or in the virtual file system).
Definition: DirectoryEntry.h:33
Id
int Id
Definition: ASTDiff.cpp:191
clang::Preprocessor::getSpellingOfSingleCharacterNumericConstant
char getSpellingOfSingleCharacterNumericConstant(const Token &Tok, bool *Invalid=nullptr) const
Given a Token Tok that is a numeric constant with length 1, return the character.
Definition: Preprocessor.h:1789
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
clang::Preprocessor::setPredefines
void setPredefines(const char *P)
Set the predefines for this Preprocessor.
Definition: Preprocessor.h:1215
clang::Preprocessor::PreambleSkipInfo::FoundNonSkipPortion
bool FoundNonSkipPortion
Definition: Preprocessor.h:441
clang::Preprocessor::InitializeForModelFile
void InitializeForModelFile()
Initialize the preprocessor to parse a model file.
Definition: Preprocessor.cpp:213
clang::Preprocessor::setPreprocessToken
void setPreprocessToken(bool Preprocess)
Definition: Preprocessor.h:1063
clang::Preprocessor::addCommentHandler
void addCommentHandler(CommentHandler *Handler)
Add the specified comment handler to the preprocessor.
Definition: Preprocessor.cpp:1384
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:92
clang::index::SymbolKind::Module
@ Module
clang::Preprocessor::isAtStartOfMacroExpansion
bool isAtStartOfMacroExpansion(SourceLocation loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the first token of the macro expansion.
Definition: Preprocessor.h:1854
LangOptions.h
clang::Preprocessor::isPCHThroughHeader
bool isPCHThroughHeader(const FileEntry *FE)
Returns true if the FileEntry is the PCH through header.
Definition: Preprocessor.cpp:597
clang::DirectoryLookup
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
Definition: DirectoryLookup.h:30
Diagnostic.h
clang::Preprocessor::getSelectorTable
SelectorTable & getSelectorTable()
Definition: Preprocessor.h:946
PreprocessorExcludedConditionalDirectiveSkipMapping.h
clang::Preprocessor::Diag
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
Definition: Preprocessor.h:1721
clang::Preprocessor::Diag
DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) const
Definition: Preprocessor.h:1725
ModuleLoader.h
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::Preprocessor::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: Preprocessor.h:938
clang::Preprocessor::createPreprocessingRecord
void createPreprocessingRecord()
Create a new preprocessing record, which will keep track of all macro expansions, macro definitions,...
Definition: Preprocessor.cpp:1441
clang::Preprocessor::isMacroDefined
bool isMacroDefined(StringRef Id)
Definition: Preprocessor.h:1065
IdentifierTable.h
clang::Preprocessor::isBacktrackEnabled
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
Definition: Preprocessor.h:1421
clang::Preprocessor::EnterSubmodule
void EnterSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Definition: PPLexerChange.cpp:687
clang::Token::needsCleaning
bool needsCleaning() const
Return true if this token has trigraphs or escaped newlines in it.
Definition: Token.h:285
clang::SelectorTable
This table allows us to fully hide how we implement multi-keyword caching.
Definition: IdentifierTable.h:865
bool
#define bool
Definition: stdbool.h:15
clang::Preprocessor::AddPragmaHandler
void AddPragmaHandler(PragmaHandler *Handler)
Definition: Preprocessor.h:1229
clang::Preprocessor::HandlePragmaPushMacro
void HandlePragmaPushMacro(Token &Tok)
Handle #pragma push_macro.
Definition: Pragma.cpp:658
clang::Preprocessor::getCodeCompletionHandler
CodeCompletionHandler * getCodeCompletionHandler() const
Retrieve the current code-completion handler.
Definition: Preprocessor.h:1265
clang::Preprocessor::LexAfterModuleImport
bool LexAfterModuleImport(Token &Result)
Lex a token following the 'import' contextual keyword.
Definition: Preprocessor.cpp:1131
clang::Preprocessor::HandleSkippedDirectiveWhileUsingPCH
void HandleSkippedDirectiveWhileUsingPCH(Token &Result, SourceLocation HashLoc)
Process directives while skipping until the through header or #pragma hdrstop is found.
Definition: PPDirectives.cpp:974
clang::Preprocessor::getMacroInfo
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
Definition: Preprocessor.h:1130
clang::PragmaIntroducer
Describes how and where the pragma was introduced.
Definition: Pragma.h:51
clang::EmptylineHandler
Abstract base class that describes a handler that will receive source ranges for empty lines encounte...
Definition: Preprocessor.h:2461
clang::CommentHandler::~CommentHandler
virtual ~CommentHandler()
clang::TokenValue::TokenValue
TokenValue(IdentifierInfo *II)
Definition: Preprocessor.h:104
clang::Preprocessor::setCounterValue
void setCounterValue(unsigned V)
Definition: Preprocessor.h:2005
clang::Preprocessor::EnterMainSourceFile
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc.
Definition: Preprocessor.cpp:530
clang::Preprocessor::GetSuppressIncludeNotFoundError
bool GetSuppressIncludeNotFoundError()
Definition: Preprocessor.h:991
clang::Lexer::getImmediateMacroName
static StringRef getImmediateMacroName(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
Retrieve the name of the immediate macro expansion.
Definition: Lexer.cpp:993
clang::EmptylineHandler::HandleEmptyline
virtual void HandleEmptyline(SourceRange Range)=0
clang::Preprocessor::getPreambleConditionalStack
ArrayRef< PPConditionalInfo > getPreambleConditionalStack() const
Definition: Preprocessor.h:2341
clang::Preprocessor::getCodeCompletionFilter
StringRef getCodeCompletionFilter()
Get the code completion token for filtering purposes.
Definition: Preprocessor.h:1298
Line
const AnnotatedLine * Line
Definition: UsingDeclarationsSorter.cpp:68
clang::Preprocessor::getLastCachedTokenLocation
SourceLocation getLastCachedTokenLocation() const
Get the location of the last cached token, suitable for setting the end location of an annotation tok...
Definition: Preprocessor.h:1565
clang::Preprocessor::getRawToken
bool getRawToken(SourceLocation Loc, Token &Result, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
Definition: Preprocessor.h:1781
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:331
clang::Preprocessor::SplitToken
SourceLocation SplitToken(SourceLocation TokLoc, unsigned Length)
Split the first Length characters out of the token starting at TokLoc and return a location pointing ...
Definition: Preprocessor.cpp:501
clang::MU_Define
@ MU_Define
Definition: Preprocessor.h:118
clang::Preprocessor::getLocalMacroDirective
MacroDirective * getLocalMacroDirective(const IdentifierInfo *II) const
Given an identifier, return its latest non-imported MacroDirective if it is #define'd and not #undef'...
Definition: Preprocessor.h:1119
clang::Preprocessor::LexUnexpandedNonComment
void LexUnexpandedNonComment(Token &Result)
Like LexNonComment, but this disables macro expansion of identifier tokens.
Definition: Preprocessor.h:1482
clang::Token::getLength
unsigned getLength() const
Definition: Token.h:129
clang::PragmaHandler
PragmaHandler - Instances of this interface defined to handle the various pragmas that the language f...
Definition: Pragma.h:65
clang::DefMacroDirective
A directive for a defined macro or a macro imported from a module.
Definition: MacroInfo.h:406
clang::Preprocessor::GetCurDirLookup
const DirectoryLookup * GetCurDirLookup()
Get the DirectoryLookup structure used to find the current FileEntry, if CurLexer is non-null and if ...
Definition: Preprocessor.h:2041
clang::MU_Undef
@ MU_Undef
Definition: Preprocessor.h:121
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition: Preprocessor.h:941
clang::Preprocessor::HandlePragmaModuleBuild
void HandlePragmaModuleBuild(Token &Tok)
Definition: Pragma.cpp:838
clang::transformer::EditKind::Range
@ Range
clang::Preprocessor::HandleComment
bool HandleComment(Token &result, SourceRange Comment)
Definition: Preprocessor.cpp:1398
clang::Preprocessor::LexOnOffSwitch
bool LexOnOffSwitch(tok::OnOffSwitch &Result)
Lex an on-off-switch (C99 6.10.6p2) and verify that it is followed by EOD.
Definition: Pragma.cpp:999
clang::Preprocessor::getSpelling
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
Definition: Preprocessor.h:1736
clang::Preprocessor::PoisonSEHIdentifiers
void PoisonSEHIdentifiers(bool Poison=true)
Definition: Preprocessor.cpp:735
clang::Preprocessor::getTokenCount
unsigned getTokenCount() const
Get the number of tokens processed so far.
Definition: Preprocessor.h:1044
clang::Preprocessor::SetMacroExpansionOnlyInDirectives
void SetMacroExpansionOnlyInDirectives()
Disables macro expansion everywhere except for preprocessor directives.
Definition: Preprocessor.h:1494
clang::Preprocessor::PreambleSkipInfo::FoundElse
bool FoundElse
Definition: Preprocessor.h:442
clang::Preprocessor::CollectPpImportSuffix
void CollectPpImportSuffix(SmallVectorImpl< Token > &Toks)
Collect the tokens of a C++20 pp-import-suffix.
Definition: Preprocessor.cpp:1077
clang::Preprocessor::getAuxTargetInfo
const TargetInfo * getAuxTargetInfo() const
Definition: Preprocessor.h:939
SourceLocation.h
clang::Preprocessor::SkipTokensWhileUsingPCH
void SkipTokensWhileUsingPCH()
Skip tokens until after the include of the through header or until after a #pragma hdrstop.
Definition: Preprocessor.cpp:626
clang::Preprocessor::getTotalMemory
size_t getTotalMemory() const
Definition: Preprocessor.cpp:321
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
clang::Preprocessor::CodeCompleteNaturalLanguage
void CodeCompleteNaturalLanguage()
Hook used by the lexer to invoke the "natural language" code completion point.
Definition: Preprocessor.cpp:450
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::Preprocessor::HandlePragmaPoison
void HandlePragmaPoison()
HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'.
Definition: Pragma.cpp:427
clang::Preprocessor::HandleDirective
void HandleDirective(Token &Result)
Callback invoked when the lexer sees a # token at the start of a line.
Definition: PPDirectives.cpp:999
clang::Preprocessor::getBuiltinInfo
Builtin::Context & getBuiltinInfo()
Definition: Preprocessor.h:947
clang::Preprocessor::hadModuleLoaderFatalFailure
bool hadModuleLoaderFatalFailure() const
Definition: Preprocessor.h:961
clang::Preprocessor::getCodeCompletionFileLoc
SourceLocation getCodeCompletionFileLoc() const
Returns the start location of the file of code-completion point.
Definition: Preprocessor.h:1655
clang::Preprocessor::DumpLocation
void DumpLocation(SourceLocation Loc) const
Definition: Preprocessor.cpp:255
clang::Preprocessor::setPreprocessedOutput
void setPreprocessedOutput(bool IsPreprocessedOutput)
Sets whether the preprocessor is responsible for producing output or if it is producing tokens to be ...
Definition: Preprocessor.h:997
clang::Preprocessor::usingPCHWithPragmaHdrStop
bool usingPCHWithPragmaHdrStop()
True if using a PCH with a #pragma hdrstop.
Definition: Preprocessor.cpp:617
clang::Preprocessor::isCodeCompletionEnabled
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
Definition: Preprocessor.h:1643
clang::Preprocessor::getPragmaARCCFCodeAuditedInfo
std::pair< IdentifierInfo *, SourceLocation > getPragmaARCCFCodeAuditedInfo() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
Definition: Preprocessor.h:1676
clang::Preprocessor::dumpMacroInfo
void dumpMacroInfo(const IdentifierInfo *II)
Definition: PPMacroExpansion.cpp:261
llvm::ArrayRef
Definition: LLVM.h:34
Lexer.h
Value
Value
Definition: UninitializedValues.cpp:102
clang::Preprocessor::hasRecordedPreamble
bool hasRecordedPreamble() const
Definition: Preprocessor.h:2337
clang::Preprocessor::setCodeCompletionIdentifierInfo
void setCodeCompletionIdentifierInfo(IdentifierInfo *Filter)
Set the code completion token for filtering purposes.
Definition: Preprocessor.h:1283
clang::Preprocessor::setEmptylineHandler
void setEmptylineHandler(EmptylineHandler *Handler)
Set empty line handler.
Definition: Preprocessor.h:1247
clang::Preprocessor::EnableBacktrackAtThisPos
void EnableBacktrackAtThisPos()
From the point that this method is called, and until CommitBacktrackedTokens() or Backtrack() is call...
Definition: PPCaching.cpp:25
clang::tok::PPKeywordKind
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
Definition: TokenKinds.h:33
clang::Preprocessor::getPragmaAssumeNonNullLoc
SourceLocation getPragmaAssumeNonNullLoc() const
The location of the currently-active #pragma clang assume_nonnull begin.
Definition: Preprocessor.h:1691
clang::Preprocessor::PreambleSkipInfo::IfTokenLoc
SourceLocation IfTokenLoc
Definition: Preprocessor.h:440
clang::Preprocessor::getCurrentLexerSubmodule
Module * getCurrentLexerSubmodule() const
Return the submodule owning the file being lexed.
Definition: Preprocessor.h:1024
clang::Preprocessor::appendDefMacroDirective
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
Definition: Preprocessor.h:1151
LLVM.h
clang::Preprocessor::DumpToken
void DumpToken(const Token &Tok, bool DumpFlags=false) const
Print the token to stderr, used for debugging.
Definition: Preprocessor.cpp:231
clang::Preprocessor::markMacroAsUsed
void markMacroAsUsed(MacroInfo *MI)
A macro is used, update information about macros that need unused warnings.
Definition: PPMacroExpansion.cpp:1870
clang::Preprocessor::HandleEndOfFile
bool HandleEndOfFile(Token &Result, SourceLocation Loc, bool isEndOfMacro=false)
Callback invoked when the lexer hits the end of the current file.
Definition: PPLexerChange.cpp:342
State
LineState State
Definition: UnwrappedLineFormatter.cpp:986
clang::Preprocessor::isMacroDefined
bool isMacroDefined(const IdentifierInfo *II)
Definition: Preprocessor.h:1068
clang::Preprocessor::getFileManager
FileManager & getFileManager() const
Definition: Preprocessor.h:940
clang::VAOptDefinitionContext
A class for tracking whether we're inside a VA_OPT during a traversal of the tokens of a variadic mac...
Definition: VariadicMacroSupport.h:66
clang::Preprocessor::getCurrentModule
Module * getCurrentModule()
Retrieves the module that we're currently building, if any.
Definition: Preprocessor.cpp:517
clang::Preprocessor::Backtrack
void Backtrack()
Make Preprocessor re-lex the tokens that were lexed since EnableBacktrackAtThisPos() was previously c...
Definition: PPCaching.cpp:40
clang::Preprocessor::isPreprocessedOutput
bool isPreprocessedOutput() const
Returns true if the preprocessor is responsible for generating output, false if it is producing token...
Definition: Preprocessor.h:1003
clang::Preprocessor::IsPreviousCachedToken
bool IsPreviousCachedToken(const Token &Tok) const
Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
Definition: PPCaching.cpp:139
clang::ModuleLoader
Abstract interface for a module loader.
Definition: ModuleLoader.h:77
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:67
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:126
clang::Preprocessor::LexStringLiteral
bool LexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
Lex a string literal, which may be the concatenation of multiple string literals and may even come fr...
Definition: Preprocessor.h:1441
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::Token::isAnnotation
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
Definition: Token.h:120
clang::Preprocessor::removeCommentHandler
void removeCommentHandler(CommentHandler *Handler)
Remove the specified comment handler.
Definition: Preprocessor.cpp:1391
clang::Preprocessor::getModuleImportLoc
SourceLocation getModuleImportLoc(Module *M) const
Definition: Preprocessor.h:1434
clang::Preprocessor::getRestrictExpansionMsg
MsgLocationPair getRestrictExpansionMsg(const IdentifierInfo *II)
Definition: Preprocessor.h:2422
clang::Preprocessor::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
Definition: Preprocessor.h:932
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:342
std
Definition: Format.h:3899
clang::Preprocessor::getModuleLoader
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with this preprocessor.
Definition: Preprocessor.h:959
clang::TranslationUnitKind
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:703
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:126
clang::Preprocessor::getSpelling
unsigned getSpelling(const Token &Tok, const char *&Buffer, bool *Invalid=nullptr) const
Get the spelling of a token into a preallocated buffer, instead of as an std::string.
Definition: Preprocessor.h:1766
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:175
clang::Preprocessor::getCodeCompletionLoc
SourceLocation getCodeCompletionLoc() const
Returns the location of the code-completion point.
Definition: Preprocessor.h:1649
clang::Preprocessor::CheckEndOfDirective
SourceLocation CheckEndOfDirective(const char *DirType, bool EnableMacros=false)
Ensure that the next token is a tok::eod token.
Definition: PPDirectives.cpp:370
clang::Preprocessor::clearCodeCompletionHandler
void clearCodeCompletionHandler()
Clear out the code completion handler.
Definition: Preprocessor.h:1270
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::Preprocessor::addPPCallbacks
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
Definition: Preprocessor.h:1035
clang::Lexer::isAtStartOfMacroExpansion
static bool isAtStartOfMacroExpansion(SourceLocation loc, const SourceManager &SM, const LangOptions &LangOpts, SourceLocation *MacroBegin=nullptr)
Returns true if the given MacroID location points at the first token of the macro expansion.
Definition: Lexer.cpp:805
clang::Preprocessor::overrideMaxTokens
void overrideMaxTokens(unsigned Value, SourceLocation Loc)
Definition: Preprocessor.h:1049
clang::Preprocessor::HandlePragmaIncludeInstead
void HandlePragmaIncludeInstead(Token &Tok)
HandlePragmaIncludeInstead - Handle #pragma clang include_instead(header).
Definition: Pragma.cpp:542
clang::Preprocessor::getMaxTokensOverrideLoc
SourceLocation getMaxTokensOverrideLoc() const
Definition: Preprocessor.h:1054
PPCallbacks.h
clang::Preprocessor::creatingPCHWithThroughHeader
bool creatingPCHWithThroughHeader()
True if creating a PCH with a through header.
Definition: Preprocessor.cpp:603
clang::Preprocessor::LookUpIdentifierInfo
IdentifierInfo * LookUpIdentifierInfo(Token &Identifier) const
Given a tok::raw_identifier token, look up the identifier information for the token and install it in...
Definition: Preprocessor.cpp:696
clang::Builtin::Context
Holds information about both target-independent and target-specific builtins, allowing easy queries b...
Definition: Builtins.h:67
clang::IdentifierInfo::hadMacroDefinition
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
Definition: IdentifierTable.h:202
clang::PragmaHandlerRegistry
llvm::Registry< PragmaHandler > PragmaHandlerRegistry
Registry of pragma handlers added by plugins.
Definition: Preprocessor.h:2470
MacroInfo.h
clang::MacroDirective
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:290
clang::Preprocessor::HandlePragmaHdrstop
void HandlePragmaHdrstop(Token &Tok)
Definition: Pragma.cpp:912
clang::Preprocessor::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: Preprocessor.h:934
clang::Preprocessor::Preprocessor
Preprocessor(std::shared_ptr< PreprocessorOptions > PPOpts, DiagnosticsEngine &diags, LangOptions &opts, SourceManager &SM, HeaderSearch &Headers, ModuleLoader &TheModuleLoader, IdentifierInfoLookup *IILookup=nullptr, bool OwnsHeaderSearch=false, TranslationUnitKind TUKind=TU_Complete)
Definition: Preprocessor.cpp:79
clang::EmptylineHandler::~EmptylineHandler
virtual ~EmptylineHandler()
clang::Preprocessor::getNumDirectives
unsigned getNumDirectives() const
Retrieve the number of Directives that have been processed by the Preprocessor.
Definition: Preprocessor.h:967
clang::Preprocessor::SetSuppressIncludeNotFoundError
void SetSuppressIncludeNotFoundError(bool Suppress)
Definition: Preprocessor.h:987
clang::Preprocessor::addRestrictExpansionMsg
void addRestrictExpansionMsg(const IdentifierInfo *II, std::string Msg, SourceLocation AnnotationLoc)
Definition: Preprocessor.h:2416
clang::Preprocessor::setPredefines
void setPredefines(StringRef P)
Definition: Preprocessor.h:1216
clang::Preprocessor::DiscardUntilEndOfDirective
SourceRange DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found.
Definition: PPDirectives.cpp:82
clang::Preprocessor::getLeafModuleMacros
ArrayRef< ModuleMacro * > getLeafModuleMacros(const IdentifierInfo *II) const
Get the list of leaf (non-overridden) module macros for a name.
Definition: Preprocessor.h:1172
clang::tok::OnOffSwitch
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
Definition: TokenKinds.h:48
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:40
clang::tok::isAnnotation
bool isAnnotation(TokenKind K)
Return true if this is any of tok::annot_* kinds.
Definition: TokenKinds.cpp:49
clang::tok::isLiteral
bool isLiteral(TokenKind K)
Return true if this is a "literal" kind, like a numeric constant, string, etc.
Definition: TokenKinds.h:86
clang::Preprocessor::setDiagnostics
void setDiagnostics(DiagnosticsEngine &D)
Definition: Preprocessor.h:935
clang::Preprocessor::getPredefines
const std::string & getPredefines() const
Definition: Preprocessor.h:1210
clang::IdentifierTable
Implements an efficient mapping from strings to IdentifierInfo nodes.
Definition: IdentifierTable.h:531
s
__device__ __2f16 float bool s
Definition: __clang_hip_libdevice_declares.h:315
clang::Preprocessor::isInPrimaryFile
bool isInPrimaryFile() const
Return true if we're in the top-level file, not in a #include.
Definition: PPLexerChange.cpp:35
clang::Preprocessor::getLocForEndOfToken
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
Definition: Preprocessor.h:1845
clang::Preprocessor::makeModuleVisible
void makeModuleVisible(Module *M, SourceLocation Loc)
Definition: Preprocessor.cpp:1306
clang::Preprocessor::isCurrentLexer
bool isCurrentLexer(const PreprocessorLexer *L) const
Return true if we are lexing directly from the specified lexer.
Definition: Preprocessor.h:1006
clang::Preprocessor::recomputeCurLexerKind
void recomputeCurLexerKind()
Recompute the current lexer kind based on the CurLexer/ CurTokenLexer pointers.
Definition: Preprocessor.cpp:378
clang::Preprocessor::DumpMacro
void DumpMacro(const MacroInfo &MI) const
Definition: Preprocessor.cpp:259
clang::Preprocessor::HandlePragmaDependency
void HandlePragmaDependency(Token &DependencyTok)
HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah.
Definition: Pragma.cpp:575
clang::Preprocessor::macros
llvm::iterator_range< macro_iterator > macros(bool IncludeExternalMacros=true) const
Definition: Preprocessor.h:1196
clang::Preprocessor::HandlePragmaIncludeAlias
void HandlePragmaIncludeAlias(Token &Tok)
Definition: Pragma.cpp:716
clang::Preprocessor::setPragmaARCCFCodeAuditedInfo
void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident, SourceLocation Loc)
Set the location of the currently-active #pragma clang arc_cf_code_audited begin.
Definition: Preprocessor.h:1682
clang::TU_Complete
@ TU_Complete
The translation unit is a complete translation unit.
Definition: LangOptions.h:705
clang::MU_Other
@ MU_Other
Definition: Preprocessor.h:115
clang::Preprocessor::RemovePragmaHandler
void RemovePragmaHandler(PragmaHandler *Handler)
Definition: Preprocessor.h:1239
clang::Preprocessor::LeaveSubmodule
Module * LeaveSubmodule(bool ForPragma)
Definition: PPLexerChange.cpp:764
clang::Preprocessor::setTokenWatcher
void setTokenWatcher(llvm::unique_function< void(const clang::Token &)> F)
Register a function that would be called on each token in the final expanded token stream.
Definition: Preprocessor.h:1059
clang::Preprocessor::PreambleSkipInfo
Definition: Preprocessor.h:438
clang::Lexer::AdvanceToTokenCharacter
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
Definition: Lexer.h:367
clang::Lexer::getLocForEndOfToken
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Definition: Lexer.cpp:783
clang::Preprocessor::checkModuleIsAvailable
static bool checkModuleIsAvailable(const LangOptions &LangOpts, const TargetInfo &TargetInfo, DiagnosticsEngine &Diags, Module *M)
Check that the given module is available, producing a diagnostic if not.
Definition: PPDirectives.cpp:1748
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::Preprocessor::LexUnexpandedToken
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
Definition: Preprocessor.h:1469
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:130
clang::Preprocessor::isRecordingPreamble
bool isRecordingPreamble() const
Definition: Preprocessor.h:2333
SM
#define SM(sm)
Definition: Cuda.cpp:78
clang::Preprocessor::HandlePoisonedIdentifier
void HandlePoisonedIdentifier(Token &Identifier)
Display reason for poisoned identifier.
Definition: Preprocessor.cpp:749
clang::Preprocessor::appendMacroDirective
void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD)
Add a directive to the macro directive history for this identifier.
Definition: PPMacroExpansion.cpp:71
clang::Preprocessor::EnterTokenStream
void EnterTokenStream(std::unique_ptr< Token[]> Toks, unsigned NumToks, bool DisableMacroExpansion, bool IsReinject)
Definition: Preprocessor.h:1379
clang::Preprocessor::getHeaderSearchInfo
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:942
Token.h
clang::MacroDirective::DefInfo
Definition: MacroInfo.h:338
clang::Preprocessor::getEmptylineHandler
EmptylineHandler * getEmptylineHandler() const
Definition: Preprocessor.h:1249
clang::Preprocessor::SawDateOrTime
bool SawDateOrTime() const
Returns true if the preprocessor has seen a use of DATE or TIME in the file so far.
Definition: Preprocessor.h:2001
clang::Preprocessor::EnterAnnotationToken
void EnterAnnotationToken(SourceRange Range, tok::TokenKind Kind, void *AnnotationVal)
Enter an annotation token into the token stream.
Definition: PPDirectives.cpp:1649
clang::Preprocessor::getExternalSource
ExternalPreprocessorSource * getExternalSource() const
Definition: Preprocessor.h:954
clang::Preprocessor::mightHavePendingAnnotationTokens
bool mightHavePendingAnnotationTokens()
Determine whether it's possible for a future call to Lex to produce an annotation token created by a ...
Definition: Preprocessor.h:1601
clang::Preprocessor::~Preprocessor
~Preprocessor()
Definition: Preprocessor.cpp:169
clang::Preprocessor::LexNonComment
void LexNonComment(Token &Result)
Lex a token.
Definition: Preprocessor.h:1462
clang::Preprocessor::getPredefinesFileID
FileID getPredefinesFileID() const
Returns the FileID for the preprocessor predefines.
Definition: Preprocessor.h:1027
clang::Preprocessor::emitMacroExpansionWarnings
void emitMacroExpansionWarnings(const Token &Identifier)
Definition: Preprocessor.h:2426
clang::Preprocessor::getMacroInfo
MacroInfo * getMacroInfo(const IdentifierInfo *II)
Definition: Preprocessor.h:1134
clang::MacroUse
MacroUse
Context in which macro name is used.
Definition: Preprocessor.h:113
clang::Preprocessor::RevertCachedTokens
void RevertCachedTokens(unsigned N)
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens...
Definition: Preprocessor.h:1519
clang::Preprocessor::EnterSourceFile
bool EnterSourceFile(FileID FID, 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...
Definition: PPLexerChange.cpp:69
clang::ModuleMacro
Represents a macro directive exported by a module.
Definition: MacroInfo.h:488
clang::Preprocessor::isMacroDefinedInLocalModule
bool isMacroDefinedInLocalModule(const IdentifierInfo *II, Module *M)
Determine whether II is defined as a macro within the module M, if that is a module that we've alread...
Definition: Preprocessor.h:1076
clang::Preprocessor::setMainFileDir
void setMainFileDir(const DirectoryEntry *Dir)
Set the directory in which the main file should be considered to have been found, if it is not a real...
Definition: Preprocessor.h:1703
clang::Preprocessor::getIdentifierInfo
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Definition: Preprocessor.h:1220
clang::Preprocessor::macro_begin
macro_iterator macro_begin(bool IncludeExternalMacros=true) const
Definition: Preprocessor.cpp:307
clang::Preprocessor::getHeaderToIncludeForDiagnostics
const FileEntry * getHeaderToIncludeForDiagnostics(SourceLocation IncLoc, SourceLocation MLoc)
We want to produce a diagnostic at location IncLoc concerning an unreachable effect at location MLoc ...
Definition: PPDirectives.cpp:752
clang::Preprocessor::parseSimpleIntegerLiteral
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value)
Parses a simple integer literal to get its numeric value.
Definition: Preprocessor.cpp:1364
clang::Preprocessor::Initialize
void Initialize(const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
Initialize the preprocessor using information about the target.
Definition: Preprocessor.cpp:195
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1508
clang::Preprocessor::CommitBacktrackedTokens
void CommitBacktrackedTokens()
Disable the last EnableBacktrackAtThisPos call.
Definition: PPCaching.cpp:32
clang::Preprocessor::getPreprocessingRecord
PreprocessingRecord * getPreprocessingRecord() const
Retrieve the preprocessing record, or NULL if there is no preprocessing record.
Definition: Preprocessor.h:1306
clang::MacroInfo::getDefinitionLoc
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
Definition: MacroInfo.h:123