@@ -2462,21 +2462,33 @@ TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type,
2462
2462
LLDB_SCOPED_TIMER ();
2463
2463
FALLBACK (GetNumChildren,
2464
2464
(ReconstructType (type), omit_empty_base_classes, exe_ctx));
2465
- if (exe_ctx)
2466
- if (auto *exe_scope = exe_ctx->GetBestExecutionContextScope ())
2467
- if (auto *runtime =
2468
- SwiftLanguageRuntime::Get (exe_scope->CalculateProcess ()))
2469
- if (auto num_children =
2470
- runtime->GetNumChildren (GetCanonicalType (type), nullptr ))
2471
- // Use a lambda to intercept and unwrap the `Optional` return value.
2472
- // Optional<uint32_t> uses more lax equivalency function.
2473
- return [&]() -> llvm::Optional<uint32_t > {
2474
- auto impl = [&]() { return num_children; };
2475
- VALIDATE_AND_RETURN (
2476
- impl, GetNumChildren, type,
2477
- (ReconstructType (type), omit_empty_base_classes, exe_ctx),
2478
- (ReconstructType (type), omit_empty_base_classes, exe_ctx));
2479
- }().getValueOr (0 );
2465
+
2466
+ auto impl = [&]() -> llvm::Optional<uint32_t > {
2467
+ if (exe_ctx)
2468
+ if (auto *exe_scope = exe_ctx->GetBestExecutionContextScope ())
2469
+ if (auto *runtime =
2470
+ SwiftLanguageRuntime::Get (exe_scope->CalculateProcess ()))
2471
+ return runtime->GetNumChildren (GetCanonicalType (type), nullptr );
2472
+
2473
+ if (CompilerType clang_type = GetAsClangTypeOrNull (type)) {
2474
+ bool is_signed;
2475
+ // Clang-imported enum types always have one child in Swift.
2476
+ if (clang_type.IsEnumerationType (is_signed))
2477
+ return 1 ;
2478
+ return clang_type.GetNumChildren (omit_empty_base_classes, exe_ctx);
2479
+ }
2480
+ return {};
2481
+ };
2482
+ if (llvm::Optional<uint32_t > num_children = impl ())
2483
+ // Use a lambda to intercept and unwrap the `Optional` return value.
2484
+ // Optional<uint32_t> uses more lax equivalency function.
2485
+ return [&]() -> llvm::Optional<uint32_t > {
2486
+ auto impl = [&]() { return num_children; };
2487
+ VALIDATE_AND_RETURN (
2488
+ impl, GetNumChildren, type,
2489
+ (ReconstructType (type), omit_empty_base_classes, exe_ctx),
2490
+ (ReconstructType (type), omit_empty_base_classes, exe_ctx));
2491
+ }().getValueOr (0 );
2480
2492
2481
2493
LLDB_LOGF (GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES),
2482
2494
" Using SwiftASTContext::GetNumChildren fallback for type %s" ,
0 commit comments