Debian Codegraph @

src/checks/level1/virtual-signal.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 "virtual-signal.h"
8 #include "AccessSpecifierManager.h"
9 #include "ClazyContext.h"
10 #include "QtUtils.h"
11
12 #include <clang/AST/DeclCXX.h>
13 #include <clang/Basic/LLVM.h>
14 #include <llvm/Support/Casting.h>
15
16 using namespace clang;
17
18 void VirtualSignal::VisitDecl(Decl *stmt)
19 {
20 auto *method = dyn_cast<CXXMethodDecl>(stmt);
21 if (!method || !method->isVirtual()) {
22 return;
23 }
24
25 const AccessSpecifierManager *accessSpecifierManager = m_context->accessSpecifierManager;
26 if (!accessSpecifierManager) {
27 return;
28 }
29
30 QtAccessSpecifierType qst = accessSpecifierManager->qtAccessSpecifierType(method);
31 if (qst == QtAccessSpecifier_Signal) {
32 for (const auto *m : method->overridden_methods()) {
33 if (const auto *baseClass = m->getParent()) {
34 if (!clazy::isQObject(baseClass, m_context->qtNamespace())) {
35 // It's possible that the signal is overriding a method from a non-QObject base class
36 // if the derived class inherits both QObject and some other interface.
37 return;
38 }
39 }
40 }
41
42 emitWarning(method, "signal is virtual");
43 }
44 }