xref: /netbsd-src/external/apache2/llvm/dist/clang/lib/AST/Interp/Source.cpp (revision 7330f729ccf0bd976a06f95fad452fe774fc7fd1)
1*7330f729Sjoerg //===--- Source.cpp - Source expression tracking ----------------*- C++ -*-===//
2*7330f729Sjoerg //
3*7330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*7330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
5*7330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*7330f729Sjoerg //
7*7330f729Sjoerg //===----------------------------------------------------------------------===//
8*7330f729Sjoerg 
9*7330f729Sjoerg #include "Source.h"
10*7330f729Sjoerg #include "clang/AST/Expr.h"
11*7330f729Sjoerg 
12*7330f729Sjoerg using namespace clang;
13*7330f729Sjoerg using namespace clang::interp;
14*7330f729Sjoerg 
getLoc() const15*7330f729Sjoerg SourceLocation SourceInfo::getLoc() const {
16*7330f729Sjoerg   if (const Expr *E = asExpr())
17*7330f729Sjoerg     return E->getExprLoc();
18*7330f729Sjoerg   if (const Stmt *S = asStmt())
19*7330f729Sjoerg     return S->getBeginLoc();
20*7330f729Sjoerg   if (const Decl *D = asDecl())
21*7330f729Sjoerg     return D->getBeginLoc();
22*7330f729Sjoerg   return SourceLocation();
23*7330f729Sjoerg }
24*7330f729Sjoerg 
asExpr() const25*7330f729Sjoerg const Expr *SourceInfo::asExpr() const {
26*7330f729Sjoerg   if (auto *S = Source.dyn_cast<const Stmt *>())
27*7330f729Sjoerg     return dyn_cast<Expr>(S);
28*7330f729Sjoerg   return nullptr;
29*7330f729Sjoerg }
30*7330f729Sjoerg 
getExpr(Function * F,CodePtr PC) const31*7330f729Sjoerg const Expr *SourceMapper::getExpr(Function *F, CodePtr PC) const {
32*7330f729Sjoerg   if (const Expr *E = getSource(F, PC).asExpr())
33*7330f729Sjoerg     return E;
34*7330f729Sjoerg   llvm::report_fatal_error("missing source expression");
35*7330f729Sjoerg }
36*7330f729Sjoerg 
getLocation(Function * F,CodePtr PC) const37*7330f729Sjoerg SourceLocation SourceMapper::getLocation(Function *F, CodePtr PC) const {
38*7330f729Sjoerg   return getSource(F, PC).getLoc();
39*7330f729Sjoerg }
40