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

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 FUNCTION_ARGS_BY_REF_H
0011 #define FUNCTION_ARGS_BY_REF_H
0012 
0013 #include "checkbase.h"
0014 
0015 #include <string>
0016 
0017 class ClazyContext;
0018 
0019 namespace clang
0020 {
0021 class Decl;
0022 class VarDecl;
0023 class FixItHint;
0024 class ParmVarDecl;
0025 class FunctionDecl;
0026 class Stmt;
0027 }
0028 
0029 namespace clazy
0030 {
0031 struct QualTypeClassification;
0032 }
0033 
0034 /**
0035  * Finds functions where big non-trivial types are passed by value instead of const-ref.
0036  * Looks into the body of the functions to see if the argument are read-only, it doesn't emit a warning otherwise.
0037  */
0038 class FunctionArgsByRef : public CheckBase
0039 {
0040 public:
0041     FunctionArgsByRef(const std::string &name, ClazyContext *context);
0042     void VisitDecl(clang::Decl *decl) override;
0043     void VisitStmt(clang::Stmt *stmt) override;
0044 
0045 private:
0046     static bool shouldIgnoreClass(clang::CXXRecordDecl *);
0047     static bool shouldIgnoreOperator(clang::FunctionDecl *);
0048     static bool shouldIgnoreFunction(clang::FunctionDecl *);
0049     void processFunction(clang::FunctionDecl *);
0050     void addFixits(std::vector<clang::FixItHint> &fixits, clang::FunctionDecl *, unsigned int parmIndex);
0051     clang::FixItHint fixit(const clang::ParmVarDecl *, clazy::QualTypeClassification);
0052 };
0053 
0054 #endif