| 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 "qlatin1string-non-ascii.h" |
| 9 |
#include "HierarchyUtils.h" |
| 10 |
#include "Utils.h" |
| 11 |
|
| 12 |
#include <clang/AST/DeclCXX.h> |
| 13 |
#include <clang/AST/Expr.h> |
| 14 |
#include <clang/AST/ExprCXX.h> |
| 15 |
#include <clang/AST/Stmt.h> |
| 16 |
#include <clang/Basic/LLVM.h> |
| 17 |
#include <llvm/Support/Casting.h> |
| 18 |
|
| 19 |
using namespace clang; |
| 20 |
|
| 21 |
void QLatin1StringNonAscii::VisitStmt(clang::Stmt *stmt) |
| 22 |
{ |
| 23 |
auto *constructExpr = dyn_cast<CXXConstructExpr>(stmt); |
| 24 |
CXXConstructorDecl *ctor = constructExpr ? constructExpr->getConstructor() : nullptr; |
| 25 |
|
| 26 |
if (!ctor || ctor->getQualifiedNameAsString() != qtNamespaced("QLatin1String::QLatin1String")) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
auto *lt = clazy::getFirstChildOfType2<StringLiteral>(stmt); |
| 31 |
if (lt && !Utils::isAscii(lt)) { |
| 32 |
emitWarning(stmt, "QLatin1String with non-ascii literal"); |
| 33 |
} |
| 34 |
} |