1 //===--- Source.cpp - Source expression tracking ----------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 #include "clang/AST/Expr.h"
12 using namespace clang;
13 using namespace clang::interp;
15 SourceLocation SourceInfo::getLoc() const {
16 if (const Expr *E = asExpr())
17 return E->getExprLoc();
18 if (const Stmt *S = asStmt())
19 return S->getBeginLoc();
20 if (const Decl *D = asDecl())
21 return D->getBeginLoc();
22 return SourceLocation();
25 const Expr *SourceInfo::asExpr() const {
26 if (auto *S = Source.dyn_cast<const Stmt *>())
27 return dyn_cast<Expr>(S);
31 const Expr *SourceMapper::getExpr(Function *F, CodePtr PC) const {
32 if (const Expr *E = getSource(F, PC).asExpr())
34 llvm::report_fatal_error("missing source expression");
37 SourceLocation SourceMapper::getLocation(Function *F, CodePtr PC) const {
38 return getSource(F, PC).getLoc();