Debian Codegraph @

src/checks/level2/function-args-by-ref.h

raw
1 /*
2 SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB a KDAB Group company [email protected]
3 SPDX-FileContributor: Sérgio Martins <[email protected]>
4
5 SPDX-FileCopyrightText: 2015 Sergio Martins <[email protected]>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9
10 #ifndef FUNCTION_ARGS_BY_REF_H
11 #define FUNCTION_ARGS_BY_REF_H
12
13 #include "checkbase.h"
14
15 namespace clang
16 {
17 class VarDecl;
18 class FixItHint;
19 class ParmVarDecl;
20 class FunctionDecl;
21 }
22
23 namespace clazy
24 {
25 struct QualTypeClassification;
26 }
27
28 /**
29 * Finds functions where big non-trivial types are passed by value instead of const-ref.
30 * Looks into the body of the functions to see if the argument are read-only, it doesn't emit a warning otherwise.
31 */
32 class FunctionArgsByRef : public CheckBase
33 {
34 public:
35 using CheckBase::CheckBase;
36 void VisitDecl(clang::Decl *decl) override;
37 void VisitStmt(clang::Stmt *stmt) override;
38
39 private:
40 bool shouldIgnoreClass(clang::CXXRecordDecl *);
41 static bool shouldIgnoreOperator(clang::FunctionDecl *);
42 static bool shouldIgnoreFunction(clang::FunctionDecl *);
43 void processFunction(clang::FunctionDecl *);
44 void addFixits(std::vector<clang::FixItHint> &fixits, clang::FunctionDecl *, unsigned int parmIndex);
45 };
46
47 #endif