https://github.com/b10902118 created https://github.com/llvm/llvm-project/pull/171834
Improve code flow by handling unhandled decls upon detected. >From c114e278d76293a440ea1ee62727f2b550f74938 Mon Sep 17 00:00:00 2001 From: Bill Tsui <[email protected]> Date: Thu, 11 Dec 2025 19:09:07 +0800 Subject: [PATCH] [clang][index][NFC] Refactor indexDecl for unhandled decls Improve code flow by handling unhandled decls upon detected. --- clang/lib/Index/IndexDecl.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp index df875e0b40079..96d5c4a210c1e 100644 --- a/clang/lib/Index/IndexDecl.cpp +++ b/clang/lib/Index/IndexDecl.cpp @@ -40,10 +40,10 @@ class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> { explicit IndexingDeclVisitor(IndexingContext &indexCtx) : IndexCtx(indexCtx) { } - bool Handled = true; - + // Default handler for declarations not matched by more specific Visit* methods. bool VisitDecl(const Decl *D) { - Handled = false; + if (isa<DeclContext>(D)) + return IndexCtx.indexDeclContext(cast<DeclContext>(D)); return true; } @@ -784,15 +784,9 @@ bool IndexingContext::indexDecl(const Decl *D) { if (isTemplateImplicitInstantiation(D) && !shouldIndexImplicitInstantiation()) return true; + // Dispatch the Decl by kind to specific Visit* that index the whole subtree. IndexingDeclVisitor Visitor(*this); - bool ShouldContinue = Visitor.Visit(D); - if (!ShouldContinue) - return false; - - if (!Visitor.Handled && isa<DeclContext>(D)) - return indexDeclContext(cast<DeclContext>(D)); - - return true; + return Visitor.Visit(D); } bool IndexingContext::indexDeclContext(const DeclContext *DC) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
