xref: /llvm-project/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp (revision 41d29b15e89e864719a78ff6cfb994c72d9e569d)
1 //===--- AndroidTidyModule.cpp - clang-tidy--------------------------------===//
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 #include "../ClangTidy.h"
11 #include "../ClangTidyModule.h"
12 #include "../ClangTidyModuleRegistry.h"
13 #include "CloexecAccept4Check.h"
14 #include "CloexecAcceptCheck.h"
15 #include "CloexecCreatCheck.h"
16 #include "CloexecEpollCreate1Check.h"
17 #include "CloexecEpollCreateCheck.h"
18 #include "CloexecDupCheck.h"
19 #include "CloexecFopenCheck.h"
20 #include "CloexecInotifyInit1Check.h"
21 #include "CloexecInotifyInitCheck.h"
22 #include "CloexecMemfdCreateCheck.h"
23 #include "CloexecOpenCheck.h"
24 #include "CloexecSocketCheck.h"
25 
26 using namespace clang::ast_matchers;
27 
28 namespace clang {
29 namespace tidy {
30 namespace android {
31 
32 /// This module is for Android specific checks.
33 class AndroidModule : public ClangTidyModule {
34 public:
35   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
36     CheckFactories.registerCheck<CloexecAccept4Check>("android-cloexec-accept4");
37     CheckFactories.registerCheck<CloexecAcceptCheck>("android-cloexec-accept");
38     CheckFactories.registerCheck<CloexecCreatCheck>("android-cloexec-creat");
39     CheckFactories.registerCheck<CloexecEpollCreate1Check>(
40         "android-cloexec-epoll-create1");
41     CheckFactories.registerCheck<CloexecEpollCreateCheck>(
42         "android-cloexec-epoll-create");
43     CheckFactories.registerCheck<CloexecDupCheck>("android-cloexec-dup");
44     CheckFactories.registerCheck<CloexecFopenCheck>("android-cloexec-fopen");
45     CheckFactories.registerCheck<CloexecInotifyInitCheck>(
46         "android-cloexec-inotify-init");
47     CheckFactories.registerCheck<CloexecInotifyInit1Check>(
48         "android-cloexec-inotify-init1");
49     CheckFactories.registerCheck<CloexecMemfdCreateCheck>(
50         "android-cloexec-memfd-create");
51     CheckFactories.registerCheck<CloexecOpenCheck>("android-cloexec-open");
52     CheckFactories.registerCheck<CloexecSocketCheck>("android-cloexec-socket");
53   }
54 };
55 
56 // Register the AndroidTidyModule using this statically initialized variable.
57 static ClangTidyModuleRegistry::Add<AndroidModule>
58     X("android-module", "Adds Android platform checks.");
59 
60 } // namespace android
61 
62 // This anchor is used to force the linker to link in the generated object file
63 // and thus register the AndroidModule.
64 volatile int AndroidModuleAnchorSource = 0;
65 
66 } // namespace tidy
67 } // namespace clang
68