-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerlCheck.cpp
140 lines (128 loc) · 5.51 KB
/
PerlCheck.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "PerlLiteralFunctionCheck.h"
#include "PerlUndefSetsvCheck.h"
#include "PerlUndefSetpvXCheck.h"
#include "PerlMortalFunctionCheck.h"
#include "clang-tidy/ClangTidy.h"
#include "clang-tidy/ClangTidyCheck.h"
#include "clang-tidy/ClangTidyModule.h"
#include "clang-tidy/ClangTidyModuleRegistry.h"
using namespace clang;
using namespace clang::tidy;
using namespace clang::ast_matchers;
namespace {
class PerlCheckModule : public ClangTidyModule
{
public:
void addCheckFactories(ClangTidyCheckFactories& CheckFactories) override
{
CheckFactories.registerCheckFactory(
"perl-literal-sv_setpvn",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "sv_setpvn", "sv_setpvs",
1, 2, llvm::SmallVector{ 0, 1 });
});
CheckFactories.registerCheckFactory(
"perl-literal-sv_setpvn_mg",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "sv_setpvn_mg", "sv_setpvs_mg",
1, 2, llvm::SmallVector{ 0, 1 });
});
CheckFactories.registerCheckFactory(
"perl-literal-newSVpvn",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "newSVpvn", "newSVpvs",
0, 1, llvm::SmallVector{ 0 });
});
CheckFactories.registerCheckFactory(
"perl-literal-newSVpvn_flags",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "newSVpvn_flags", "newSVpvs_flags",
0, 1, llvm::SmallVector{ 0, 2 });
});
CheckFactories.registerCheckFactory(
"perl-literal-hv_fetch",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "hv_fetch", "hv_fetchs",
1, 2, llvm::SmallVector{ 0, 1, 3 });
});
CheckFactories.registerCheckFactory(
"perl-literal-sv_catpvn",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "sv_catpvn", "sv_catpvs",
1, 2, llvm::SmallVector{ 0, 1 });
});
CheckFactories.registerCheckFactory(
"perl-literal-sv_catpvn_flags",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "sv_catpvn_flags", "sv_catpvs_flags",
1, 2, llvm::SmallVector{ 0, 1, 3 });
});
CheckFactories.registerCheckFactory(
"perl-literal-sv_catpvn_nomg",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "sv_catpvn_nomg", "sv_catpvs_nomg",
1, 2, llvm::SmallVector{ 0, 1 });
});
CheckFactories.registerCheckFactory(
"perl-literal-savepvn",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "savepvn", "savepvs",
0, 1, llvm::SmallVector{ 0 });
});
CheckFactories.registerCheckFactory(
"perl-literal-get_cvn_flags",
[](llvm::StringRef Name, ClangTidyContext *Context){
return std::make_unique<PerlLiteralFunctionCheck>(
Name, Context, "get_cvn_flags", "get_cvs",
0, 1, llvm::SmallVector{ 0, 2 });
});
CheckFactories.registerCheck<PerlUndefSetsvCheck>("perl-undef-sv_setsv");
CheckFactories.registerCheckFactory(
"perl-undef-sv_setpv",
[](llvm::StringRef Name, ClangTidyContext *Context) {
return std::make_unique<PerlUndefSetpvXCheck>(
Name, Context, "sv_setpv", "Perl_sv_setpv");
});
CheckFactories.registerCheckFactory(
"perl-undef-sv_setpvn",
[](llvm::StringRef Name, ClangTidyContext *Context) {
return std::make_unique<PerlUndefSetpvXCheck>(
Name, Context, "sv_setpvn", "Perl_sv_setpvn");
});
CheckFactories.registerCheckFactory(
"perl-mortal-newSVpvn",
[](llvm::StringRef Name, ClangTidyContext *Context) {
return std::make_unique<PerlMortalFunctionCheck>(
Name, Context, "newSVpvn", "newSVpvn_flags",
-1, llvm::SmallVector{ 0, 1, -1 }, "SVs_TEMP"sv
);
});
#if 1
CheckFactories.registerCheckFactory(
"perl-mortal-newSVsv",
[](llvm::StringRef Name, ClangTidyContext *Context) {
return std::make_unique<PerlMortalFunctionCheck>(
Name, Context, "newSVsv", "sv_mortalcopy",
-1, llvm::SmallVector{ 0 }, ""sv, false
);
});
#endif
}
};
} // namespace
namespace clang::tidy {
// Register the module using this statically initialized variable.
static ClangTidyModuleRegistry::Add<::PerlCheckModule> perlCheckInit(
"perl-check", "Add checks perl source checks.");
// This anchor is used to force the linker to link in the generated object file and thus register the module.
volatile int perlCheckAnchorSource = 0;
} // namespace clang::tidy