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

0001 /*
0002     SPDX-FileCopyrightText: 2015 Sergio Martins <smartins@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef QSTRING_REF_H
0008 #define QSTRING_REF_H
0009 
0010 #include "checkbase.h"
0011 
0012 #include <string>
0013 #include <vector>
0014 
0015 class ClazyContext;
0016 
0017 namespace clang
0018 {
0019 class Stmt;
0020 class CallExpr;
0021 class CXXMemberCallExpr;
0022 class FixItHint;
0023 }
0024 
0025 /**
0026  * Finds places where the QString::fooRef() should be used instead QString::foo(), to save allocations
0027  *
0028  * See README-qstringref for more info.
0029  */
0030 class StringRefCandidates : public CheckBase
0031 {
0032 public:
0033     StringRefCandidates(const std::string &name, ClazyContext *context);
0034     void VisitStmt(clang::Stmt *stmt) override;
0035 
0036 private:
0037     bool processCase1(clang::CXXMemberCallExpr *);
0038     bool processCase2(clang::CallExpr *call);
0039     bool isConvertedToSomethingElse(clang::Stmt *s) const;
0040 
0041     std::vector<clang::CallExpr *> m_alreadyProcessedChainedCalls;
0042     std::vector<clang::FixItHint> fixit(clang::CXXMemberCallExpr *);
0043 };
0044 
0045 #endif