Debian Codegraph @

src/StmtBodyRange.h

raw
1 /*
2 Copyright (C) Sérgio Martins <[email protected]>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #ifndef CLAZY_BODYRANGE_H
8 #define CLAZY_BODYRANGE_H
9
10 #include <clang/AST/Stmt.h>
11 #include <clang/Basic/SourceLocation.h>
12 #include <clang/Basic/SourceManager.h>
13
14 struct StmtBodyRange {
15 clang::Stmt *body = nullptr;
16 const clang::SourceManager *const sm = nullptr;
17 const clang::SourceLocation searchUntilLoc; // We don't search after this point
18
19 explicit StmtBodyRange(clang::Stmt *body, const clang::SourceManager *sm = nullptr, clang::SourceLocation searchUntilLoc = {})
20 : body(body)
21 , sm(sm)
22 , searchUntilLoc(searchUntilLoc)
23 {
24 }
25
26 bool isValid() const
27 {
28 return body != nullptr;
29 }
30
31 bool isOutsideRange(clang::Stmt *stmt) const
32 {
33 return isOutsideRange(stmt ? stmt->getBeginLoc() : clang::SourceLocation());
34 }
35
36 bool isOutsideRange(clang::SourceLocation loc) const
37 {
38 if (loc.isInvalid()) {
39 return true;
40 }
41
42 if (!sm || searchUntilLoc.isInvalid()) {
43 return false;
44 }
45
46 return sm->isBeforeInSLocAddrSpace(searchUntilLoc, loc);
47 }
48 };
49
50 #endif