xiaobai created this revision.
xiaobai added reviewers: jingham, clayborg, JDevlieghere.

Instead of hardcoding ClangASTContext and ObjCLanguageRuntime, we can
generalize this by creating the method CalculateCompleteType in
LanguageRuntime and moving the current MaybeCalculateCompleteType
implementation into ObjCLanguageruntime::CalculateCompleteType


https://reviews.llvm.org/D64159

Files:
  include/lldb/Target/LanguageRuntime.h
  include/lldb/Target/ObjCLanguageRuntime.h
  source/Core/ValueObject.cpp
  source/Target/ObjCLanguageRuntime.cpp

Index: source/Target/ObjCLanguageRuntime.cpp
===================================================================
--- source/Target/ObjCLanguageRuntime.cpp
+++ source/Target/ObjCLanguageRuntime.cpp
@@ -398,3 +398,40 @@
         "The ObjC Exception breakpoint doesn't support extra options.");
   return error;
 }
+
+CompilerType
+ObjCLanguageRuntime::CalculateCompleteType(CompilerType base_type) {
+  CompilerType type_to_return;
+
+  CompilerType class_type;
+  bool is_pointer_type = false;
+
+  if (ClangASTContext::IsObjCObjectPointerType(base_type, &class_type))
+    is_pointer_type = true;
+  else if (ClangASTContext::IsObjCObjectOrInterfaceType(base_type))
+    class_type = base_type;
+  else
+    return type_to_return;
+
+  if (!class_type)
+    return type_to_return;
+
+  ConstString class_name(class_type.GetConstTypeName());
+  if (!class_name)
+    return type_to_return;
+
+  TypeSP complete_objc_class_type_sp = LookupInCompleteClassCache(class_name);
+  if (!complete_objc_class_type_sp)
+    return type_to_return;
+
+  CompilerType complete_class(
+      complete_objc_class_type_sp->GetFullCompilerType());
+  if (complete_class.GetCompleteType()) {
+    if (is_pointer_type)
+      type_to_return = complete_class.GetPointerType();
+    else
+      type_to_return = complete_class;
+  }
+
+  return type_to_return;
+}
Index: source/Core/ValueObject.cpp
===================================================================
--- source/Core/ValueObject.cpp
+++ source/Core/ValueObject.cpp
@@ -35,7 +35,6 @@
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/LanguageRuntime.h"
-#include "lldb/Target/ObjCLanguageRuntime.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Target.h"
@@ -280,52 +279,20 @@
       return compiler_type;
   }
 
-  CompilerType class_type;
-  bool is_pointer_type = false;
-
-  if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type)) {
-    is_pointer_type = true;
-  } else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type)) {
-    class_type = compiler_type;
-  } else {
-    return compiler_type;
-  }
-
   m_did_calculate_complete_objc_class_type = true;
 
-  if (class_type) {
-    ConstString class_name(class_type.GetConstTypeName());
+  ProcessSP process_sp(
+      GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
 
-    if (class_name) {
-      ProcessSP process_sp(
-          GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
-
-      if (process_sp) {
-        ObjCLanguageRuntime *objc_language_runtime(
-            ObjCLanguageRuntime::Get(*process_sp));
-
-        if (objc_language_runtime) {
-          TypeSP complete_objc_class_type_sp =
-              objc_language_runtime->LookupInCompleteClassCache(class_name);
-
-          if (complete_objc_class_type_sp) {
-            CompilerType complete_class(
-                complete_objc_class_type_sp->GetFullCompilerType());
+  if (!process_sp)
+    return compiler_type;
 
-            if (complete_class.GetCompleteType()) {
-              if (is_pointer_type) {
-                m_override_type = complete_class.GetPointerType();
-              } else {
-                m_override_type = complete_class;
-              }
+  if (auto *runtime =
+          process_sp->GetLanguageRuntime(GetObjectRuntimeLanguage())) {
+    m_override_type = runtime->CalculateCompleteType(compiler_type);
 
-              if (m_override_type.IsValid())
-                return m_override_type;
-            }
-          }
-        }
-      }
-    }
+    if (m_override_type.IsValid())
+      return m_override_type;
   }
   return compiler_type;
 }
Index: include/lldb/Target/ObjCLanguageRuntime.h
===================================================================
--- include/lldb/Target/ObjCLanguageRuntime.h
+++ include/lldb/Target/ObjCLanguageRuntime.h
@@ -250,6 +250,8 @@
 
   lldb::TypeSP LookupInCompleteClassCache(ConstString &name);
 
+  CompilerType CalculateCompleteType(CompilerType base_type) override;
+
   virtual UtilityFunction *CreateObjectChecker(const char *) = 0;
 
   virtual ObjCRuntimeVersions GetRuntimeVersion() const {
Index: include/lldb/Target/LanguageRuntime.h
===================================================================
--- include/lldb/Target/LanguageRuntime.h
+++ include/lldb/Target/LanguageRuntime.h
@@ -156,6 +156,10 @@
   /// from the user interface.
   virtual bool IsWhitelistedRuntimeValue(ConstString name) { return false; }
 
+  virtual CompilerType CalculateCompleteType(CompilerType base_type) {
+    return CompilerType();
+  }
+
   virtual void ModulesDidLoad(const ModuleList &module_list) {}
 
   // Called by the Clang expression evaluation engine to allow runtimes to
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to