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