File indexing completed on 2024-05-12 17:13:15

0001 /*
0002     This file is part of the clazy static checker.
0003 
0004     Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
0005     Author: SĂ©rgio Martins <sergio.martins@kdab.com>
0006 
0007     Copyright (C) 2015 Sergio Martins <smartins@kde.org>
0008 
0009     This library is free software; you can redistribute it and/or
0010     modify it under the terms of the GNU Library General Public
0011     License as published by the Free Software Foundation; either
0012     version 2 of the License, or (at your option) any later version.
0013 
0014     This library is distributed in the hope that it will be useful,
0015     but WITHOUT ANY WARRANTY; without even the implied warranty of
0016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017     Library General Public License for more details.
0018 
0019     You should have received a copy of the GNU Library General Public License
0020     along with this library; see the file COPYING.LIB.  If not, write to
0021     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0022     Boston, MA 02110-1301, USA.
0023 */
0024 
0025 #ifndef OLD_STYLE_CONNECT_H
0026 #define OLD_STYLE_CONNECT_H
0027 
0028 #include "checkbase.h"
0029 
0030 #include <clang/Basic/SourceLocation.h>
0031 
0032 #include <string>
0033 #include <vector>
0034 
0035 class ClazyContext;
0036 
0037 namespace clang {
0038 class CallExpr;
0039 class CXXMemberCallExpr;
0040 class Expr;
0041 class FixItHint;
0042 class FunctionDecl;
0043 class MacroInfo;
0044 class Stmt;
0045 class Token;
0046 }
0047 
0048 struct PrivateSlot
0049 {
0050     typedef std::vector<PrivateSlot> List;
0051     std::string objName;
0052     std::string name;
0053 };
0054 
0055 /**
0056  * Finds usages of old-style Qt connect statements.
0057  *
0058  * See README-old-style-connect for more information.
0059  */
0060 class OldStyleConnect
0061     : public CheckBase
0062 {
0063 public:
0064     OldStyleConnect(const std::string &name, ClazyContext *context);
0065     void VisitStmt(clang::Stmt *) override;
0066     void addPrivateSlot(const PrivateSlot &);
0067 protected:
0068     void VisitMacroExpands(const clang::Token &macroNameTok, const clang::SourceRange &, const clang::MacroInfo *minfo = nullptr) override;
0069 private:
0070     std::string signalOrSlotNameFromMacro(clang::SourceLocation macroLoc);
0071 
0072     template <typename T>
0073     std::vector<clang::FixItHint> fixits(int classification, T *callOrCtor);
0074 
0075     bool isSignalOrSlot(clang::SourceLocation loc, std::string &macroName) const;
0076 
0077     template <typename T>
0078     int classifyConnect(clang::FunctionDecl *connectFunc, T *connectCall) const;
0079 
0080     bool isQPointer(clang::Expr *expr) const;
0081     bool isPrivateSlot(const std::string &name) const;
0082     PrivateSlot::List m_privateSlots;
0083 };
0084 
0085 #endif