File indexing completed on 2024-05-12 05:40:56
0001 /* 0002 SPDX-FileCopyrightText: 2018 Sergio Martins <smartins@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "lowercase-qml-type-name.h" 0008 #include "HierarchyUtils.h" 0009 #include "QtUtils.h" 0010 #include "TypeUtils.h" 0011 #include "Utils.h" 0012 0013 #include <cctype> 0014 #include <clang/AST/AST.h> 0015 0016 using namespace clang; 0017 0018 LowercaseQMlTypeName::LowercaseQMlTypeName(const std::string &name, ClazyContext *context) 0019 : CheckBase(name, context) 0020 { 0021 } 0022 0023 void LowercaseQMlTypeName::VisitStmt(clang::Stmt *stmt) 0024 { 0025 auto *callExpr = dyn_cast<CallExpr>(stmt); 0026 if (!callExpr) { 0027 return; 0028 } 0029 0030 FunctionDecl *func = callExpr->getDirectCallee(); 0031 if (!func) { 0032 return; 0033 } 0034 0035 StringRef name = clazy::name(func); 0036 0037 Expr *arg = nullptr; 0038 0039 if (name == "qmlRegisterType" || name == "qmlRegisterUncreatableType") { 0040 arg = callExpr->getNumArgs() <= 3 ? nullptr : callExpr->getArg(3); 0041 } 0042 0043 if (!arg) { 0044 return; 0045 } 0046 0047 auto *literal = clazy::getFirstChildOfType2<StringLiteral>(arg); 0048 if (!literal) { 0049 return; 0050 } 0051 0052 StringRef str = literal->getString(); 0053 0054 if (str.empty() || !isupper(str[0])) { 0055 emitWarning(arg, "QML types must begin with uppercase"); 0056 } 0057 }