Skip to content

Commit 24604ec

Browse files
committedJul 12, 2019
[Core] Generalize ValueObject::MaybeCalculateCompleteType
Summary: Instead of hardcoding ClangASTContext and ObjCLanguageRuntime, we can generalize this by creating the method GetRuntimeType in LanguageRuntime and moving the current MaybeCalculateCompleteType implementation into ObjCLanguageruntime::GetRuntimeType Reviewers: jingham, clayborg, JDevlieghere Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D64159 llvm-svn: 365939
1 parent cb5ecae commit 24604ec

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
lines changed
 

‎lldb/include/lldb/Target/LanguageRuntime.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ class LanguageRuntime : public PluginInterface {
156156
/// from the user interface.
157157
virtual bool IsWhitelistedRuntimeValue(ConstString name) { return false; }
158158

159+
virtual llvm::Optional<CompilerType> GetRuntimeType(CompilerType base_type) {
160+
return llvm::None;
161+
}
162+
159163
virtual void ModulesDidLoad(const ModuleList &module_list) {}
160164

161165
// Called by the Clang expression evaluation engine to allow runtimes to

‎lldb/include/lldb/Target/ObjCLanguageRuntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ class ObjCLanguageRuntime : public LanguageRuntime {
250250

251251
lldb::TypeSP LookupInCompleteClassCache(ConstString &name);
252252

253+
llvm::Optional<CompilerType> GetRuntimeType(CompilerType base_type) override;
254+
253255
virtual UtilityFunction *CreateObjectChecker(const char *) = 0;
254256

255257
virtual ObjCRuntimeVersions GetRuntimeVersion() const {

‎lldb/source/Core/ValueObject.cpp

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "lldb/Target/ExecutionContext.h"
3636
#include "lldb/Target/Language.h"
3737
#include "lldb/Target/LanguageRuntime.h"
38-
#include "lldb/Target/ObjCLanguageRuntime.h"
3938
#include "lldb/Target/Process.h"
4039
#include "lldb/Target/StackFrame.h"
4140
#include "lldb/Target/Target.h"
@@ -280,51 +279,21 @@ CompilerType ValueObject::MaybeCalculateCompleteType() {
280279
return compiler_type;
281280
}
282281

283-
CompilerType class_type;
284-
bool is_pointer_type = false;
285-
286-
if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type)) {
287-
is_pointer_type = true;
288-
} else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type)) {
289-
class_type = compiler_type;
290-
} else {
291-
return compiler_type;
292-
}
293-
294282
m_did_calculate_complete_objc_class_type = true;
295283

296-
if (class_type) {
297-
ConstString class_name(class_type.GetConstTypeName());
298-
299-
if (class_name) {
300-
ProcessSP process_sp(
301-
GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
302-
303-
if (process_sp) {
304-
ObjCLanguageRuntime *objc_language_runtime(
305-
ObjCLanguageRuntime::Get(*process_sp));
306-
307-
if (objc_language_runtime) {
308-
TypeSP complete_objc_class_type_sp =
309-
objc_language_runtime->LookupInCompleteClassCache(class_name);
284+
ProcessSP process_sp(
285+
GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
310286

311-
if (complete_objc_class_type_sp) {
312-
CompilerType complete_class(
313-
complete_objc_class_type_sp->GetFullCompilerType());
314-
315-
if (complete_class.GetCompleteType()) {
316-
if (is_pointer_type) {
317-
m_override_type = complete_class.GetPointerType();
318-
} else {
319-
m_override_type = complete_class;
320-
}
287+
if (!process_sp)
288+
return compiler_type;
321289

322-
if (m_override_type.IsValid())
323-
return m_override_type;
324-
}
325-
}
326-
}
327-
}
290+
if (auto *runtime =
291+
process_sp->GetLanguageRuntime(GetObjectRuntimeLanguage())) {
292+
if (llvm::Optional<CompilerType> complete_type =
293+
runtime->GetRuntimeType(compiler_type)) {
294+
m_override_type = complete_type.getValue();
295+
if (m_override_type.IsValid())
296+
return m_override_type;
328297
}
329298
}
330299
return compiler_type;

‎lldb/source/Target/ObjCLanguageRuntime.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,38 @@ Status ObjCLanguageRuntime::ObjCExceptionPrecondition::ConfigurePrecondition(
398398
"The ObjC Exception breakpoint doesn't support extra options.");
399399
return error;
400400
}
401+
402+
llvm::Optional<CompilerType>
403+
ObjCLanguageRuntime::GetRuntimeType(CompilerType base_type) {
404+
CompilerType class_type;
405+
bool is_pointer_type = false;
406+
407+
if (ClangASTContext::IsObjCObjectPointerType(base_type, &class_type))
408+
is_pointer_type = true;
409+
else if (ClangASTContext::IsObjCObjectOrInterfaceType(base_type))
410+
class_type = base_type;
411+
else
412+
return llvm::None;
413+
414+
if (!class_type)
415+
return llvm::None;
416+
417+
ConstString class_name(class_type.GetConstTypeName());
418+
if (!class_name)
419+
return llvm::None;
420+
421+
TypeSP complete_objc_class_type_sp = LookupInCompleteClassCache(class_name);
422+
if (!complete_objc_class_type_sp)
423+
return llvm::None;
424+
425+
CompilerType complete_class(
426+
complete_objc_class_type_sp->GetFullCompilerType());
427+
if (complete_class.GetCompleteType()) {
428+
if (is_pointer_type)
429+
return complete_class.GetPointerType();
430+
else
431+
return complete_class;
432+
}
433+
434+
return llvm::None;
435+
}

0 commit comments

Comments
 (0)