1
0
mirror of synced 2024-12-11 07:26:00 +01:00

patterns: Update pattern_language and implement support for new bitfield features (#992)

This requires https://github.com/WerWolv/PatternLanguage/pull/34 to be
merged first, and then this can be amended to update the submodule and
merged to add support for the new features.
This commit is contained in:
Zaggy1024 2023-03-26 04:01:37 -05:00 committed by GitHub
parent 5e175b118d
commit 5fa264ea18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 18 deletions

@ -1 +1 @@
Subproject commit a2fbf46b5132f5c4a061527f4caf12d11ac0eebf Subproject commit ea717d9c835e0f1364e8c8befed674becef5222f

View File

@ -29,6 +29,7 @@ namespace hex::plugin::builtin::ui {
void visit(pl::ptrn::PatternArrayDynamic& pattern) override; void visit(pl::ptrn::PatternArrayDynamic& pattern) override;
void visit(pl::ptrn::PatternArrayStatic& pattern) override; void visit(pl::ptrn::PatternArrayStatic& pattern) override;
void visit(pl::ptrn::PatternBitfieldField& pattern) override; void visit(pl::ptrn::PatternBitfieldField& pattern) override;
void visit(pl::ptrn::PatternBitfieldArray& pattern) override;
void visit(pl::ptrn::PatternBitfield& pattern) override; void visit(pl::ptrn::PatternBitfield& pattern) override;
void visit(pl::ptrn::PatternBoolean& pattern) override; void visit(pl::ptrn::PatternBoolean& pattern) override;
void visit(pl::ptrn::PatternCharacter& pattern) override; void visit(pl::ptrn::PatternCharacter& pattern) override;

View File

@ -92,13 +92,34 @@ namespace hex::plugin::builtin::ui {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
} }
inline void drawOffsetColumnForBitfieldMember(const pl::ptrn::PatternBitfieldMember &pattern) {
auto bitOffset = pattern.getBitOffsetForDisplay();
if (pattern.getBitSize() <= 1)
ImGui::TextFormatted("bit {0}", bitOffset);
else
ImGui::TextFormatted("bits {0} - {1}", bitOffset, bitOffset + pattern.getBitSize() - 1);
}
void drawOffsetColumn(const pl::ptrn::Pattern& pattern) { void drawOffsetColumn(const pl::ptrn::Pattern& pattern) {
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", pattern.getOffset(), pattern.getOffset() + pattern.getSize() - (pattern.getSize() == 0 ? 0 : 1)); if (auto *bitfieldMember = dynamic_cast<pl::ptrn::PatternBitfieldMember const*>(&pattern); bitfieldMember != nullptr && bitfieldMember->getParentBitfield() != nullptr)
drawOffsetColumnForBitfieldMember(*bitfieldMember);
else
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", pattern.getOffset(), pattern.getOffset() + pattern.getSize() - (pattern.getSize() == 0 ? 0 : 1));
ImGui::TableNextColumn(); ImGui::TableNextColumn();
} }
inline void drawSizeColumnForBitfieldMember(const pl::ptrn::PatternBitfieldMember &pattern) {
if (pattern.getBitSize() == 1)
ImGui::TextFormatted("1 bit");
else
ImGui::TextFormatted("{0} bits", pattern.getBitSize());
}
void drawSizeColumn(const pl::ptrn::Pattern& pattern) { void drawSizeColumn(const pl::ptrn::Pattern& pattern) {
ImGui::TextFormatted("0x{0:04X}", pattern.getSize()); if (auto *bitfieldMember = dynamic_cast<pl::ptrn::PatternBitfieldMember const*>(&pattern); bitfieldMember != nullptr && bitfieldMember->getParentBitfield() != nullptr)
drawSizeColumnForBitfieldMember(*bitfieldMember);
else
ImGui::TextFormatted("0x{0:04X}", pattern.getSize());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
} }
@ -261,18 +282,9 @@ namespace hex::plugin::builtin::ui {
ImGui::SameLine(); ImGui::SameLine();
drawNameColumn(pattern); drawNameColumn(pattern);
drawColorColumn(pattern); drawColorColumn(pattern);
drawOffsetColumnForBitfieldMember(pattern);
auto firstBitIdx = pattern.getBitOffset();
auto lastBitIdx = firstBitIdx + (pattern.getBitSize() - 1);
if (firstBitIdx == lastBitIdx)
ImGui::TextFormatted("bit {0}", firstBitIdx);
else
ImGui::TextFormatted("bits {0} - {1}", firstBitIdx, lastBitIdx);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (pattern.getBitSize() == 1) drawSizeColumnForBitfieldMember(pattern);
ImGui::TextFormatted("{0} bit", pattern.getBitSize());
else
ImGui::TextFormatted("{0} bits", pattern.getBitSize());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "bits"); ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "bits");
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@ -280,6 +292,10 @@ namespace hex::plugin::builtin::ui {
ImGui::TextFormatted("{}", pattern.getFormattedValue()); ImGui::TextFormatted("{}", pattern.getFormattedValue());
} }
void PatternDrawer::visit(pl::ptrn::PatternBitfieldArray& pattern) {
drawArray(pattern, pattern, pattern.isInlined());
}
void PatternDrawer::visit(pl::ptrn::PatternBitfield& pattern) { void PatternDrawer::visit(pl::ptrn::PatternBitfield& pattern) {
bool open = true; bool open = true;
if (!pattern.isInlined() && this->m_treeStyle != TreeStyle::Flattened) { if (!pattern.isInlined() && this->m_treeStyle != TreeStyle::Flattened) {
@ -770,14 +786,14 @@ namespace hex::plugin::builtin::ui {
return left->getDisplayName() > right->getDisplayName(); return left->getDisplayName() > right->getDisplayName();
} else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("offset")) { } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("offset")) {
if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending)
return left->getOffset() < right->getOffset(); return left->getOffsetForSorting() < right->getOffsetForSorting();
else else
return left->getOffset() > right->getOffset(); return left->getOffsetForSorting() > right->getOffsetForSorting();
} else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("size")) { } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("size")) {
if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending)
return left->getSize() < right->getSize(); return left->getSizeForSorting() < right->getSizeForSorting();
else else
return left->getSize() > right->getSize(); return left->getSizeForSorting() > right->getSizeForSorting();
} else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("value")) { } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("value")) {
if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending)
return left->getValue() < right->getValue(); return left->getValue() < right->getValue();