Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/clang/lib/AST/Interp/Source.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- Source.cpp - Source expression tracking ----------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "Source.h"
10
#include "clang/AST/Expr.h"
11
12
using namespace clang;
13
using namespace clang::interp;
14
15
0
SourceLocation SourceInfo::getLoc() const {
16
0
  if (const Expr *E = asExpr())
17
0
    return E->getExprLoc();
18
0
  if (const Stmt *S = asStmt())
19
0
    return S->getBeginLoc();
20
0
  if (const Decl *D = asDecl())
21
0
    return D->getBeginLoc();
22
0
  return SourceLocation();
23
0
}
24
25
0
SourceRange SourceInfo::getRange() const {
26
0
  if (const Expr *E = asExpr())
27
0
    return E->getSourceRange();
28
0
  if (const Stmt *S = asStmt())
29
0
    return S->getSourceRange();
30
0
  if (const Decl *D = asDecl())
31
0
    return D->getSourceRange();
32
0
  return SourceRange();
33
0
}
34
35
0
const Expr *SourceInfo::asExpr() const {
36
0
  if (auto *S = Source.dyn_cast<const Stmt *>())
37
0
    return dyn_cast<Expr>(S);
38
0
  return nullptr;
39
0
}
40
41
0
const Expr *SourceMapper::getExpr(const Function *F, CodePtr PC) const {
42
0
  if (const Expr *E = getSource(F, PC).asExpr())
43
0
    return E;
44
0
  llvm::report_fatal_error("missing source expression");
45
0
}
46
47
0
SourceLocation SourceMapper::getLocation(const Function *F, CodePtr PC) const {
48
0
  return getSource(F, PC).getLoc();
49
0
}
50
51
0
SourceRange SourceMapper::getRange(const Function *F, CodePtr PC) const {
52
0
  return getSource(F, PC).getRange();
53
0
}