10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/Lex/HeaderSearch.h"
13#include "clang/Lex/HeaderSearchOptions.h"
14#include "clang/Lex/Preprocessor.h"
23class RestrictedIncludesPPCallbacks
24 :
public portability::RestrictedIncludesPPCallbacks {
26 explicit RestrictedIncludesPPCallbacks(
27 RestrictSystemLibcHeadersCheck &Check,
const SourceManager &SM,
28 const SmallString<128> CompilerIncudeDir)
29 : portability::RestrictedIncludesPPCallbacks(Check, SM),
30 CompilerIncudeDir(CompilerIncudeDir) {}
32 void InclusionDirective(SourceLocation HashLoc,
const Token &IncludeTok,
34 CharSourceRange FilenameRange,
35 OptionalFileEntryRef File, StringRef SearchPath,
36 StringRef RelativePath,
const Module *SuggestedModule,
38 SrcMgr::CharacteristicKind FileType)
override;
41 const SmallString<128> CompilerIncudeDir;
46void RestrictedIncludesPPCallbacks::InclusionDirective(
47 SourceLocation HashLoc,
const Token &IncludeTok, StringRef
FileName,
48 bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
49 StringRef SearchPath, StringRef RelativePath,
const Module *SuggestedModule,
50 bool ModuleImported, SrcMgr::CharacteristicKind FileType) {
52 if (SrcMgr::isSystem(FileType) && SearchPath == CompilerIncudeDir)
56 RelativePath, SuggestedModule, ModuleImported, FileType);
60 const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
61 SmallString<128> CompilerIncudeDir =
62 StringRef(PP->getHeaderSearchInfo().getHeaderSearchOpts().ResourceDir);
63 llvm::sys::path::append(CompilerIncudeDir,
"include");
64 PP->addPPCallbacks(std::make_unique<RestrictedIncludesPPCallbacks>(
65 *
this, SM, CompilerIncudeDir));
bool IsAngled
true if this was an include with angle brackets
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