/* SPDX-FileCopyrightText: 2016 Sergio Martins SPDX-License-Identifier: LGPL-2.0-or-later */ #include "child-event-qobject-cast.h" #include "HierarchyUtils.h" #include "QtUtils.h" #include "StringUtils.h" #include "clazy_stl.h" #include #include #include #include #include #include #include #include #include #include using namespace clang; void ChildEventQObjectCast::VisitDecl(Decl *decl) { auto *childEventMethod = dyn_cast(decl); if (!childEventMethod) { return; } Stmt *body = decl->getBody(); if (!body) { return; } auto methodName = childEventMethod->getNameAsString(); if (!clazy::equalsAny(methodName, {"event", "childEvent", "eventFilter"})) { return; } if (!clazy::isQObject(childEventMethod->getParent(), m_context->qtNamespace())) { return; } auto callExprs = clazy::getStatements(body, &(sm())); for (auto *callExpr : callExprs) { if (callExpr->getNumArgs() != 1) { continue; } const FunctionDecl *fdecl = callExpr->getDirectCallee(); if (fdecl && clazy::name(fdecl) == "qobject_cast") { auto *childCall = dyn_cast(callExpr->getArg(0)); // The call to event->child() if (!childCall) { continue; } auto *childFDecl = childCall->getDirectCallee(); if (!childFDecl || childFDecl->getQualifiedNameAsString() != qtNamespaced("QChildEvent::child")) { continue; } emitWarning(childCall, "qobject_cast in childEvent"); } } }