10 #include "clang/Lex/PPCallbacks.h"
11 #include "clang/Lex/Preprocessor.h"
12 #include "clang/Lex/Token.h"
21 : Inserter(Inserter) {}
25 const Token &IncludeToken, StringRef FileNameRef,
26 bool IsAngled, CharSourceRange FileNameRange,
27 Optional<FileEntryRef> ,
28 StringRef , StringRef ,
30 SrcMgr::CharacteristicKind )
override {
31 Inserter->addInclude(FileNameRef,
IsAngled, HashLocation,
32 IncludeToken.getEndLoc());
40 bool SelfContainedDiags)
41 : Style(Style), SelfContainedDiags(SelfContainedDiags) {}
44 assert(
PP &&
"PP shouldn't be null");
45 SourceMgr = &
PP->getSourceManager();
48 if (!IncludeSorterByFile.empty())
49 IncludeSorterByFile.clear();
50 if (!InsertedHeaders.empty())
51 InsertedHeaders.clear();
52 PP->addPPCallbacks(std::make_unique<IncludeInserterCallback>(
this));
56 assert(SourceMgr &&
"SourceMgr shouldn't be null; did you remember to call "
57 "registerPreprocessor()?");
60 std::unique_ptr<IncludeSorter> &
Entry = IncludeSorterByFile[FileID];
63 Entry = std::make_unique<IncludeSorter>(
65 SourceMgr->getFilename(SourceMgr->getLocForStartOfFile(FileID)), Style);
70 llvm::Optional<FixItHint>
72 bool IsAngled = Header.consume_front(
"<");
73 if (
IsAngled != Header.consume_back(
">"))
79 if (!SelfContainedDiags && !InsertedHeaders[FileID].insert(Header).second)
85 llvm::Optional<FixItHint>
87 assert(SourceMgr &&
"SourceMgr shouldn't be null; did you remember to call "
88 "registerPreprocessor()?");
93 SourceLocation HashLocation,
94 SourceLocation EndLocation) {
95 assert(SourceMgr &&
"SourceMgr shouldn't be null; did you remember to call "
96 "registerPreprocessor()?");
97 FileID FileID = SourceMgr->getFileID(HashLocation);