@@ -249,6 +249,51 @@ void ValueObject::ClearDynamicTypeInformation() {
249249 SetSyntheticChildren (lldb::SyntheticChildrenSP ());
250250}
251251
252+ CompilerType ValueObject::LookupInModulesVendor (ConstString class_name,
253+ Target &target) {
254+ assert (class_name);
255+
256+ auto *persistent_state = llvm::cast<ClangPersistentVariables>(
257+ target.GetPersistentExpressionStateForLanguage (lldb::eLanguageTypeC));
258+ if (!persistent_state)
259+ return {};
260+
261+ auto clang_modules_decl_vendor_sp =
262+ persistent_state->GetClangModulesDeclVendor ();
263+ if (!clang_modules_decl_vendor_sp)
264+ return {};
265+
266+ auto types = clang_modules_decl_vendor_sp->FindTypes (
267+ class_name, /* max_matches*/ UINT32_MAX);
268+ if (types.empty ())
269+ return {};
270+
271+ return types.front ();
272+ }
273+
274+ CompilerType ValueObject::LookupInRuntime (ConstString class_name,
275+ Process &process) {
276+ auto *objc_language_runtime = ObjCLanguageRuntime::Get (process);
277+ if (!objc_language_runtime)
278+ return {};
279+
280+ auto *runtime_vendor = objc_language_runtime->GetDeclVendor ();
281+ if (!runtime_vendor)
282+ return {};
283+
284+ std::vector<CompilerDecl> compiler_decls;
285+ runtime_vendor->FindDecls (class_name, false , UINT32_MAX, compiler_decls);
286+ if (compiler_decls.empty ())
287+ return {};
288+
289+ auto *ctx =
290+ llvm::dyn_cast<TypeSystemClang>(compiler_decls[0 ].GetTypeSystem ());
291+ if (!ctx)
292+ return {};
293+
294+ return ctx->GetTypeForDecl (compiler_decls[0 ].GetOpaqueDecl ());
295+ }
296+
252297CompilerType ValueObject::MaybeCalculateCompleteType () {
253298 CompilerType compiler_type (GetCompilerTypeImpl ());
254299
@@ -277,7 +322,6 @@ CompilerType ValueObject::MaybeCalculateCompleteType() {
277322 }
278323 }
279324
280- std::vector<clang::NamedDecl *> decls;
281325 CompilerType class_type;
282326 bool is_pointer_type = false ;
283327 if (TypeSystemClang::IsObjCObjectPointerType (compiler_type, &class_type))
@@ -291,49 +335,18 @@ CompilerType ValueObject::MaybeCalculateCompleteType() {
291335 if (!class_name)
292336 return compiler_type;
293337
294- // try the modules
295- if (TargetSP target_sp = GetTargetSP ()) {
296- auto *persistent_state = llvm::cast<ClangPersistentVariables>(
297- target_sp->GetPersistentExpressionStateForLanguage (lldb::eLanguageTypeC));
298- if (!persistent_state)
299- return compiler_type;
300-
301- if (auto clang_modules_decl_vendor =
302- persistent_state->GetClangModulesDeclVendor ()) {
303- ConstString key_cs (class_name);
304- auto types = clang_modules_decl_vendor->FindTypes (
305- key_cs, /* max_matches*/ UINT32_MAX);
306- if (!types.empty ()) {
307- auto module_type = types.front ();
308- m_override_type =
309- is_pointer_type ? module_type.GetPointerType () : module_type;
310- }
311-
312- if (m_override_type.IsValid ())
313- return m_override_type;
338+ if (auto target_sp = GetTargetSP ()) {
339+ if (CompilerType found = LookupInModulesVendor (class_name, *target_sp)) {
340+ m_override_type = is_pointer_type ? found.GetPointerType () : found;
341+ return m_override_type;
314342 }
315343 }
316344
317- // then try the runtime
318- if (auto *objc_language_runtime = ObjCLanguageRuntime::Get (*process_sp)) {
319- if (auto *runtime_vendor = objc_language_runtime->GetDeclVendor ()) {
320- std::vector<CompilerDecl> compiler_decls;
321- runtime_vendor->FindDecls (class_name, false , UINT32_MAX, compiler_decls);
322- if (!compiler_decls.empty ()) {
323- auto *ctx =
324- llvm::dyn_cast<TypeSystemClang>(compiler_decls[0 ].GetTypeSystem ());
325- if (ctx) {
326- CompilerType runtime_type =
327- ctx->GetTypeForDecl (compiler_decls[0 ].GetOpaqueDecl ());
328- m_override_type =
329- is_pointer_type ? runtime_type.GetPointerType () : runtime_type;
330- }
331- }
332-
333- if (m_override_type.IsValid ())
334- return m_override_type;
335- }
345+ if (CompilerType found = LookupInRuntime (class_name, *process_sp)) {
346+ m_override_type = is_pointer_type ? found.GetPointerType () : found;
347+ return m_override_type;
336348 }
349+
337350 return compiler_type;
338351}
339352
0 commit comments