Skip to content

Commit 90696d1

Browse files
authored
[clang][bytecode][NFC] Simplify visitDeclRef (#123380)
Try to reduce indentation here.
1 parent e240261 commit 90696d1

File tree

1 file changed

+56
-49
lines changed

1 file changed

+56
-49
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6194,60 +6194,67 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
61946194
return revisit(VD);
61956195
}
61966196

6197-
if (D != InitializingDecl) {
6198-
// Try to lazily visit (or emit dummy pointers for) declarations
6199-
// we haven't seen yet.
6200-
if (Ctx.getLangOpts().CPlusPlus) {
6201-
if (const auto *VD = dyn_cast<VarDecl>(D)) {
6202-
const auto typeShouldBeVisited = [&](QualType T) -> bool {
6203-
if (T.isConstant(Ctx.getASTContext()))
6204-
return true;
6205-
return T->isReferenceType();
6206-
};
6197+
// Avoid infinite recursion.
6198+
if (D == InitializingDecl)
6199+
return this->emitDummyPtr(D, E);
6200+
6201+
// Try to lazily visit (or emit dummy pointers for) declarations
6202+
// we haven't seen yet.
6203+
// For C.
6204+
if (!Ctx.getLangOpts().CPlusPlus) {
6205+
if (const auto *VD = dyn_cast<VarDecl>(D);
6206+
VD && VD->getAnyInitializer() &&
6207+
VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak())
6208+
return revisit(VD);
6209+
return this->emitDummyPtr(D, E);
6210+
}
62076211

6208-
// DecompositionDecls are just proxies for us.
6209-
if (isa<DecompositionDecl>(VD))
6210-
return revisit(VD);
6211-
6212-
if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) &&
6213-
typeShouldBeVisited(VD->getType())) {
6214-
if (const Expr *Init = VD->getAnyInitializer();
6215-
Init && !Init->isValueDependent()) {
6216-
// Whether or not the evaluation is successul doesn't really matter
6217-
// here -- we will create a global variable in any case, and that
6218-
// will have the state of initializer evaluation attached.
6219-
APValue V;
6220-
SmallVector<PartialDiagnosticAt> Notes;
6221-
(void)Init->EvaluateAsInitializer(V, Ctx.getASTContext(), VD, Notes,
6222-
true);
6223-
return this->visitDeclRef(D, E);
6224-
}
6225-
return revisit(VD);
6226-
}
6212+
// ... and C++.
6213+
const auto *VD = dyn_cast<VarDecl>(D);
6214+
if (!VD)
6215+
return this->emitDummyPtr(D, E);
62276216

6228-
// FIXME: The evaluateValue() check here is a little ridiculous, since
6229-
// it will ultimately call into Context::evaluateAsInitializer(). In
6230-
// other words, we're evaluating the initializer, just to know if we can
6231-
// evaluate the initializer.
6232-
if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) &&
6233-
VD->getInit() && !VD->getInit()->isValueDependent()) {
6217+
const auto typeShouldBeVisited = [&](QualType T) -> bool {
6218+
if (T.isConstant(Ctx.getASTContext()))
6219+
return true;
6220+
return T->isReferenceType();
6221+
};
62346222

6235-
if (VD->evaluateValue())
6236-
return revisit(VD);
6223+
// DecompositionDecls are just proxies for us.
6224+
if (isa<DecompositionDecl>(VD))
6225+
return revisit(VD);
6226+
6227+
if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) &&
6228+
typeShouldBeVisited(VD->getType())) {
6229+
if (const Expr *Init = VD->getAnyInitializer();
6230+
Init && !Init->isValueDependent()) {
6231+
// Whether or not the evaluation is successul doesn't really matter
6232+
// here -- we will create a global variable in any case, and that
6233+
// will have the state of initializer evaluation attached.
6234+
APValue V;
6235+
SmallVector<PartialDiagnosticAt> Notes;
6236+
(void)Init->EvaluateAsInitializer(V, Ctx.getASTContext(), VD, Notes,
6237+
true);
6238+
return this->visitDeclRef(D, E);
6239+
}
6240+
return revisit(VD);
6241+
}
6242+
6243+
// FIXME: The evaluateValue() check here is a little ridiculous, since
6244+
// it will ultimately call into Context::evaluateAsInitializer(). In
6245+
// other words, we're evaluating the initializer, just to know if we can
6246+
// evaluate the initializer.
6247+
if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) &&
6248+
VD->getInit() && !VD->getInit()->isValueDependent()) {
6249+
6250+
if (VD->evaluateValue())
6251+
return revisit(VD);
62376252

6238-
if (!D->getType()->isReferenceType())
6239-
return this->emitDummyPtr(D, E);
6253+
if (!D->getType()->isReferenceType())
6254+
return this->emitDummyPtr(D, E);
62406255

6241-
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
6242-
/*InitializerFailed=*/true, E);
6243-
}
6244-
}
6245-
} else {
6246-
if (const auto *VD = dyn_cast<VarDecl>(D);
6247-
VD && VD->getAnyInitializer() &&
6248-
VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak())
6249-
return revisit(VD);
6250-
}
6256+
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
6257+
/*InitializerFailed=*/true, E);
62516258
}
62526259

62536260
return this->emitDummyPtr(D, E);

0 commit comments

Comments
 (0)