clang  10.0.0svn
CurrentSourceLocExprScope.h
Go to the documentation of this file.
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.
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).
35 
36  const Expr *getDefaultExpr() const { return DefaultExpr; }
37 
38  explicit CurrentSourceLocExprScope() = default;
39 
40 private:
41  explicit CurrentSourceLocExprScope(const Expr *DefaultExpr)
42  : DefaultExpr(DefaultExpr) {}
43 
46  operator=(CurrentSourceLocExprScope const &) = default;
47 };
48 
50 public:
51  SourceLocExprScopeGuard(const Expr *DefaultExpr,
53  : Current(Current), OldVal(Current), Enable(false) {
54  assert(DefaultExpr && "the new scope should not be empty");
55  if ((Enable = (Current.getDefaultExpr() == nullptr)))
56  Current = CurrentSourceLocExprScope(DefaultExpr);
57  }
58 
60  if (Enable)
61  Current = OldVal;
62  }
63 
64 private:
66  SourceLocExprScopeGuard &operator=(SourceLocExprScopeGuard const &) = delete;
67 
70  bool Enable;
71 };
72 
73 } // end namespace clang
74 
75 #endif // LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H
This represents one expression.
Definition: Expr.h:108
#define false
Definition: stdbool.h:17
Represents the current source location and context used to determine the value of the source location...
Dataflow Directional Tag Classes.
SourceLocExprScopeGuard(const Expr *DefaultExpr, CurrentSourceLocExprScope &Current)