File indexing completed on 2024-05-12 05:41:03
0001 /* 0002 SPDX-FileCopyrightText: 2019 Sergio Martins <smartins@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "signal-with-return-value.h" 0008 #include "AccessSpecifierManager.h" 0009 #include "ClazyContext.h" 0010 #include "HierarchyUtils.h" 0011 #include "QtUtils.h" 0012 #include "TypeUtils.h" 0013 #include "Utils.h" 0014 0015 #include <clang/AST/AST.h> 0016 0017 using namespace clang; 0018 0019 SignalWithReturnValue::SignalWithReturnValue(const std::string &name, ClazyContext *context) 0020 : CheckBase(name, context) 0021 { 0022 context->enableAccessSpecifierManager(); 0023 } 0024 0025 void SignalWithReturnValue::VisitDecl(clang::Decl *decl) 0026 { 0027 AccessSpecifierManager *accessSpecifierManager = m_context->accessSpecifierManager; 0028 auto *method = dyn_cast<CXXMethodDecl>(decl); 0029 if (!accessSpecifierManager || !method) { 0030 return; 0031 } 0032 0033 if (method->isThisDeclarationADefinition() && !method->hasInlineBody()) { 0034 return; 0035 } 0036 0037 const bool methodIsSignal = accessSpecifierManager->qtAccessSpecifierType(method) == QtAccessSpecifier_Signal; 0038 if (!methodIsSignal || accessSpecifierManager->isScriptable(method)) { 0039 return; 0040 } 0041 0042 if (!method->getReturnType()->isVoidType()) { 0043 emitWarning(decl, 0044 std::string(clazy::name(method)) 0045 + "() should return void. For a clean design signals shouldn't assume a single slot are connected to them."); 0046 } 0047 0048 for (auto *param : method->parameters()) { 0049 QualType qt = param->getType(); 0050 if (qt->isReferenceType() && !qt->getPointeeType().isConstQualified()) { 0051 emitWarning(decl, 0052 std::string(clazy::name(method)) 0053 + "() shouldn't receive parameters by ref. For a clean design signals shouldn't assume a single slot are connected to them."); 0054 } 0055 } 0056 }