/* SPDX-FileCopyrightText: 2017 Sergio Martins SPDX-License-Identifier: LGPL-2.0-or-later */ #include "install-event-filter.h" #include "HierarchyUtils.h" #include "TypeUtils.h" #include "Utils.h" #include #include #include #include #include #include #include using namespace clang; void InstallEventFilter::VisitStmt(clang::Stmt *stmt) { auto *memberCallExpr = dyn_cast(stmt); if (!memberCallExpr || memberCallExpr->getNumArgs() != 1) { return; } FunctionDecl *func = memberCallExpr->getDirectCallee(); if (!func || func->getQualifiedNameAsString() != qtNamespaced("QObject::installEventFilter")) { return; } Expr *expr = memberCallExpr->getImplicitObjectArgument(); if (!expr) { return; } if (Stmt *firstChild = clazy::getFirstChildAtDepth(expr, 1); !firstChild || !isa(firstChild)) { return; } Expr *arg1 = memberCallExpr->getArg(0); arg1 = arg1 ? arg1->IgnoreCasts() : nullptr; const CXXRecordDecl *record = clazy::typeAsRecord(arg1); auto methods = Utils::methodsFromString(record, "eventFilter"); for (auto *method : methods) { if (method->getQualifiedNameAsString() != qtNamespaced("QObject::eventFilter")) { // It overrides it, probably on purpose then, don't warn. return; } } emitWarning(stmt, "'this' should usually be the filter object, not the monitored one."); }