Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:30

0001 //===--- CurrentSourceLocExprScope.h ----------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines types used to track the current context needed to evaluate
0010 //  a SourceLocExpr.
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 /// Represents the current source location and context used to determine the
0023 /// value of the source location builtins (ex. __builtin_LINE), including the
0024 /// context of default argument and default initializer expressions.
0025 class CurrentSourceLocExprScope {
0026   /// The CXXDefaultArgExpr or CXXDefaultInitExpr we're currently evaluating.
0027   const Expr *DefaultExpr = nullptr;
0028 
0029 public:
0030   /// A RAII style scope guard used for tracking the current source
0031   /// location and context as used by the source location builtins
0032   /// (ex. __builtin_LINE).
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 } // end namespace clang
0073 
0074 #endif // LLVM_CLANG_AST_CURRENTSOURCELOCEXPRSCOPE_H