| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2019 Sergio Martins <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "signal-with-return-value.h" |
| 8 |
#include "AccessSpecifierManager.h" |
| 9 |
#include "ClazyContext.h" |
| 10 |
#include "QtUtils.h" |
| 11 |
#include "TypeUtils.h" |
| 12 |
#include "Utils.h" |
| 13 |
|
| 14 |
#include <clang/AST/AST.h> |
| 15 |
|
| 16 |
using namespace clang; |
| 17 |
|
| 18 |
void SignalWithReturnValue::VisitDecl(clang::Decl *decl) |
| 19 |
{ |
| 20 |
const AccessSpecifierManager *accessSpecifierManager = m_context->accessSpecifierManager; |
| 21 |
auto *method = dyn_cast<CXXMethodDecl>(decl); |
| 22 |
if (!accessSpecifierManager || !method) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
if (method->isThisDeclarationADefinition() && !method->hasInlineBody()) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
const bool methodIsSignal = accessSpecifierManager->qtAccessSpecifierType(method) == QtAccessSpecifier_Signal; |
| 31 |
if (!methodIsSignal || accessSpecifierManager->isScriptable(method)) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
if (!method->getReturnType()->isVoidType()) { |
| 36 |
emitWarning(decl, |
| 37 |
std::string(clazy::name(method)) |
| 38 |
+ "() should return void. For a clean design signals shouldn't assume a single slot are connected to them."); |
| 39 |
} |
| 40 |
|
| 41 |
for (auto *param : method->parameters()) { |
| 42 |
QualType qt = param->getType(); |
| 43 |
if (qt->isReferenceType() && !qt->getPointeeType().isConstQualified()) { |
| 44 |
emitWarning(decl, |
| 45 |
std::string(clazy::name(method)) |
| 46 |
+ "() shouldn't receive parameters by ref. For a clean design signals shouldn't assume a single slot are connected to them."); |
| 47 |
} |
| 48 |
} |
| 49 |
} |