clang-tools  10.0.0git
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
25 public:
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
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Read-only set of strings represented as a list of positive and negative globs.
Definition: GlobList.h:25
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Checks for allowed includes and suggests removal of any others.
Base class for all clang-tidy checks.
RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context)
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
PathRef FileName
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
bool contains(StringRef S)
Returns true if the pattern matches S.
Definition: GlobList.cpp:54
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.