Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
17.8k
  const Expr *getDefaultExpr() const { return DefaultExpr; }
37
38
17.9M
  explicit CurrentSourceLocExprScope() = default;
39
40
private:
41
  explicit CurrentSourceLocExprScope(const Expr *DefaultExpr)
42
16.9k
      : 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
17.2k
      : Current(Current), OldVal(Current), Enable(false) {
54
17.2k
    assert(DefaultExpr && "the new scope should not be empty");
55
17.2k
    if ((Enable = (Current.getDefaultExpr() == nullptr)))
56
16.9k
      Current = CurrentSourceLocExprScope(DefaultExpr);
57
17.2k
  }
58
59
17.2k
  ~SourceLocExprScopeGuard() {
60
17.2k
    if (Enable)
61
16.9k
      Current = OldVal;
62
17.2k
  }
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