clang 20.0.0git
Source.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
9#include "Source.h"
10#include "clang/AST/Expr.h"
11
12using namespace clang;
13using namespace clang::interp;
14
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();
23}
24
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();
33}
34
35const Expr *SourceInfo::asExpr() const {
36 if (const auto *S = dyn_cast_if_present<const Stmt *>(Source))
37 return dyn_cast<Expr>(S);
38 return nullptr;
39}
40
41const Expr *SourceMapper::getExpr(const Function *F, CodePtr PC) const {
42 if (const Expr *E = getSource(F, PC).asExpr())
43 return E;
44 return nullptr;
45}
46
48 return getSource(F, PC).getLoc();
49}
50
52 return getSource(F, PC).getRange();
53}
const Decl * D
Expr * E
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:434
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:430
This represents one expression.
Definition: Expr.h:110
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:324
Pointer into the code segment.
Definition: Source.h:30
Bytecode function.
Definition: Function.h:81
const Decl * asDecl() const
Definition: Source.h:89
const Expr * asExpr() const
Definition: Source.cpp:35
const Stmt * asStmt() const
Definition: Source.h:86
SourceLocation getLoc() const
Definition: Source.cpp:15
SourceRange getRange() const
Definition: Source.cpp:25
virtual SourceInfo getSource(const Function *F, CodePtr PC) const =0
Returns source information for a given PC in a function.
SourceLocation getLocation(const Function *F, CodePtr PC) const
Returns the location from which an opcode originates.
Definition: Source.cpp:47
SourceRange getRange(const Function *F, CodePtr PC) const
Definition: Source.cpp:51
const Expr * getExpr(const Function *F, CodePtr PC) const
Returns the expression if an opcode belongs to one, null otherwise.
Definition: Source.cpp:41
The JSON file list parser is used to communicate input to InstallAPI.