Debian Codegraph @

src/checks/level0/lowercase-qml-type-name.cpp

raw
1 /*
2 SPDX-FileCopyrightText: 2018 Sergio Martins <[email protected]>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #include "lowercase-qml-type-name.h"
8 #include "HierarchyUtils.h"
9 #include "QtUtils.h"
10 #include "TypeUtils.h"
11 #include "Utils.h"
12
13 #include <cctype>
14 #include <clang/AST/AST.h>
15
16 using namespace clang;
17
18 void LowercaseQMlTypeName::VisitStmt(clang::Stmt *stmt)
19 {
20 auto *callExpr = dyn_cast<CallExpr>(stmt);
21 if (!callExpr) {
22 return;
23 }
24
25 const FunctionDecl *func = callExpr->getDirectCallee();
26 if (!func) {
27 return;
28 }
29
30 StringRef name = clazy::name(func);
31
32 Expr *arg = nullptr;
33
34 if (name == "qmlRegisterType" || name == "qmlRegisterUncreatableType") {
35 arg = callExpr->getNumArgs() <= 3 ? nullptr : callExpr->getArg(3);
36 }
37
38 if (!arg) {
39 return;
40 }
41
42 auto *literal = clazy::getFirstChildOfType2<StringLiteral>(arg);
43 if (!literal) {
44 return;
45 }
46
47 StringRef str = literal->getString();
48
49 if (str.empty() || !isupper(str[0])) {
50 emitWarning(arg, "QML types must begin with uppercase");
51 }
52 }