clang  19.0.0git
PPCallbacks.h
Go to the documentation of this file.
1 //===--- PPCallbacks.h - Callbacks for Preprocessor actions -----*- 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 PPCallbacks interface.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LEX_PPCALLBACKS_H
15 #define LLVM_CLANG_LEX_PPCALLBACKS_H
16 
20 #include "clang/Lex/ModuleLoader.h"
21 #include "clang/Lex/Pragma.h"
22 #include "llvm/ADT/StringRef.h"
23 
24 namespace clang {
25 class Token;
26 class IdentifierInfo;
27 class MacroDefinition;
28 class MacroDirective;
29 class MacroArgs;
30 
31 /// This interface provides a way to observe the actions of the
32 /// preprocessor as it does its thing.
33 ///
34 /// Clients can define their hooks here to implement preprocessor level tools.
35 class PPCallbacks {
36 public:
37  virtual ~PPCallbacks();
38 
41  };
42 
43  /// Callback invoked whenever a source file is entered or exited.
44  ///
45  /// \param Loc Indicates the new location.
46  /// \param PrevFID the file that was exited if \p Reason is ExitFile or the
47  /// the file before the new one entered for \p Reason EnterFile.
50  FileID PrevFID = FileID()) {
51  }
52 
54 
55  /// Callback invoked whenever the \p Lexer moves to a different file for
56  /// lexing. Unlike \p FileChanged line number directives and other related
57  /// pragmas do not trigger callbacks to \p LexedFileChanged.
58  ///
59  /// \param FID The \p FileID that the \p Lexer moved to.
60  ///
61  /// \param Reason Whether the \p Lexer entered a new file or exited one.
62  ///
63  /// \param FileType The \p CharacteristicKind of the file the \p Lexer moved
64  /// to.
65  ///
66  /// \param PrevFID The \p FileID the \p Lexer was using before the change.
67  ///
68  /// \param Loc The location where the \p Lexer entered a new file from or the
69  /// location that the \p Lexer moved into after exiting a file.
70  virtual void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
72  FileID PrevFID, SourceLocation Loc) {}
73 
74  /// Callback invoked whenever a source file is skipped as the result
75  /// of header guard optimization.
76  ///
77  /// \param SkippedFile The file that is skipped instead of entering \#include
78  ///
79  /// \param FilenameTok The file name token in \#include "FileName" directive
80  /// or macro expanded file name token from \#include MACRO(PARAMS) directive.
81  /// Note that FilenameTok contains corresponding quotes/angles symbols.
82  virtual void FileSkipped(const FileEntryRef &SkippedFile,
83  const Token &FilenameTok,
85 
86  /// Callback invoked whenever the preprocessor cannot find a file for an
87  /// inclusion directive.
88  ///
89  /// \param FileName The name of the file being included, as written in the
90  /// source code.
91  ///
92  /// \returns true to indicate that the preprocessor should skip this file
93  /// and not issue any diagnostic.
94  virtual bool FileNotFound(StringRef FileName) { return false; }
95 
96  /// Callback invoked whenever an inclusion directive of
97  /// any kind (\c \#include, \c \#import, etc.) has been processed, regardless
98  /// of whether the inclusion will actually result in an inclusion.
99  ///
100  /// \param HashLoc The location of the '#' that starts the inclusion
101  /// directive.
102  ///
103  /// \param IncludeTok The token that indicates the kind of inclusion
104  /// directive, e.g., 'include' or 'import'.
105  ///
106  /// \param FileName The name of the file being included, as written in the
107  /// source code.
108  ///
109  /// \param IsAngled Whether the file name was enclosed in angle brackets;
110  /// otherwise, it was enclosed in quotes.
111  ///
112  /// \param FilenameRange The character range of the quotes or angle brackets
113  /// for the written file name.
114  ///
115  /// \param File The actual file that may be included by this inclusion
116  /// directive.
117  ///
118  /// \param SearchPath Contains the search path which was used to find the file
119  /// in the file system. If the file was found via an absolute include path,
120  /// SearchPath will be empty. For framework includes, the SearchPath and
121  /// RelativePath will be split up. For example, if an include of "Some/Some.h"
122  /// is found via the framework path
123  /// "path/to/Frameworks/Some.framework/Headers/Some.h", SearchPath will be
124  /// "path/to/Frameworks/Some.framework/Headers" and RelativePath will be
125  /// "Some.h".
126  ///
127  /// \param RelativePath The path relative to SearchPath, at which the include
128  /// file was found. This is equal to FileName except for framework includes.
129  ///
130  /// \param SuggestedModule The module suggested for this header, if any.
131  ///
132  /// \param ModuleImported Whether this include was translated into import of
133  /// \p SuggestedModule.
134  ///
135  /// \param FileType The characteristic kind, indicates whether a file or
136  /// directory holds normal user code, system code, or system code which is
137  /// implicitly 'extern "C"' in C++ mode.
138  ///
139  virtual void InclusionDirective(SourceLocation HashLoc,
140  const Token &IncludeTok, StringRef FileName,
141  bool IsAngled, CharSourceRange FilenameRange,
143  StringRef SearchPath, StringRef RelativePath,
144  const Module *SuggestedModule,
145  bool ModuleImported,
147 
148  /// Callback invoked whenever a submodule was entered.
149  ///
150  /// \param M The submodule we have entered.
151  ///
152  /// \param ImportLoc The location of import directive token.
153  ///
154  /// \param ForPragma If entering from pragma directive.
155  ///
156  virtual void EnteredSubmodule(Module *M, SourceLocation ImportLoc,
157  bool ForPragma) { }
158 
159  /// Callback invoked whenever a submodule was left.
160  ///
161  /// \param M The submodule we have left.
162  ///
163  /// \param ImportLoc The location of import directive token.
164  ///
165  /// \param ForPragma If entering from pragma directive.
166  ///
167  virtual void LeftSubmodule(Module *M, SourceLocation ImportLoc,
168  bool ForPragma) { }
169 
170  /// Callback invoked whenever there was an explicit module-import
171  /// syntax.
172  ///
173  /// \param ImportLoc The location of import directive token.
174  ///
175  /// \param Path The identifiers (and their locations) of the module
176  /// "path", e.g., "std.vector" would be split into "std" and "vector".
177  ///
178  /// \param Imported The imported module; can be null if importing failed.
179  ///
180  virtual void moduleImport(SourceLocation ImportLoc,
181  ModuleIdPath Path,
182  const Module *Imported) {
183  }
184 
185  /// Callback invoked when the end of the main file is reached.
186  ///
187  /// No subsequent callbacks will be made.
188  virtual void EndOfMainFile() {
189  }
190 
191  /// Callback invoked when a \#ident or \#sccs directive is read.
192  /// \param Loc The location of the directive.
193  /// \param str The text of the directive.
194  ///
195  virtual void Ident(SourceLocation Loc, StringRef str) {
196  }
197 
198  /// Callback invoked when start reading any pragma directive.
200  PragmaIntroducerKind Introducer) {
201  }
202 
203  /// Callback invoked when a \#pragma comment directive is read.
205  StringRef Str) {
206  }
207 
208  /// Callback invoked when a \#pragma mark comment is read.
209  virtual void PragmaMark(SourceLocation Loc, StringRef Trivia) {
210  }
211 
212  /// Callback invoked when a \#pragma detect_mismatch directive is
213  /// read.
214  virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,
215  StringRef Value) {
216  }
217 
218  /// Callback invoked when a \#pragma clang __debug directive is read.
219  /// \param Loc The location of the debug directive.
220  /// \param DebugType The identifier following __debug.
221  virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType) {
222  }
223 
224  /// Determines the kind of \#pragma invoking a call to PragmaMessage.
226  /// \#pragma message has been invoked.
228 
229  /// \#pragma GCC warning has been invoked.
231 
232  /// \#pragma GCC error has been invoked.
233  PMK_Error
234  };
235 
236  /// Callback invoked when a \#pragma message directive is read.
237  /// \param Loc The location of the message directive.
238  /// \param Namespace The namespace of the message directive.
239  /// \param Kind The type of the message directive.
240  /// \param Str The text of the message directive.
241  virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace,
242  PragmaMessageKind Kind, StringRef Str) {
243  }
244 
245  /// Callback invoked when a \#pragma gcc diagnostic push directive
246  /// is read.
248  StringRef Namespace) {
249  }
250 
251  /// Callback invoked when a \#pragma gcc diagnostic pop directive
252  /// is read.
254  StringRef Namespace) {
255  }
256 
257  /// Callback invoked when a \#pragma gcc diagnostic directive is read.
258  virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
259  diag::Severity mapping, StringRef Str) {}
260 
261  /// Called when an OpenCL extension is either disabled or
262  /// enabled with a pragma.
263  virtual void PragmaOpenCLExtension(SourceLocation NameLoc,
264  const IdentifierInfo *Name,
265  SourceLocation StateLoc, unsigned State) {
266  }
267 
268  /// Callback invoked when a \#pragma warning directive is read.
279  };
281  PragmaWarningSpecifier WarningSpec,
282  ArrayRef<int> Ids) {}
283 
284  /// Callback invoked when a \#pragma warning(push) directive is read.
286  }
287 
288  /// Callback invoked when a \#pragma warning(pop) directive is read.
290  }
291 
292  /// Callback invoked when a \#pragma execution_character_set(push) directive
293  /// is read.
294  virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) {}
295 
296  /// Callback invoked when a \#pragma execution_character_set(pop) directive
297  /// is read.
299 
300  /// Callback invoked when a \#pragma clang assume_nonnull begin directive
301  /// is read.
303 
304  /// Callback invoked when a \#pragma clang assume_nonnull end directive
305  /// is read.
307 
308  /// Called by Preprocessor::HandleMacroExpandedIdentifier when a
309  /// macro invocation is found.
310  virtual void MacroExpands(const Token &MacroNameTok,
311  const MacroDefinition &MD, SourceRange Range,
312  const MacroArgs *Args) {}
313 
314  /// Hook called whenever a macro definition is seen.
315  virtual void MacroDefined(const Token &MacroNameTok,
316  const MacroDirective *MD) {
317  }
318 
319  /// Hook called whenever a macro \#undef is seen.
320  /// \param MacroNameTok The active Token
321  /// \param MD A MacroDefinition for the named macro.
322  /// \param Undef New MacroDirective if the macro was defined, null otherwise.
323  ///
324  /// MD is released immediately following this callback.
325  virtual void MacroUndefined(const Token &MacroNameTok,
326  const MacroDefinition &MD,
327  const MacroDirective *Undef) {
328  }
329 
330  /// Hook called whenever the 'defined' operator is seen.
331  /// \param MD The MacroDirective if the name was a macro, null otherwise.
332  virtual void Defined(const Token &MacroNameTok, const MacroDefinition &MD,
333  SourceRange Range) {
334  }
335 
336  /// Hook called when a '__has_include' or '__has_include_next' directive is
337  /// read.
338  virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
341 
342  /// Hook called when a source range is skipped.
343  /// \param Range The SourceRange that was skipped. The range begins at the
344  /// \#if/\#else directive and ends after the \#endif/\#else directive.
345  /// \param EndifLoc The end location of the 'endif' token, which may precede
346  /// the range skipped by the directive (e.g excluding comments after an
347  /// 'endif').
348  virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) {
349  }
350 
353  };
354 
355  /// Hook called whenever an \#if is seen.
356  /// \param Loc the source location of the directive.
357  /// \param ConditionRange The SourceRange of the expression being tested.
358  /// \param ConditionValue The evaluated value of the condition.
359  ///
360  // FIXME: better to pass in a list (or tree!) of Tokens.
361  virtual void If(SourceLocation Loc, SourceRange ConditionRange,
362  ConditionValueKind ConditionValue) {
363  }
364 
365  /// Hook called whenever an \#elif is seen.
366  /// \param Loc the source location of the directive.
367  /// \param ConditionRange The SourceRange of the expression being tested.
368  /// \param ConditionValue The evaluated value of the condition.
369  /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
370  // FIXME: better to pass in a list (or tree!) of Tokens.
371  virtual void Elif(SourceLocation Loc, SourceRange ConditionRange,
372  ConditionValueKind ConditionValue, SourceLocation IfLoc) {
373  }
374 
375  /// Hook called whenever an \#ifdef is seen.
376  /// \param Loc the source location of the directive.
377  /// \param MacroNameTok Information on the token being tested.
378  /// \param MD The MacroDefinition if the name was a macro, null otherwise.
379  virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
380  const MacroDefinition &MD) {
381  }
382 
383  /// Hook called whenever an \#elifdef branch is taken.
384  /// \param Loc the source location of the directive.
385  /// \param MacroNameTok Information on the token being tested.
386  /// \param MD The MacroDefinition if the name was a macro, null otherwise.
387  virtual void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
388  const MacroDefinition &MD) {
389  }
390  /// Hook called whenever an \#elifdef is skipped.
391  /// \param Loc the source location of the directive.
392  /// \param ConditionRange The SourceRange of the expression being tested.
393  /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
394  // FIXME: better to pass in a list (or tree!) of Tokens.
395  virtual void Elifdef(SourceLocation Loc, SourceRange ConditionRange,
396  SourceLocation IfLoc) {
397  }
398 
399  /// Hook called whenever an \#ifndef is seen.
400  /// \param Loc the source location of the directive.
401  /// \param MacroNameTok Information on the token being tested.
402  /// \param MD The MacroDefiniton if the name was a macro, null otherwise.
403  virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
404  const MacroDefinition &MD) {
405  }
406 
407  /// Hook called whenever an \#elifndef branch is taken.
408  /// \param Loc the source location of the directive.
409  /// \param MacroNameTok Information on the token being tested.
410  /// \param MD The MacroDefinition if the name was a macro, null otherwise.
411  virtual void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
412  const MacroDefinition &MD) {
413  }
414  /// Hook called whenever an \#elifndef is skipped.
415  /// \param Loc the source location of the directive.
416  /// \param ConditionRange The SourceRange of the expression being tested.
417  /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
418  // FIXME: better to pass in a list (or tree!) of Tokens.
419  virtual void Elifndef(SourceLocation Loc, SourceRange ConditionRange,
420  SourceLocation IfLoc) {
421  }
422 
423  /// Hook called whenever an \#else is seen.
424  /// \param Loc the source location of the directive.
425  /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
426  virtual void Else(SourceLocation Loc, SourceLocation IfLoc) {
427  }
428 
429  /// Hook called whenever an \#endif is seen.
430  /// \param Loc the source location of the directive.
431  /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
432  virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) {
433  }
434 };
435 
436 /// Simple wrapper class for chaining callbacks.
438  std::unique_ptr<PPCallbacks> First, Second;
439 
440 public:
441  PPChainedCallbacks(std::unique_ptr<PPCallbacks> _First,
442  std::unique_ptr<PPCallbacks> _Second)
443  : First(std::move(_First)), Second(std::move(_Second)) {}
444 
446 
449  FileID PrevFID) override {
450  First->FileChanged(Loc, Reason, FileType, PrevFID);
451  Second->FileChanged(Loc, Reason, FileType, PrevFID);
452  }
453 
456  SourceLocation Loc) override {
457  First->LexedFileChanged(FID, Reason, FileType, PrevFID, Loc);
458  Second->LexedFileChanged(FID, Reason, FileType, PrevFID, Loc);
459  }
460 
461  void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
463  First->FileSkipped(SkippedFile, FilenameTok, FileType);
464  Second->FileSkipped(SkippedFile, FilenameTok, FileType);
465  }
466 
467  bool FileNotFound(StringRef FileName) override {
468  bool Skip = First->FileNotFound(FileName);
469  // Make sure to invoke the second callback, no matter if the first already
470  // returned true to skip the file.
471  Skip |= Second->FileNotFound(FileName);
472  return Skip;
473  }
474 
475  void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
476  StringRef FileName, bool IsAngled,
477  CharSourceRange FilenameRange,
478  OptionalFileEntryRef File, StringRef SearchPath,
479  StringRef RelativePath, const Module *SuggestedModule,
480  bool ModuleImported,
482  First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
483  FilenameRange, File, SearchPath, RelativePath,
484  SuggestedModule, ModuleImported, FileType);
485  Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
486  FilenameRange, File, SearchPath, RelativePath,
487  SuggestedModule, ModuleImported, FileType);
488  }
489 
491  bool ForPragma) override {
492  First->EnteredSubmodule(M, ImportLoc, ForPragma);
493  Second->EnteredSubmodule(M, ImportLoc, ForPragma);
494  }
495 
496  void LeftSubmodule(Module *M, SourceLocation ImportLoc,
497  bool ForPragma) override {
498  First->LeftSubmodule(M, ImportLoc, ForPragma);
499  Second->LeftSubmodule(M, ImportLoc, ForPragma);
500  }
501 
503  const Module *Imported) override {
504  First->moduleImport(ImportLoc, Path, Imported);
505  Second->moduleImport(ImportLoc, Path, Imported);
506  }
507 
508  void EndOfMainFile() override {
509  First->EndOfMainFile();
510  Second->EndOfMainFile();
511  }
512 
513  void Ident(SourceLocation Loc, StringRef str) override {
514  First->Ident(Loc, str);
515  Second->Ident(Loc, str);
516  }
517 
519  PragmaIntroducerKind Introducer) override {
520  First->PragmaDirective(Loc, Introducer);
521  Second->PragmaDirective(Loc, Introducer);
522  }
523 
525  StringRef Str) override {
526  First->PragmaComment(Loc, Kind, Str);
527  Second->PragmaComment(Loc, Kind, Str);
528  }
529 
530  void PragmaMark(SourceLocation Loc, StringRef Trivia) override {
531  First->PragmaMark(Loc, Trivia);
532  Second->PragmaMark(Loc, Trivia);
533  }
534 
536  StringRef Value) override {
537  First->PragmaDetectMismatch(Loc, Name, Value);
538  Second->PragmaDetectMismatch(Loc, Name, Value);
539  }
540 
541  void PragmaDebug(SourceLocation Loc, StringRef DebugType) override {
542  First->PragmaDebug(Loc, DebugType);
543  Second->PragmaDebug(Loc, DebugType);
544  }
545 
546  void PragmaMessage(SourceLocation Loc, StringRef Namespace,
547  PragmaMessageKind Kind, StringRef Str) override {
548  First->PragmaMessage(Loc, Namespace, Kind, Str);
549  Second->PragmaMessage(Loc, Namespace, Kind, Str);
550  }
551 
552  void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override {
553  First->PragmaDiagnosticPush(Loc, Namespace);
554  Second->PragmaDiagnosticPush(Loc, Namespace);
555  }
556 
557  void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override {
558  First->PragmaDiagnosticPop(Loc, Namespace);
559  Second->PragmaDiagnosticPop(Loc, Namespace);
560  }
561 
562  void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
563  diag::Severity mapping, StringRef Str) override {
564  First->PragmaDiagnostic(Loc, Namespace, mapping, Str);
565  Second->PragmaDiagnostic(Loc, Namespace, mapping, Str);
566  }
567 
568  void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
571 
573  SourceLocation StateLoc, unsigned State) override {
574  First->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State);
575  Second->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State);
576  }
577 
579  ArrayRef<int> Ids) override {
580  First->PragmaWarning(Loc, WarningSpec, Ids);
581  Second->PragmaWarning(Loc, WarningSpec, Ids);
582  }
583 
585  First->PragmaWarningPush(Loc, Level);
586  Second->PragmaWarningPush(Loc, Level);
587  }
588 
590  First->PragmaWarningPop(Loc);
591  Second->PragmaWarningPop(Loc);
592  }
593 
594  void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override {
595  First->PragmaExecCharsetPush(Loc, Str);
596  Second->PragmaExecCharsetPush(Loc, Str);
597  }
598 
600  First->PragmaExecCharsetPop(Loc);
601  Second->PragmaExecCharsetPop(Loc);
602  }
603 
605  First->PragmaAssumeNonNullBegin(Loc);
606  Second->PragmaAssumeNonNullBegin(Loc);
607  }
608 
610  First->PragmaAssumeNonNullEnd(Loc);
611  Second->PragmaAssumeNonNullEnd(Loc);
612  }
613 
614  void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
615  SourceRange Range, const MacroArgs *Args) override {
616  First->MacroExpands(MacroNameTok, MD, Range, Args);
617  Second->MacroExpands(MacroNameTok, MD, Range, Args);
618  }
619 
620  void MacroDefined(const Token &MacroNameTok,
621  const MacroDirective *MD) override {
622  First->MacroDefined(MacroNameTok, MD);
623  Second->MacroDefined(MacroNameTok, MD);
624  }
625 
626  void MacroUndefined(const Token &MacroNameTok,
627  const MacroDefinition &MD,
628  const MacroDirective *Undef) override {
629  First->MacroUndefined(MacroNameTok, MD, Undef);
630  Second->MacroUndefined(MacroNameTok, MD, Undef);
631  }
632 
633  void Defined(const Token &MacroNameTok, const MacroDefinition &MD,
634  SourceRange Range) override {
635  First->Defined(MacroNameTok, MD, Range);
636  Second->Defined(MacroNameTok, MD, Range);
637  }
638 
639  void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override {
640  First->SourceRangeSkipped(Range, EndifLoc);
641  Second->SourceRangeSkipped(Range, EndifLoc);
642  }
643 
644  /// Hook called whenever an \#if is seen.
645  void If(SourceLocation Loc, SourceRange ConditionRange,
646  ConditionValueKind ConditionValue) override {
647  First->If(Loc, ConditionRange, ConditionValue);
648  Second->If(Loc, ConditionRange, ConditionValue);
649  }
650 
651  /// Hook called whenever an \#elif is seen.
652  void Elif(SourceLocation Loc, SourceRange ConditionRange,
653  ConditionValueKind ConditionValue, SourceLocation IfLoc) override {
654  First->Elif(Loc, ConditionRange, ConditionValue, IfLoc);
655  Second->Elif(Loc, ConditionRange, ConditionValue, IfLoc);
656  }
657 
658  /// Hook called whenever an \#ifdef is seen.
659  void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
660  const MacroDefinition &MD) override {
661  First->Ifdef(Loc, MacroNameTok, MD);
662  Second->Ifdef(Loc, MacroNameTok, MD);
663  }
664 
665  /// Hook called whenever an \#elifdef is taken.
666  void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
667  const MacroDefinition &MD) override {
668  First->Elifdef(Loc, MacroNameTok, MD);
669  Second->Elifdef(Loc, MacroNameTok, MD);
670  }
671  /// Hook called whenever an \#elifdef is skipped.
672  void Elifdef(SourceLocation Loc, SourceRange ConditionRange,
673  SourceLocation IfLoc) override {
674  First->Elifdef(Loc, ConditionRange, IfLoc);
675  Second->Elifdef(Loc, ConditionRange, IfLoc);
676  }
677 
678  /// Hook called whenever an \#ifndef is seen.
679  void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
680  const MacroDefinition &MD) override {
681  First->Ifndef(Loc, MacroNameTok, MD);
682  Second->Ifndef(Loc, MacroNameTok, MD);
683  }
684 
685  /// Hook called whenever an \#elifndef is taken.
686  void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
687  const MacroDefinition &MD) override {
688  First->Elifndef(Loc, MacroNameTok, MD);
689  Second->Elifndef(Loc, MacroNameTok, MD);
690  }
691  /// Hook called whenever an \#elifndef is skipped.
692  void Elifndef(SourceLocation Loc, SourceRange ConditionRange,
693  SourceLocation IfLoc) override {
694  First->Elifndef(Loc, ConditionRange, IfLoc);
695  Second->Elifndef(Loc, ConditionRange, IfLoc);
696  }
697 
698  /// Hook called whenever an \#else is seen.
699  void Else(SourceLocation Loc, SourceLocation IfLoc) override {
700  First->Else(Loc, IfLoc);
701  Second->Else(Loc, IfLoc);
702  }
703 
704  /// Hook called whenever an \#endif is seen.
705  void Endif(SourceLocation Loc, SourceLocation IfLoc) override {
706  First->Endif(Loc, IfLoc);
707  Second->Endif(Loc, IfLoc);
708  }
709 };
710 
711 } // end namespace clang
712 
713 #endif
Defines the Diagnostic IDs-related interfaces.
llvm::MachO::FileType FileType
Definition: MachO.h:45
SourceRange Range
Definition: SemaObjC.cpp:754
SourceLocation Loc
Definition: SemaObjC.cpp:755
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
LineState State
Represents a character-granular source range.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition: FileEntry.h:57
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
One of these records is kept for each identifier that is lexed.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
Definition: MacroArgs.h:30
A description of the current definition of a macro.
Definition: MacroInfo.h:590
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
Describes a module or submodule.
Definition: Module.h:105
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition: PPCallbacks.h:35
virtual void PragmaExecCharsetPop(SourceLocation Loc)
Callback invoked when a #pragma execution_character_set(pop) directive is read.
Definition: PPCallbacks.h:298
virtual void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer)
Callback invoked when start reading any pragma directive.
Definition: PPCallbacks.h:199
virtual void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range)
Hook called whenever the 'defined' operator is seen.
Definition: PPCallbacks.h:332
virtual void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic push directive is read.
Definition: PPCallbacks.h:247
virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, StringRef Str)
Callback invoked when a #pragma comment directive is read.
Definition: PPCallbacks.h:204
virtual void Elifndef(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc)
Hook called whenever an #elifndef is skipped.
Definition: PPCallbacks.h:419
virtual void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, ArrayRef< int > Ids)
Definition: PPCallbacks.h:280
virtual void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args)
Called by Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is found.
Definition: PPCallbacks.h:310
virtual void Elifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #elifndef branch is taken.
Definition: PPCallbacks.h:411
virtual ~PPCallbacks()
virtual void EnteredSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Callback invoked whenever a submodule was entered.
Definition: PPCallbacks.h:156
virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc)
Hook called whenever an #elif is seen.
Definition: PPCallbacks.h:371
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType)
Callback invoked when a #pragma clang __debug directive is read.
Definition: PPCallbacks.h:221
virtual void EndOfMainFile()
Callback invoked when the end of the main file is reached.
Definition: PPCallbacks.h:188
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID=FileID())
Callback invoked whenever a source file is entered or exited.
Definition: PPCallbacks.h:48
virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #ifndef is seen.
Definition: PPCallbacks.h:403
virtual void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue)
Hook called whenever an #if is seen.
Definition: PPCallbacks.h:361
virtual void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok, SrcMgr::CharacteristicKind FileType)
Callback invoked whenever a source file is skipped as the result of header guard optimization.
Definition: PPCallbacks.h:82
virtual void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef)
Hook called whenever a macro #undef is seen.
Definition: PPCallbacks.h:325
virtual void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD)
Hook called whenever a macro definition is seen.
Definition: PPCallbacks.h:315
virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity mapping, StringRef Str)
Callback invoked when a #pragma gcc diagnostic directive is read.
Definition: PPCallbacks.h:258
virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #ifdef is seen.
Definition: PPCallbacks.h:379
virtual void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State)
Called when an OpenCL extension is either disabled or enabled with a pragma.
Definition: PPCallbacks.h:263
PragmaWarningSpecifier
Callback invoked when a #pragma warning directive is read.
Definition: PPCallbacks.h:269
virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
Callback invoked when a #pragma detect_mismatch directive is read.
Definition: PPCallbacks.h:214
virtual void PragmaAssumeNonNullEnd(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull end directive is read.
Definition: PPCallbacks.h:306
virtual void PragmaAssumeNonNullBegin(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull begin directive is read.
Definition: PPCallbacks.h:302
virtual void PragmaMark(SourceLocation Loc, StringRef Trivia)
Callback invoked when a #pragma mark comment is read.
Definition: PPCallbacks.h:209
virtual void Ident(SourceLocation Loc, StringRef str)
Callback invoked when a #ident or #sccs directive is read.
Definition: PPCallbacks.h:195
virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, OptionalFileEntryRef File, SrcMgr::CharacteristicKind FileType)
Hook called when a '__has_include' or '__has_include_next' directive is read.
Definition: PPCallbacks.cpp:17
virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str)
Callback invoked when a #pragma message directive is read.
Definition: PPCallbacks.h:241
virtual void Elifdef(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc)
Hook called whenever an #elifdef is skipped.
Definition: PPCallbacks.h:395
virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc)
Hook called when a source range is skipped.
Definition: PPCallbacks.h:348
virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str)
Callback invoked when a #pragma execution_character_set(push) directive is read.
Definition: PPCallbacks.h:294
virtual void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic pop directive is read.
Definition: PPCallbacks.h:253
virtual void PragmaWarningPop(SourceLocation Loc)
Callback invoked when a #pragma warning(pop) directive is read.
Definition: PPCallbacks.h:289
virtual void Elifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #elifdef branch is taken.
Definition: PPCallbacks.h:387
virtual void LexedFileChanged(FileID FID, LexedFileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID, SourceLocation Loc)
Callback invoked whenever the Lexer moves to a different file for lexing.
Definition: PPCallbacks.h:70
virtual void LeftSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Callback invoked whenever a submodule was left.
Definition: PPCallbacks.h:167
virtual void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType)
Callback invoked whenever an inclusion directive of any kind (#include, #import, etc....
Definition: PPCallbacks.h:139
virtual void Else(SourceLocation Loc, SourceLocation IfLoc)
Hook called whenever an #else is seen.
Definition: PPCallbacks.h:426
PragmaMessageKind
Determines the kind of #pragma invoking a call to PragmaMessage.
Definition: PPCallbacks.h:225
@ PMK_Warning
#pragma GCC warning has been invoked.
Definition: PPCallbacks.h:230
@ PMK_Error
#pragma GCC error has been invoked.
Definition: PPCallbacks.h:233
@ PMK_Message
#pragma message has been invoked.
Definition: PPCallbacks.h:227
virtual bool FileNotFound(StringRef FileName)
Callback invoked whenever the preprocessor cannot find a file for an inclusion directive.
Definition: PPCallbacks.h:94
virtual void PragmaWarningPush(SourceLocation Loc, int Level)
Callback invoked when a #pragma warning(push) directive is read.
Definition: PPCallbacks.h:285
virtual void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported)
Callback invoked whenever there was an explicit module-import syntax.
Definition: PPCallbacks.h:180
virtual void Endif(SourceLocation Loc, SourceLocation IfLoc)
Hook called whenever an #endif is seen.
Definition: PPCallbacks.h:432
Simple wrapper class for chaining callbacks.
Definition: PPCallbacks.h:437
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override
Hook called whenever a macro #undef is seen.
Definition: PPCallbacks.h:626
void EnteredSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma) override
Callback invoked whenever a submodule was entered.
Definition: PPCallbacks.h:490
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override
Called by Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is found.
Definition: PPCallbacks.h:614
void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override
Hook called whenever an #if is seen.
Definition: PPCallbacks.h:645
void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) override
Callback invoked whenever a source file is entered or exited.
Definition: PPCallbacks.h:447
void Endif(SourceLocation Loc, SourceLocation IfLoc) override
Hook called whenever an #endif is seen.
Definition: PPCallbacks.h:705
void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override
Callback invoked when a #pragma execution_character_set(push) directive is read.
Definition: PPCallbacks.h:594
void Elifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #elifndef is taken.
Definition: PPCallbacks.h:686
void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, OptionalFileEntryRef File, SrcMgr::CharacteristicKind FileType) override
Hook called when a '__has_include' or '__has_include_next' directive is read.
Definition: PPCallbacks.cpp:24
void PragmaAssumeNonNullEnd(SourceLocation Loc) override
Callback invoked when a #pragma clang assume_nonnull end directive is read.
Definition: PPCallbacks.h:609
void PragmaWarningPop(SourceLocation Loc) override
Callback invoked when a #pragma warning(pop) directive is read.
Definition: PPCallbacks.h:589
void Elifndef(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc) override
Hook called whenever an #elifndef is skipped.
Definition: PPCallbacks.h:692
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override
Hook called when a source range is skipped.
Definition: PPCallbacks.h:639
void LeftSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma) override
Callback invoked whenever a submodule was left.
Definition: PPCallbacks.h:496
void PragmaWarningPush(SourceLocation Loc, int Level) override
Callback invoked when a #pragma warning(push) directive is read.
Definition: PPCallbacks.h:584
void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value) override
Callback invoked when a #pragma detect_mismatch directive is read.
Definition: PPCallbacks.h:535
void PragmaDebug(SourceLocation Loc, StringRef DebugType) override
Callback invoked when a #pragma clang __debug directive is read.
Definition: PPCallbacks.h:541
void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range) override
Hook called whenever the 'defined' operator is seen.
Definition: PPCallbacks.h:633
void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity mapping, StringRef Str) override
Callback invoked when a #pragma gcc diagnostic directive is read.
Definition: PPCallbacks.h:562
void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) override
Callback invoked when start reading any pragma directive.
Definition: PPCallbacks.h:518
void PragmaAssumeNonNullBegin(SourceLocation Loc) override
Callback invoked when a #pragma clang assume_nonnull begin directive is read.
Definition: PPCallbacks.h:604
void Else(SourceLocation Loc, SourceLocation IfLoc) override
Hook called whenever an #else is seen.
Definition: PPCallbacks.h:699
void Ident(SourceLocation Loc, StringRef str) override
Callback invoked when a #ident or #sccs directive is read.
Definition: PPCallbacks.h:513
void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #ifdef is seen.
Definition: PPCallbacks.h:659
void Elifdef(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc) override
Hook called whenever an #elifdef is skipped.
Definition: PPCallbacks.h:672
void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override
Callback invoked when a #pragma gcc diagnostic push directive is read.
Definition: PPCallbacks.h:552
void EndOfMainFile() override
Callback invoked when the end of the main file is reached.
Definition: PPCallbacks.h:508
void PragmaExecCharsetPop(SourceLocation Loc) override
Callback invoked when a #pragma execution_character_set(pop) directive is read.
Definition: PPCallbacks.h:599
bool FileNotFound(StringRef FileName) override
Callback invoked whenever the preprocessor cannot find a file for an inclusion directive.
Definition: PPCallbacks.h:467
void LexedFileChanged(FileID FID, LexedFileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID, SourceLocation Loc) override
Callback invoked whenever the Lexer moves to a different file for lexing.
Definition: PPCallbacks.h:454
void PragmaMark(SourceLocation Loc, StringRef Trivia) override
Callback invoked when a #pragma mark comment is read.
Definition: PPCallbacks.h:530
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State) override
Called when an OpenCL extension is either disabled or enabled with a pragma.
Definition: PPCallbacks.h:572
PPChainedCallbacks(std::unique_ptr< PPCallbacks > _First, std::unique_ptr< PPCallbacks > _Second)
Definition: PPCallbacks.h:441
void Elifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #elifdef is taken.
Definition: PPCallbacks.h:666
void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str) override
Callback invoked when a #pragma message directive is read.
Definition: PPCallbacks.h:546
void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, StringRef Str) override
Callback invoked when a #pragma comment directive is read.
Definition: PPCallbacks.h:524
void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override
Callback invoked when a #pragma gcc diagnostic pop directive is read.
Definition: PPCallbacks.h:557
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override
Callback invoked whenever there was an explicit module-import syntax.
Definition: PPCallbacks.h:502
void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, ArrayRef< int > Ids) override
Definition: PPCallbacks.h:578
void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #ifndef is seen.
Definition: PPCallbacks.h:679
void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) override
Callback invoked whenever a source file is skipped as the result of header guard optimization.
Definition: PPCallbacks.h:461
void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) override
Hook called whenever an #elif is seen.
Definition: PPCallbacks.h:652
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
Hook called whenever a macro definition is seen.
Definition: PPCallbacks.h:620
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) override
Callback invoked whenever an inclusion directive of any kind (#include, #import, etc....
Definition: PPCallbacks.h:475
Encodes a location in the source.
A trivial tuple used to represent a source range.
Token - This structure provides full information about a lexed token.
Definition: Token.h:36
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:81
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
Definition: DiagnosticIDs.h:85
The JSON file list parser is used to communicate input to InstallAPI.
PragmaIntroducerKind
Describes how the pragma was introduced, e.g., with #pragma, _Pragma, or __pragma.
Definition: Pragma.h:32
Definition: Format.h:5433