clang-tools 10.0.0

RestrictSystemIncludesCheck.h
Go to the documentation of this file.
1 //===--- RestrictSystemIncludesCheck.h - clang-tidy---------- ----*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
11
12 #include "../ClangTidyCheck.h"
13 #include "../GlobList.h"
14
15 namespace clang {
16 namespace tidy {
17 namespace fuchsia {
18
19 /// Checks for allowed includes and suggests removal of any others. If no
20 /// includes are specified, the check will exit without issuing any warnings.
21 ///
22 /// For the user-facing documentation see:
23 /// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html
24 class RestrictSystemIncludesCheck : public ClangTidyCheck {
25 public:
26 RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context)
27 : ClangTidyCheck(Name, Context),
28 AllowedIncludes(Options.get("Includes", "*")),
29 AllowedIncludesGlobList(AllowedIncludes) {}
30
31 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
32 Preprocessor *ModuleExpanderPP) override;
33 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
34 bool contains(StringRef FileName) {
35 return AllowedIncludesGlobList.contains(FileName);
36 }
37
38 private:
39 std::string AllowedIncludes;
40 GlobList AllowedIncludesGlobList;
41 };
42
43 } // namespace fuchsia
44 } // namespace tidy
45 } // namespace clang
46
47 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
clang::tidy::fuchsia::RestrictSystemIncludesCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition: RestrictSystemIncludesCheck.cpp:103
clang::tidy::GlobList
Read-only set of strings represented as a list of positive and negative globs.
Definition: GlobList.h:25
clang::tidy::fuchsia::RestrictSystemIncludesCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: RestrictSystemIncludesCheck.cpp:109
clang::tidy::fuchsia::RestrictSystemIncludesCheck
Checks for allowed includes and suggests removal of any others.
Definition: RestrictSystemIncludesCheck.h:24
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::fuchsia::RestrictSystemIncludesCheck::RestrictSystemIncludesCheck
RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context)
Definition: RestrictSystemIncludesCheck.h:26
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidyCheck.h:184
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
FileName
PathRef FileName
Definition: CodeComplete.cpp:1018
clang::tidy::fuchsia::RestrictSystemIncludesCheck::contains
bool contains(StringRef FileName)
Definition: RestrictSystemIncludesCheck.h:34
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:28
clang::tidy::GlobList::contains
bool contains(StringRef S)
Returns true if the pattern matches S.
Definition: GlobList.cpp:54
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77