File indexing completed on 2026-05-10 08:36:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_AST_CURRENTSOURCELOCEXPRSCOPE_H
0015 #define LLVM_CLANG_AST_CURRENTSOURCELOCEXPRSCOPE_H
0016
0017 #include <cassert>
0018
0019 namespace clang {
0020 class Expr;
0021
0022
0023
0024
0025 class CurrentSourceLocExprScope {
0026
0027 const Expr *DefaultExpr = nullptr;
0028
0029 public:
0030
0031
0032
0033 class SourceLocExprScopeGuard;
0034
0035 const Expr *getDefaultExpr() const { return DefaultExpr; }
0036
0037 explicit CurrentSourceLocExprScope() = default;
0038
0039 private:
0040 explicit CurrentSourceLocExprScope(const Expr *DefaultExpr)
0041 : DefaultExpr(DefaultExpr) {}
0042
0043 CurrentSourceLocExprScope(CurrentSourceLocExprScope const &) = default;
0044 CurrentSourceLocExprScope &
0045 operator=(CurrentSourceLocExprScope const &) = default;
0046 };
0047
0048 class CurrentSourceLocExprScope::SourceLocExprScopeGuard {
0049 public:
0050 SourceLocExprScopeGuard(const Expr *DefaultExpr,
0051 CurrentSourceLocExprScope &Current)
0052 : Current(Current), OldVal(Current), Enable(false) {
0053 assert(DefaultExpr && "the new scope should not be empty");
0054 if ((Enable = (Current.getDefaultExpr() == nullptr)))
0055 Current = CurrentSourceLocExprScope(DefaultExpr);
0056 }
0057
0058 ~SourceLocExprScopeGuard() {
0059 if (Enable)
0060 Current = OldVal;
0061 }
0062
0063 private:
0064 SourceLocExprScopeGuard(SourceLocExprScopeGuard const &) = delete;
0065 SourceLocExprScopeGuard &operator=(SourceLocExprScopeGuard const &) = delete;
0066
0067 CurrentSourceLocExprScope &Current;
0068 CurrentSourceLocExprScope OldVal;
0069 bool Enable;
0070 };
0071
0072 }
0073
0074 #endif