1
0
mirror of synced 2024-11-24 15:50:16 +01:00

patterns: Updated pattern language

This commit is contained in:
WerWolv 2023-01-23 13:53:29 +01:00
parent c30f8fa459
commit a51e4afb05
5 changed files with 18 additions and 18 deletions

@ -1 +1 @@
Subproject commit f73f87c9ccb43c19ef4b02dffb752b890da7afed
Subproject commit 69a3d4c05eb6bb1efe7fd926fc99f2982e22a59a

View File

@ -31,7 +31,7 @@ namespace hex::plugin::builtin {
{
/* demangle(mangled_string) */
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "demangle", FunctionParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto mangledString = Token::literalToString(params[0], false);
const auto mangledString = params[0].toString(false);
return llvm::demangle(mangledString);
});
@ -41,7 +41,7 @@ namespace hex::plugin::builtin {
{
/* get(url) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsHexHttp, "get", FunctionParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto url = Token::literalToString(params[0], false);
const auto url = params[0].toString(false);
hex::Net net;
return net.getString(url).get().body;

View File

@ -27,7 +27,7 @@ namespace hex::plugin::builtin {
ImPlot::PlotLineG("##line", [](void *data, int idx) -> ImPlotPoint {
auto &iteratable = *static_cast<pl::ptrn::Iteratable *>(data);
return { static_cast<double>(idx), pl::core::Token::literalToFloatingPoint(iteratable.getEntry(idx)->getValue()) };
return { static_cast<double>(idx), iteratable.getEntry(idx)->getValue().toFloatingPoint() };
}, &iteratable, iteratable.getEntryCount());
ImPlot::EndPlot();
@ -50,8 +50,8 @@ namespace hex::plugin::builtin {
void drawBitmapVisualizer(pl::ptrn::Pattern &pattern, pl::ptrn::Iteratable &, bool shouldReset, const std::vector<pl::core::Token::Literal> &arguments) {
static ImGui::Texture texture;
if (shouldReset) {
auto width = pl::core::Token::literalToUnsigned(arguments[1]);
auto height = pl::core::Token::literalToUnsigned(arguments[2]);
auto width = arguments[1].toUnsigned();
auto height = arguments[2].toUnsigned();
std::vector<u8> data;
data.resize(width * height * 4);
@ -73,9 +73,9 @@ namespace hex::plugin::builtin {
static std::vector<Disassembly> disassembly;
if (shouldReset) {
auto baseAddress = pl::core::Token::literalToUnsigned(arguments[1]);
auto architecture = pl::core::Token::literalToUnsigned(arguments[2]);
auto mode = pl::core::Token::literalToUnsigned(arguments[3]);
auto baseAddress = arguments[1].toUnsigned();
auto architecture = arguments[2].toUnsigned();
auto mode = arguments[3].toUnsigned();
disassembly.clear();
@ -136,9 +136,9 @@ namespace hex::plugin::builtin {
T value;
if (std::floating_point<T>)
value = pl::core::Token::literalToFloatingPoint(child->getValue());
value = child->getValue().toFloatingPoint();
else
value = pl::core::Token::literalToUnsigned(child->getValue());
value = child->getValue().toUnsigned();
result.push_back(value);
}
@ -152,8 +152,8 @@ namespace hex::plugin::builtin {
};
void draw3DVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, const std::vector<pl::core::Token::Literal> &arguments) {
auto verticesPattern = pl::core::Token::literalToPattern(arguments[1]);
auto indicesPattern = pl::core::Token::literalToPattern(arguments[2]);
auto verticesPattern = arguments[1].toPattern();
auto indicesPattern = arguments[2].toPattern();
static ImGui::Texture texture;
static float scaling = 0.5F;

View File

@ -378,7 +378,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
if (variable.outVariable) {
ImGui::TextUnformatted(pl::core::Token::literalToString(variable.value, true).c_str());
ImGui::TextUnformatted(variable.value.toString(true).c_str());
} else if (variable.inVariable) {
const std::string label { "##" + name };

View File

@ -114,7 +114,7 @@ namespace hex::plugin::builtin::ui {
}
void drawVisualizer(const std::vector<pl::core::Token::Literal> &arguments, pl::ptrn::Pattern &pattern, pl::ptrn::Iteratable &iteratable, bool reset) {
auto visualizerName = pl::core::Token::literalToString(arguments.front(), true);
auto visualizerName = arguments.front().toString(true);
const auto &visualizers = ContentRegistry::PatternLanguage::impl::getVisualizers();
@ -360,10 +360,10 @@ namespace hex::plugin::builtin::ui {
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
if (ImGui::BeginCombo("##Enum", pattern.getFormattedValue().c_str())) {
auto currValue = pl::core::Token::literalToUnsigned(pattern.getValue());
auto currValue = pattern.getValue().toUnsigned();
for (auto &value : pattern.getEnumValues()) {
auto min = pl::core::Token::literalToUnsigned(value.min);
auto max = pl::core::Token::literalToUnsigned(value.max);
auto min = value.min.toUnsigned();
auto max = value.max.toUnsigned();
bool isSelected = min <= currValue && max >= currValue;
if (ImGui::Selectable(fmt::format("{}::{} (0x{:0{}X})", pattern.getTypeName(), value.name, min, pattern.getSize() * 2).c_str(), isSelected)) {