[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / lib / AST / Interp / Source.cpp
blob4e032c92d26df162fbeb4426f37806192a5eb19d
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 //===----------------------------------------------------------------------===//
9 #include "Source.h"
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 SourceRange SourceInfo::getRange() const {
26 if (const Expr *E = asExpr())
27 return E->getSourceRange();
28 if (const Stmt *S = asStmt())
29 return S->getSourceRange();
30 if (const Decl *D = asDecl())
31 return D->getSourceRange();
32 return SourceRange();
35 const Expr *SourceInfo::asExpr() const {
36 if (auto *S = Source.dyn_cast<const Stmt *>())
37 return dyn_cast<Expr>(S);
38 return nullptr;
41 const Expr *SourceMapper::getExpr(const Function *F, CodePtr PC) const {
42 if (const Expr *E = getSource(F, PC).asExpr())
43 return E;
44 llvm::report_fatal_error("missing source expression");
47 SourceLocation SourceMapper::getLocation(const Function *F, CodePtr PC) const {
48 return getSource(F, PC).getLoc();
51 SourceRange SourceMapper::getRange(const Function *F, CodePtr PC) const {
52 return getSource(F, PC).getRange();