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;