clang-tools 8.0.0

RestrictSystemIncludesCheck.h
Go to the documentation of this file.
1 //===--- RestrictSystemIncludesCheck.h - clang-tidy---------- ----*- C++-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
12
13 #include "../ClangTidy.h"
14 #include "../ClangTidyDiagnosticConsumer.h"
15 #include "../utils/OptionsUtils.h"
16
17 namespace clang {
18 namespace tidy {
19 namespace fuchsia {
20
21 /// Checks for allowed includes and suggests removal of any others. If no
22 /// includes are specified, the check will exit without issuing any warnings.
23 ///
24 /// For the user-facing documentation see:
25 /// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html
26 class RestrictSystemIncludesCheck : public ClangTidyCheck {
27 public:
28 RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context)
29 : ClangTidyCheck(Name, Context),
30 AllowedIncludes(Options.get("Includes", "*")),
31 AllowedIncludesGlobList(AllowedIncludes) {}
32
33 void registerPPCallbacks(CompilerInstance &Compiler) override;
34 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
35 bool contains(StringRef FileName) {
36 return AllowedIncludesGlobList.contains(FileName);
37 }
38
39 private:
40 std::string AllowedIncludes;
41 GlobList AllowedIncludesGlobList;
42 };
43
44 } // namespace fuchsia
45 } // namespace tidy
46 } // namespace clang
47
48 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
clang::tidy::GlobList
Read-only set of strings represented as a list of positive and negative globs.
Definition: ClangTidyDiagnosticConsumer.h:54
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:111
clang::tidy::GlobList::contains
bool contains(StringRef S)
Returns true if the pattern matches S.
Definition: ClangTidyDiagnosticConsumer.h:62
clang::tidy::fuchsia::RestrictSystemIncludesCheck
Checks for allowed includes and suggests removal of any others.
Definition: RestrictSystemIncludesCheck.h:26
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::fuchsia::RestrictSystemIncludesCheck::RestrictSystemIncludesCheck
RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context)
Definition: RestrictSystemIncludesCheck.h:28
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidy.h:183
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:98
FileName
PathRef FileName
Definition: CodeComplete.cpp:1004
clang::tidy::fuchsia::RestrictSystemIncludesCheck::contains
bool contains(StringRef FileName)
Definition: RestrictSystemIncludesCheck.h:35
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::tidy::fuchsia::RestrictSystemIncludesCheck::registerPPCallbacks
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
Definition: RestrictSystemIncludesCheck.cpp:104
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:100