[clang] b15a946 - [clang][Interp][NFC] Refactor VisitDeclRefExpr
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 3 07:42:49 PDT 2023
Author: Timm Bäder
Date: 2023-04-03T16:42:25+02:00
New Revision: b15a946b9f59f91518ae5e2cb6125592d9c1bf3c
URL: https://github.com/llvm/llvm-project/commit/b15a946b9f59f91518ae5e2cb6125592d9c1bf3c
DIFF: https://github.com/llvm/llvm-project/commit/b15a946b9f59f91518ae5e2cb6125592d9c1bf3c.diff
LOG: [clang][Interp][NFC] Refactor VisitDeclRefExpr
Make it clearer that we only need to check for variables and parameters
if we don't have the easy case. Also only do the IsReference check if
necessary.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ee5dd73159a6..e620b4f9b2f6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1840,37 +1840,41 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
- const auto *Decl = E->getDecl();
+ const auto *D = E->getDecl();
+
+ if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
+ return this->emitConst(ECD->getInitVal(), E);
+ } else if (const auto *BD = dyn_cast<BindingDecl>(D)) {
+ return this->visit(BD->getBinding());
+ } else if (const auto *FuncDecl = dyn_cast<FunctionDecl>(D)) {
+ const Function *F = getFunction(FuncDecl);
+ return F && this->emitGetFnPtr(F, E);
+ }
+
// References are implemented via pointers, so when we see a DeclRefExpr
// pointing to a reference, we need to get its value directly (i.e. the
// pointer to the actual value) instead of a pointer to the pointer to the
// value.
- bool IsReference = Decl->getType()->isReferenceType();
+ bool IsReference = D->getType()->isReferenceType();
- if (auto It = Locals.find(Decl); It != Locals.end()) {
+ // Check for local/global variables and parameters.
+ if (auto It = Locals.find(D); It != Locals.end()) {
const unsigned Offset = It->second.Offset;
if (IsReference)
return this->emitGetLocal(PT_Ptr, Offset, E);
return this->emitGetPtrLocal(Offset, E);
- } else if (auto GlobalIndex = P.getGlobal(Decl)) {
+ } else if (auto GlobalIndex = P.getGlobal(D)) {
if (IsReference)
return this->emitGetGlobal(PT_Ptr, *GlobalIndex, E);
return this->emitGetPtrGlobal(*GlobalIndex, E);
- } else if (const auto *PVD = dyn_cast<ParmVarDecl>(Decl)) {
+ } else if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
if (auto It = this->Params.find(PVD); It != this->Params.end()) {
if (IsReference)
return this->emitGetParam(PT_Ptr, It->second, E);
return this->emitGetPtrParam(It->second, E);
}
- } else if (const auto *ECD = dyn_cast<EnumConstantDecl>(Decl)) {
- return this->emitConst(ECD->getInitVal(), E);
- } else if (const auto *BD = dyn_cast<BindingDecl>(Decl)) {
- return this->visit(BD->getBinding());
- } else if (const auto *FuncDecl = dyn_cast<FunctionDecl>(Decl)) {
- const Function *F = getFunction(FuncDecl);
- return F && this->emitGetFnPtr(F, E);
}
return false;
More information about the cfe-commits
mailing list