Debian Codegraph @

src/checks/level0/connect-by-name.cpp

raw
1 /*
2 SPDX-FileCopyrightText: 2017 Sergio Martins <[email protected]>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #include "connect-by-name.h"
8 #include "AccessSpecifierManager.h"
9 #include "ClazyContext.h"
10 #include "clazy_stl.h"
11
12 #include <clang/AST/DeclCXX.h>
13 #include <clang/Basic/LLVM.h>
14 #include <llvm/Support/Casting.h>
15
16 #include <vector>
17
18 using namespace clang;
19
20 void ConnectByName::VisitDecl(clang::Decl *decl)
21 {
22 auto *record = dyn_cast<CXXRecordDecl>(decl);
23 if (!record) {
24 return;
25 }
26
27 const AccessSpecifierManager *accessSpecifierManager = m_context->accessSpecifierManager;
28 if (!accessSpecifierManager) {
29 return;
30 }
31
32 for (auto *method : record->methods()) {
33 std::string name = method->getNameAsString();
34 if (clazy::startsWith(name, "on_")) {
35 QtAccessSpecifierType qst = accessSpecifierManager->qtAccessSpecifierType(method);
36 if (qst == QtAccessSpecifier_Slot) {
37 auto tokens = clazy::splitString(name, '_');
38 if (tokens.size() == 3) {
39 emitWarning(method, "Slots named on_foo_bar are error prone");
40 }
41 }
42 }
43 }
44 }