9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H
12#include "../ClangTidyCheck.h"
13#include "../GlobList.h"
14#include "clang/Lex/PPCallbacks.h"
26 std::string DefaultAllowedIncludes =
"*")
28 AllowedIncludes(
Options.get(
"Includes", DefaultAllowedIncludes)),
29 AllowedIncludesGlobList(AllowedIncludes) {}
32 Preprocessor *ModuleExpanderPP)
override;
39 std::string AllowedIncludes;
46 const SourceManager &SM)
47 : Check(Check), SM(SM) {}
51 CharSourceRange FilenameRange,
52 OptionalFileEntryRef File, StringRef SearchPath,
53 StringRef RelativePath,
const Module *SuggestedModule,
55 SrcMgr::CharacteristicKind FileType)
override;
59 struct IncludeDirective {
60 IncludeDirective() =
default;
61 IncludeDirective(SourceLocation Loc, CharSourceRange Range,
62 StringRef
Filename, StringRef FullPath,
bool IsInMainFile)
64 IsInMainFile(IsInMainFile) {}
67 CharSourceRange
Range;
68 std::string IncludeFile;
69 std::string IncludePath;
73 using FileIncludes = llvm::SmallVector<IncludeDirective, 8>;
74 llvm::SmallDenseMap<FileID, FileIncludes> IncludeDirectives;
76 RestrictSystemIncludesCheck &Check;
77 const SourceManager &SM;
llvm::SmallString< 256U > Name
CharSourceRange Range
SourceRange for the file name.
std::string Filename
Filename as a string.
bool IsAngled
true if this was an include with angle brackets
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Read-only set of strings represented as a list of positive and negative globs.
virtual bool contains(StringRef S) const
Returns true if the pattern matches S.
Checks for allowed includes and suggests removal of any others.
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context, std::string DefaultAllowedIncludes="*")
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
bool contains(StringRef FileName)
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
RestrictedIncludesPPCallbacks(RestrictSystemIncludesCheck &Check, const SourceManager &SM)
void EndOfMainFile() override
llvm::StringMap< ClangTidyValue > OptionMap