14#ifndef LLVM_CLANG_LEX_PPCALLBACKS_H
15#define LLVM_CLANG_LEX_PPCALLBACKS_H
22#include "llvm/ADT/StringRef.h"
83 const Token &FilenameTok,
143 StringRef SearchPath, StringRef RelativePath,
144 const Module *SuggestedModule,
248 StringRef Namespace) {
254 StringRef Namespace) {
438 std::unique_ptr<PPCallbacks> First, Second;
442 std::unique_ptr<PPCallbacks> _Second)
443 :
First(
std::move(_First)), Second(
std::move(_Second)) {}
449 FileID PrevFID)
override {
451 Second->FileChanged(Loc, Reason,
FileType, PrevFID);
457 First->LexedFileChanged(FID, Reason,
FileType, PrevFID, Loc);
458 Second->LexedFileChanged(FID, Reason,
FileType, PrevFID, Loc);
464 Second->FileSkipped(SkippedFile, FilenameTok,
FileType);
471 Skip |= Second->FileNotFound(
FileName);
479 StringRef RelativePath,
const Module *SuggestedModule,
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);
491 bool ForPragma)
override {
492 First->EnteredSubmodule(M, ImportLoc, ForPragma);
493 Second->EnteredSubmodule(M, ImportLoc, ForPragma);
497 bool ForPragma)
override {
498 First->LeftSubmodule(M, ImportLoc, ForPragma);
499 Second->LeftSubmodule(M, ImportLoc, ForPragma);
503 const Module *Imported)
override {
504 First->moduleImport(ImportLoc, Path, Imported);
505 Second->moduleImport(ImportLoc, Path, Imported);
509 First->EndOfMainFile();
510 Second->EndOfMainFile();
514 First->Ident(Loc, str);
515 Second->Ident(Loc, str);
520 First->PragmaDirective(Loc, Introducer);
521 Second->PragmaDirective(Loc, Introducer);
525 StringRef Str)
override {
526 First->PragmaComment(Loc, Kind, Str);
527 Second->PragmaComment(Loc, Kind, Str);
531 First->PragmaMark(Loc, Trivia);
532 Second->PragmaMark(Loc, Trivia);
536 StringRef
Value)
override {
537 First->PragmaDetectMismatch(Loc, Name,
Value);
538 Second->PragmaDetectMismatch(Loc, Name,
Value);
542 First->PragmaDebug(Loc, DebugType);
543 Second->PragmaDebug(Loc, DebugType);
548 First->PragmaMessage(Loc, Namespace, Kind, Str);
549 Second->PragmaMessage(Loc, Namespace, Kind, Str);
553 First->PragmaDiagnosticPush(Loc, Namespace);
554 Second->PragmaDiagnosticPush(Loc, Namespace);
558 First->PragmaDiagnosticPop(Loc, Namespace);
559 Second->PragmaDiagnosticPop(Loc, Namespace);
564 First->PragmaDiagnostic(Loc, Namespace, mapping, Str);
565 Second->PragmaDiagnostic(Loc, Namespace, mapping, Str);
574 First->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State);
575 Second->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State);
580 First->PragmaWarning(Loc, WarningSpec, Ids);
581 Second->PragmaWarning(Loc, WarningSpec, Ids);
585 First->PragmaWarningPush(Loc, Level);
586 Second->PragmaWarningPush(Loc, Level);
590 First->PragmaWarningPop(Loc);
591 Second->PragmaWarningPop(Loc);
595 First->PragmaExecCharsetPush(Loc, Str);
596 Second->PragmaExecCharsetPush(Loc, Str);
600 First->PragmaExecCharsetPop(Loc);
601 Second->PragmaExecCharsetPop(Loc);
605 First->PragmaAssumeNonNullBegin(Loc);
606 Second->PragmaAssumeNonNullBegin(Loc);
610 First->PragmaAssumeNonNullEnd(Loc);
611 Second->PragmaAssumeNonNullEnd(Loc);
616 First->MacroExpands(MacroNameTok, MD, Range, Args);
617 Second->MacroExpands(MacroNameTok, MD, Range, Args);
622 First->MacroDefined(MacroNameTok, MD);
623 Second->MacroDefined(MacroNameTok, MD);
629 First->MacroUndefined(MacroNameTok, MD, Undef);
630 Second->MacroUndefined(MacroNameTok, MD, Undef);
635 First->Defined(MacroNameTok, MD, Range);
636 Second->Defined(MacroNameTok, MD, Range);
640 First->SourceRangeSkipped(Range, EndifLoc);
641 Second->SourceRangeSkipped(Range, EndifLoc);
647 First->If(Loc, ConditionRange, ConditionValue);
648 Second->If(Loc, ConditionRange, ConditionValue);
654 First->Elif(Loc, ConditionRange, ConditionValue, IfLoc);
655 Second->Elif(Loc, ConditionRange, ConditionValue, IfLoc);
661 First->Ifdef(Loc, MacroNameTok, MD);
662 Second->Ifdef(Loc, MacroNameTok, MD);
668 First->Elifdef(Loc, MacroNameTok, MD);
669 Second->Elifdef(Loc, MacroNameTok, MD);
674 First->Elifdef(Loc, ConditionRange, IfLoc);
675 Second->Elifdef(Loc, ConditionRange, IfLoc);
681 First->Ifndef(Loc, MacroNameTok, MD);
682 Second->Ifndef(Loc, MacroNameTok, MD);
688 First->Elifndef(Loc, MacroNameTok, MD);
689 Second->Elifndef(Loc, MacroNameTok, MD);
694 First->Elifndef(Loc, ConditionRange, IfLoc);
695 Second->Elifndef(Loc, ConditionRange, IfLoc);
700 First->Else(Loc, IfLoc);
701 Second->Else(Loc, IfLoc);
706 First->Endif(Loc, IfLoc);
707 Second->Endif(Loc, IfLoc);
Defines the Diagnostic IDs-related interfaces.
llvm::MachO::FileType FileType
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
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...
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 ...
A description of the current definition of a macro.
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Describes a module or submodule.
This interface provides a way to observe the actions of the preprocessor as it does its thing.
virtual void PragmaExecCharsetPop(SourceLocation Loc)
Callback invoked when a #pragma execution_character_set(pop) directive is read.
virtual void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer)
Callback invoked when start reading any pragma directive.
virtual void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range)
Hook called whenever the 'defined' operator is seen.
virtual void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic push directive is read.
virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, StringRef Str)
Callback invoked when a #pragma comment directive is read.
virtual void Elifndef(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc)
Hook called whenever an #elifndef is skipped.
virtual void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, ArrayRef< int > Ids)
virtual void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args)
Called by Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is found.
virtual void Elifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #elifndef branch is taken.
virtual void EnteredSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Callback invoked whenever a submodule was entered.
virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc)
Hook called whenever an #elif is seen.
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType)
Callback invoked when a #pragma clang __debug directive is read.
virtual void EndOfMainFile()
Callback invoked when the end of the main file is reached.
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID=FileID())
Callback invoked whenever a source file is entered or exited.
virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #ifndef is seen.
virtual void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue)
Hook called whenever an #if is seen.
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.
virtual void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef)
Hook called whenever a macro #undef is seen.
virtual void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD)
Hook called whenever a macro definition is seen.
virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity mapping, StringRef Str)
Callback invoked when a #pragma gcc diagnostic directive is read.
virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #ifdef is seen.
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.
PragmaWarningSpecifier
Callback invoked when a #pragma warning directive is read.
virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
Callback invoked when a #pragma detect_mismatch directive is read.
virtual void PragmaAssumeNonNullEnd(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull end directive is read.
virtual void PragmaAssumeNonNullBegin(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull begin directive is read.
virtual void PragmaMark(SourceLocation Loc, StringRef Trivia)
Callback invoked when a #pragma mark comment is read.
virtual void Ident(SourceLocation Loc, StringRef str)
Callback invoked when a #ident or #sccs directive is read.
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.
virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str)
Callback invoked when a #pragma message directive is read.
virtual void Elifdef(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc)
Hook called whenever an #elifdef is skipped.
virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc)
Hook called when a source range is skipped.
virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str)
Callback invoked when a #pragma execution_character_set(push) directive is read.
virtual void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic pop directive is read.
virtual void PragmaWarningPop(SourceLocation Loc)
Callback invoked when a #pragma warning(pop) directive is read.
virtual void Elifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #elifdef branch is taken.
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.
virtual void LeftSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Callback invoked whenever a submodule was left.
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....
virtual void Else(SourceLocation Loc, SourceLocation IfLoc)
Hook called whenever an #else is seen.
PragmaMessageKind
Determines the kind of #pragma invoking a call to PragmaMessage.
@ PMK_Warning
#pragma GCC warning has been invoked.
@ PMK_Error
#pragma GCC error has been invoked.
@ PMK_Message
#pragma message has been invoked.
virtual bool FileNotFound(StringRef FileName)
Callback invoked whenever the preprocessor cannot find a file for an inclusion directive.
virtual void PragmaWarningPush(SourceLocation Loc, int Level)
Callback invoked when a #pragma warning(push) directive is read.
virtual void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported)
Callback invoked whenever there was an explicit module-import syntax.
virtual void Endif(SourceLocation Loc, SourceLocation IfLoc)
Hook called whenever an #endif is seen.
Simple wrapper class for chaining callbacks.
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override
Hook called whenever a macro #undef is seen.
void EnteredSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma) override
Callback invoked whenever a submodule was entered.
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override
Called by Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is found.
void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override
Hook called whenever an #if is seen.
void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) override
Callback invoked whenever a source file is entered or exited.
void Endif(SourceLocation Loc, SourceLocation IfLoc) override
Hook called whenever an #endif is seen.
void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override
Callback invoked when a #pragma execution_character_set(push) directive is read.
void Elifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #elifndef is taken.
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.
void PragmaAssumeNonNullEnd(SourceLocation Loc) override
Callback invoked when a #pragma clang assume_nonnull end directive is read.
void PragmaWarningPop(SourceLocation Loc) override
Callback invoked when a #pragma warning(pop) directive is read.
void Elifndef(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc) override
Hook called whenever an #elifndef is skipped.
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override
Hook called when a source range is skipped.
void LeftSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma) override
Callback invoked whenever a submodule was left.
void PragmaWarningPush(SourceLocation Loc, int Level) override
Callback invoked when a #pragma warning(push) directive is read.
void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value) override
Callback invoked when a #pragma detect_mismatch directive is read.
void PragmaDebug(SourceLocation Loc, StringRef DebugType) override
Callback invoked when a #pragma clang __debug directive is read.
void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range) override
Hook called whenever the 'defined' operator is seen.
void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity mapping, StringRef Str) override
Callback invoked when a #pragma gcc diagnostic directive is read.
~PPChainedCallbacks() override
void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) override
Callback invoked when start reading any pragma directive.
void PragmaAssumeNonNullBegin(SourceLocation Loc) override
Callback invoked when a #pragma clang assume_nonnull begin directive is read.
void Else(SourceLocation Loc, SourceLocation IfLoc) override
Hook called whenever an #else is seen.
void Ident(SourceLocation Loc, StringRef str) override
Callback invoked when a #ident or #sccs directive is read.
void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #ifdef is seen.
void Elifdef(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc) override
Hook called whenever an #elifdef is skipped.
void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override
Callback invoked when a #pragma gcc diagnostic push directive is read.
void EndOfMainFile() override
Callback invoked when the end of the main file is reached.
void PragmaExecCharsetPop(SourceLocation Loc) override
Callback invoked when a #pragma execution_character_set(pop) directive is read.
bool FileNotFound(StringRef FileName) override
Callback invoked whenever the preprocessor cannot find a file for an inclusion directive.
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.
void PragmaMark(SourceLocation Loc, StringRef Trivia) override
Callback invoked when a #pragma mark comment is read.
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.
PPChainedCallbacks(std::unique_ptr< PPCallbacks > _First, std::unique_ptr< PPCallbacks > _Second)
void Elifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #elifdef is taken.
void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str) override
Callback invoked when a #pragma message directive is read.
void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, StringRef Str) override
Callback invoked when a #pragma comment directive is read.
void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override
Callback invoked when a #pragma gcc diagnostic pop directive is read.
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override
Callback invoked whenever there was an explicit module-import syntax.
void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, ArrayRef< int > Ids) override
void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #ifndef is seen.
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.
void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) override
Hook called whenever an #elif is seen.
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
Hook called whenever a macro definition is seen.
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....
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.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
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.