File indexing completed on 2024-04-28 05:38:34

0001 /*
0002     SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB a KDAB Group company info@kdab.com
0003     SPDX-FileContributor: SĂ©rgio Martins <sergio.martins@kdab.com>
0004 
0005     SPDX-FileCopyrightText: 2015 Sergio Martins <smartins@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef CLAZY_UNNEEDED_CAST_H
0011 #define CLAZY_UNNEEDED_CAST_H
0012 
0013 #include "checkbase.h"
0014 
0015 #include <string>
0016 
0017 class ClazyContext;
0018 namespace clang
0019 {
0020 class CXXNamedCastExpr;
0021 class CXXRecordDecl;
0022 class Stmt;
0023 } // namespace clang
0024 
0025 namespace
0026 {
0027 class CXXNAmedCastExpr;
0028 }
0029 
0030 /**
0031  * Finds redundant casts.
0032  * See README-unneeded-cast.md for more info.
0033  */
0034 class UnneededCast : public CheckBase
0035 {
0036 public:
0037     UnneededCast(const std::string &name, ClazyContext *context);
0038     void VisitStmt(clang::Stmt *stm) override;
0039 
0040 private:
0041     bool handleNamedCast(clang::CXXNamedCastExpr *);
0042     bool handleQObjectCast(clang::Stmt *);
0043     bool maybeWarn(clang::Stmt *, clang::CXXRecordDecl *from, clang::CXXRecordDecl *to, bool isQObjectCast = false);
0044 };
0045 
0046 #endif