/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/CurrentSourceLocExprScope.h
Line | Count | Source |
1 | | //===--- CurrentSourceLocExprScope.h ----------------------------*- C++ -*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file defines types used to track the current context needed to evaluate |
11 | | // a SourceLocExpr. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #ifndef LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H |
16 | | #define LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H |
17 | | |
18 | | #include <cassert> |
19 | | |
20 | | namespace clang { |
21 | | class Expr; |
22 | | |
23 | | /// Represents the current source location and context used to determine the |
24 | | /// value of the source location builtins (ex. __builtin_LINE), including the |
25 | | /// context of default argument and default initializer expressions. |
26 | | class CurrentSourceLocExprScope { |
27 | | /// The CXXDefaultArgExpr or CXXDefaultInitExpr we're currently evaluating. |
28 | | const Expr *DefaultExpr = nullptr; |
29 | | |
30 | | public: |
31 | | /// A RAII style scope guard used for tracking the current source |
32 | | /// location and context as used by the source location builtins |
33 | | /// (ex. __builtin_LINE). |
34 | | class SourceLocExprScopeGuard; |
35 | | |
36 | 14.9k | const Expr *getDefaultExpr() const { return DefaultExpr; } |
37 | | |
38 | 20.4M | explicit CurrentSourceLocExprScope() = default; |
39 | | |
40 | | private: |
41 | | explicit CurrentSourceLocExprScope(const Expr *DefaultExpr) |
42 | 14.0k | : DefaultExpr(DefaultExpr) {} |
43 | | |
44 | | CurrentSourceLocExprScope(CurrentSourceLocExprScope const &) = default; |
45 | | CurrentSourceLocExprScope & |
46 | | operator=(CurrentSourceLocExprScope const &) = default; |
47 | | }; |
48 | | |
49 | | class CurrentSourceLocExprScope::SourceLocExprScopeGuard { |
50 | | public: |
51 | | SourceLocExprScopeGuard(const Expr *DefaultExpr, |
52 | | CurrentSourceLocExprScope &Current) |
53 | 14.3k | : Current(Current), OldVal(Current), Enable(false) { |
54 | 14.3k | assert(DefaultExpr && "the new scope should not be empty"); |
55 | 14.3k | if ((Enable = (Current.getDefaultExpr() == nullptr))) |
56 | 14.0k | Current = CurrentSourceLocExprScope(DefaultExpr); |
57 | 14.3k | } |
58 | | |
59 | 14.3k | ~SourceLocExprScopeGuard() { |
60 | 14.3k | if (Enable) |
61 | 14.0k | Current = OldVal; |
62 | 14.3k | } |
63 | | |
64 | | private: |
65 | | SourceLocExprScopeGuard(SourceLocExprScopeGuard const &) = delete; |
66 | | SourceLocExprScopeGuard &operator=(SourceLocExprScopeGuard const &) = delete; |
67 | | |
68 | | CurrentSourceLocExprScope &Current; |
69 | | CurrentSourceLocExprScope OldVal; |
70 | | bool Enable; |
71 | | }; |
72 | | |
73 | | } // end namespace clang |
74 | | |
75 | | #endif // LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H |