clang 10.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
12 using namespace clang;
13 using namespace clang::interp;
14
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();
23 }
24
25 const Expr *SourceInfo::asExpr() const {
26 if (auto *S = Source.dyn_cast<const Stmt *>())
27 return dyn_cast<Expr>(S);
28 return nullptr;
29 }
30
31 const Expr *SourceMapper::getExpr(Function *F, CodePtr PC) const {
32 if (const Expr *E = getSource(F, PC).asExpr())
33 return E;
34 llvm::report_fatal_error("missing source expression");
35 }
36
37 SourceLocation SourceMapper::getLocation(Function *F, CodePtr PC) const {
38 return getSource(F, PC).getLoc();
39 }
clang::interp::CodePtr
Pointer into the code segment.
Definition: Source.h:25
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:66
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
clang::interp::SourceInfo::getLoc
SourceLocation getLoc() const
Definition: Source.cpp:15
Source.h
clang::interp::SourceInfo::asStmt
const Stmt * asStmt() const
Definition: Source.h:89
clang::Expr
This represents one expression.
Definition: Expr.h:108
clang::interp::SourceInfo::asDecl
const Decl * asDecl() const
Definition: Source.h:90
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::interp::Function
Bytecode function.
Definition: Function.h:59
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::interp::SourceMapper::getExpr
const Expr * getExpr(Function *F, CodePtr PC) const
Returns the expression if an opcode belongs to one, null otherwise.
Definition: Source.cpp:31
clang::interp
Definition: ASTContext.h:146
Expr.h
clang::interp::SourceMapper::getLocation
SourceLocation getLocation(Function *F, CodePtr PC) const
Returns the location from which an opcode originates.
Definition: Source.cpp:37
clang::interp::SourceInfo::asExpr
const Expr * asExpr() const
Definition: Source.cpp:25