Debian Codegraph @

src/checks/manuallevel/reserve-candidates.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 CLAZY_RESERVE_CANDIDATES
11 #define CLAZY_RESERVE_CANDIDATES
12
13 #include "checkbase.h"
14
15 #include <vector>
16
17 namespace clang
18 {
19 class ValueDecl;
20 class Expr;
21 class CallExpr;
22 class SourceLocation;
23 }
24
25 /**
26 * Recommends places that are missing QList::reserve() or QVector::reserve().
27 *
28 * Only local variables are contemplated, containers that are members of a class are ignored due to
29 * high false-positive rate.
30 *
31 * There some chance of false-positives.
32 */
33 class ReserveCandidates : public CheckBase
34 {
35 public:
36 using CheckBase::CheckBase;
37 void VisitStmt(clang::Stmt *stm) override;
38
39 private:
40 bool registerReserveStatement(clang::Stmt *stmt);
41 bool containerWasReserved(clang::ValueDecl *) const;
42 bool acceptsValueDecl(clang::ValueDecl *valueDecl) const;
43 bool expressionIsComplex(clang::Expr *) const;
44 bool loopIsComplex(clang::Stmt *, bool &isLoop) const;
45 bool isInComplexLoop(clang::Stmt *, clang::SourceLocation declLocation, bool isMemberVariable) const;
46 bool isReserveCandidate(clang::ValueDecl *valueDecl, clang::Stmt *loopBody, clang::CallExpr *callExpr) const;
47 bool isCandidateMethod(clang::CXXMethodDecl *methodDecl);
48 bool isCandidate(clang::CallExpr *oper);
49
50 std::vector<clang::ValueDecl *> m_foundReserves;
51 };
52
53 #endif