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