File indexing completed on 2024-04-28 05:38:31
0001 /* 0002 SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB a KDAB Group company info@kdab.com 0003 SPDX-FileContributor: SĂ©rgio Martins <sergio.martins@kdab.com> 0004 0005 SPDX-FileCopyrightText: 2015 Sergio Martins <smartins@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef OLD_STYLE_CONNECT_H 0011 #define OLD_STYLE_CONNECT_H 0012 0013 #include "checkbase.h" 0014 0015 #include <clang/Basic/SourceLocation.h> 0016 0017 #include <string> 0018 #include <vector> 0019 0020 class ClazyContext; 0021 0022 namespace clang 0023 { 0024 class CallExpr; 0025 class CXXMemberCallExpr; 0026 class Expr; 0027 class FixItHint; 0028 class FunctionDecl; 0029 class MacroInfo; 0030 class Stmt; 0031 class Token; 0032 } 0033 0034 struct PrivateSlot { 0035 using List = std::vector<PrivateSlot>; 0036 std::string objName; 0037 std::string name; 0038 }; 0039 0040 /** 0041 * Finds usages of old-style Qt connect statements. 0042 * 0043 * See README-old-style-connect for more information. 0044 */ 0045 class OldStyleConnect : public CheckBase 0046 { 0047 public: 0048 OldStyleConnect(const std::string &name, ClazyContext *context); 0049 void VisitStmt(clang::Stmt *) override; 0050 void addPrivateSlot(const PrivateSlot &); 0051 0052 protected: 0053 void VisitMacroExpands(const clang::Token ¯oNameTok, const clang::SourceRange &, const clang::MacroInfo *minfo = nullptr) override; 0054 0055 private: 0056 std::string signalOrSlotNameFromMacro(clang::SourceLocation macroLoc); 0057 0058 template<typename T> 0059 std::vector<clang::FixItHint> fixits(int classification, T *callOrCtor); 0060 0061 bool isSignalOrSlot(clang::SourceLocation loc, std::string ¯oName) const; 0062 0063 template<typename T> 0064 int classifyConnect(clang::FunctionDecl *connectFunc, T *connectCall) const; 0065 0066 bool isQPointer(clang::Expr *expr) const; 0067 bool isPrivateSlot(const std::string &name) const; 0068 PrivateSlot::List m_privateSlots; 0069 }; 0070 0071 #endif