Debian Codegraph @

src/checks/manuallevel/tr-non-literal.cpp

raw
1 /*
2 SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company [email protected]
3 SPDX-FileContributor: Sérgio Martins <[email protected]>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8 #include "tr-non-literal.h"
9 #include "HierarchyUtils.h"
10
11 #include <clang/AST/Decl.h>
12 #include <clang/AST/Expr.h>
13 #include <clang/AST/Stmt.h>
14 #include <clang/Basic/LLVM.h>
15 #include <llvm/Support/Casting.h>
16
17 using namespace clang;
18
19 void TrNonLiteral::VisitStmt(clang::Stmt *stmt)
20 {
21 auto *callExpr = dyn_cast<CallExpr>(stmt);
22 if (!callExpr || callExpr->getNumArgs() <= 0) {
23 return;
24 }
25
26 FunctionDecl *func = callExpr->getDirectCallee();
27 if (!func || func->getQualifiedNameAsString() != qtNamespaced("QObject::tr")) {
28 return;
29 }
30
31 Expr *arg1 = callExpr->getArg(0);
32 if (clazy::getFirstChildOfType2<StringLiteral>(arg1) == nullptr) {
33 emitWarning(stmt, "tr() without a literal string");
34 }
35 }