File indexing completed on 2026-05-10 08:36:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_LEX_PPCALLBACKS_H
0015 #define LLVM_CLANG_LEX_PPCALLBACKS_H
0016
0017 #include "clang/Basic/DiagnosticIDs.h"
0018 #include "clang/Basic/SourceLocation.h"
0019 #include "clang/Basic/SourceManager.h"
0020 #include "clang/Lex/ModuleLoader.h"
0021 #include "clang/Lex/Pragma.h"
0022 #include "llvm/ADT/StringRef.h"
0023
0024 namespace clang {
0025 class Token;
0026 class IdentifierInfo;
0027 class MacroDefinition;
0028 class MacroDirective;
0029 class MacroArgs;
0030 struct LexEmbedParametersResult;
0031
0032
0033
0034
0035
0036 class PPCallbacks {
0037 public:
0038 virtual ~PPCallbacks();
0039
0040 enum FileChangeReason {
0041 EnterFile, ExitFile, SystemHeaderPragma, RenameFile
0042 };
0043
0044
0045
0046
0047
0048
0049 virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
0050 SrcMgr::CharacteristicKind FileType,
0051 FileID PrevFID = FileID()) {
0052 }
0053
0054 enum class LexedFileChangeReason { EnterFile, ExitFile };
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 virtual void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
0072 SrcMgr::CharacteristicKind FileType,
0073 FileID PrevFID, SourceLocation Loc) {}
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 virtual void FileSkipped(const FileEntryRef &SkippedFile,
0084 const Token &FilenameTok,
0085 SrcMgr::CharacteristicKind FileType) {}
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 virtual bool EmbedFileNotFound(StringRef FileName) { return false; }
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 virtual void EmbedDirective(SourceLocation HashLoc, StringRef FileName,
0112 bool IsAngled, OptionalFileEntryRef File,
0113 const LexEmbedParametersResult &Params) {}
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 virtual bool FileNotFound(StringRef FileName) { return false; }
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 virtual void InclusionDirective(SourceLocation HashLoc,
0169 const Token &IncludeTok, StringRef FileName,
0170 bool IsAngled, CharSourceRange FilenameRange,
0171 OptionalFileEntryRef File,
0172 StringRef SearchPath, StringRef RelativePath,
0173 const Module *SuggestedModule,
0174 bool ModuleImported,
0175 SrcMgr::CharacteristicKind FileType) {}
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185 virtual void EnteredSubmodule(Module *M, SourceLocation ImportLoc,
0186 bool ForPragma) { }
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 virtual void LeftSubmodule(Module *M, SourceLocation ImportLoc,
0197 bool ForPragma) { }
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209 virtual void moduleImport(SourceLocation ImportLoc,
0210 ModuleIdPath Path,
0211 const Module *Imported) {
0212 }
0213
0214
0215
0216
0217 virtual void EndOfMainFile() {
0218 }
0219
0220
0221
0222
0223
0224 virtual void Ident(SourceLocation Loc, StringRef str) {
0225 }
0226
0227
0228 virtual void PragmaDirective(SourceLocation Loc,
0229 PragmaIntroducerKind Introducer) {
0230 }
0231
0232
0233 virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
0234 StringRef Str) {
0235 }
0236
0237
0238 virtual void PragmaMark(SourceLocation Loc, StringRef Trivia) {
0239 }
0240
0241
0242
0243 virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,
0244 StringRef Value) {
0245 }
0246
0247
0248
0249
0250 virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType) {
0251 }
0252
0253
0254 enum PragmaMessageKind {
0255
0256 PMK_Message,
0257
0258
0259 PMK_Warning,
0260
0261
0262 PMK_Error
0263 };
0264
0265
0266
0267
0268
0269
0270 virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace,
0271 PragmaMessageKind Kind, StringRef Str) {
0272 }
0273
0274
0275
0276 virtual void PragmaDiagnosticPush(SourceLocation Loc,
0277 StringRef Namespace) {
0278 }
0279
0280
0281
0282 virtual void PragmaDiagnosticPop(SourceLocation Loc,
0283 StringRef Namespace) {
0284 }
0285
0286
0287 virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
0288 diag::Severity mapping, StringRef Str) {}
0289
0290
0291
0292 virtual void PragmaOpenCLExtension(SourceLocation NameLoc,
0293 const IdentifierInfo *Name,
0294 SourceLocation StateLoc, unsigned State) {
0295 }
0296
0297
0298 enum PragmaWarningSpecifier {
0299 PWS_Default,
0300 PWS_Disable,
0301 PWS_Error,
0302 PWS_Once,
0303 PWS_Suppress,
0304 PWS_Level1,
0305 PWS_Level2,
0306 PWS_Level3,
0307 PWS_Level4,
0308 };
0309 virtual void PragmaWarning(SourceLocation Loc,
0310 PragmaWarningSpecifier WarningSpec,
0311 ArrayRef<int> Ids) {}
0312
0313
0314 virtual void PragmaWarningPush(SourceLocation Loc, int Level) {
0315 }
0316
0317
0318 virtual void PragmaWarningPop(SourceLocation Loc) {
0319 }
0320
0321
0322
0323 virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) {}
0324
0325
0326
0327 virtual void PragmaExecCharsetPop(SourceLocation Loc) {}
0328
0329
0330
0331 virtual void PragmaAssumeNonNullBegin(SourceLocation Loc) {}
0332
0333
0334
0335 virtual void PragmaAssumeNonNullEnd(SourceLocation Loc) {}
0336
0337
0338
0339 virtual void MacroExpands(const Token &MacroNameTok,
0340 const MacroDefinition &MD, SourceRange Range,
0341 const MacroArgs *Args) {}
0342
0343
0344 virtual void MacroDefined(const Token &MacroNameTok,
0345 const MacroDirective *MD) {
0346 }
0347
0348
0349
0350
0351
0352
0353
0354 virtual void MacroUndefined(const Token &MacroNameTok,
0355 const MacroDefinition &MD,
0356 const MacroDirective *Undef) {
0357 }
0358
0359
0360
0361 virtual void Defined(const Token &MacroNameTok, const MacroDefinition &MD,
0362 SourceRange Range) {
0363 }
0364
0365
0366 virtual void HasEmbed(SourceLocation Loc, StringRef FileName, bool IsAngled,
0367 OptionalFileEntryRef File) {}
0368
0369
0370
0371 virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
0372 OptionalFileEntryRef File,
0373 SrcMgr::CharacteristicKind FileType);
0374
0375
0376
0377
0378
0379
0380
0381 virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) {
0382 }
0383
0384 enum ConditionValueKind {
0385 CVK_NotEvaluated, CVK_False, CVK_True
0386 };
0387
0388
0389
0390
0391
0392
0393
0394 virtual void If(SourceLocation Loc, SourceRange ConditionRange,
0395 ConditionValueKind ConditionValue) {
0396 }
0397
0398
0399
0400
0401
0402
0403
0404 virtual void Elif(SourceLocation Loc, SourceRange ConditionRange,
0405 ConditionValueKind ConditionValue, SourceLocation IfLoc) {
0406 }
0407
0408
0409
0410
0411
0412 virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
0413 const MacroDefinition &MD) {
0414 }
0415
0416
0417
0418
0419
0420 virtual void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
0421 const MacroDefinition &MD) {
0422 }
0423
0424
0425
0426
0427
0428 virtual void Elifdef(SourceLocation Loc, SourceRange ConditionRange,
0429 SourceLocation IfLoc) {
0430 }
0431
0432
0433
0434
0435
0436 virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
0437 const MacroDefinition &MD) {
0438 }
0439
0440
0441
0442
0443
0444 virtual void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
0445 const MacroDefinition &MD) {
0446 }
0447
0448
0449
0450
0451
0452 virtual void Elifndef(SourceLocation Loc, SourceRange ConditionRange,
0453 SourceLocation IfLoc) {
0454 }
0455
0456
0457
0458
0459 virtual void Else(SourceLocation Loc, SourceLocation IfLoc) {
0460 }
0461
0462
0463
0464
0465 virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) {
0466 }
0467 };
0468
0469
0470 class PPChainedCallbacks : public PPCallbacks {
0471 std::unique_ptr<PPCallbacks> First, Second;
0472
0473 public:
0474 PPChainedCallbacks(std::unique_ptr<PPCallbacks> _First,
0475 std::unique_ptr<PPCallbacks> _Second)
0476 : First(std::move(_First)), Second(std::move(_Second)) {}
0477
0478 ~PPChainedCallbacks() override;
0479
0480 void FileChanged(SourceLocation Loc, FileChangeReason Reason,
0481 SrcMgr::CharacteristicKind FileType,
0482 FileID PrevFID) override {
0483 First->FileChanged(Loc, Reason, FileType, PrevFID);
0484 Second->FileChanged(Loc, Reason, FileType, PrevFID);
0485 }
0486
0487 void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
0488 SrcMgr::CharacteristicKind FileType, FileID PrevFID,
0489 SourceLocation Loc) override {
0490 First->LexedFileChanged(FID, Reason, FileType, PrevFID, Loc);
0491 Second->LexedFileChanged(FID, Reason, FileType, PrevFID, Loc);
0492 }
0493
0494 void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
0495 SrcMgr::CharacteristicKind FileType) override {
0496 First->FileSkipped(SkippedFile, FilenameTok, FileType);
0497 Second->FileSkipped(SkippedFile, FilenameTok, FileType);
0498 }
0499
0500 bool EmbedFileNotFound(StringRef FileName) override {
0501 bool Skip = First->FileNotFound(FileName);
0502
0503
0504 Skip |= Second->FileNotFound(FileName);
0505 return Skip;
0506 }
0507
0508 void EmbedDirective(SourceLocation HashLoc, StringRef FileName, bool IsAngled,
0509 OptionalFileEntryRef File,
0510 const LexEmbedParametersResult &Params) override {
0511 First->EmbedDirective(HashLoc, FileName, IsAngled, File, Params);
0512 Second->EmbedDirective(HashLoc, FileName, IsAngled, File, Params);
0513 }
0514
0515 bool FileNotFound(StringRef FileName) override {
0516 bool Skip = First->FileNotFound(FileName);
0517
0518
0519 Skip |= Second->FileNotFound(FileName);
0520 return Skip;
0521 }
0522
0523 void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
0524 StringRef FileName, bool IsAngled,
0525 CharSourceRange FilenameRange,
0526 OptionalFileEntryRef File, StringRef SearchPath,
0527 StringRef RelativePath, const Module *SuggestedModule,
0528 bool ModuleImported,
0529 SrcMgr::CharacteristicKind FileType) override {
0530 First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
0531 FilenameRange, File, SearchPath, RelativePath,
0532 SuggestedModule, ModuleImported, FileType);
0533 Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
0534 FilenameRange, File, SearchPath, RelativePath,
0535 SuggestedModule, ModuleImported, FileType);
0536 }
0537
0538 void EnteredSubmodule(Module *M, SourceLocation ImportLoc,
0539 bool ForPragma) override {
0540 First->EnteredSubmodule(M, ImportLoc, ForPragma);
0541 Second->EnteredSubmodule(M, ImportLoc, ForPragma);
0542 }
0543
0544 void LeftSubmodule(Module *M, SourceLocation ImportLoc,
0545 bool ForPragma) override {
0546 First->LeftSubmodule(M, ImportLoc, ForPragma);
0547 Second->LeftSubmodule(M, ImportLoc, ForPragma);
0548 }
0549
0550 void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
0551 const Module *Imported) override {
0552 First->moduleImport(ImportLoc, Path, Imported);
0553 Second->moduleImport(ImportLoc, Path, Imported);
0554 }
0555
0556 void EndOfMainFile() override {
0557 First->EndOfMainFile();
0558 Second->EndOfMainFile();
0559 }
0560
0561 void Ident(SourceLocation Loc, StringRef str) override {
0562 First->Ident(Loc, str);
0563 Second->Ident(Loc, str);
0564 }
0565
0566 void PragmaDirective(SourceLocation Loc,
0567 PragmaIntroducerKind Introducer) override {
0568 First->PragmaDirective(Loc, Introducer);
0569 Second->PragmaDirective(Loc, Introducer);
0570 }
0571
0572 void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
0573 StringRef Str) override {
0574 First->PragmaComment(Loc, Kind, Str);
0575 Second->PragmaComment(Loc, Kind, Str);
0576 }
0577
0578 void PragmaMark(SourceLocation Loc, StringRef Trivia) override {
0579 First->PragmaMark(Loc, Trivia);
0580 Second->PragmaMark(Loc, Trivia);
0581 }
0582
0583 void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,
0584 StringRef Value) override {
0585 First->PragmaDetectMismatch(Loc, Name, Value);
0586 Second->PragmaDetectMismatch(Loc, Name, Value);
0587 }
0588
0589 void PragmaDebug(SourceLocation Loc, StringRef DebugType) override {
0590 First->PragmaDebug(Loc, DebugType);
0591 Second->PragmaDebug(Loc, DebugType);
0592 }
0593
0594 void PragmaMessage(SourceLocation Loc, StringRef Namespace,
0595 PragmaMessageKind Kind, StringRef Str) override {
0596 First->PragmaMessage(Loc, Namespace, Kind, Str);
0597 Second->PragmaMessage(Loc, Namespace, Kind, Str);
0598 }
0599
0600 void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override {
0601 First->PragmaDiagnosticPush(Loc, Namespace);
0602 Second->PragmaDiagnosticPush(Loc, Namespace);
0603 }
0604
0605 void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override {
0606 First->PragmaDiagnosticPop(Loc, Namespace);
0607 Second->PragmaDiagnosticPop(Loc, Namespace);
0608 }
0609
0610 void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
0611 diag::Severity mapping, StringRef Str) override {
0612 First->PragmaDiagnostic(Loc, Namespace, mapping, Str);
0613 Second->PragmaDiagnostic(Loc, Namespace, mapping, Str);
0614 }
0615
0616 void HasEmbed(SourceLocation Loc, StringRef FileName, bool IsAngled,
0617 OptionalFileEntryRef File) override {
0618 First->HasEmbed(Loc, FileName, IsAngled, File);
0619 Second->HasEmbed(Loc, FileName, IsAngled, File);
0620 }
0621
0622 void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
0623 OptionalFileEntryRef File,
0624 SrcMgr::CharacteristicKind FileType) override;
0625
0626 void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name,
0627 SourceLocation StateLoc, unsigned State) override {
0628 First->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State);
0629 Second->PragmaOpenCLExtension(NameLoc, Name, StateLoc, State);
0630 }
0631
0632 void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec,
0633 ArrayRef<int> Ids) override {
0634 First->PragmaWarning(Loc, WarningSpec, Ids);
0635 Second->PragmaWarning(Loc, WarningSpec, Ids);
0636 }
0637
0638 void PragmaWarningPush(SourceLocation Loc, int Level) override {
0639 First->PragmaWarningPush(Loc, Level);
0640 Second->PragmaWarningPush(Loc, Level);
0641 }
0642
0643 void PragmaWarningPop(SourceLocation Loc) override {
0644 First->PragmaWarningPop(Loc);
0645 Second->PragmaWarningPop(Loc);
0646 }
0647
0648 void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override {
0649 First->PragmaExecCharsetPush(Loc, Str);
0650 Second->PragmaExecCharsetPush(Loc, Str);
0651 }
0652
0653 void PragmaExecCharsetPop(SourceLocation Loc) override {
0654 First->PragmaExecCharsetPop(Loc);
0655 Second->PragmaExecCharsetPop(Loc);
0656 }
0657
0658 void PragmaAssumeNonNullBegin(SourceLocation Loc) override {
0659 First->PragmaAssumeNonNullBegin(Loc);
0660 Second->PragmaAssumeNonNullBegin(Loc);
0661 }
0662
0663 void PragmaAssumeNonNullEnd(SourceLocation Loc) override {
0664 First->PragmaAssumeNonNullEnd(Loc);
0665 Second->PragmaAssumeNonNullEnd(Loc);
0666 }
0667
0668 void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
0669 SourceRange Range, const MacroArgs *Args) override {
0670 First->MacroExpands(MacroNameTok, MD, Range, Args);
0671 Second->MacroExpands(MacroNameTok, MD, Range, Args);
0672 }
0673
0674 void MacroDefined(const Token &MacroNameTok,
0675 const MacroDirective *MD) override {
0676 First->MacroDefined(MacroNameTok, MD);
0677 Second->MacroDefined(MacroNameTok, MD);
0678 }
0679
0680 void MacroUndefined(const Token &MacroNameTok,
0681 const MacroDefinition &MD,
0682 const MacroDirective *Undef) override {
0683 First->MacroUndefined(MacroNameTok, MD, Undef);
0684 Second->MacroUndefined(MacroNameTok, MD, Undef);
0685 }
0686
0687 void Defined(const Token &MacroNameTok, const MacroDefinition &MD,
0688 SourceRange Range) override {
0689 First->Defined(MacroNameTok, MD, Range);
0690 Second->Defined(MacroNameTok, MD, Range);
0691 }
0692
0693 void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override {
0694 First->SourceRangeSkipped(Range, EndifLoc);
0695 Second->SourceRangeSkipped(Range, EndifLoc);
0696 }
0697
0698
0699 void If(SourceLocation Loc, SourceRange ConditionRange,
0700 ConditionValueKind ConditionValue) override {
0701 First->If(Loc, ConditionRange, ConditionValue);
0702 Second->If(Loc, ConditionRange, ConditionValue);
0703 }
0704
0705
0706 void Elif(SourceLocation Loc, SourceRange ConditionRange,
0707 ConditionValueKind ConditionValue, SourceLocation IfLoc) override {
0708 First->Elif(Loc, ConditionRange, ConditionValue, IfLoc);
0709 Second->Elif(Loc, ConditionRange, ConditionValue, IfLoc);
0710 }
0711
0712
0713 void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
0714 const MacroDefinition &MD) override {
0715 First->Ifdef(Loc, MacroNameTok, MD);
0716 Second->Ifdef(Loc, MacroNameTok, MD);
0717 }
0718
0719
0720 void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
0721 const MacroDefinition &MD) override {
0722 First->Elifdef(Loc, MacroNameTok, MD);
0723 Second->Elifdef(Loc, MacroNameTok, MD);
0724 }
0725
0726 void Elifdef(SourceLocation Loc, SourceRange ConditionRange,
0727 SourceLocation IfLoc) override {
0728 First->Elifdef(Loc, ConditionRange, IfLoc);
0729 Second->Elifdef(Loc, ConditionRange, IfLoc);
0730 }
0731
0732
0733 void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
0734 const MacroDefinition &MD) override {
0735 First->Ifndef(Loc, MacroNameTok, MD);
0736 Second->Ifndef(Loc, MacroNameTok, MD);
0737 }
0738
0739
0740 void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
0741 const MacroDefinition &MD) override {
0742 First->Elifndef(Loc, MacroNameTok, MD);
0743 Second->Elifndef(Loc, MacroNameTok, MD);
0744 }
0745
0746 void Elifndef(SourceLocation Loc, SourceRange ConditionRange,
0747 SourceLocation IfLoc) override {
0748 First->Elifndef(Loc, ConditionRange, IfLoc);
0749 Second->Elifndef(Loc, ConditionRange, IfLoc);
0750 }
0751
0752
0753 void Else(SourceLocation Loc, SourceLocation IfLoc) override {
0754 First->Else(Loc, IfLoc);
0755 Second->Else(Loc, IfLoc);
0756 }
0757
0758
0759 void Endif(SourceLocation Loc, SourceLocation IfLoc) override {
0760 First->Endif(Loc, IfLoc);
0761 Second->Endif(Loc, IfLoc);
0762 }
0763 };
0764
0765 }
0766
0767 #endif