/* SPDX-FileCopyrightText: 2017 Sergio Martins SPDX-License-Identifier: LGPL-2.0-or-later */ #include "lambda-unique-connection.h" #include "HierarchyUtils.h" #include "QtUtils.h" #include #include #include #include #include #include #include #include using namespace clang; void LambdaUniqueConnection::VisitStmt(clang::Stmt *stmt) { auto *call = dyn_cast(stmt); if (!call) { return; } // We want this signature: // connect(const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) FunctionDecl *func = call->getDirectCallee(); if (!func || func->getNumParams() != 5 || !func->isTemplateInstantiation() || !clazy::isConnect(func, m_context->qtNamespace()) || !clazy::connectHasPMFStyle(func)) { return; } Expr *typeArg = call->getArg(4); // The type std::vector result; clazy::getChilds(typeArg, result); bool found = false; for (auto *declRef : result) { if (auto *enumConstant = dyn_cast(declRef->getDecl())) { if (clazy::name(enumConstant) == "UniqueConnection") { found = true; break; } } } if (!found) { return; } FunctionTemplateSpecializationInfo *tsi = func->getTemplateSpecializationInfo(); if (!tsi) { return; } FunctionTemplateDecl *temp = tsi->getTemplate(); const TemplateParameterList *tempParams = temp->getTemplateParameters(); if (tempParams->size() != 2) { return; } const CXXMethodDecl *method = clazy::pmfFromConnect(call, 3, m_context->qtNamespace()); if (method) { // How else to detect if it's the right overload ? It's all templated stuff with the same // names for all the template arguments return; } emitWarning(typeArg, "UniqueConnection is not supported with non-member functions"); }