File indexing completed on 2026-05-10 08:36:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
0010 #define LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
0011
0012 #include "clang/Lex/PPCallbacks.h"
0013 #include "clang/Lex/Preprocessor.h"
0014 #include "llvm/ADT/DenseSet.h"
0015
0016 namespace llvm::vfs {
0017 class OverlayFileSystem;
0018 class InMemoryFileSystem;
0019 }
0020
0021 namespace clang {
0022 class CompilerInstance;
0023
0024 namespace serialization {
0025 class ModuleFile;
0026 }
0027
0028 namespace tooling {
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 class ExpandModularHeadersPPCallbacks : public PPCallbacks {
0042 public:
0043 ExpandModularHeadersPPCallbacks(
0044 CompilerInstance *CI,
0045 IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS);
0046 ~ExpandModularHeadersPPCallbacks();
0047
0048
0049
0050
0051
0052
0053
0054 Preprocessor *getPreprocessor() const;
0055
0056 private:
0057 class FileRecorder;
0058
0059 void handleModuleFile(serialization::ModuleFile *MF);
0060 void parseToLocation(SourceLocation Loc);
0061
0062
0063 void FileChanged(SourceLocation Loc, FileChangeReason Reason,
0064 SrcMgr::CharacteristicKind FileType,
0065 FileID PrevFID) override;
0066
0067 void InclusionDirective(SourceLocation DirectiveLoc,
0068 const Token &IncludeToken, StringRef IncludedFilename,
0069 bool IsAngled, CharSourceRange FilenameRange,
0070 OptionalFileEntryRef IncludedFile,
0071 StringRef SearchPath, StringRef RelativePath,
0072 const Module *SuggestedModule, bool ModuleImported,
0073 SrcMgr::CharacteristicKind FileType) override;
0074
0075 void EndOfMainFile() override;
0076
0077
0078
0079
0080 void Ident(SourceLocation Loc, StringRef) override;
0081 void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind) override;
0082 void PragmaComment(SourceLocation Loc, const IdentifierInfo *,
0083 StringRef) override;
0084 void PragmaDetectMismatch(SourceLocation Loc, StringRef, StringRef) override;
0085 void PragmaDebug(SourceLocation Loc, StringRef) override;
0086 void PragmaMessage(SourceLocation Loc, StringRef, PragmaMessageKind,
0087 StringRef) override;
0088 void PragmaDiagnosticPush(SourceLocation Loc, StringRef) override;
0089 void PragmaDiagnosticPop(SourceLocation Loc, StringRef) override;
0090 void PragmaDiagnostic(SourceLocation Loc, StringRef, diag::Severity,
0091 StringRef) override;
0092 void HasInclude(SourceLocation Loc, StringRef, bool, OptionalFileEntryRef,
0093 SrcMgr::CharacteristicKind) override;
0094 void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *,
0095 SourceLocation StateLoc, unsigned) override;
0096 void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier,
0097 ArrayRef<int>) override;
0098 void PragmaWarningPush(SourceLocation Loc, int) override;
0099 void PragmaWarningPop(SourceLocation Loc) override;
0100 void PragmaAssumeNonNullBegin(SourceLocation Loc) override;
0101 void PragmaAssumeNonNullEnd(SourceLocation Loc) override;
0102 void MacroExpands(const Token &MacroNameTok, const MacroDefinition &,
0103 SourceRange Range, const MacroArgs *) override;
0104 void MacroDefined(const Token &MacroNameTok,
0105 const MacroDirective *MD) override;
0106 void MacroUndefined(const Token &, const MacroDefinition &,
0107 const MacroDirective *Undef) override;
0108 void Defined(const Token &MacroNameTok, const MacroDefinition &,
0109 SourceRange Range) override;
0110 void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override;
0111 void If(SourceLocation Loc, SourceRange, ConditionValueKind) override;
0112 void Elif(SourceLocation Loc, SourceRange, ConditionValueKind,
0113 SourceLocation) override;
0114 void Ifdef(SourceLocation Loc, const Token &,
0115 const MacroDefinition &) override;
0116 void Ifndef(SourceLocation Loc, const Token &,
0117 const MacroDefinition &) override;
0118 void Else(SourceLocation Loc, SourceLocation) override;
0119 void Endif(SourceLocation Loc, SourceLocation) override;
0120
0121 std::unique_ptr<FileRecorder> Recorder;
0122
0123 llvm::DenseSet<serialization::ModuleFile *> VisitedModules;
0124
0125 CompilerInstance &Compiler;
0126
0127 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFs;
0128
0129 SourceManager &Sources;
0130 DiagnosticsEngine Diags;
0131 LangOptions LangOpts;
0132 TrivialModuleLoader ModuleLoader;
0133
0134 std::unique_ptr<HeaderSearch> HeaderInfo;
0135 std::unique_ptr<Preprocessor> PP;
0136 bool EnteredMainFile = false;
0137 bool StartedLexing = false;
0138 Token CurrentToken;
0139 };
0140
0141 }
0142 }
0143
0144 #endif