Debian Codegraph @

src/LoopUtils.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_LOOP_UTILS_H
11 #define CLAZY_LOOP_UTILS_H
12
13 #include <clang/AST/Stmt.h>
14 #include <clang/AST/StmtCXX.h>
15 #include <llvm/Support/Casting.h>
16
17 namespace clang
18 {
19 class Stmt;
20 class SourceManager;
21 class SourceLocation;
22 class Expr;
23 class ParentMap;
24 class VarDecl;
25 }
26
27 namespace clazy
28 {
29 /**
30 * Returns the body of a for, range-foor, while or do-while loop
31 */
32 clang::Stmt *bodyFromLoop(clang::Stmt *);
33
34 /**
35 * Recursively goes through stmt's children and returns true if it finds a "break", "continue" or a "return" stmt
36 * All child statements that are on a source code line <
37 * If onlyBeforThisLoc is valid, then this function will only return true if the break/return/continue happens before
38 */
39 bool loopCanBeInterrupted(clang::Stmt *loop, const clang::SourceManager &sm, clang::SourceLocation onlyBeforeThisLoc);
40
41 /**
42 * Returns true if stmt is a for, while or do-while loop
43 */
44 inline bool isLoop(clang::Stmt *stmt)
45 {
46 return llvm::isa<clang::DoStmt>(stmt) || llvm::isa<clang::WhileStmt>(stmt) || llvm::isa<clang::ForStmt>(stmt) || llvm::isa<clang::CXXForRangeStmt>(stmt);
47 }
48
49 /**
50 * Returns the container expression for a range-loop or Q_FOREACH
51 *
52 * Q_FOREACH (auto f, expression) or for (auto i : expression)
53 */
54 clang::Expr *containerExprForLoop(clang::Stmt *loop, const std::string &qtNamespace);
55
56 /**
57 * Returns the container decl for a range-loop or Q_FOREACH
58 *
59 * Q_FOREACH (auto f, container) or for (auto i : container)
60 */
61 clang::VarDecl *containerDeclForLoop(clang::Stmt *loop, const std::string &qtNamespace);
62
63 /**
64 * Returns true of stmt is inside a for, while or do-while loop.
65 * If yes, returns the loop statement, otherwise nullptr.
66 */
67 clang::Stmt *isInLoop(clang::ParentMap *pmap, clang::Stmt *stmt);
68 }
69
70 #endif