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

0001 /*
0002     SPDX-FileCopyrightText: 2020 The Qt Company Ltd.
0003     SPDX-FileCopyrightText: 2020 Lucie Gerard <lucie.gerard@qt.io>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef CLAZY_QT6_QLATINSTRINGCHAR_TO_U_H
0009 #define CLAZY_QT6_QLATINSTRINGCHAR_TO_U_H
0010 
0011 #include "checkbase.h"
0012 
0013 #include <string>
0014 #include <vector>
0015 
0016 class ClazyContext;
0017 
0018 namespace clang
0019 {
0020 class Stmt;
0021 class FixItHint;
0022 class CXXConstructExpr;
0023 class CXXOperatorCallExpr;
0024 class Expr;
0025 class CXXMemberCallExpr;
0026 
0027 class CXXFunctionalCastExpr;
0028 }
0029 
0030 /**
0031  * Replaces QLatin1String( ) calls with u""
0032  * Replaces QLatin1Char( ) calls with u''.
0033  *
0034  */
0035 class Qt6QLatin1StringCharToU : public CheckBase
0036 {
0037 public:
0038     explicit Qt6QLatin1StringCharToU(const std::string &name, ClazyContext *context);
0039     void VisitStmt(clang::Stmt *stmt) override;
0040     void VisitMacroExpands(const clang::Token &MacroNameTok, const clang::SourceRange &range, const clang::MacroInfo *minfo = nullptr) override;
0041 
0042 private:
0043     std::vector<clang::SourceLocation> m_listingMacroExpand;
0044     std::vector<clang::SourceLocation> m_emittedWarningsInMacro;
0045     bool warningAlreadyEmitted(clang::SourceLocation sploc);
0046     bool checkCTorExpr(clang::Stmt *stmt, bool check_parents);
0047     void lookForLeftOver(clang::Stmt *stmt, bool found_QString_QChar = false);
0048     std::string buildReplacement(clang::Stmt *stmt, bool &noFix, bool extra = false, bool ancestorIsCondition = false, int ancestorConditionChildNumber = 0);
0049 
0050     bool isInterestingCtorCall(clang::CXXConstructExpr *ctorExpr, const ClazyContext *const context, bool check_parent = true);
0051     bool relatedToQStringOrQChar(clang::Stmt *stmt, const ClazyContext *const context);
0052     bool foundQCharOrQString(clang::Stmt *stmt);
0053 
0054     bool m_QStringOrQChar_fix = false;
0055     bool m_QChar = false;
0056     bool m_QChar_noFix = false;
0057 };
0058 
0059 #endif