1 //===--- CurrentSourceLocExprScope.h ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines types used to track the current context needed to evaluate
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H
16 #define LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H
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;
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;
36 const Expr *getDefaultExpr() const { return DefaultExpr; }
38 explicit CurrentSourceLocExprScope() = default;
41 explicit CurrentSourceLocExprScope(const Expr *DefaultExpr)
42 : DefaultExpr(DefaultExpr) {}
44 CurrentSourceLocExprScope(CurrentSourceLocExprScope const &) = default;
45 CurrentSourceLocExprScope &
46 operator=(CurrentSourceLocExprScope const &) = default;
49 class CurrentSourceLocExprScope::SourceLocExprScopeGuard {
51 SourceLocExprScopeGuard(const Expr *DefaultExpr,
52 CurrentSourceLocExprScope &Current)
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);
59 ~SourceLocExprScopeGuard() {
65 SourceLocExprScopeGuard(SourceLocExprScopeGuard const &) = delete;
66 SourceLocExprScopeGuard &operator=(SourceLocExprScopeGuard const &) = delete;
68 CurrentSourceLocExprScope &Current;
69 CurrentSourceLocExprScope OldVal;
73 } // end namespace clang
75 #endif // LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H