File indexing completed on 2024-05-12 17:13:14
0001 /* 0002 This file is part of the clazy static checker. 0003 0004 Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com 0005 Author: Sérgio Martins <sergio.martins@kdab.com> 0006 0007 Copyright (C) 2015 Sergio Martins <smartins@kde.org> 0008 0009 This library is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU Library General Public 0011 License as published by the Free Software Foundation; either 0012 version 2 of the License, or (at your option) any later version. 0013 0014 This library is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Library General Public License for more details. 0018 0019 You should have received a copy of the GNU Library General Public License 0020 along with this library; see the file COPYING.LIB. If not, write to 0021 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0022 Boston, MA 02110-1301, USA. 0023 */ 0024 0025 #ifndef FUNCTION_ARGS_BY_REF_H 0026 #define FUNCTION_ARGS_BY_REF_H 0027 0028 #include "checkbase.h" 0029 0030 #include <string> 0031 0032 class ClazyContext; 0033 0034 namespace clang { 0035 class Decl; 0036 class VarDecl; 0037 class FixItHint; 0038 class ParmVarDecl; 0039 class FunctionDecl; 0040 class Stmt; 0041 } 0042 0043 namespace clazy { 0044 struct QualTypeClassification; 0045 } 0046 0047 /** 0048 * Finds functions where big non-trivial types are passed by value instead of const-ref. 0049 * Looks into the body of the functions to see if the argument are read-only, it doesn't emit a warning otherwise. 0050 */ 0051 class FunctionArgsByRef 0052 : public CheckBase 0053 { 0054 public: 0055 FunctionArgsByRef(const std::string &name, ClazyContext *context); 0056 void VisitDecl(clang::Decl *decl) override; 0057 void VisitStmt(clang::Stmt *stmt) override; 0058 private: 0059 static bool shouldIgnoreClass(clang::CXXRecordDecl *); 0060 static bool shouldIgnoreOperator(clang::FunctionDecl *); 0061 static bool shouldIgnoreFunction(clang::FunctionDecl *); 0062 void processFunction(clang::FunctionDecl *); 0063 void addFixits(std::vector<clang::FixItHint> &fixits, clang::FunctionDecl *, unsigned int parmIndex); 0064 clang::FixItHint fixit(const clang::ParmVarDecl *, clazy::QualTypeClassification); 0065 }; 0066 0067 #endif