Skip to content

Commit 9b6322b

Browse files
committed
project Adopt more C++23 features, like std::views
Also avoid taking refs to small objects like `ADT::Range` and `ADT::MemoryMap`
1 parent 5772203 commit 9b6322b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+690
-506
lines changed

include/ADT/AddressResolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace ADT {
124124
std::variant<BindParseError, RebaseParseError, PatchParseError>;
125125

126126
static auto
127-
FromLoadCommands(const ADT::MemoryMap &Map,
127+
FromLoadCommands(const ADT::MemoryMap Map,
128128
const MachO::Header &Header,
129129
const MachO::DyldInfoCommand *DyldInfo,
130130
const MachO::LinkeditDataCommand *ChainedFixups,

include/ADT/DeVirtualizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace ADT {
1818
void **EndOut = nullptr) const noexcept -> void * = 0;
1919

2020
[[nodiscard]] virtual auto
21-
getMapForVmRange(const ADT::Range &Range,
21+
getMapForVmRange(const ADT::Range Range,
2222
bool IgnoreSectionBounds = false) const noexcept
2323
-> std::optional<ADT::MemoryMap> = 0;
2424

include/ADT/Tree.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,10 @@ namespace ADT {
484484
auto Node = this->Current;
485485
this->Current = nullptr;
486486

487-
for (; DepthLevel != 0; DepthLevel--, Node = Node->parent()) {
487+
for (;
488+
this->DepthLevel != 0;
489+
this->DepthLevel--, Node = Node->parent())
490+
{
488491
if (const auto PrevSibling = Node->prevSibling()) {
489492
Current = PrevSibling->get(PrevSibling);
490493
break;

include/ADT/Trie.h

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ namespace ADT {
305305
std::unique_ptr<IterateInfo> Info;
306306
std::unique_ptr<StackInfo> NextStack;
307307

308-
TrieParser &Parser;
308+
TrieParser *Parser;
309309

310310
void SetupInfoForNewStack() noexcept {
311311
this->Info->stringRef().append(NextStack->node().prefix());
@@ -465,11 +465,11 @@ namespace ADT {
465465

466466
// Prepare the next-stack before returning.
467467
const auto Error =
468-
Parser.ParseNextNode(this->Begin,
469-
Ptr,
470-
this->End,
471-
this->Info->rangeListRef(),
472-
&this->NextStack->node());
468+
Parser->ParseNextNode(this->Begin,
469+
Ptr,
470+
this->End,
471+
this->Info->rangeListRef(),
472+
&this->NextStack->node());
473473

474474
UpdateOffset();
475475
if (Error != Error::None) {
@@ -496,6 +496,11 @@ namespace ADT {
496496
return Error::None;
497497
}
498498
public:
499+
using difference_type = std::ptrdiff_t;
500+
using value_type = IterateInfo;
501+
502+
explicit Iterator() noexcept = default;
503+
499504
explicit
500505
Iterator(uint8_t *const Begin,
501506
uint8_t *const End,
@@ -504,7 +509,7 @@ namespace ADT {
504509
const ParseOptions &Options = ParseOptions()) noexcept
505510
: Begin(Begin), End(End),
506511
Info(std::make_unique<IterateInfo>(ExportInfoParser)),
507-
Parser(Parser)
512+
Parser(&Parser)
508513
{
509514
Info->setMaxDepth(Options.MaxDepth);
510515

@@ -594,6 +599,34 @@ namespace ADT {
594599
return this->Info.get();
595600
}
596601

602+
[[nodiscard]] constexpr
603+
auto operator<=>(const Iterator &Other) const noexcept = default;
604+
605+
[[nodiscard]]
606+
inline auto operator==(const Iterator &Other) const noexcept {
607+
if (this->Begin != Other.Begin && this->End != Other.End) {
608+
return false;
609+
}
610+
611+
if (this->Info.StackList.empty()) {
612+
if (Other.Info.StackList.empty()) {
613+
return true;
614+
} else {
615+
return false;
616+
}
617+
} else if (Other.Info.StackList.empty()) {
618+
return false;
619+
}
620+
621+
const auto &Stack = this->Info.StackList.back();
622+
const auto &OtherStack = Other.Info.StackList.back();
623+
624+
const auto &Node = Stack.node();
625+
const auto &OtherNode = OtherStack.node();
626+
627+
return Node.offset() == OtherNode.offset();
628+
}
629+
597630
[[nodiscard]]
598631
inline auto operator==(const IteratorEnd &) const noexcept {
599632
return this->isAtEnd();
@@ -629,6 +662,11 @@ namespace ADT {
629662
return *this;
630663
}
631664
public:
665+
using difference_type = std::ptrdiff_t;
666+
using value_type = IterateInfo;
667+
668+
ExportIterator() noexcept = default;
669+
632670
explicit
633671
ExportIterator(
634672
uint8_t *Begin,
@@ -647,7 +685,7 @@ namespace ADT {
647685

648686
explicit
649687
ExportIterator(
650-
const ADT::MemoryMap &Map,
688+
const ADT::MemoryMap Map,
651689
TrieParser &TrieParser,
652690
T &ExportInfoParser,
653691
const ParseOptions &Options = ParseOptions()) noexcept
@@ -660,6 +698,10 @@ namespace ADT {
660698
}
661699
}
662700

701+
inline ExportIterator(const ExportIterator &Other) noexcept {
702+
this->Iter = Other.Iter;
703+
}
704+
663705
[[nodiscard]] inline auto &info() noexcept {
664706
return this->Iter.info();
665707
}
@@ -703,7 +745,7 @@ namespace ADT {
703745
return this->Iter.info();
704746
}
705747

706-
[[nodiscard]] inline const auto &operator*() const noexcept {
748+
[[nodiscard]] inline auto &operator*() const noexcept {
707749
return this->Iter.info();
708750
}
709751

@@ -715,6 +757,21 @@ namespace ADT {
715757
return &this->Iter.info();
716758
}
717759

760+
inline auto operator=(const ExportIterator &Other) noexcept
761+
-> decltype(*this)
762+
{
763+
this->Iter = Other.Iter;
764+
return *this;
765+
}
766+
767+
[[nodiscard]] constexpr auto
768+
operator<=>(const ExportIterator &Other) const noexcept = default;
769+
770+
[[nodiscard]]
771+
inline auto operator==(const Iterator &Other) const noexcept {
772+
return this->Iter == Other.Iter;
773+
}
774+
718775
[[nodiscard]]
719776
inline auto operator==(const IteratorEnd &End) const noexcept {
720777
return this->Iter== End;
@@ -741,7 +798,7 @@ namespace ADT {
741798
ExportInfoParser(ExportInfoParser) {};
742799

743800
constexpr explicit
744-
Trie(const ADT::MemoryMap &Map,
801+
Trie(const ADT::MemoryMap Map,
745802
TrieParser &TrieParser,
746803
T &ExportInfoParser) noexcept
747804
: Begin(Map.base<uint8_t>()),
@@ -803,7 +860,7 @@ namespace ADT {
803860
ExportInfoParser(ExportInfoParser) {}
804861

805862
explicit
806-
ExportMap(const ADT::MemoryMap &Map,
863+
ExportMap(const ADT::MemoryMap Map,
807864
TrieParser &Parser,
808865
T &ExportInfoParser) noexcept
809866
: Begin(Map.base<uint8_t>()),

include/Dyld3/Platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <optional>
1111
#include <string_view>
12+
1213
#include "Utils/Assert.h"
1314

1415
namespace Dyld3 {

include/DyldSharedCache/DeVirtualizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace DyldSharedCache {
2828
void **EndOut = nullptr) const noexcept override;
2929

3030
[[nodiscard]] std::optional<ADT::MemoryMap>
31-
getMapForVmRange(const ADT::Range &Range,
31+
getMapForVmRange(const ADT::Range Range,
3232
bool IgnoreProtBounds = false) const noexcept override;
3333

3434
[[nodiscard]] constexpr auto map() const noexcept {

include/DyldSharedCache/Headers.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,6 @@ namespace DyldSharedCache {
483483
[[nodiscard]] constexpr auto hasSubCacheArray() const noexcept;
484484
};
485485

486-
struct SlideInfoBase {
487-
uint32_t Version;
488-
};
489-
490486
enum class SlideInfoVersion {
491487
V1 = 1,
492488
V2,
@@ -495,6 +491,14 @@ namespace DyldSharedCache {
495491
V5
496492
};
497493

494+
struct SlideInfoBase {
495+
uint32_t Version;
496+
497+
[[nodiscard]] constexpr auto version() const noexcept {
498+
return SlideInfoVersion(this->Version);
499+
}
500+
};
501+
498502
struct SlideInfoV1 : public SlideInfoBase {
499503
struct Entry {
500504
uint8_t Bits[4096 / (8 * 4)];

include/DyldSharedCache/ProgramTrie.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace DyldSharedCache {
5454
: ADT::Trie<DylibIndexInfo>(Begin, End, TrieParser, Info) {}
5555

5656
explicit
57-
ProgramTrieMap(const ADT::MemoryMap &Map,
57+
ProgramTrieMap(const ADT::MemoryMap Map,
5858
ADT::TrieParser &TrieParser) noexcept
5959
: ADT::Trie<DylibIndexInfo>(Map, TrieParser, Info) {}
6060

include/Mach/Machine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <optional>
1111
#include <string_view>
12+
1213
#include "Utils/Assert.h"
1314

1415
namespace Mach {

include/MachO/BindInfo.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ namespace MachO {
733733
bool Is64Bit : 1;
734734
public:
735735
explicit
736-
BindOpcodeListBase(const ADT::MemoryMap &Map,
736+
BindOpcodeListBase(const ADT::MemoryMap Map,
737737
const bool Is64Bit) noexcept
738738
: Begin(Map.base<const BindByte>()), End(Map.end<const BindByte>()),
739739
Is64Bit(Is64Bit) {}
@@ -1179,7 +1179,7 @@ namespace MachO {
11791179
};
11801180

11811181
for (; !this->isAtEnd(); this->Iter++) {
1182-
if (Iter->hasError()) {
1182+
if (this->Iter->hasError()) {
11831183
return this->Iter->error();
11841184
}
11851185

@@ -1380,8 +1380,8 @@ namespace MachO {
13801380
Is64Bit(Is64Bit) {}
13811381

13821382
constexpr explicit
1383-
BindActionListBase(const ADT::MemoryMap &Map,
1384-
const ADT::Range &Range,
1383+
BindActionListBase(const ADT::MemoryMap Map,
1384+
const ADT::Range Range,
13851385
const SegmentList &SegList,
13861386
const bool Is64Bit) noexcept
13871387
: Map(Map.base<uint8_t>()), SegList(SegList),
@@ -1461,7 +1461,7 @@ namespace MachO {
14611461
}
14621462

14631463
[[nodiscard]] inline auto
1464-
getMapForVmRange(ADT::Range &VmRange,
1464+
getMapForVmRange(ADT::Range VmRange,
14651465
const SegmentList &SegmentList,
14661466
UnorderedMap &MapOut) const noexcept
14671467
-> BindOpcodeParseResult
@@ -1541,4 +1541,3 @@ namespace MachO {
15411541
using LazyBindActionList = BindActionListBase<BindInfoKind::Lazy>;
15421542
using WeakBindActionList = BindActionListBase<BindInfoKind::Weak>;
15431543
}
1544-

0 commit comments

Comments
 (0)