Go to the documentation of this file.
14 #ifndef LLVM_CLANG_LEX_PPCALLBACKS_H
15 #define LLVM_CLANG_LEX_PPCALLBACKS_H
22 #include "llvm/ADT/StringRef.h"
27 class MacroDefinition;
61 const Token &FilenameTok,
123 const Token &IncludeTok,
128 StringRef SearchPath,
129 StringRef RelativePath,
230 StringRef Namespace) {
236 StringRef Namespace) {
377 std::unique_ptr<PPCallbacks> First, Second;
381 std::unique_ptr<PPCallbacks> _Second)
382 :
First(
std::move(_First)), Second(
std::move(_Second)) {}
388 FileID PrevFID)
override {
389 First->FileChanged(Loc, Reason, FileType, PrevFID);
390 Second->FileChanged(Loc, Reason, FileType, PrevFID);
395 First->FileSkipped(SkippedFile, FilenameTok, FileType);
396 Second->FileSkipped(SkippedFile, FilenameTok, FileType);
401 return First->FileNotFound(FileName, RecoveryPath) ||
402 Second->FileNotFound(FileName, RecoveryPath);
406 StringRef FileName,
bool IsAngled,
408 StringRef SearchPath, StringRef RelativePath,
411 First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
412 FilenameRange,
File, SearchPath, RelativePath,
414 Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
415 FilenameRange,
File, SearchPath, RelativePath,
420 bool ForPragma)
override {
421 First->EnteredSubmodule(M, ImportLoc, ForPragma);
422 Second->EnteredSubmodule(M, ImportLoc, ForPragma);
426 bool ForPragma)
override {
427 First->LeftSubmodule(M, ImportLoc, ForPragma);
428 Second->LeftSubmodule(M, ImportLoc, ForPragma);
432 const Module *Imported)
override {
433 First->moduleImport(ImportLoc, Path, Imported);
434 Second->moduleImport(ImportLoc, Path, Imported);
438 First->EndOfMainFile();
439 Second->EndOfMainFile();
443 First->Ident(Loc, str);
444 Second->Ident(Loc, str);
449 First->PragmaDirective(Loc, Introducer);
450 Second->PragmaDirective(Loc, Introducer);
454 StringRef Str)
override {
456 Second->PragmaComment(Loc,
Kind, Str);
460 StringRef
Value)
override {
461 First->PragmaDetectMismatch(Loc, Name,
Value);
462 Second->PragmaDetectMismatch(Loc, Name,
Value);
466 First->PragmaDebug(Loc, DebugType);
467 Second->PragmaDebug(Loc, DebugType);
472 First->PragmaMessage(Loc, Namespace,
Kind, Str);
473 Second->PragmaMessage(Loc, Namespace,
Kind, Str);
477 First->PragmaDiagnosticPush(Loc, Namespace);
478 Second->PragmaDiagnosticPush(Loc, Namespace);
482 First->PragmaDiagnosticPop(Loc, Namespace);
483 Second->PragmaDiagnosticPop(Loc, Namespace);
488 First->PragmaDiagnostic(Loc, Namespace, mapping, Str);
489 Second->PragmaDiagnostic(Loc, Namespace, mapping, Str);
498 First->PragmaOpenCLExtension(NameLoc, Name, StateLoc,
State);
499 Second->PragmaOpenCLExtension(NameLoc, Name, StateLoc,
State);
504 First->PragmaWarning(Loc, WarningSpec, Ids);
505 Second->PragmaWarning(Loc, WarningSpec, Ids);
510 Second->PragmaWarningPush(Loc,
Level);
514 First->PragmaWarningPop(Loc);
515 Second->PragmaWarningPop(Loc);
519 First->PragmaExecCharsetPush(Loc, Str);
520 Second->PragmaExecCharsetPush(Loc, Str);
524 First->PragmaExecCharsetPop(Loc);
525 Second->PragmaExecCharsetPop(Loc);
529 First->PragmaAssumeNonNullBegin(Loc);
530 Second->PragmaAssumeNonNullBegin(Loc);
534 First->PragmaAssumeNonNullEnd(Loc);
535 Second->PragmaAssumeNonNullEnd(Loc);
540 First->MacroExpands(MacroNameTok, MD, Range, Args);
541 Second->MacroExpands(MacroNameTok, MD, Range, Args);
546 First->MacroDefined(MacroNameTok, MD);
547 Second->MacroDefined(MacroNameTok, MD);
553 First->MacroUndefined(MacroNameTok, MD, Undef);
554 Second->MacroUndefined(MacroNameTok, MD, Undef);
559 First->Defined(MacroNameTok, MD, Range);
560 Second->Defined(MacroNameTok, MD, Range);
564 First->SourceRangeSkipped(Range, EndifLoc);
565 Second->SourceRangeSkipped(Range, EndifLoc);
571 First->If(Loc, ConditionRange, ConditionValue);
572 Second->If(Loc, ConditionRange, ConditionValue);
578 First->Elif(Loc, ConditionRange, ConditionValue, IfLoc);
579 Second->Elif(Loc, ConditionRange, ConditionValue, IfLoc);
585 First->Ifdef(Loc, MacroNameTok, MD);
586 Second->Ifdef(Loc, MacroNameTok, MD);
592 First->Ifndef(Loc, MacroNameTok, MD);
593 Second->Ifndef(Loc, MacroNameTok, MD);
598 First->Else(Loc, IfLoc);
599 Second->Else(Loc, IfLoc);
604 First->Endif(Loc, IfLoc);
605 Second->Endif(Loc, IfLoc);
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) override
Callback invoked when start reading any pragma directive.
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 PragmaAssumeNonNullBegin(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull begin directive is read.
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType)
Callback invoked when a #pragma clang __debug directive is read.
PragmaIntroducerKind
Describes how the pragma was introduced, e.g., with #pragma, _Pragma, or __pragma.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
void EnteredSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma) override
Callback invoked whenever a submodule was entered.
virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc)
Hook called when a source range is skipped.
A trivial tuple used to represent a source range.
virtual void PragmaAssumeNonNullEnd(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull end directive is read.
virtual void Ident(SourceLocation Loc, StringRef str)
Callback invoked when a #ident or #sccs directive is read.
virtual void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue)
Hook called whenever an #if is seen.
void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) override
Hook called whenever an #elif is seen.
void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override
Hook called whenever an #if is seen.
A description of the current definition of a macro.
Encodes a location in the source.
void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, Optional< FileEntryRef > File, SrcMgr::CharacteristicKind FileType) override
Hook called when a '__has_include' or '__has_include_next' directive is read.
@ PMK_Error
#pragma GCC error has been invoked.
This interface provides a way to observe the actions of the preprocessor as it does its thing.
virtual void EnteredSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Callback invoked whenever a submodule was entered.
virtual void LeftSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Callback invoked whenever a submodule was left.
virtual void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef)
Hook called whenever a macro #undef is seen.
virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, StringRef Str)
Callback invoked when a #pragma comment directive is read.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override
Callback invoked when a #pragma gcc diagnostic pop directive is read.
virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
Callback invoked when a #pragma detect_mismatch directive is read.
virtual void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic push directive is read.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
PPChainedCallbacks(std::unique_ptr< PPCallbacks > _First, std::unique_ptr< PPCallbacks > _Second)
virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #ifndef is seen.
void PragmaAssumeNonNullBegin(SourceLocation Loc) override
Callback invoked when a #pragma clang assume_nonnull begin directive is read.
Token - This structure provides full information about a lexed token.
void EndOfMainFile() override
Callback invoked when the end of the main file is reached.
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.
virtual void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args)
Called by Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is found.
Describes a module or submodule.
void PragmaWarningPop(SourceLocation Loc) override
Callback invoked when a #pragma warning(pop) directive is read.
void Endif(SourceLocation Loc, SourceLocation IfLoc) override
Hook called whenever an #endif is seen.
virtual void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer)
Callback invoked when start reading any pragma directive.
void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #ifdef is seen.
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
Hook called whenever a macro definition is seen.
void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override
Callback invoked when a #pragma execution_character_set(push) directive 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.
virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str)
Callback invoked when a #pragma execution_character_set(push) directive is read.
virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc)
Hook called whenever an #elif is seen.
virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str)
Callback invoked when a #pragma message directive is read.
void Else(SourceLocation Loc, SourceLocation IfLoc) override
Hook called whenever an #else 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 PragmaAssumeNonNullEnd(SourceLocation Loc) override
Callback invoked when a #pragma clang assume_nonnull end directive is read.
virtual void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType)
Callback invoked whenever an inclusion directive of any kind (#include, #import, etc....
void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override
Callback invoked when a #pragma gcc diagnostic push directive is read.
virtual void PragmaWarning(SourceLocation Loc, StringRef WarningSpec, ArrayRef< int > Ids)
Callback invoked when a #pragma warning directive is read.
void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Hook called whenever an #ifndef is seen.
virtual bool FileNotFound(StringRef FileName, SmallVectorImpl< char > &RecoveryPath)
Callback invoked whenever an inclusion directive results in a file-not-found error.
@ PMK_Warning
#pragma GCC warning has been invoked.
Simple wrapper class for chaining callbacks.
void LeftSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma) override
Callback invoked whenever a submodule was left.
virtual void Else(SourceLocation Loc, SourceLocation IfLoc)
Hook called whenever an #else is seen.
@ PMK_Message
#pragma message has been invoked.
bool FileNotFound(StringRef FileName, SmallVectorImpl< char > &RecoveryPath) override
Callback invoked whenever an inclusion directive results in a file-not-found error.
Cached information about one file (either on disk or in the virtual file system).
void PragmaWarning(SourceLocation Loc, StringRef WarningSpec, ArrayRef< int > Ids) override
Callback invoked when a #pragma warning directive is read.
void PragmaWarningPush(SourceLocation Loc, int Level) override
Callback invoked when a #pragma warning(push) directive is read.
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 InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override
Callback invoked whenever an inclusion directive of any kind (#include, #import, etc....
virtual void Endif(SourceLocation Loc, SourceLocation IfLoc)
Hook called whenever an #endif is seen.
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override
Hook called whenever a macro #undef is seen.
virtual void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range)
Hook called whenever the 'defined' operator is seen.
void Ident(SourceLocation Loc, StringRef str) override
Callback invoked when a #ident or #sccs directive is read.
Represents a character-granular source range.
virtual void EndOfMainFile()
Callback invoked when the end of the main file is reached.
void PragmaDebug(SourceLocation Loc, StringRef DebugType) override
Callback invoked when a #pragma clang __debug directive is read.
virtual void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace)
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 PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str) override
Callback invoked when a #pragma message directive is read.
One of these records is kept for each identifier that is lexed.
void PragmaExecCharsetPop(SourceLocation Loc) override
Callback invoked when a #pragma execution_character_set(pop) directive is read.
virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, Optional< FileEntryRef > File, SrcMgr::CharacteristicKind FileType)
Hook called when a '__has_include' or '__has_include_next' directive is read.
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override
Hook called when a source range is skipped.
~PPChainedCallbacks() override
void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value) override
Callback invoked when a #pragma detect_mismatch directive is read.
Dataflow Directional Tag Classes.
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.
void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range) override
Hook called whenever the 'defined' operator is seen.
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
PragmaMessageKind
Determines the kind of #pragma invoking a call to PragmaMessage.
virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #ifdef is seen.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
virtual void PragmaExecCharsetPop(SourceLocation Loc)
Callback invoked when a #pragma execution_character_set(pop) directive is read.
virtual void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD)
Hook called whenever a macro definition is seen.
void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity mapping, StringRef Str) override
Callback invoked when a #pragma gcc diagnostic directive is read.
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 PragmaWarningPush(SourceLocation Loc, int Level)
Callback invoked when a #pragma warning(push) directive is read.
virtual void PragmaWarningPop(SourceLocation Loc)
Callback invoked when a #pragma warning(pop) 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 PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity mapping, StringRef Str)
Callback invoked when a #pragma gcc diagnostic directive is read.
void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, StringRef Str) override
Callback invoked when a #pragma comment directive is read.