Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/include/pl/patterns/pattern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ namespace pl::ptrn {
friend class core::Evaluator;
};

inline std::shared_ptr<Pattern> make_shared_pattern_raw(Pattern *p)
{
return std::shared_ptr<Pattern>(p, [](Pattern*){});
}

class Pattern {
public:
constexpr static u64 MainSectionId = 0x0000'0000'0000'0000;
Expand Down
4 changes: 2 additions & 2 deletions lib/include/pl/patterns/pattern_array_dynamic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace pl::ptrn {

result += " ]";

return Pattern::callUserFormatFunc(PatternRef::create(this), true).value_or(result);
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this), true).value_or(result);
}

[[nodiscard]] bool operator==(const Pattern &other) const override {
Expand Down Expand Up @@ -208,7 +208,7 @@ namespace pl::ptrn {
}

std::string formatDisplayValue() override {
return Pattern::callUserFormatFunc(PatternRef::create(this)).value_or("[ ... ]");
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this)).value_or("[ ... ]");
}

std::vector<u8> getRawBytes() override {
Expand Down
4 changes: 2 additions & 2 deletions lib/include/pl/patterns/pattern_array_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace pl::ptrn {
}

std::string formatDisplayValue() override {
return Pattern::callUserFormatFunc(PatternRef::create(this)).value_or("[ ... ]");
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this)).value_or("[ ... ]");
}

[[nodiscard]] std::string toString() override {
Expand Down Expand Up @@ -220,7 +220,7 @@ namespace pl::ptrn {

result += " ]";

return Pattern::callUserFormatFunc(PatternRef::create(this), true).value_or(result);
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this), true).value_or(result);
}

std::vector<u8> getRawBytes() override {
Expand Down
10 changes: 5 additions & 5 deletions lib/include/pl/patterns/pattern_bitfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ namespace pl::ptrn {

result += " ]";

return Pattern::callUserFormatFunc(PatternRef::create(this), true).value_or(result);
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this), true).value_or(result);
}

[[nodiscard]] bool operator==(const Pattern &other) const override {
Expand Down Expand Up @@ -495,7 +495,7 @@ namespace pl::ptrn {
}

std::string formatDisplayValue() override {
return Pattern::callUserFormatFunc(PatternRef::create(this)).value_or("[ ... ]");
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this)).value_or("[ ... ]");
}

void sort(const std::function<bool (const Pattern *, const Pattern *)> &comparator) override {
Expand Down Expand Up @@ -691,7 +691,7 @@ namespace pl::ptrn {

result += " }";

return Pattern::callUserFormatFunc(PatternRef::create(this), true).value_or(result);
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this), true).value_or(result);
}

std::string formatDisplayValue() override {
Expand Down Expand Up @@ -725,9 +725,9 @@ namespace pl::ptrn {
}

if (valueString.size() > 64)
return Pattern::callUserFormatFunc(PatternRef::create(this)).value_or(fmt::format("{{ ... }}", valueString));
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this)).value_or(fmt::format("{{ ... }}", valueString));
else
return Pattern::callUserFormatFunc(PatternRef::create(this)).value_or(fmt::format("{{ {} }}", valueString));
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this)).value_or(fmt::format("{{ {} }}", valueString));
}

void setEndian(std::endian endian) override {
Expand Down
2 changes: 1 addition & 1 deletion lib/include/pl/patterns/pattern_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace pl::ptrn {

[[nodiscard]] std::string toString() override {
u128 value = this->getValue().toUnsigned();
return Pattern::callUserFormatFunc(PatternRef::create(this), true).value_or(getEnumName(this->getTypeName(), value, m_enumValues));
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this), true).value_or(getEnumName(this->getTypeName(), value, m_enumValues));
}

std::vector<u8> getRawBytes() override {
Expand Down
2 changes: 1 addition & 1 deletion lib/include/pl/patterns/pattern_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace pl::ptrn {
[[nodiscard]] std::string toString() override {
auto result = this->m_pointedAt->toString();

return Pattern::callUserFormatFunc(PatternRef::create(this), true).value_or(result);
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this), true).value_or(result);
}

std::vector<u8> getRawBytes() override {
Expand Down
4 changes: 2 additions & 2 deletions lib/include/pl/patterns/pattern_struct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace pl::ptrn {

result += " }";

return Pattern::callUserFormatFunc(PatternRef::create(this), true).value_or(result);
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this), true).value_or(result);
}

void sort(const std::function<bool (const Pattern *, const Pattern *)> &comparator) override {
Expand Down Expand Up @@ -199,7 +199,7 @@ namespace pl::ptrn {
}

std::string formatDisplayValue() override {
return Pattern::callUserFormatFunc(PatternRef::create(this)).value_or("{ ... }");
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this)).value_or("{ ... }");
}

std::vector<u8> getRawBytes() override {
Expand Down
4 changes: 2 additions & 2 deletions lib/include/pl/patterns/pattern_union.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace pl::ptrn {

result += " }";

return Pattern::callUserFormatFunc(PatternRef::create(this), true).value_or(result);
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this), true).value_or(result);
}

void sort(const std::function<bool (const Pattern *, const Pattern *)> &comparator) override {
Expand Down Expand Up @@ -198,7 +198,7 @@ namespace pl::ptrn {
}

std::string formatDisplayValue() override {
return Pattern::callUserFormatFunc(PatternRef::create(this)).value_or("{ ... }");
return Pattern::callUserFormatFunc(make_shared_pattern_raw(this)).value_or("{ ... }");
}

std::vector<u8> getRawBytes() override {
Expand Down
Loading