150
|
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
|