| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB a KDAB Group company [email protected] |
| 3 |
SPDX-FileContributor: Sérgio Martins <[email protected]> |
| 4 |
|
| 5 |
SPDX-FileCopyrightText: 2015 Sergio Martins <[email protected]> |
| 6 |
|
| 7 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 8 |
*/ |
| 9 |
|
| 10 |
#ifndef OLD_STYLE_CONNECT_H |
| 11 |
#define OLD_STYLE_CONNECT_H |
| 12 |
|
| 13 |
#include "checkbase.h" |
| 14 |
|
| 15 |
#include <clang/Basic/SourceLocation.h> |
| 16 |
|
| 17 |
#include <string> |
| 18 |
#include <vector> |
| 19 |
|
| 20 |
namespace clang |
| 21 |
{ |
| 22 |
class FixItHint; |
| 23 |
class FunctionDecl; |
| 24 |
class MacroInfo; |
| 25 |
class Token; |
| 26 |
} |
| 27 |
|
| 28 |
struct PrivateSlot { |
| 29 |
using List = std::vector<PrivateSlot>; |
| 30 |
std::string objName; |
| 31 |
std::string name; |
| 32 |
}; |
| 33 |
|
| 34 |
/** |
| 35 |
* Finds usages of old-style Qt connect statements. |
| 36 |
* |
| 37 |
* See README-old-style-connect for more information. |
| 38 |
*/ |
| 39 |
class OldStyleConnect : public CheckBase |
| 40 |
{ |
| 41 |
public: |
| 42 |
using CheckBase::CheckBase; |
| 43 |
void VisitStmt(clang::Stmt *) override; |
| 44 |
void addPrivateSlot(const PrivateSlot &); |
| 45 |
|
| 46 |
protected: |
| 47 |
void VisitMacroExpands(const clang::Token ¯oNameTok, const clang::SourceRange &, const clang::MacroInfo *minfo = nullptr) override; |
| 48 |
|
| 49 |
private: |
| 50 |
std::string signalOrSlotNameFromMacro(clang::SourceLocation macroLoc); |
| 51 |
|
| 52 |
template<typename T> |
| 53 |
std::vector<clang::FixItHint> fixits(int classification, T *callOrCtor); |
| 54 |
|
| 55 |
bool isSignalOrSlot(clang::SourceLocation loc, std::string ¯oName) const; |
| 56 |
|
| 57 |
template<typename T> |
| 58 |
int classifyConnect(clang::FunctionDecl *connectFunc, T *connectCall) const; |
| 59 |
|
| 60 |
bool isQPointer(clang::Expr *expr) const; |
| 61 |
bool isPrivateSlot(const std::string &name) const; |
| 62 |
PrivateSlot::List m_privateSlots; |
| 63 |
}; |
| 64 |
|
| 65 |
#endif |