1
0
mirror of synced 2025-01-30 19:43:43 +01:00

patterns: Added [[inline]] attribute

This commit is contained in:
WerWolv 2021-09-27 13:31:10 +02:00
parent 5db608c3fc
commit 888976873a
3 changed files with 131 additions and 140 deletions

View File

@ -1,47 +0,0 @@
namespace std::math {
fn min_u(u128 a, u128 b) {
return (a < b) ? a : b;
};
fn min_i(s128 a, s128 b) {
return (a < b) ? a : b;
};
fn min_f(double a, double b) {
return (a < b) ? a : b;
};
fn max_u(u128 a, u128 b) {
return (a > b) ? a : b;
};
fn max_i(s128 a, s128 b) {
return (a > b) ? a : b;
};
fn max_f(double a, double b) {
return (a > b) ? a : b;
};
fn abs_i(s128 value) {
return value < 0 ? -value : value;
};
fn abs_d(double value) {
return value < 0 ? -value : value;
};
fn ceil(double value) {
s128 cast;
cast = value;
return cast + 1;
};
}
std::print("{}", std::math::ceil(123.6));

View File

@ -572,6 +572,14 @@ namespace hex::pl {
pattern->setComment(*value);
} else if (name == "hidden" && noValue()) {
pattern->setHidden(true);
} else if (name == "inline" && noValue()) {
auto inlinable = dynamic_cast<Inlinable*>(pattern);
if (inlinable == nullptr)
LogConsole::abortEvaluation("inline attribute can only be applied to nested types", node);
else
inlinable->setInlined(true);
} else if (name == "format" && requiresValue()) {
auto functions = evaluator->getCustomFunctions();
if (!functions.contains(*value))

View File

@ -43,6 +43,14 @@ namespace hex::pl {
}
class Inlinable {
public:
[[nodiscard]] bool isInlined() const { return this->m_inlined; }
void setInlined(bool inlined) { this->m_inlined = inlined; }
private:
bool m_inlined = false;
};
class PatternData {
public:
PatternData(u64 offset, size_t size, u32 color = 0)
@ -619,7 +627,7 @@ namespace hex::pl {
[[nodiscard]] bool operator==(const PatternData &other) const override { return areCommonPropertiesEqual<decltype(*this)>(other); }
};
class PatternDataDynamicArray : public PatternData {
class PatternDataDynamicArray : public PatternData, public Inlinable {
public:
PatternDataDynamicArray(u64 offset, size_t size, u32 color = 0)
: PatternData(offset, size, color) {
@ -654,9 +662,11 @@ namespace hex::pl {
if (this->m_entries.empty())
return;
bool open = true;
if (this->isInlined()) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
bool open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap);
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
this->drawCommentTooltip();
ImGui::TableNextColumn();
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
@ -676,11 +686,13 @@ namespace hex::pl {
ImGui::TableNextColumn();
ImGui::Text("%s", "{ ... }");
}
if (open) {
for (auto &member : this->m_entries)
member->draw(provider);
if (!this->isInlined())
ImGui::TreePop();
}
}
@ -747,7 +759,7 @@ namespace hex::pl {
std::vector<PatternData*> m_entries;
};
class PatternDataStaticArray : public PatternData {
class PatternDataStaticArray : public PatternData, public Inlinable {
public:
PatternDataStaticArray(u64 offset, size_t size, u32 color = 0)
: PatternData(offset, size, color) {
@ -769,9 +781,12 @@ namespace hex::pl {
if (this->getEntryCount() == 0)
return;
bool open = true;
if (this->isInlined()) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
bool open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap);
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
this->drawCommentTooltip();
ImGui::TableNextColumn();
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
@ -791,6 +806,7 @@ namespace hex::pl {
ImGui::TableNextColumn();
ImGui::Text("%s", "{ ... }");
}
if (open) {
auto entry = this->m_template->clone();
@ -801,6 +817,7 @@ namespace hex::pl {
}
delete entry;
if (!this->isInlined())
ImGui::TreePop();
}
}
@ -879,7 +896,7 @@ namespace hex::pl {
size_t m_entryCount;
};
class PatternDataStruct : public PatternData {
class PatternDataStruct : public PatternData, public Inlinable {
public:
PatternDataStruct(u64 offset, size_t size, u32 color = 0) : PatternData(offset, size, color){
}
@ -908,9 +925,12 @@ namespace hex::pl {
}
void createEntry(prv::Provider* &provider) override {
bool open = true;
if (!this->isInlined()) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
bool open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
this->drawCommentTooltip();
ImGui::TableNextColumn();
ImGui::TableNextColumn();
@ -921,11 +941,13 @@ namespace hex::pl {
ImGui::TextColored(ImColor(0xFFD69C56), "struct"); ImGui::SameLine(); ImGui::Text("%s", this->getTypeName().c_str());
ImGui::TableNextColumn();
ImGui::Text("%s", "{ ... }");
}
if (open) {
for (auto &member : this->m_sortedMembers)
member->draw(provider);
if (!this->isInlined())
ImGui::TreePop();
}
@ -1009,7 +1031,7 @@ namespace hex::pl {
std::vector<PatternData*> m_sortedMembers;
};
class PatternDataUnion : public PatternData {
class PatternDataUnion : public PatternData, public Inlinable {
public:
PatternDataUnion(u64 offset, size_t size, u32 color = 0) : PatternData(offset, size, color) {
@ -1039,9 +1061,12 @@ namespace hex::pl {
}
void createEntry(prv::Provider* &provider) override {
bool open = true;
if (this->isInlined()) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
bool open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap);
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
this->drawCommentTooltip();
ImGui::TableNextColumn();
ImGui::TableNextColumn();
@ -1053,11 +1078,13 @@ namespace hex::pl {
ImGui::TableNextColumn();
ImGui::Text("%s", "{ ... }");
}
if (open) {
for (auto &member : this->m_sortedMembers)
member->draw(provider);
if (!this->isInlined())
ImGui::TreePop();
}
@ -1252,7 +1279,6 @@ namespace hex::pl {
std::reverse(value.begin(), value.end());
ImGui::TableNextRow();
ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap);
ImGui::TableNextColumn();
ImGui::Text("%s", this->getDisplayName().c_str());
ImGui::TableNextColumn();
@ -1303,7 +1329,7 @@ namespace hex::pl {
u8 m_bitOffset, m_bitSize;
};
class PatternDataBitfield : public PatternData {
class PatternDataBitfield : public PatternData, public Inlinable {
public:
PatternDataBitfield(u64 offset, size_t size, u32 color = 0) : PatternData(offset, size, color) {
@ -1330,9 +1356,11 @@ namespace hex::pl {
if (this->m_endian == std::endian::little)
std::reverse(value.begin(), value.end());
bool open = true;
if (this->isInlined()) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
bool open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap);
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
this->drawCommentTooltip();
ImGui::TableNextColumn();
ImGui::TableNextColumn();
@ -1349,12 +1377,14 @@ namespace hex::pl {
valueString += "}";
ImGui::TextUnformatted(valueString.c_str());
}
if (open) {
for (auto &field : this->m_fields)
field->draw(provider);
if (!this->isInlined())
ImGui::TreePop();
}