File indexing completed on 2024-04-28 05:38:28
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 FOREACH_DETACHMENTS_H 0011 #define FOREACH_DETACHMENTS_H 0012 0013 #include "checkbase.h" 0014 0015 #include <string> 0016 0017 class ClazyContext; 0018 0019 namespace clang 0020 { 0021 class ForStmt; 0022 class ValueDecl; 0023 class Stmt; 0024 class CXXForRangeStmt; 0025 } 0026 0027 /** 0028 * - Foreach: 0029 * - Finds places where you're detaching the foreach container. 0030 * - Finds places where big or non-trivial types are passed by value instead of const-ref. 0031 * - Finds places where you're using foreach on STL containers. It causes deep-copy. 0032 * - For Range Loops: 0033 * - Finds places where you're using C++11 for range loops with Qt containers. (potential detach) 0034 */ 0035 class Foreach : public CheckBase 0036 { 0037 public: 0038 Foreach(const std::string &name, ClazyContext *context); 0039 void VisitStmt(clang::Stmt *stmt) override; 0040 0041 private: 0042 void checkBigTypeMissingRef(); 0043 bool containsDetachments(clang::Stmt *stmt, clang::ValueDecl *containerValueDecl); 0044 clang::ForStmt *m_lastForStmt = nullptr; 0045 }; 0046 0047 #endif