From 88f8bb9848ddb8c63588d4ee1b9899a88e38754a Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 6 Aug 2022 21:38:09 +0200 Subject: [PATCH] sys: Updated to new pattern language library structure --- lib/external/pattern_language | 2 +- lib/libimhex/include/hex/api/event.hpp | 6 +- .../content/views/view_pattern_data.hpp | 2 +- .../content/views/view_pattern_editor.hpp | 19 +++--- plugins/builtin/include/pattern_drawer.hpp | 68 +++++++++---------- .../source/content/pl_builtin_functions.cpp | 10 +-- plugins/builtin/source/content/pl_pragmas.cpp | 6 +- .../content/views/view_pattern_data.cpp | 10 +-- .../content/views/view_pattern_editor.cpp | 44 ++++++------ plugins/builtin/source/pattern_drawer.cpp | 64 ++++++++--------- 10 files changed, 115 insertions(+), 116 deletions(-) diff --git a/lib/external/pattern_language b/lib/external/pattern_language index a8c44795d..656c97551 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit a8c44795db376db7ebc7957a11cc309cfb22e0d2 +Subproject commit 656c975514e9ebb1008b0d1153c530f2e1220aa8 diff --git a/lib/libimhex/include/hex/api/event.hpp b/lib/libimhex/include/hex/api/event.hpp index 6214f287a..9ae5afd4d 100644 --- a/lib/libimhex/include/hex/api/event.hpp +++ b/lib/libimhex/include/hex/api/event.hpp @@ -18,16 +18,12 @@ struct GLFWwindow; -namespace pl { - class Pattern; -} - namespace hex { class EventId { public: explicit constexpr EventId(const char *func = __builtin_FUNCTION(), u32 line = __builtin_LINE()) { - this->m_hash = line ^ 123456789; + this->m_hash = line ^ 987654321; for (auto c : std::string_view(func)) { this->m_hash = (this->m_hash >> 5) | (this->m_hash << 27); this->m_hash ^= c; diff --git a/plugins/builtin/include/content/views/view_pattern_data.hpp b/plugins/builtin/include/content/views/view_pattern_data.hpp index 834d9b102..a7ac7dfab 100644 --- a/plugins/builtin/include/content/views/view_pattern_data.hpp +++ b/plugins/builtin/include/content/views/view_pattern_data.hpp @@ -21,7 +21,7 @@ namespace hex::plugin::builtin { void drawContent() override; private: - std::map> m_sortedPatterns; + std::map> m_sortedPatterns; hex::PatternDrawer m_patternDrawer; }; diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 9989478c9..e250aa51a 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -12,7 +13,7 @@ #include -namespace pl { class Pattern; } +namespace pl::ptrn { class Pattern; } namespace hex::plugin::builtin { @@ -29,8 +30,8 @@ namespace hex::plugin::builtin { bool inVariable; bool outVariable; - pl::Token::ValueType type; - pl::Token::Literal value; + pl::core::Token::ValueType type; + pl::core::Token::Literal value; }; enum class EnvVarType @@ -44,7 +45,7 @@ namespace hex::plugin::builtin { struct EnvVar { u64 id; std::string name; - pl::Token::Literal value; + pl::core::Token::Literal value; EnvVarType type; bool operator==(const EnvVar &other) const { @@ -67,9 +68,9 @@ namespace hex::plugin::builtin { bool m_lastEvaluationProcessed = true; bool m_lastEvaluationResult = false; - std::optional m_lastEvaluationError; - std::vector> m_lastEvaluationLog; - std::map m_lastEvaluationOutVars; + std::optional m_lastEvaluationError; + std::vector> m_lastEvaluationLog; + std::map m_lastEvaluationOutVars; std::atomic m_runningEvaluators = 0; std::atomic m_runningParsers = 0; @@ -79,7 +80,7 @@ namespace hex::plugin::builtin { bool m_acceptPatternWindowOpen = false; TextEditor m_textEditor; - std::vector> m_console; + std::vector> m_console; std::map m_patternVariables; @@ -97,7 +98,7 @@ namespace hex::plugin::builtin { void drawEnvVars(ImVec2 size); void drawVariableSettings(ImVec2 size); - void drawPatternTooltip(pl::Pattern *pattern); + void drawPatternTooltip(pl::ptrn::Pattern *pattern); void loadPatternFile(const std::fs::path &path); diff --git a/plugins/builtin/include/pattern_drawer.hpp b/plugins/builtin/include/pattern_drawer.hpp index 027bd20c4..282a70fb4 100644 --- a/plugins/builtin/include/pattern_drawer.hpp +++ b/plugins/builtin/include/pattern_drawer.hpp @@ -7,7 +7,7 @@ namespace hex { template - concept ArrayPattern = requires(u64 displayEnd, T pattern, std::function fn) { + concept ArrayPattern = requires(u64 displayEnd, T pattern, std::function fn) { { pattern.forEachArrayEntry(displayEnd, fn) } -> std::same_as; }; @@ -15,32 +15,32 @@ namespace hex { public: PatternDrawer() = default; - void visit(pl::PatternArrayDynamic& pattern) override; - void visit(pl::PatternArrayStatic& pattern) override; - void visit(pl::PatternBitfieldField& pattern) override; - void visit(pl::PatternBitfield& pattern) override; - void visit(pl::PatternBoolean& pattern) override; - void visit(pl::PatternCharacter& pattern) override; - void visit(pl::PatternEnum& pattern) override; - void visit(pl::PatternFloat& pattern) override; - void visit(pl::PatternPadding& pattern) override; - void visit(pl::PatternPointer& pattern) override; - void visit(pl::PatternSigned& pattern) override; - void visit(pl::PatternString& pattern) override; - void visit(pl::PatternStruct& pattern) override; - void visit(pl::PatternUnion& pattern) override; - void visit(pl::PatternUnsigned& pattern) override; - void visit(pl::PatternWideCharacter& pattern) override; - void visit(pl::PatternWideString& pattern) override; + void visit(pl::ptrn::PatternArrayDynamic& pattern) override; + void visit(pl::ptrn::PatternArrayStatic& pattern) override; + void visit(pl::ptrn::PatternBitfieldField& pattern) override; + void visit(pl::ptrn::PatternBitfield& pattern) override; + void visit(pl::ptrn::PatternBoolean& pattern) override; + void visit(pl::ptrn::PatternCharacter& pattern) override; + void visit(pl::ptrn::PatternEnum& pattern) override; + void visit(pl::ptrn::PatternFloat& pattern) override; + void visit(pl::ptrn::PatternPadding& pattern) override; + void visit(pl::ptrn::PatternPointer& pattern) override; + void visit(pl::ptrn::PatternSigned& pattern) override; + void visit(pl::ptrn::PatternString& pattern) override; + void visit(pl::ptrn::PatternStruct& pattern) override; + void visit(pl::ptrn::PatternUnion& pattern) override; + void visit(pl::ptrn::PatternUnsigned& pattern) override; + void visit(pl::ptrn::PatternWideCharacter& pattern) override; + void visit(pl::ptrn::PatternWideString& pattern) override; private: - void createDefaultEntry(const pl::Pattern &pattern, const std::string &value, pl::Token::Literal &&literal) const; - void createLeafNode(const pl::Pattern& pattern) const; - bool createTreeNode(const pl::Pattern& pattern) const; + void createDefaultEntry(const pl::ptrn::Pattern &pattern, const std::string &value, pl::core::Token::Literal &&literal) const; + void createLeafNode(const pl::ptrn::Pattern& pattern) const; + bool createTreeNode(const pl::ptrn::Pattern& pattern) const; - void makeSelectable(const pl::Pattern &pattern) const; + void makeSelectable(const pl::ptrn::Pattern &pattern) const; - void draw(pl::Pattern& pattern); + void draw(pl::ptrn::Pattern& pattern); template void drawArray(T& pattern) { @@ -56,20 +56,20 @@ namespace hex { this->drawArrayEnd(pattern, opened); } - bool drawArrayRoot(pl::Pattern& pattern, size_t entryCount, bool isInlined); - void drawArrayNode(u64 idx, u64& displayEnd, pl::Pattern& pattern); - void drawArrayEnd(pl::Pattern& pattern, bool opened); + bool drawArrayRoot(pl::ptrn::Pattern& pattern, size_t entryCount, bool isInlined); + void drawArrayNode(u64 idx, u64& displayEnd, pl::ptrn::Pattern& pattern); + void drawArrayEnd(pl::ptrn::Pattern& pattern, bool opened); - void drawCommentTooltip(const pl::Pattern &pattern) const; - void drawTypenameColumn(const pl::Pattern& pattern, const std::string& pattern_name) const; - void drawNameColumn(const pl::Pattern& pattern) const; - void drawColorColumn(const pl::Pattern& pattern) const; - void drawOffsetColumn(const pl::Pattern& pattern) const; - void drawSizeColumn(const pl::Pattern& pattern) const; + void drawCommentTooltip(const pl::ptrn::Pattern &pattern) const; + void drawTypenameColumn(const pl::ptrn::Pattern& pattern, const std::string& pattern_name) const; + void drawNameColumn(const pl::ptrn::Pattern& pattern) const; + void drawColorColumn(const pl::ptrn::Pattern& pattern) const; + void drawOffsetColumn(const pl::ptrn::Pattern& pattern) const; + void drawSizeColumn(const pl::ptrn::Pattern& pattern) const; - u64& getDisplayEnd(const pl::Pattern& pattern); + u64& getDisplayEnd(const pl::ptrn::Pattern& pattern); private: - std::map m_displayEnd; + std::map m_displayEnd; }; }; \ No newline at end of file diff --git a/plugins/builtin/source/content/pl_builtin_functions.cpp b/plugins/builtin/source/content/pl_builtin_functions.cpp index e7bdf270e..665d4dfc8 100644 --- a/plugins/builtin/source/content/pl_builtin_functions.cpp +++ b/plugins/builtin/source/content/pl_builtin_functions.cpp @@ -2,18 +2,18 @@ #include -#include -#include -#include +#include +#include +#include #include namespace hex::plugin::builtin { void registerPatternLanguageFunctions() { - using namespace pl; + using namespace pl::core; using FunctionParameterCount = pl::api::FunctionParameterCount; - api::Namespace nsStdHttp = { "builtin", "std", "http" }; + pl::api::Namespace nsStdHttp = { "builtin", "std", "http" }; { /* get(url) */ ContentRegistry::PatternLanguage::addDangerousFunction(nsStdHttp, "get", FunctionParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { diff --git a/plugins/builtin/source/content/pl_pragmas.cpp b/plugins/builtin/source/content/pl_pragmas.cpp index 071df4092..9aceeb113 100644 --- a/plugins/builtin/source/content/pl_pragmas.cpp +++ b/plugins/builtin/source/content/pl_pragmas.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include namespace hex::plugin::builtin { @@ -71,10 +71,10 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::addPragma("bitfield_order", [](pl::PatternLanguage &runtime, const std::string &value) { if (value == "left_to_right") { - runtime.getInternals().evaluator->setBitfieldOrder(pl::BitfieldOrder::LeftToRight); + runtime.getInternals().evaluator->setBitfieldOrder(pl::core::BitfieldOrder::LeftToRight); return true; } else if (value == "right_to_left") { - runtime.getInternals().evaluator->setBitfieldOrder(pl::BitfieldOrder::RightToLeft); + runtime.getInternals().evaluator->setBitfieldOrder(pl::core::BitfieldOrder::RightToLeft); return true; } else { return false; diff --git a/plugins/builtin/source/content/views/view_pattern_data.cpp b/plugins/builtin/source/content/views/view_pattern_data.cpp index eb29ecc96..1cb8bc262 100644 --- a/plugins/builtin/source/content/views/view_pattern_data.cpp +++ b/plugins/builtin/source/content/views/view_pattern_data.cpp @@ -20,7 +20,7 @@ namespace hex::plugin::builtin { EventManager::unsubscribe(this); } - static bool sortPatterns(prv::Provider *provider, const ImGuiTableSortSpecs* sortSpecs, const pl::Pattern * left, const pl::Pattern * right) { + static bool sortPatterns(prv::Provider *provider, const ImGuiTableSortSpecs* sortSpecs, const pl::ptrn::Pattern * left, const pl::ptrn::Pattern * right) { if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("name")) { if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) return left->getDisplayName() > right->getDisplayName(); @@ -67,7 +67,7 @@ namespace hex::plugin::builtin { return false; } - static bool beginPatternTable(prv::Provider *&provider, const std::vector> &patterns, std::vector &sortedPatterns) { + static bool beginPatternTable(prv::Provider *&provider, const std::vector> &patterns, std::vector &sortedPatterns) { if (ImGui::BeginTable("##Patterntable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) { ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("hex.builtin.view.pattern_data.var_name"_lang, 0, 0, ImGui::GetID("name")); @@ -81,16 +81,16 @@ namespace hex::plugin::builtin { if (sortSpecs->SpecsDirty || sortedPatterns.empty()) { sortedPatterns.clear(); - std::transform(patterns.begin(), patterns.end(), std::back_inserter(sortedPatterns), [](const std::shared_ptr &pattern) { + std::transform(patterns.begin(), patterns.end(), std::back_inserter(sortedPatterns), [](const std::shared_ptr &pattern) { return pattern.get(); }); - std::sort(sortedPatterns.begin(), sortedPatterns.end(), [&sortSpecs, &provider](pl::Pattern *left, pl::Pattern *right) -> bool { + std::sort(sortedPatterns.begin(), sortedPatterns.end(), [&sortSpecs, &provider](pl::ptrn::Pattern *left, pl::ptrn::Pattern *right) -> bool { return sortPatterns(provider, sortSpecs, left, right); }); for (auto &pattern : sortedPatterns) - pattern->sort([&sortSpecs, &provider](const pl::Pattern *left, const pl::Pattern *right){ + pattern->sort([&sortSpecs, &provider](const pl::ptrn::Pattern *left, const pl::ptrn::Pattern *right){ return sortPatterns(provider, sortSpecs, left, right); }); diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 172fdc286..43269fce9 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -2,11 +2,11 @@ #include -#include #include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -418,7 +418,7 @@ namespace hex::plugin::builtin { if (!this->m_lastEvaluationResult) { if (this->m_lastEvaluationError) { TextEditor::ErrorMarkers errorMarkers = { - {this->m_lastEvaluationError->getLineNumber(), this->m_lastEvaluationError->what()} + { this->m_lastEvaluationError->line, this->m_lastEvaluationError->message } }; this->m_textEditor.SetErrorMarkers(errorMarkers); } @@ -447,16 +447,18 @@ namespace hex::plugin::builtin { const auto &[level, message] = this->m_console[i]; switch (level) { - case pl::LogConsole::Level::Debug: + using enum pl::core::LogConsole::Level; + + case Debug: ImGui::PushStyleColor(ImGuiCol_Text, this->m_textEditor.GetPalette()[u32(TextEditor::PaletteIndex::Comment)]); break; - case pl::LogConsole::Level::Info: + case Info: ImGui::PushStyleColor(ImGuiCol_Text, this->m_textEditor.GetPalette()[u32(TextEditor::PaletteIndex::Default)]); break; - case pl::LogConsole::Level::Warning: + case Warning: ImGui::PushStyleColor(ImGuiCol_Text, this->m_textEditor.GetPalette()[u32(TextEditor::PaletteIndex::Preprocessor)]); break; - case pl::LogConsole::Level::Error: + case Error: ImGui::PushStyleColor(ImGuiCol_Text, this->m_textEditor.GetPalette()[u32(TextEditor::PaletteIndex::ErrorMarker)]); break; default: @@ -591,27 +593,27 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); if (variable.outVariable) { - ImGui::TextUnformatted(pl::Token::literalToString(variable.value, true).c_str()); + ImGui::TextUnformatted(pl::core::Token::literalToString(variable.value, true).c_str()); } else if (variable.inVariable) { const std::string label { "##" + name }; - if (pl::Token::isSigned(variable.type)) { + if (pl::core::Token::isSigned(variable.type)) { i64 value = hex::get_or(variable.value, 0); ImGui::InputScalar(label.c_str(), ImGuiDataType_S64, &value); variable.value = i128(value); - } else if (pl::Token::isUnsigned(variable.type)) { + } else if (pl::core::Token::isUnsigned(variable.type)) { u64 value = hex::get_or(variable.value, 0); ImGui::InputScalar(label.c_str(), ImGuiDataType_U64, &value); variable.value = u128(value); - } else if (pl::Token::isFloatingPoint(variable.type)) { + } else if (pl::core::Token::isFloatingPoint(variable.type)) { double value = hex::get_or(variable.value, 0.0); ImGui::InputScalar(label.c_str(), ImGuiDataType_Double, &value); variable.value = value; - } else if (variable.type == pl::Token::ValueType::Boolean) { + } else if (variable.type == pl::core::Token::ValueType::Boolean) { bool value = hex::get_or(variable.value, false); ImGui::Checkbox(label.c_str(), &value); variable.value = value; - } else if (variable.type == pl::Token::ValueType::Character) { + } else if (variable.type == pl::core::Token::ValueType::Character) { char buffer[2]; ImGui::InputText(label.c_str(), buffer, 2); variable.value = buffer[0]; @@ -667,7 +669,7 @@ namespace hex::plugin::builtin { } - void ViewPatternEditor::drawPatternTooltip(pl::Pattern *pattern) { + void ViewPatternEditor::drawPatternTooltip(pl::ptrn::Pattern *pattern) { ImGui::PushID(pattern); { ImGui::ColorButton(pattern->getVariableName().c_str(), ImColor(pattern->getColor())); @@ -749,11 +751,11 @@ namespace hex::plugin::builtin { if (ast) { for (auto &node : *ast) { - if (auto variableDecl = dynamic_cast(node.get())) { - auto type = dynamic_cast(variableDecl->getType().get()); + if (auto variableDecl = dynamic_cast(node.get())) { + auto type = dynamic_cast(variableDecl->getType().get()); if (type == nullptr) continue; - auto builtinType = dynamic_cast(type->getType().get()); + auto builtinType = dynamic_cast(type->getType().get()); if (builtinType == nullptr) continue; PatternVariable variable = { @@ -784,13 +786,13 @@ namespace hex::plugin::builtin { EventManager::post(); std::thread([this, code] { - std::map envVars; + std::map envVars; for (const auto &[id, name, value, type] : this->m_envVarEntries) envVars.insert({ name, value }); this->parsePattern(code); - std::map inVariables; + std::map inVariables; for (auto &[name, variable] : this->m_patternVariables) { if (variable.inVariable) inVariables[name] = variable.value; diff --git a/plugins/builtin/source/pattern_drawer.cpp b/plugins/builtin/source/pattern_drawer.cpp index d28294723..1f1a27599 100644 --- a/plugins/builtin/source/pattern_drawer.cpp +++ b/plugins/builtin/source/pattern_drawer.cpp @@ -34,15 +34,15 @@ namespace { namespace hex { - void PatternDrawer::visit(pl::PatternArrayDynamic& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternArrayDynamic& pattern) { this->drawArray(pattern); } - void PatternDrawer::visit(pl::PatternArrayStatic& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternArrayStatic& pattern) { this->drawArray(pattern); } - void PatternDrawer::visit(pl::PatternBitfieldField& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternBitfieldField& pattern) { ImGui::TableNextRow(); createLeafNode(pattern); ImGui::TableNextColumn(); @@ -72,7 +72,7 @@ namespace hex { ImGui::TextFormatted("{}", pattern.getFormattedValue()); } - void PatternDrawer::visit(pl::PatternBitfield& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternBitfield& pattern) { bool open = true; if (!pattern.isInlined()) { ImGui::TableNextRow(); @@ -101,15 +101,15 @@ namespace hex { } } - void PatternDrawer::visit(pl::PatternBoolean& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternBoolean& pattern) { this->createDefaultEntry(pattern, pattern.getFormattedValue(), static_cast(pattern.getValue())); } - void PatternDrawer::visit(pl::PatternCharacter& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternCharacter& pattern) { this->createDefaultEntry(pattern, pattern.getFormattedValue(), pattern.getValue()); } - void PatternDrawer::visit(pl::PatternEnum& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternEnum& pattern) { ImGui::TableNextRow(); createLeafNode(pattern); drawCommentTooltip(pattern); @@ -124,7 +124,7 @@ namespace hex { ImGui::TextFormatted("{}", pattern.getFormattedValue()); } - void PatternDrawer::visit(pl::PatternFloat& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternFloat& pattern) { if (pattern.getSize() == 4) { this->createDefaultEntry(pattern, pattern.getFormattedValue(), static_cast(pattern.getValue())); } else if (pattern.getSize() == 8) { @@ -132,12 +132,12 @@ namespace hex { } } - void PatternDrawer::visit(pl::PatternPadding& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternPadding& pattern) { // Do nothing hex::unused(pattern); } - void PatternDrawer::visit(pl::PatternPointer& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternPointer& pattern) { bool open = true; if (!pattern.isInlined()) { @@ -166,16 +166,16 @@ namespace hex { } } - void PatternDrawer::visit(pl::PatternSigned& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternSigned& pattern) { this->createDefaultEntry(pattern, pattern.getFormattedValue(), pattern.getValue()); } - void PatternDrawer::visit(pl::PatternString& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternString& pattern) { if (pattern.getSize() > 0) this->createDefaultEntry(pattern, pattern.getFormattedValue(), pattern.getValue()); } - void PatternDrawer::visit(pl::PatternStruct& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternStruct& pattern) { bool open = true; if (!pattern.isInlined()) { @@ -204,7 +204,7 @@ namespace hex { } } - void PatternDrawer::visit(pl::PatternUnion& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternUnion& pattern) { bool open = true; if (!pattern.isInlined()) { @@ -233,20 +233,20 @@ namespace hex { } } - void PatternDrawer::visit(pl::PatternUnsigned& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternUnsigned& pattern) { this->createDefaultEntry(pattern, pattern.getFormattedValue(), pattern.getValue()); } - void PatternDrawer::visit(pl::PatternWideCharacter& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternWideCharacter& pattern) { this->createDefaultEntry(pattern, pattern.getFormattedValue(), u128(pattern.getValue())); } - void PatternDrawer::visit(pl::PatternWideString& pattern) { + void PatternDrawer::visit(pl::ptrn::PatternWideString& pattern) { if (pattern.getSize() > 0) this->createDefaultEntry(pattern, pattern.getFormattedValue(), pattern.getValue()); } - void PatternDrawer::createDefaultEntry(const pl::Pattern &pattern, const std::string &value, pl::Token::Literal &&literal) const { + void PatternDrawer::createDefaultEntry(const pl::ptrn::Pattern &pattern, const std::string &value, pl::core::Token::Literal &&literal) const { ImGui::TableNextRow(); createLeafNode(pattern); ImGui::TableNextColumn(); @@ -264,7 +264,7 @@ namespace hex { ImGui::TextFormatted("{}", pattern.formatDisplayValue(value, literal)); } - void PatternDrawer::makeSelectable(const pl::Pattern &pattern) const { + void PatternDrawer::makeSelectable(const pl::ptrn::Pattern &pattern) const { ImGui::PushID(static_cast(pattern.getOffset())); ImGui::PushID(pattern.getVariableName().c_str()); if (ImGui::Selectable("##PatternLine", false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) { @@ -276,7 +276,7 @@ namespace hex { } - void PatternDrawer::drawCommentTooltip(const pl::Pattern &pattern) const { + void PatternDrawer::drawCommentTooltip(const pl::ptrn::Pattern &pattern) const { if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) && pattern.getComment().has_value()) { ImGui::BeginTooltip(); ImGui::TextUnformatted(pattern.getComment()->c_str()); @@ -284,14 +284,14 @@ namespace hex { } } - void PatternDrawer::draw(pl::Pattern& pattern) { + void PatternDrawer::draw(pl::ptrn::Pattern& pattern) { if (pattern.isHidden()) return; pattern.accept(*this); } - bool PatternDrawer::drawArrayRoot(pl::Pattern& pattern, size_t entryCount, bool isInlined) { + bool PatternDrawer::drawArrayRoot(pl::ptrn::Pattern& pattern, size_t entryCount, bool isInlined) { if (entryCount == 0) return false; @@ -325,7 +325,7 @@ namespace hex { return open; } - void PatternDrawer::drawArrayNode(u64 idx, u64& displayEnd, pl::Pattern& pattern) { + void PatternDrawer::drawArrayNode(u64 idx, u64& displayEnd, pl::ptrn::Pattern& pattern) { u64 lastVisible = displayEnd - 1; ImGui::PushID(pattern.getOffset()); @@ -344,7 +344,7 @@ namespace hex { ImGui::PopID(); } - void PatternDrawer::drawArrayEnd(pl::Pattern& pattern, bool opened) { + void PatternDrawer::drawArrayEnd(pl::ptrn::Pattern& pattern, bool opened) { if (opened) { ImGui::TreePop(); } else { @@ -353,14 +353,14 @@ namespace hex { } } - void PatternDrawer::createLeafNode(const pl::Pattern& pattern) const { + void PatternDrawer::createLeafNode(const pl::ptrn::Pattern& pattern) const { ImGui::TreeNodeEx(pattern.getDisplayName().c_str(), ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap); } - bool PatternDrawer::createTreeNode(const pl::Pattern& pattern) const { + bool PatternDrawer::createTreeNode(const pl::ptrn::Pattern& pattern) const { if (pattern.isSealed()) { ImGui::Selectable(pattern.getDisplayName().c_str(), false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap); return false; @@ -369,34 +369,34 @@ namespace hex { return ImGui::TreeNodeEx(pattern.getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth); } - void PatternDrawer::drawTypenameColumn(const pl::Pattern& pattern, const std::string& pattern_name) const { + void PatternDrawer::drawTypenameColumn(const pl::ptrn::Pattern& pattern, const std::string& pattern_name) const { ImGui::TextFormattedColored(ImColor(0xFFD69C56), pattern_name); ImGui::SameLine(); ImGui::TextUnformatted(pattern.getTypeName().c_str()); ImGui::TableNextColumn(); } - void PatternDrawer::drawNameColumn(const pl::Pattern& pattern) const { + void PatternDrawer::drawNameColumn(const pl::ptrn::Pattern& pattern) const { ImGui::TextUnformatted(pattern.getDisplayName().c_str()); ImGui::TableNextColumn(); } - void PatternDrawer::drawColorColumn(const pl::Pattern& pattern) const { + void PatternDrawer::drawColorColumn(const pl::ptrn::Pattern& pattern) const { ImGui::ColorButton("color", ImColor(pattern.getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight())); ImGui::TableNextColumn(); } - void PatternDrawer::drawOffsetColumn(const pl::Pattern& pattern) const { + void PatternDrawer::drawOffsetColumn(const pl::ptrn::Pattern& pattern) const { ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", pattern.getOffset(), pattern.getOffset() + pattern.getSize() - (pattern.getSize() == 0 ? 0 : 1)); ImGui::TableNextColumn(); } - void PatternDrawer::drawSizeColumn(const pl::Pattern& pattern) const { + void PatternDrawer::drawSizeColumn(const pl::ptrn::Pattern& pattern) const { ImGui::TextFormatted("0x{0:04X}", pattern.getSize()); ImGui::TableNextColumn(); } - u64& PatternDrawer::getDisplayEnd(const pl::Pattern& pattern) { + u64& PatternDrawer::getDisplayEnd(const pl::ptrn::Pattern& pattern) { auto it = m_displayEnd.find(&pattern); if (it != m_displayEnd.end()) { return it->second;