Debian Codegraph @

src/checks/manuallevel/qproperty-type-mismatch.h

raw
1 /*
2 SPDX-FileCopyrightText: 2019 Jean-Michaël Celerier <[email protected]>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #ifndef CLAZY_QPROPERTY_TYPE_MISMATCH_H
8 #define CLAZY_QPROPERTY_TYPE_MISMATCH_H
9
10 #include "checkbase.h"
11
12 #include <clang/Basic/SourceLocation.h>
13
14 #include <string>
15 #include <unordered_map>
16 #include <vector>
17
18 namespace clang
19 {
20 class CXXMethodDecl;
21 class FieldDecl;
22 class MacroInfo;
23 class Token;
24 class TypeAliasDecl;
25 } // namespace clang
26
27 /**
28 * See README-qproperty-type-mismatch.md for more info.
29 */
30 class QPropertyTypeMismatch : public CheckBase
31 {
32 public:
33 using CheckBase::CheckBase;
34 void VisitDecl(clang::Decl *) override;
35
36 private:
37 void VisitMethod(const clang::CXXMethodDecl &);
38 void VisitField(const clang::FieldDecl &);
39 void VisitTypedef(const clang::TypedefNameDecl *);
40
41 void VisitMacroExpands(const clang::Token &MacroNameTok, const clang::SourceRange &range, const clang::MacroInfo *minfo = nullptr) override;
42
43 struct Property {
44 clang::SourceLocation loc;
45 bool member{};
46 std::string name;
47 std::string type;
48 std::string read;
49 std::string write;
50 std::string notify;
51 };
52
53 std::vector<Property> m_qproperties;
54 std::string cleanupType(clang::QualType type, bool unscoped = false) const;
55 void checkMethodAgainstProperty(const Property &prop, const clang::CXXMethodDecl &method, const std::string &methodName);
56 void checkFieldAgainstProperty(const Property &prop, const clang::FieldDecl &method, const std::string &methodName);
57
58 bool typesMatch(const std::string &type1, clang::QualType type2Qt, std::string &type2Cleaned) const;
59 std::unordered_map<std::string, clang::QualType> m_typedefMap;
60 };
61
62 #endif