Skip to content

Commit 8af00d6

Browse files
authored
Merge pull request #8217 from Michael137/lldb/type-synthetic-return-api-nfc-to-next
[lldb][Swift][NFC] Adapt Swift formatters to new TypeSynthetic::Update() API This patch adapts the Swift formatters to the new return type of the TypeSynthetic::Update API. * `return false` -> `ChildCacheState::eRefetch` * `return true` -> `ChildCacheState::eReuse`
2 parents e917b82 + a6c7252 commit 8af00d6

12 files changed

+75
-57
lines changed

lldb/source/Plugins/Language/Swift/FoundationValueTypes.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "lldb/Target/Target.h"
2525
#include "lldb/Utility/DataExtractor.h"
2626
#include "lldb/Utility/Status.h"
27+
#include "lldb/lldb-enumerations.h"
2728

2829
using namespace lldb;
2930
using namespace lldb_private;
@@ -590,7 +591,7 @@ class URLComponentsSyntheticChildrenFrontEnd
590591
return nullptr;
591592
}
592593

593-
bool Update() override {
594+
lldb::ChildCacheState Update() override {
594595
static ConstString g__handle("_handle");
595596
static ConstString g__pointer("_pointer");
596597

@@ -609,23 +610,23 @@ class URLComponentsSyntheticChildrenFrontEnd
609610
ValueObjectSP underlying_sp =
610611
m_backend.GetChildAtNamePath({g__handle, g__pointer});
611612
if (!underlying_sp)
612-
return false;
613+
return ChildCacheState::eRefetch;
613614

614615
ObjCLanguageRuntime *objc_runtime =
615616
ObjCLanguageRuntime::Get(*m_backend.GetProcessSP());
616617
if (!objc_runtime)
617-
return false;
618+
return ChildCacheState::eRefetch;
618619

619620
ObjCLanguageRuntime::ClassDescriptorSP class_descriptor_sp =
620621
objc_runtime->GetClassDescriptor(*underlying_sp);
621622
if (!class_descriptor_sp)
622-
return false;
623+
return ChildCacheState::eRefetch;
623624

624625
m_synth_backend_up = std::make_unique<ObjCRuntimeSyntheticProvider>(
625626
SyntheticChildren::Flags(), class_descriptor_sp);
626627
m_synth_frontend_up = m_synth_backend_up->GetFrontEnd(*underlying_sp);
627628
if (!m_synth_frontend_up)
628-
return false;
629+
return ChildCacheState::eRefetch;
629630
else
630631
m_synth_frontend_up->Update();
631632

@@ -640,7 +641,7 @@ class URLComponentsSyntheticChildrenFrontEnd
640641

641642
SetValid(CheckValid());
642643

643-
return false;
644+
return ChildCacheState::eRefetch;
644645
}
645646

646647
bool MightHaveChildren() override { return true; }

lldb/source/Plugins/Language/Swift/ObjCRuntimeSyntheticProvider.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
1717
#include "lldb/DataFormatters/TypeSynthetic.h"
18+
#include "lldb/lldb-enumerations.h"
1819

1920
namespace lldb_private {
2021
class ObjCRuntimeSyntheticProvider : public SyntheticChildren {
@@ -49,7 +50,9 @@ class ObjCRuntimeSyntheticProvider : public SyntheticChildren {
4950

5051
size_t CalculateNumChildren() override;
5152
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
52-
bool Update() override { return false; }
53+
lldb::ChildCacheState Update() override {
54+
return lldb::ChildCacheState::eRefetch;
55+
}
5356
bool MightHaveChildren() override { return true; }
5457
size_t GetIndexOfChildWithName(ConstString name) override;
5558

lldb/source/Plugins/Language/Swift/SwiftArray.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
// FIXME: we should not need this
2424
#include "Plugins/Language/ObjC/Cocoa.h"
25+
#include "lldb/lldb-enumerations.h"
2526

2627
using namespace lldb;
2728
using namespace lldb_private;
@@ -488,9 +489,9 @@ lldb_private::formatters::swift::ArraySyntheticFrontEnd::GetChildAtIndex(
488489
return child_sp;
489490
}
490491

491-
bool lldb_private::formatters::swift::ArraySyntheticFrontEnd::Update() {
492+
lldb::ChildCacheState lldb_private::formatters::swift::ArraySyntheticFrontEnd::Update() {
492493
m_array_buffer = SwiftArrayBufferHandler::CreateBufferHandler(m_backend);
493-
return false;
494+
return ChildCacheState::eRefetch;
494495
}
495496

496497
bool lldb_private::formatters::swift::ArraySyntheticFrontEnd::IsValid() {

lldb/source/Plugins/Language/Swift/SwiftArray.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef liblldb_SwiftArray_h_
1414
#define liblldb_SwiftArray_h_
1515

16+
#include "lldb/lldb-enumerations.h"
1617
#include "lldb/lldb-forward.h"
1718

1819
#include "lldb/Utility/ConstString.h"
@@ -165,7 +166,7 @@ class ArraySyntheticFrontEnd : public SyntheticChildrenFrontEnd {
165166
ArraySyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
166167
size_t CalculateNumChildren() override;
167168
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
168-
bool Update() override;
169+
lldb::ChildCacheState Update() override;
169170
bool MightHaveChildren() override;
170171
size_t GetIndexOfChildWithName(ConstString name) override;
171172
bool IsValid();

lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "lldb/Utility/DataBufferHeap.h"
2323
#include "lldb/Utility/Status.h"
2424
#include "lldb/Utility/Timer.h"
25+
#include "lldb/lldb-enumerations.h"
2526
#include "swift/AST/Types.h"
2627
#include "swift/Demangling/ManglingMacros.h"
2728
#include "llvm/ADT/StringRef.h"
@@ -712,7 +713,7 @@ class EnumSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
712713

713714
size_t CalculateNumChildren() override;
714715
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
715-
bool Update() override;
716+
lldb::ChildCacheState Update() override;
716717
bool MightHaveChildren() override;
717718
size_t GetIndexOfChildWithName(ConstString name) override;
718719

@@ -748,13 +749,14 @@ lldb_private::formatters::swift::EnumSyntheticFrontEnd::GetChildAtIndex(
748749
return m_backend.GetChildAtIndex(m_child_index, true);
749750
}
750751

751-
bool lldb_private::formatters::swift::EnumSyntheticFrontEnd::Update() {
752+
lldb::ChildCacheState
753+
lldb_private::formatters::swift::EnumSyntheticFrontEnd::Update() {
752754
m_element_name.Clear();
753755
m_child_index = UINT32_MAX;
754756
m_exe_ctx_ref = m_backend.GetExecutionContextRef();
755757
m_element_name.SetCString(m_backend.GetValueAsCString());
756758
m_child_index = m_backend.GetIndexOfChildWithName(m_element_name);
757-
return false;
759+
return ChildCacheState::eRefetch;
758760
}
759761

760762
bool lldb_private::formatters::swift::EnumSyntheticFrontEnd::

lldb/source/Plugins/Language/Swift/SwiftHashedContainer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "lldb/Utility/DataBufferHeap.h"
2323

2424
#include "Plugins/Language/ObjC/NSDictionary.h"
25+
#include "lldb/lldb-enumerations.h"
2526

2627
#include "llvm/ADT/StringRef.h"
2728

@@ -719,10 +720,10 @@ HashedSyntheticChildrenFrontEnd::GetChildAtIndex(size_t idx) {
719720
return child_sp;
720721
}
721722

722-
bool
723+
lldb::ChildCacheState
723724
HashedSyntheticChildrenFrontEnd::Update() {
724725
m_buffer = m_config.CreateHandler(m_backend);
725-
return false;
726+
return ChildCacheState::eRefetch;
726727
}
727728

728729
bool

lldb/source/Plugins/Language/Swift/SwiftHashedContainer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef liblldb_SwiftHashedContainer_h_
1414
#define liblldb_SwiftHashedContainer_h_
1515

16+
#include "lldb/lldb-enumerations.h"
1617
#include "lldb/lldb-forward.h"
1718

1819
#include "lldb/Utility/ConstString.h"
@@ -135,7 +136,7 @@ class HashedSyntheticChildrenFrontEnd : public SyntheticChildrenFrontEnd {
135136

136137
size_t CalculateNumChildren() override;
137138
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
138-
bool Update() override;
139+
lldb::ChildCacheState Update() override;
139140
bool MightHaveChildren() override;
140141
size_t GetIndexOfChildWithName(ConstString name) override;
141142

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <functional>
4141
#include <mutex>
4242

43+
#include "lldb/lldb-enumerations.h"
4344
#include "swift/AST/ImportCache.h"
4445
#include "swift/Basic/InitializeSwiftModules.h"
4546
#include "swift/Demangling/ManglingMacros.h"
@@ -850,7 +851,7 @@ class ValueObjectWrapperSyntheticChildren : public SyntheticChildren {
850851
return m_backend.GetName() == name ? 0 : UINT32_MAX;
851852
}
852853

853-
bool Update() override { return false; }
854+
lldb::ChildCacheState Update() override { return ChildCacheState::eRefetch; }
854855

855856
bool MightHaveChildren() override { return true; }
856857

lldb/source/Plugins/Language/Swift/SwiftOptional.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Target/Process.h"
1919
#include "lldb/Utility/DataBufferHeap.h"
2020
#include "lldb/Utility/DataExtractor.h"
21+
#include "lldb/lldb-enumerations.h"
2122

2223
using namespace lldb;
2324
using namespace lldb_private;
@@ -227,7 +228,7 @@ lldb::ValueObjectSP lldb_private::formatters::swift::
227228
return child;
228229
}
229230

230-
bool lldb_private::formatters::swift::SwiftOptionalSyntheticFrontEnd::Update() {
231+
lldb::ChildCacheState lldb_private::formatters::swift::SwiftOptionalSyntheticFrontEnd::Update() {
231232
m_some = nullptr;
232233
m_is_none = true;
233234
m_children = false;
@@ -237,14 +238,14 @@ bool lldb_private::formatters::swift::SwiftOptionalSyntheticFrontEnd::Update() {
237238
if (!m_some) {
238239
m_is_none = true;
239240
m_children = false;
240-
return false;
241+
return ChildCacheState::eRefetch;
241242
}
242243

243244
m_is_none = false;
244245

245246
m_children = (m_some->GetNumChildren() > 0);
246247

247-
return false;
248+
return ChildCacheState::eRefetch;
248249
}
249250

250251
bool lldb_private::formatters::swift::SwiftOptionalSyntheticFrontEnd::

lldb/source/Plugins/Language/Swift/SwiftOptional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class SwiftOptionalSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
8484

8585
size_t CalculateNumChildren() override;
8686
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
87-
bool Update() override;
87+
lldb::ChildCacheState Update() override;
8888
bool MightHaveChildren() override;
8989
size_t GetIndexOfChildWithName(ConstString name) override;
9090
lldb::ValueObjectSP GetSyntheticValue() override;

0 commit comments

Comments
 (0)