mirror of https://github.com/WerWolv/ImHex.git
sys: Updated to new pattern language library structure
This commit is contained in:
parent
4f37345324
commit
88f8bb9848
|
@ -1 +1 @@
|
|||
Subproject commit a8c44795db376db7ebc7957a11cc309cfb22e0d2
|
||||
Subproject commit 656c975514e9ebb1008b0d1153c530f2e1220aa8
|
|
@ -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;
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace hex::plugin::builtin {
|
|||
void drawContent() override;
|
||||
|
||||
private:
|
||||
std::map<prv::Provider *, std::vector<pl::Pattern*>> m_sortedPatterns;
|
||||
std::map<prv::Provider *, std::vector<pl::ptrn::Pattern*>> m_sortedPatterns;
|
||||
hex::PatternDrawer m_patternDrawer;
|
||||
};
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <hex/ui/view.hpp>
|
||||
#include <pl/pattern_language.hpp>
|
||||
#include <pl/core/errors/error.hpp>
|
||||
#include <hex/providers/provider.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
@ -12,7 +13,7 @@
|
|||
|
||||
#include <TextEditor.h>
|
||||
|
||||
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<pl::PatternLanguageError> m_lastEvaluationError;
|
||||
std::vector<std::pair<pl::LogConsole::Level, std::string>> m_lastEvaluationLog;
|
||||
std::map<std::string, pl::Token::Literal> m_lastEvaluationOutVars;
|
||||
std::optional<pl::core::err::PatternLanguageError> m_lastEvaluationError;
|
||||
std::vector<std::pair<pl::core::LogConsole::Level, std::string>> m_lastEvaluationLog;
|
||||
std::map<std::string, pl::core::Token::Literal> m_lastEvaluationOutVars;
|
||||
|
||||
std::atomic<u32> m_runningEvaluators = 0;
|
||||
std::atomic<u32> m_runningParsers = 0;
|
||||
|
@ -79,7 +80,7 @@ namespace hex::plugin::builtin {
|
|||
bool m_acceptPatternWindowOpen = false;
|
||||
|
||||
TextEditor m_textEditor;
|
||||
std::vector<std::pair<pl::LogConsole::Level, std::string>> m_console;
|
||||
std::vector<std::pair<pl::core::LogConsole::Level, std::string>> m_console;
|
||||
|
||||
std::map<std::string, PatternVariable> 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);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
namespace hex {
|
||||
|
||||
template<typename T>
|
||||
concept ArrayPattern = requires(u64 displayEnd, T pattern, std::function<void(int, pl::Pattern&)> fn) {
|
||||
concept ArrayPattern = requires(u64 displayEnd, T pattern, std::function<void(int, pl::ptrn::Pattern&)> fn) {
|
||||
{ pattern.forEachArrayEntry(displayEnd, fn) } -> std::same_as<void>;
|
||||
};
|
||||
|
||||
|
@ -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<ArrayPattern T>
|
||||
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<const pl::Pattern*, u64> m_displayEnd;
|
||||
std::map<const pl::ptrn::Pattern*, u64> m_displayEnd;
|
||||
};
|
||||
};
|
|
@ -2,18 +2,18 @@
|
|||
|
||||
#include <hex/helpers/net.hpp>
|
||||
|
||||
#include <pl/token.hpp>
|
||||
#include <pl/log_console.hpp>
|
||||
#include <pl/evaluator.hpp>
|
||||
#include <pl/core/token.hpp>
|
||||
#include <pl/core/log_console.hpp>
|
||||
#include <pl/core/evaluator.hpp>
|
||||
#include <pl/patterns/pattern.hpp>
|
||||
|
||||
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<Token::Literal> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/providers/provider.hpp>
|
||||
|
||||
#include <pl/evaluator.hpp>
|
||||
#include <pl/core/evaluator.hpp>
|
||||
|
||||
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;
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace hex::plugin::builtin {
|
|||
EventManager::unsubscribe<EventHighlightingChanged>(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<std::shared_ptr<pl::Pattern>> &patterns, std::vector<pl::Pattern*> &sortedPatterns) {
|
||||
static bool beginPatternTable(prv::Provider *&provider, const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, std::vector<pl::ptrn::Pattern*> &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<pl::Pattern> &pattern) {
|
||||
std::transform(patterns.begin(), patterns.end(), std::back_inserter(sortedPatterns), [](const std::shared_ptr<pl::ptrn::Pattern> &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);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <pl/preprocessor.hpp>
|
||||
#include <pl/patterns/pattern.hpp>
|
||||
#include <pl/ast/ast_node_variable_decl.hpp>
|
||||
#include <pl/ast/ast_node_type_decl.hpp>
|
||||
#include <pl/ast/ast_node_builtin_type.hpp>
|
||||
#include <pl/core/preprocessor.hpp>
|
||||
#include <pl/core/ast/ast_node_variable_decl.hpp>
|
||||
#include <pl/core/ast/ast_node_type_decl.hpp>
|
||||
#include <pl/core/ast/ast_node_builtin_type.hpp>
|
||||
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
@ -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<i128>(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<u128>(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<double>(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<bool>(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<pl::ASTNodeVariableDecl *>(node.get())) {
|
||||
auto type = dynamic_cast<pl::ASTNodeTypeDecl *>(variableDecl->getType().get());
|
||||
if (auto variableDecl = dynamic_cast<pl::core::ast::ASTNodeVariableDecl *>(node.get())) {
|
||||
auto type = dynamic_cast<pl::core::ast::ASTNodeTypeDecl *>(variableDecl->getType().get());
|
||||
if (type == nullptr) continue;
|
||||
|
||||
auto builtinType = dynamic_cast<pl::ASTNodeBuiltinType *>(type->getType().get());
|
||||
auto builtinType = dynamic_cast<pl::core::ast::ASTNodeBuiltinType *>(type->getType().get());
|
||||
if (builtinType == nullptr) continue;
|
||||
|
||||
PatternVariable variable = {
|
||||
|
@ -784,13 +786,13 @@ namespace hex::plugin::builtin {
|
|||
EventManager::post<EventHighlightingChanged>();
|
||||
|
||||
std::thread([this, code] {
|
||||
std::map<std::string, pl::Token::Literal> envVars;
|
||||
std::map<std::string, pl::core::Token::Literal> envVars;
|
||||
for (const auto &[id, name, value, type] : this->m_envVarEntries)
|
||||
envVars.insert({ name, value });
|
||||
|
||||
this->parsePattern(code);
|
||||
|
||||
std::map<std::string, pl::Token::Literal> inVariables;
|
||||
std::map<std::string, pl::core::Token::Literal> inVariables;
|
||||
for (auto &[name, variable] : this->m_patternVariables) {
|
||||
if (variable.inVariable)
|
||||
inVariables[name] = variable.value;
|
||||
|
|
|
@ -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<bool>(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<float>(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<int>(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;
|
||||
|
|
Loading…
Reference in New Issue