mirror of
https://github.com/NohamR/Reclass.git
synced 2026-05-10 19:59:21 +00:00
feat: type selector overhaul, fuzzy search, address parser, value tracking
Redesign type selector popup with fuzzy subsequence matching, per-category icons, field summary tooltips, compact chips, and pointer target primitives. Add address expression parser with arithmetic and register support. Enable track value changes by default.
This commit is contained in:
@@ -10,20 +10,28 @@ namespace rcx {
|
||||
// "<Program.exe> + 0xDE" → module base + offset
|
||||
// "[<Program.exe> + 0xDE] - AB" → dereference pointer, then subtract
|
||||
// "7ff6`6cce0000" → WinDbg-style backtick separator (stripped before parsing)
|
||||
// "base + e_lfanew" → C/C++ style identifier resolution
|
||||
// "0xFF & 0x0F" → bitwise AND
|
||||
// "1 << 4" → shift left
|
||||
//
|
||||
// Grammar (standard operator precedence: *, / bind tighter than +, -):
|
||||
// Grammar (C operator precedence):
|
||||
//
|
||||
// expr = term (('+' | '-') term)*
|
||||
// term = unary (('*' | '/') unary)*
|
||||
// unary = '-' unary | atom
|
||||
// atom = '[' expr ']' -- read pointer at address (dereference)
|
||||
// | '<' moduleName '>' -- resolve module base address
|
||||
// | '(' expr ')' -- grouping
|
||||
// | hexLiteral -- hex number, optional 0x prefix
|
||||
// bitwiseOr = bitwiseXor ('|' bitwiseXor)*
|
||||
// bitwiseXor = bitwiseAnd ('^' bitwiseAnd)*
|
||||
// bitwiseAnd = shift ('&' shift)*
|
||||
// shift = expr (('<<' | '>>') expr)*
|
||||
// expr = term (('+' | '-') term)*
|
||||
// term = unary (('*' | '/') unary)*
|
||||
// unary = '-' unary | '~' unary | atom
|
||||
// atom = '[' bitwiseOr ']' -- read pointer at address (dereference)
|
||||
// | '<' moduleName '>' -- resolve module base address
|
||||
// | '(' bitwiseOr ')' -- grouping
|
||||
// | identifier -- C/C++ name resolved via callback
|
||||
// | hexLiteral -- hex number, optional 0x prefix
|
||||
//
|
||||
// All numeric literals are hexadecimal (base 16).
|
||||
// Module names and pointer reads are resolved via optional callbacks.
|
||||
// Without callbacks, modules and dereferences evaluate to 0 (syntax-check mode).
|
||||
// Identifiers: [a-zA-Z_][a-zA-Z0-9_]* containing at least one non-hex char.
|
||||
// Pure hex-digit words (e.g. "DEAD") are treated as hex literals.
|
||||
|
||||
class ExpressionParser {
|
||||
public:
|
||||
@@ -36,7 +44,7 @@ public:
|
||||
return error("empty expression");
|
||||
|
||||
uint64_t value = 0;
|
||||
if (!parseExpression(value))
|
||||
if (!parseBitwiseOr(value))
|
||||
return error(m_error);
|
||||
|
||||
skipSpaces();
|
||||
@@ -90,8 +98,89 @@ private:
|
||||
|| (ch >= 'A' && ch <= 'F');
|
||||
}
|
||||
|
||||
static bool isIdentStart(QChar ch) {
|
||||
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_';
|
||||
}
|
||||
|
||||
static bool isIdentChar(QChar ch) {
|
||||
return isIdentStart(ch) || (ch >= '0' && ch <= '9');
|
||||
}
|
||||
|
||||
// ── Recursive descent parsing ──
|
||||
|
||||
// bitwiseOr = bitwiseXor ('|' bitwiseXor)*
|
||||
bool parseBitwiseOr(uint64_t& result) {
|
||||
if (!parseBitwiseXor(result))
|
||||
return false;
|
||||
for (;;) {
|
||||
skipSpaces();
|
||||
if (peek() != '|')
|
||||
break;
|
||||
advance();
|
||||
uint64_t rhs = 0;
|
||||
if (!parseBitwiseXor(rhs))
|
||||
return false;
|
||||
result |= rhs;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// bitwiseXor = bitwiseAnd ('^' bitwiseAnd)*
|
||||
bool parseBitwiseXor(uint64_t& result) {
|
||||
if (!parseBitwiseAnd(result))
|
||||
return false;
|
||||
for (;;) {
|
||||
skipSpaces();
|
||||
if (peek() != '^')
|
||||
break;
|
||||
advance();
|
||||
uint64_t rhs = 0;
|
||||
if (!parseBitwiseAnd(rhs))
|
||||
return false;
|
||||
result ^= rhs;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// bitwiseAnd = shift ('&' shift)*
|
||||
bool parseBitwiseAnd(uint64_t& result) {
|
||||
if (!parseShift(result))
|
||||
return false;
|
||||
for (;;) {
|
||||
skipSpaces();
|
||||
if (peek() != '&')
|
||||
break;
|
||||
advance();
|
||||
uint64_t rhs = 0;
|
||||
if (!parseShift(rhs))
|
||||
return false;
|
||||
result &= rhs;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// shift = expr (('<<' | '>>') expr)*
|
||||
bool parseShift(uint64_t& result) {
|
||||
if (!parseExpression(result))
|
||||
return false;
|
||||
for (;;) {
|
||||
skipSpaces();
|
||||
QChar c = peek();
|
||||
if (c != '<' && c != '>')
|
||||
break;
|
||||
// Must be << or >> (not < or > alone)
|
||||
if (m_pos + 1 >= m_input.size() || m_input[m_pos + 1] != c)
|
||||
break;
|
||||
bool isLeft = (c == '<');
|
||||
advance(); advance(); // skip << or >>
|
||||
uint64_t rhs = 0;
|
||||
if (!parseExpression(rhs))
|
||||
return false;
|
||||
result = isLeft ? (result << rhs) : (result >> rhs);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// expr = term (('+' | '-') term)*
|
||||
bool parseExpression(uint64_t& result) {
|
||||
if (!parseTerm(result))
|
||||
@@ -140,7 +229,7 @@ private:
|
||||
return true;
|
||||
}
|
||||
|
||||
// unary = '-' unary | atom
|
||||
// unary = '-' unary | '~' unary | atom
|
||||
bool parseUnary(uint64_t& result) {
|
||||
skipSpaces();
|
||||
if (peek() == '-') {
|
||||
@@ -151,10 +240,18 @@ private:
|
||||
result = static_cast<uint64_t>(-static_cast<int64_t>(inner));
|
||||
return true;
|
||||
}
|
||||
if (peek() == '~') {
|
||||
advance();
|
||||
uint64_t inner = 0;
|
||||
if (!parseUnary(inner))
|
||||
return false;
|
||||
result = ~inner;
|
||||
return true;
|
||||
}
|
||||
return parseAtom(result);
|
||||
}
|
||||
|
||||
// atom = '[' expr ']' | '<' name '>' | '(' expr ')' | hexLiteral
|
||||
// atom = '[' bitwiseOr ']' | '<' name '>' | '(' bitwiseOr ')' | identifier | hexLiteral
|
||||
bool parseAtom(uint64_t& result) {
|
||||
skipSpaces();
|
||||
if (atEnd())
|
||||
@@ -165,15 +262,55 @@ private:
|
||||
if (ch == '[') return parseDereference(result);
|
||||
if (ch == '<') return parseModuleName(result);
|
||||
if (ch == '(') return parseGrouping(result);
|
||||
|
||||
// Try identifier before hex — identifiers start with [a-zA-Z_]
|
||||
if (isIdentStart(ch))
|
||||
return parseIdentifierOrHex(result);
|
||||
|
||||
return parseHexNumber(result);
|
||||
}
|
||||
|
||||
// '[' expr ']' — read the pointer value at the computed address
|
||||
// Identifier or hex literal disambiguation.
|
||||
// Scan [a-zA-Z_][a-zA-Z0-9_]*. If it contains any non-hex char → identifier.
|
||||
// Otherwise → backtrack and parse as hex number.
|
||||
bool parseIdentifierOrHex(uint64_t& result) {
|
||||
int start = m_pos;
|
||||
bool hasNonHex = false;
|
||||
|
||||
// Scan full token
|
||||
while (!atEnd() && isIdentChar(peek())) {
|
||||
if (!isHexDigit(peek()))
|
||||
hasNonHex = true;
|
||||
advance();
|
||||
}
|
||||
|
||||
QString token = m_input.mid(start, m_pos - start);
|
||||
|
||||
if (!hasNonHex) {
|
||||
// Pure hex digits (e.g. "DEAD") — backtrack, parse as hex
|
||||
m_pos = start;
|
||||
return parseHexNumber(result);
|
||||
}
|
||||
|
||||
// It's an identifier — resolve via callback
|
||||
if (!m_callbacks || !m_callbacks->resolveIdentifier) {
|
||||
result = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
result = m_callbacks->resolveIdentifier(token, &ok);
|
||||
if (!ok)
|
||||
return fail(QStringLiteral("unknown identifier '%1'").arg(token));
|
||||
return true;
|
||||
}
|
||||
|
||||
// '[' bitwiseOr ']' — read the pointer value at the computed address
|
||||
bool parseDereference(uint64_t& result) {
|
||||
advance(); // skip '['
|
||||
|
||||
uint64_t address = 0;
|
||||
if (!parseExpression(address))
|
||||
if (!parseBitwiseOr(address))
|
||||
return false;
|
||||
if (!expect(']'))
|
||||
return false;
|
||||
@@ -220,10 +357,10 @@ private:
|
||||
return true;
|
||||
}
|
||||
|
||||
// '(' expr ')' — parenthesized sub-expression for grouping
|
||||
// '(' bitwiseOr ')' — parenthesized sub-expression for grouping
|
||||
bool parseGrouping(uint64_t& result) {
|
||||
advance(); // skip '('
|
||||
if (!parseExpression(result))
|
||||
if (!parseBitwiseOr(result))
|
||||
return false;
|
||||
return expect(')');
|
||||
}
|
||||
@@ -290,7 +427,7 @@ QString AddressParser::validate(const QString& formula)
|
||||
if (cleaned.isEmpty())
|
||||
return QStringLiteral("empty");
|
||||
|
||||
// Parse with no callbacks — modules and dereferences succeed but return 0.
|
||||
// Parse with no callbacks — modules, dereferences, identifiers succeed but return 0.
|
||||
// This checks syntax only.
|
||||
ExpressionParser parser(cleaned, nullptr);
|
||||
auto result = parser.parse();
|
||||
|
||||
@@ -15,6 +15,7 @@ struct AddressParseResult {
|
||||
struct AddressParserCallbacks {
|
||||
std::function<uint64_t(const QString& name, bool* ok)> resolveModule;
|
||||
std::function<uint64_t(uint64_t addr, bool* ok)> readPointer;
|
||||
std::function<uint64_t(const QString& name, bool* ok)> resolveIdentifier;
|
||||
};
|
||||
|
||||
class AddressParser {
|
||||
|
||||
170
src/compose.cpp
170
src/compose.cpp
@@ -1,4 +1,5 @@
|
||||
#include "core.h"
|
||||
#include "addressparser.h"
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
@@ -394,12 +395,21 @@ void composeParent(ComposeState& state, const NodeTree& tree,
|
||||
return;
|
||||
}
|
||||
|
||||
const QVector<int>& children = childIndices(state, node.id);
|
||||
const QVector<int>& allChildren = childIndices(state, node.id);
|
||||
|
||||
// Split children into regular nodes and helpers (helpers render at the end)
|
||||
QVector<int> regular, helperIdxs;
|
||||
for (int ci : allChildren) {
|
||||
if (tree.nodes[ci].isHelper)
|
||||
helperIdxs.append(ci);
|
||||
else
|
||||
regular.append(ci);
|
||||
}
|
||||
|
||||
int childDepth = depth + 1;
|
||||
|
||||
// Primitive arrays with no child nodes: synthesize element lines dynamically
|
||||
if (node.kind == NodeKind::Array && children.isEmpty()
|
||||
if (node.kind == NodeKind::Array && regular.isEmpty()
|
||||
&& node.elementKind != NodeKind::Struct && node.elementKind != NodeKind::Array) {
|
||||
int elemSize = sizeForKind(node.elementKind);
|
||||
int eTW = state.effectiveTypeW(node.id);
|
||||
@@ -443,7 +453,7 @@ void composeParent(ComposeState& state, const NodeTree& tree,
|
||||
|
||||
// Struct arrays with refId but no child nodes: synthesize by expanding the
|
||||
// referenced struct for each element (like repeated pointer deref)
|
||||
if (node.kind == NodeKind::Array && children.isEmpty()
|
||||
if (node.kind == NodeKind::Array && regular.isEmpty()
|
||||
&& node.elementKind == NodeKind::Struct && node.refId != 0) {
|
||||
int refIdx = tree.indexOfId(node.refId);
|
||||
if (refIdx >= 0) {
|
||||
@@ -460,7 +470,7 @@ void composeParent(ComposeState& state, const NodeTree& tree,
|
||||
|
||||
// Embedded struct with refId but no child nodes: expand referenced struct's
|
||||
// children at this node's offset (single instance, like array with count=1)
|
||||
if (node.kind == NodeKind::Struct && children.isEmpty() && node.refId != 0) {
|
||||
if (node.kind == NodeKind::Struct && regular.isEmpty() && node.refId != 0) {
|
||||
int refIdx = tree.indexOfId(node.refId);
|
||||
if (refIdx >= 0) {
|
||||
const QVector<int>& refChildren = childIndices(state, node.refId);
|
||||
@@ -504,7 +514,7 @@ void composeParent(ComposeState& state, const NodeTree& tree,
|
||||
// For arrays, render children as condensed (no header/footer for struct elements)
|
||||
bool childrenAreArrayElements = (node.kind == NodeKind::Array);
|
||||
int elementIdx = 0;
|
||||
for (int childIdx : children) {
|
||||
for (int childIdx : regular) {
|
||||
// Pass this container's id as the scope for children (for per-scope widths)
|
||||
// For array elements, also pass the element index for [N] separator
|
||||
composeNode(state, tree, prov, childIdx, childDepth, base, rootId,
|
||||
@@ -512,6 +522,156 @@ void composeParent(ComposeState& state, const NodeTree& tree,
|
||||
childrenAreArrayElements ? elementIdx++ : -1,
|
||||
childrenAreArrayElements ? absAddr : 0);
|
||||
}
|
||||
|
||||
// ── Static helpers: render after regular children, before footer ──
|
||||
if (!helperIdxs.isEmpty() && !node.collapsed) {
|
||||
// Separator line
|
||||
{
|
||||
LineMeta lm;
|
||||
lm.nodeIdx = nodeIdx;
|
||||
lm.nodeId = node.id;
|
||||
lm.depth = childDepth;
|
||||
lm.lineKind = LineKind::Field;
|
||||
lm.nodeKind = NodeKind::Hex8; // neutral kind for separator
|
||||
lm.foldLevel = computeFoldLevel(childDepth, false);
|
||||
lm.markerMask = 0;
|
||||
lm.offsetText = QString(state.offsetHexDigits, QChar(' '));
|
||||
state.emitLine(fmt::indent(childDepth)
|
||||
+ QStringLiteral("\u2500\u2500\u2500 helpers \u2500\u2500\u2500"), lm);
|
||||
}
|
||||
|
||||
// Build identifier resolver for helper expressions
|
||||
auto makeResolver = [&](uint64_t parentAbsAddr) {
|
||||
AddressParserCallbacks cbs;
|
||||
cbs.resolveIdentifier = [&tree, &prov, ®ular, parentAbsAddr]
|
||||
(const QString& name, bool* ok) -> uint64_t {
|
||||
if (name == QStringLiteral("base")) {
|
||||
*ok = true;
|
||||
return parentAbsAddr;
|
||||
}
|
||||
// Find sibling field by name, read its value
|
||||
for (int ci : regular) {
|
||||
const Node& sib = tree.nodes[ci];
|
||||
if (sib.name == name) {
|
||||
int sz = sib.byteSize();
|
||||
uint64_t sibAddr = parentAbsAddr + sib.offset;
|
||||
if (sz > 0 && prov.isValid() && prov.isReadable(sibAddr, sz)) {
|
||||
*ok = true;
|
||||
if (sz == 1) return (uint64_t)prov.readU8(sibAddr);
|
||||
if (sz == 2) return (uint64_t)prov.readU16(sibAddr);
|
||||
if (sz == 4) return (uint64_t)prov.readU32(sibAddr);
|
||||
return prov.readU64(sibAddr);
|
||||
}
|
||||
*ok = false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
*ok = false;
|
||||
return 0;
|
||||
};
|
||||
cbs.readPointer = [&prov](uint64_t addr, bool* ok) -> uint64_t {
|
||||
if (prov.isValid() && prov.isReadable(addr, 8)) {
|
||||
*ok = true;
|
||||
return prov.readU64(addr);
|
||||
}
|
||||
*ok = false;
|
||||
return 0;
|
||||
};
|
||||
return cbs;
|
||||
};
|
||||
|
||||
auto cbs = makeResolver(absAddr);
|
||||
|
||||
for (int hi : helperIdxs) {
|
||||
const Node& helper = tree.nodes[hi];
|
||||
|
||||
// Evaluate expression → absolute address
|
||||
uint64_t helperAddr = 0;
|
||||
bool exprOk = false;
|
||||
if (!helper.offsetExpr.isEmpty()) {
|
||||
auto result = AddressParser::evaluate(helper.offsetExpr, 8, &cbs);
|
||||
exprOk = result.ok;
|
||||
if (result.ok)
|
||||
helperAddr = result.value;
|
||||
}
|
||||
|
||||
// Format: "▸ type name = expr → 0xADDR" (or "= expr (error)" on failure)
|
||||
int typeW = state.effectiveTypeW(node.id);
|
||||
int nameW = state.effectiveNameW(node.id);
|
||||
|
||||
QString typeName;
|
||||
if (helper.kind == NodeKind::Struct)
|
||||
typeName = fmt::structTypeName(helper);
|
||||
else if (helper.kind == NodeKind::Pointer64 || helper.kind == NodeKind::Pointer32)
|
||||
typeName = fmt::pointerTypeName(helper.kind, resolvePointerTarget(tree, helper.refId));
|
||||
else
|
||||
typeName = fmt::typeNameRaw(helper.kind);
|
||||
|
||||
bool overflow = state.compactColumns && typeName.size() > typeW;
|
||||
QString type = overflow ? typeName : typeName.leftJustified(typeW);
|
||||
QString name = overflow ? helper.name : helper.name.leftJustified(nameW);
|
||||
|
||||
QString exprPart;
|
||||
if (!helper.offsetExpr.isEmpty()) {
|
||||
if (exprOk)
|
||||
exprPart = QStringLiteral("= %1 \u2192 0x%2")
|
||||
.arg(helper.offsetExpr)
|
||||
.arg(QString::number(helperAddr, 16).toUpper());
|
||||
else
|
||||
exprPart = QStringLiteral("= %1 (error)").arg(helper.offsetExpr);
|
||||
}
|
||||
|
||||
QString line = fmt::indent(childDepth) + type
|
||||
+ QStringLiteral(" ") + name
|
||||
+ QStringLiteral(" ") + exprPart;
|
||||
|
||||
LineMeta lm;
|
||||
lm.nodeIdx = hi;
|
||||
lm.nodeId = helper.id;
|
||||
lm.depth = childDepth;
|
||||
lm.lineKind = LineKind::Header;
|
||||
lm.nodeKind = helper.kind;
|
||||
lm.foldHead = true;
|
||||
lm.foldCollapsed = true; // helpers always start collapsed
|
||||
lm.isHelperLine = true;
|
||||
lm.foldLevel = computeFoldLevel(childDepth, true);
|
||||
lm.markerMask = (1u << M_STRUCT_BG);
|
||||
lm.offsetText = QStringLiteral("~") + QString::number(helperAddr, 16)
|
||||
.toUpper().rightJustified(state.offsetHexDigits - 1, '0');
|
||||
lm.offsetAddr = helperAddr;
|
||||
lm.ptrBase = state.currentPtrBase;
|
||||
lm.effectiveTypeW = overflow ? typeName.size() : typeW;
|
||||
lm.effectiveNameW = nameW;
|
||||
state.emitLine(line, lm);
|
||||
|
||||
// If helper is expanded (user clicked to expand), compose its children
|
||||
if (!helper.collapsed && exprOk) {
|
||||
if (helper.kind == NodeKind::Struct || helper.kind == NodeKind::Array) {
|
||||
// Compose helper's children at the evaluated address
|
||||
const QVector<int>& helperKids = childIndices(state, helper.id);
|
||||
for (int hci : helperKids) {
|
||||
composeNode(state, tree, prov, hci, childDepth + 1,
|
||||
helperAddr, helper.id, false, helper.id);
|
||||
}
|
||||
// Helper footer
|
||||
LineMeta flm;
|
||||
flm.nodeIdx = hi;
|
||||
flm.nodeId = helper.id;
|
||||
flm.depth = childDepth;
|
||||
flm.lineKind = LineKind::Footer;
|
||||
flm.nodeKind = helper.kind;
|
||||
flm.foldLevel = computeFoldLevel(childDepth, false);
|
||||
flm.markerMask = 0;
|
||||
int hSpan = tree.structSpan(helper.id, &state.childMap);
|
||||
flm.offsetText = fmt::fmtOffsetMargin(helperAddr + hSpan, false,
|
||||
state.offsetHexDigits);
|
||||
flm.offsetAddr = helperAddr + hSpan;
|
||||
flm.ptrBase = state.currentPtrBase;
|
||||
state.emitLine(fmt::fmtStructFooter(helper, childDepth, hSpan), flm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Footer line: skip when collapsed or for array element structs
|
||||
|
||||
@@ -481,6 +481,16 @@ void RcxController::connectEditor(RcxEditor* editor) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EditTarget::HelperExpr: {
|
||||
if (nodeIdx >= 0 && nodeIdx < m_doc->tree.nodes.size()) {
|
||||
const Node& node = m_doc->tree.nodes[nodeIdx];
|
||||
if (node.isHelper && text != node.offsetExpr) {
|
||||
m_doc->undoStack.push(new RcxCommand(this,
|
||||
cmd::ChangeOffsetExpr{node.id, node.offsetExpr, text}));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EditTarget::ArrayIndex:
|
||||
case EditTarget::ArrayCount:
|
||||
// Array navigation removed - these cases are unreachable
|
||||
@@ -1177,6 +1187,14 @@ void RcxController::applyCommand(const Command& command, bool isUndo) {
|
||||
int idx = tree.indexOfId(c.nodeId);
|
||||
if (idx >= 0)
|
||||
tree.nodes[idx].enumMembers = isUndo ? c.oldMembers : c.newMembers;
|
||||
} else if constexpr (std::is_same_v<T, cmd::ChangeOffsetExpr>) {
|
||||
int idx = tree.indexOfId(c.nodeId);
|
||||
if (idx >= 0)
|
||||
tree.nodes[idx].offsetExpr = isUndo ? c.oldExpr : c.newExpr;
|
||||
} else if constexpr (std::is_same_v<T, cmd::ToggleHelper>) {
|
||||
int idx = tree.indexOfId(c.nodeId);
|
||||
if (idx >= 0)
|
||||
tree.nodes[idx].isHelper = isUndo ? c.oldVal : c.newVal;
|
||||
}
|
||||
}, command);
|
||||
|
||||
@@ -1831,6 +1849,19 @@ void RcxController::showContextMenu(RcxEditor* editor, int line, int nodeIdx,
|
||||
menu.addAction(icon("diff-added.svg"), "Add &Child", [this, nodeId]() {
|
||||
insertNode(nodeId, 0, NodeKind::Hex64, "newField");
|
||||
});
|
||||
// Add Helper — inserts a static helper child
|
||||
menu.addAction("Add Helper", [this, nodeId]() {
|
||||
Node helper;
|
||||
helper.id = m_doc->tree.m_nextId++;
|
||||
helper.kind = NodeKind::Hex64;
|
||||
helper.name = QStringLiteral("helper");
|
||||
helper.parentId = nodeId;
|
||||
helper.offset = 0;
|
||||
helper.isHelper = true;
|
||||
helper.offsetExpr = QStringLiteral("base");
|
||||
m_doc->undoStack.push(new RcxCommand(this,
|
||||
cmd::Insert{helper, {}}));
|
||||
});
|
||||
if (node.collapsed) {
|
||||
menu.addAction(icon("expand-all.svg"), "&Expand", [this, nodeId]() {
|
||||
int ni = m_doc->tree.indexOfId(nodeId);
|
||||
@@ -1845,6 +1876,25 @@ void RcxController::showContextMenu(RcxEditor* editor, int line, int nodeIdx,
|
||||
|
||||
}
|
||||
|
||||
// Helper-specific: Edit Expression inline
|
||||
if (node.isHelper) {
|
||||
menu.addAction("Edit E&xpression", [this, editor, line, nodeId]() {
|
||||
// Build completions list: "base" + sibling field names
|
||||
QStringList completions;
|
||||
completions << QStringLiteral("base");
|
||||
int ni = m_doc->tree.indexOfId(nodeId);
|
||||
if (ni >= 0) {
|
||||
uint64_t parentId = m_doc->tree.nodes[ni].parentId;
|
||||
for (const Node& sib : m_doc->tree.nodes) {
|
||||
if (sib.parentId == parentId && !sib.isHelper && !sib.name.isEmpty())
|
||||
completions << sib.name;
|
||||
}
|
||||
}
|
||||
editor->setHelperCompletions(completions);
|
||||
editor->beginInlineEdit(EditTarget::HelperExpr, line);
|
||||
});
|
||||
}
|
||||
|
||||
// Dissolve Union: available on union itself or any of its children
|
||||
{
|
||||
uint64_t targetUnionId = 0;
|
||||
@@ -2167,164 +2217,29 @@ TypeSelectorPopup* RcxController::ensurePopup(RcxEditor* editor) {
|
||||
void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
|
||||
int nodeIdx, QPoint globalPos) {
|
||||
const Node* node = nullptr;
|
||||
if (nodeIdx >= 0 && nodeIdx < m_doc->tree.nodes.size())
|
||||
if (nodeIdx >= 0 && nodeIdx < (int)m_doc->tree.nodes.size())
|
||||
node = &m_doc->tree.nodes[nodeIdx];
|
||||
|
||||
// ── Build entry list based on mode ──
|
||||
QVector<TypeEntry> entries;
|
||||
TypeEntry currentEntry;
|
||||
bool hasCurrent = false;
|
||||
int preModId = 0; // modifier to preselect: 0=plain, 1=*, 2=**, 3=[n]
|
||||
int preArrayCount = 0; // array count when preModId==3
|
||||
|
||||
auto addPrimitives = [&](bool enabled, bool excludeStructArrayPad) {
|
||||
for (const auto& m : kKindMeta) {
|
||||
if (excludeStructArrayPad &&
|
||||
(m.kind == NodeKind::Struct || m.kind == NodeKind::Array))
|
||||
continue;
|
||||
TypeEntry e;
|
||||
e.entryKind = TypeEntry::Primitive;
|
||||
e.primitiveKind = m.kind;
|
||||
e.displayName = QString::fromLatin1(m.typeName);
|
||||
e.enabled = enabled;
|
||||
entries.append(e);
|
||||
}
|
||||
};
|
||||
|
||||
auto addComposites = [&](const std::function<bool(const Node&, const TypeEntry&)>& isCurrent) {
|
||||
for (const auto& n : m_doc->tree.nodes) {
|
||||
if (n.parentId != 0 || n.kind != NodeKind::Struct) continue;
|
||||
TypeEntry e;
|
||||
e.entryKind = TypeEntry::Composite;
|
||||
e.structId = n.id;
|
||||
e.displayName = n.structTypeName.isEmpty() ? n.name : n.structTypeName;
|
||||
e.classKeyword = n.resolvedClassKeyword();
|
||||
entries.append(e);
|
||||
if (!hasCurrent && node && isCurrent(*node, e)) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
switch (mode) {
|
||||
case TypePopupMode::Root:
|
||||
// No primitives in Root mode – only project types are valid roots
|
||||
addComposites([&](const Node&, const TypeEntry& e) {
|
||||
return e.structId == m_viewRootId;
|
||||
});
|
||||
break;
|
||||
|
||||
case TypePopupMode::FieldType: {
|
||||
addPrimitives(/*enabled=*/true, /*excludeStructArrayPad=*/false);
|
||||
bool isPtr = node
|
||||
&& (node->kind == NodeKind::Pointer32 || node->kind == NodeKind::Pointer64);
|
||||
bool isTypedPtr = isPtr && node->refId != 0;
|
||||
// ── Determine modifier preset (cheap — only reads node properties) ──
|
||||
int preModId = 0;
|
||||
int preArrayCount = 0;
|
||||
if (mode == TypePopupMode::FieldType && node) {
|
||||
bool isPtr = (node->kind == NodeKind::Pointer32 || node->kind == NodeKind::Pointer64);
|
||||
bool isPrimPtr = isPtr && node->ptrDepth > 0 && node->refId == 0;
|
||||
bool isArray = node && node->kind == NodeKind::Array;
|
||||
|
||||
if (isPrimPtr) {
|
||||
// Primitive pointer (e.g. int32* or f64**) — current = element kind, modifier = *//**
|
||||
preModId = (node->ptrDepth >= 2) ? 2 : 1;
|
||||
for (auto& e : entries) {
|
||||
if (e.entryKind == TypeEntry::Primitive && e.primitiveKind == node->elementKind) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (isTypedPtr) {
|
||||
// Typed pointer (e.g. Ball*) — current = composite target, modifier = *
|
||||
preModId = 1;
|
||||
} else if (isArray) {
|
||||
// Array — modifier = [n]
|
||||
preModId = 3;
|
||||
preArrayCount = node->arrayLen;
|
||||
if (node->elementKind != NodeKind::Struct) {
|
||||
// Primitive array — mark element kind as current
|
||||
for (auto& e : entries) {
|
||||
if (e.entryKind == TypeEntry::Primitive && e.primitiveKind == node->elementKind) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (node) {
|
||||
// Plain primitive — mark current
|
||||
for (auto& e : entries) {
|
||||
if (e.entryKind == TypeEntry::Primitive && e.primitiveKind == node->kind) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// For isTypedPtr or struct-array: current is a Composite, set by addComposites below
|
||||
addComposites([&](const Node& n, const TypeEntry& e) {
|
||||
if (isTypedPtr && n.refId == e.structId) return true;
|
||||
if (isArray && n.elementKind == NodeKind::Struct && n.refId == e.structId) return true;
|
||||
return false;
|
||||
});
|
||||
break;
|
||||
bool isTypedPtr = isPtr && node->refId != 0;
|
||||
bool isArray = node->kind == NodeKind::Array;
|
||||
if (isPrimPtr) preModId = (node->ptrDepth >= 2) ? 2 : 1;
|
||||
else if (isTypedPtr) preModId = 1;
|
||||
else if (isArray) { preModId = 3; preArrayCount = node->arrayLen; }
|
||||
}
|
||||
|
||||
case TypePopupMode::ArrayElement:
|
||||
addPrimitives(/*enabled=*/true, /*excludeStructArrayPad=*/true);
|
||||
if (node) {
|
||||
for (auto& e : entries) {
|
||||
if (e.entryKind == TypeEntry::Primitive && e.primitiveKind == node->elementKind) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
addComposites([](const Node& n, const TypeEntry& e) {
|
||||
return n.elementKind == NodeKind::Struct && n.refId == e.structId;
|
||||
});
|
||||
break;
|
||||
|
||||
case TypePopupMode::PointerTarget: {
|
||||
// "void" entry as a primitive with a special display
|
||||
TypeEntry voidEntry;
|
||||
voidEntry.entryKind = TypeEntry::Primitive;
|
||||
voidEntry.primitiveKind = NodeKind::Hex8; // unused, but needs a value
|
||||
voidEntry.displayName = QStringLiteral("void");
|
||||
voidEntry.enabled = true;
|
||||
entries.append(voidEntry);
|
||||
if (node && node->refId == 0) {
|
||||
currentEntry = voidEntry;
|
||||
hasCurrent = true;
|
||||
}
|
||||
addComposites([](const Node& n, const TypeEntry& e) {
|
||||
return n.refId == e.structId;
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Add types from other open documents (not for Root mode) ──
|
||||
if (mode != TypePopupMode::Root && m_projectDocs) {
|
||||
QSet<QString> localNames;
|
||||
for (const auto& e : entries)
|
||||
if (e.entryKind == TypeEntry::Composite)
|
||||
localNames.insert(e.displayName);
|
||||
for (auto* doc : *m_projectDocs) {
|
||||
if (doc == m_doc) continue;
|
||||
for (const auto& n : doc->tree.nodes) {
|
||||
if (n.parentId != 0 || n.kind != NodeKind::Struct) continue;
|
||||
QString name = n.structTypeName.isEmpty() ? n.name : n.structTypeName;
|
||||
if (name.isEmpty() || localNames.contains(name)) continue;
|
||||
localNames.insert(name);
|
||||
TypeEntry e;
|
||||
e.entryKind = TypeEntry::Composite;
|
||||
e.structId = 0; // sentinel: not in local tree yet
|
||||
e.displayName = name;
|
||||
e.classKeyword = n.resolvedClassKeyword();
|
||||
entries.append(e);
|
||||
}
|
||||
}
|
||||
// ── Node size for same-size sorting (cheap) ──
|
||||
int nodeSize = 0;
|
||||
if (node) {
|
||||
if (mode == TypePopupMode::ArrayElement)
|
||||
nodeSize = sizeForKind(node->elementKind);
|
||||
else
|
||||
nodeSize = sizeForKind(node->kind);
|
||||
}
|
||||
|
||||
// ── Font with zoom ──
|
||||
@@ -2339,7 +2254,6 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
|
||||
// ── Position ──
|
||||
QPoint pos = globalPos;
|
||||
if (mode == TypePopupMode::Root) {
|
||||
// Bottom-left of the [▸] span on line 0
|
||||
long lineStart = sci->SendScintilla(QsciScintillaBase::SCI_POSITIONFROMLINE, 0);
|
||||
int lineH = (int)sci->SendScintilla(QsciScintillaBase::SCI_TEXTHEIGHT, 0);
|
||||
int x = (int)sci->SendScintilla(QsciScintillaBase::SCI_POINTXFROMPOSITION,
|
||||
@@ -2349,30 +2263,14 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
|
||||
pos = sci->viewport()->mapToGlobal(QPoint(x, y + lineH));
|
||||
}
|
||||
|
||||
// ── Configure and show popup ──
|
||||
// ── Configure popup + show skeleton instantly ──
|
||||
auto* popup = ensurePopup(editor);
|
||||
popup->setFont(font);
|
||||
popup->setMode(mode);
|
||||
|
||||
// Preselect modifier button to reflect current node state (after setMode resets to plain)
|
||||
if (preModId > 0)
|
||||
popup->setModifier(preModId, preArrayCount);
|
||||
|
||||
// Pass current node size for same-size sorting
|
||||
int nodeSize = 0;
|
||||
if (node) {
|
||||
if (mode == TypePopupMode::ArrayElement)
|
||||
nodeSize = sizeForKind(node->elementKind);
|
||||
else
|
||||
nodeSize = sizeForKind(node->kind);
|
||||
}
|
||||
popup->setCurrentNodeSize(nodeSize);
|
||||
|
||||
static const char* titles[] = { "Change root", "Change type",
|
||||
"Element type", "Pointer target" };
|
||||
popup->setTitle(QString::fromLatin1(titles[(int)mode]));
|
||||
popup->setTypes(entries, hasCurrent ? ¤tEntry : nullptr);
|
||||
|
||||
connect(popup, &TypeSelectorPopup::typeSelected,
|
||||
this, [this, mode, nodeIdx](const TypeEntry& entry, const QString& fullText) {
|
||||
applyTypePopupResult(mode, nodeIdx, entry, fullText);
|
||||
@@ -2383,7 +2281,6 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
|
||||
m_suppressRefresh = true;
|
||||
m_doc->undoStack.beginMacro(QStringLiteral("Create new type"));
|
||||
|
||||
// Generate unique default type name
|
||||
QString baseName = QStringLiteral("NewClass");
|
||||
QString typeName = baseName;
|
||||
int counter = 1;
|
||||
@@ -2404,7 +2301,6 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
|
||||
n.id = m_doc->tree.reserveId();
|
||||
m_doc->undoStack.push(new RcxCommand(this, cmd::Insert{n}));
|
||||
|
||||
// Populate with default hex nodes (8 x Hex64 = 64 bytes)
|
||||
for (int i = 0; i < 8; i++) {
|
||||
insertNode(n.id, i * 8, NodeKind::Hex64,
|
||||
QString("field_%1").arg(i * 8, 2, 16, QChar('0')));
|
||||
@@ -2419,7 +2315,212 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
|
||||
applyTypePopupResult(mode, nodeIdx, newEntry, QString());
|
||||
});
|
||||
|
||||
popup->popup(pos);
|
||||
popup->popupLoading(pos);
|
||||
|
||||
// ── Deferred: build entry list + fill content (runs next event-loop tick) ──
|
||||
int gen = ++m_typePopupGen;
|
||||
QTimer::singleShot(0, this, [this, popup, mode, nodeIdx, gen]() {
|
||||
if (gen != m_typePopupGen) return; // popup was reopened, discard stale load
|
||||
|
||||
const Node* node = nullptr;
|
||||
if (nodeIdx >= 0 && nodeIdx < (int)m_doc->tree.nodes.size())
|
||||
node = &m_doc->tree.nodes[nodeIdx];
|
||||
|
||||
QVector<TypeEntry> entries;
|
||||
TypeEntry currentEntry;
|
||||
bool hasCurrent = false;
|
||||
|
||||
auto addPrimitives = [&](bool enabled, bool excludeStructArrayPad) {
|
||||
for (const auto& m : kKindMeta) {
|
||||
if (excludeStructArrayPad &&
|
||||
(m.kind == NodeKind::Struct || m.kind == NodeKind::Array))
|
||||
continue;
|
||||
TypeEntry e;
|
||||
e.entryKind = TypeEntry::Primitive;
|
||||
e.primitiveKind = m.kind;
|
||||
e.displayName = QString::fromLatin1(m.typeName);
|
||||
e.enabled = enabled;
|
||||
e.sizeBytes = m.size;
|
||||
e.alignment = m.align;
|
||||
entries.append(e);
|
||||
}
|
||||
};
|
||||
|
||||
auto addComposites = [&](const std::function<bool(const Node&, const TypeEntry&)>& isCurrent) {
|
||||
for (const auto& n : m_doc->tree.nodes) {
|
||||
if (n.parentId != 0 || n.kind != NodeKind::Struct) continue;
|
||||
TypeEntry e;
|
||||
e.entryKind = TypeEntry::Composite;
|
||||
e.structId = n.id;
|
||||
e.displayName = n.structTypeName.isEmpty() ? n.name : n.structTypeName;
|
||||
e.classKeyword = n.resolvedClassKeyword();
|
||||
e.category = (e.classKeyword == QStringLiteral("enum"))
|
||||
? TypeEntry::CatEnum : TypeEntry::CatType;
|
||||
e.sizeBytes = m_doc->tree.structSpan(n.id);
|
||||
|
||||
QVector<int> kids = m_doc->tree.childrenOf(n.id);
|
||||
int nonHelperCount = 0;
|
||||
int maxAlign = 1;
|
||||
for (int i = 0; i < kids.size(); i++) {
|
||||
const Node& child = m_doc->tree.nodes[kids[i]];
|
||||
if (child.isHelper) continue;
|
||||
nonHelperCount++;
|
||||
int childAlign = alignmentFor(child.kind);
|
||||
if (childAlign > maxAlign) maxAlign = childAlign;
|
||||
if (e.fieldSummary.size() < 6) {
|
||||
auto* cm = kindMeta(child.kind);
|
||||
QString typeName = cm ? QString::fromLatin1(cm->typeName)
|
||||
: QStringLiteral("???");
|
||||
if (child.kind == NodeKind::Struct && child.refId != 0) {
|
||||
int refIdx = m_doc->tree.indexOfId(child.refId);
|
||||
if (refIdx >= 0) {
|
||||
const Node& ref = m_doc->tree.nodes[refIdx];
|
||||
typeName = ref.structTypeName.isEmpty()
|
||||
? ref.name : ref.structTypeName;
|
||||
}
|
||||
}
|
||||
e.fieldSummary << QStringLiteral("0x%1: %2 %3")
|
||||
.arg(child.offset, 2, 16, QChar('0'))
|
||||
.arg(typeName, child.name);
|
||||
}
|
||||
}
|
||||
e.fieldCount = nonHelperCount;
|
||||
e.alignment = maxAlign;
|
||||
|
||||
entries.append(e);
|
||||
if (!hasCurrent && node && isCurrent(*node, e)) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
switch (mode) {
|
||||
case TypePopupMode::Root:
|
||||
addComposites([this](const Node&, const TypeEntry& e) {
|
||||
return e.structId == m_viewRootId;
|
||||
});
|
||||
break;
|
||||
|
||||
case TypePopupMode::FieldType: {
|
||||
addPrimitives(/*enabled=*/true, /*excludeStructArrayPad=*/false);
|
||||
bool isPtr = node
|
||||
&& (node->kind == NodeKind::Pointer32 || node->kind == NodeKind::Pointer64);
|
||||
bool isTypedPtr = isPtr && node->refId != 0;
|
||||
bool isPrimPtr = isPtr && node->ptrDepth > 0 && node->refId == 0;
|
||||
bool isArray = node && node->kind == NodeKind::Array;
|
||||
|
||||
if (isPrimPtr) {
|
||||
for (auto& e : entries) {
|
||||
if (e.entryKind == TypeEntry::Primitive && e.primitiveKind == node->elementKind) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (isTypedPtr) {
|
||||
// current set by addComposites below
|
||||
} else if (isArray) {
|
||||
if (node->elementKind != NodeKind::Struct) {
|
||||
for (auto& e : entries) {
|
||||
if (e.entryKind == TypeEntry::Primitive && e.primitiveKind == node->elementKind) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (node) {
|
||||
if (!(node->kind == NodeKind::Struct && node->refId != 0)) {
|
||||
for (auto& e : entries) {
|
||||
if (e.entryKind == TypeEntry::Primitive && e.primitiveKind == node->kind) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
addComposites([&](const Node& n, const TypeEntry& e) {
|
||||
if (isTypedPtr && n.refId == e.structId) return true;
|
||||
if (isArray && n.elementKind == NodeKind::Struct && n.refId == e.structId) return true;
|
||||
if (!isPtr && !isArray && n.kind == NodeKind::Struct && n.refId == e.structId) return true;
|
||||
return false;
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case TypePopupMode::ArrayElement:
|
||||
addPrimitives(/*enabled=*/true, /*excludeStructArrayPad=*/true);
|
||||
if (node) {
|
||||
for (auto& e : entries) {
|
||||
if (e.entryKind == TypeEntry::Primitive && e.primitiveKind == node->elementKind) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
addComposites([](const Node& n, const TypeEntry& e) {
|
||||
return n.elementKind == NodeKind::Struct && n.refId == e.structId;
|
||||
});
|
||||
break;
|
||||
|
||||
case TypePopupMode::PointerTarget: {
|
||||
TypeEntry voidEntry;
|
||||
voidEntry.entryKind = TypeEntry::Primitive;
|
||||
voidEntry.primitiveKind = NodeKind::Hex8;
|
||||
voidEntry.displayName = QStringLiteral("void");
|
||||
voidEntry.enabled = true;
|
||||
entries.append(voidEntry);
|
||||
addPrimitives(/*enabled=*/true, /*excludeStructArrayPad=*/true);
|
||||
if (node && node->refId == 0 && node->ptrDepth <= 1) {
|
||||
currentEntry = voidEntry;
|
||||
hasCurrent = true;
|
||||
} else if (node && node->refId == 0 && node->ptrDepth > 0) {
|
||||
for (auto& e : entries) {
|
||||
if (e.entryKind == TypeEntry::Primitive && e.primitiveKind == node->elementKind) {
|
||||
currentEntry = e;
|
||||
hasCurrent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
addComposites([](const Node& n, const TypeEntry& e) {
|
||||
return n.refId == e.structId;
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Add types from other open documents
|
||||
if (mode != TypePopupMode::Root && m_projectDocs) {
|
||||
QSet<QString> localNames;
|
||||
for (const auto& e : entries)
|
||||
if (e.entryKind == TypeEntry::Composite)
|
||||
localNames.insert(e.displayName);
|
||||
for (auto* doc : *m_projectDocs) {
|
||||
if (doc == m_doc) continue;
|
||||
for (const auto& n : doc->tree.nodes) {
|
||||
if (n.parentId != 0 || n.kind != NodeKind::Struct) continue;
|
||||
QString name = n.structTypeName.isEmpty() ? n.name : n.structTypeName;
|
||||
if (name.isEmpty() || localNames.contains(name)) continue;
|
||||
localNames.insert(name);
|
||||
TypeEntry e;
|
||||
e.entryKind = TypeEntry::Composite;
|
||||
e.structId = 0;
|
||||
e.displayName = name;
|
||||
e.classKeyword = n.resolvedClassKeyword();
|
||||
e.category = (e.classKeyword == QStringLiteral("enum"))
|
||||
? TypeEntry::CatEnum : TypeEntry::CatType;
|
||||
e.sizeBytes = doc->tree.structSpan(n.id);
|
||||
entries.append(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
popup->setTypes(entries, hasCurrent ? ¤tEntry : nullptr);
|
||||
});
|
||||
}
|
||||
|
||||
void RcxController::applyTypePopupResult(TypePopupMode mode, int nodeIdx,
|
||||
|
||||
@@ -168,6 +168,7 @@ private:
|
||||
|
||||
// ── Cached type selector popup (avoids ~350ms cold-start on first show) ──
|
||||
QPointer<TypeSelectorPopup> m_cachedPopup;
|
||||
int m_typePopupGen = 0; // generation counter for deferred content loading
|
||||
|
||||
// ── Auto-refresh state ──
|
||||
using PageMap = QHash<uint64_t, QByteArray>;
|
||||
@@ -177,7 +178,7 @@ private:
|
||||
PageMap m_prevPages;
|
||||
QSet<int64_t> m_changedOffsets;
|
||||
QHash<uint64_t, ValueHistory> m_valueHistory;
|
||||
bool m_trackValues = false;
|
||||
bool m_trackValues = true;
|
||||
uint64_t m_refreshGen = 0;
|
||||
uint64_t m_readGen = 0;
|
||||
bool m_readInFlight = false;
|
||||
|
||||
28
src/core.h
28
src/core.h
@@ -197,6 +197,8 @@ struct Node {
|
||||
QString classKeyword; // "struct", "class", or "enum" (empty = "struct")
|
||||
uint64_t parentId = 0; // 0 = root (no parent)
|
||||
int offset = 0;
|
||||
bool isHelper = false; // static helper — excluded from struct layout
|
||||
QString offsetExpr; // C/C++ expression → absolute address (helpers only)
|
||||
int arrayLen = 1; // Array: element count
|
||||
int strLen = 64;
|
||||
bool collapsed = false;
|
||||
@@ -238,6 +240,10 @@ struct Node {
|
||||
o["classKeyword"] = classKeyword;
|
||||
o["parentId"] = QString::number(parentId);
|
||||
o["offset"] = offset;
|
||||
if (isHelper)
|
||||
o["isHelper"] = true;
|
||||
if (!offsetExpr.isEmpty())
|
||||
o["offsetExpr"] = offsetExpr;
|
||||
o["arrayLen"] = arrayLen;
|
||||
o["strLen"] = strLen;
|
||||
o["collapsed"] = collapsed;
|
||||
@@ -277,6 +283,8 @@ struct Node {
|
||||
n.classKeyword = o["classKeyword"].toString();
|
||||
n.parentId = o["parentId"].toString("0").toULongLong();
|
||||
n.offset = o["offset"].toInt(0);
|
||||
n.isHelper = o["isHelper"].toBool(false);
|
||||
n.offsetExpr = o["offsetExpr"].toString();
|
||||
n.arrayLen = qBound(1, o["arrayLen"].toInt(1), 1000000);
|
||||
n.strLen = qBound(1, o["strLen"].toInt(64), 1000000);
|
||||
n.collapsed = o["collapsed"].toBool(false);
|
||||
@@ -437,6 +445,7 @@ struct NodeTree {
|
||||
QVector<int> kids = childMap ? childMap->value(structId) : childrenOf(structId);
|
||||
for (int ci : kids) {
|
||||
const Node& c = nodes[ci];
|
||||
if (c.isHelper) continue; // helpers don't affect struct size
|
||||
int sz = (c.kind == NodeKind::Struct || c.kind == NodeKind::Array)
|
||||
? structSpan(c.id, childMap, visited) : c.byteSize();
|
||||
int end = c.offset + sz;
|
||||
@@ -591,6 +600,7 @@ struct LineMeta {
|
||||
QString pointerTargetName; // Resolved target type name for Pointer32/64 (empty = "void")
|
||||
bool isArrayElement = false; // true for synthesized primitive array element lines
|
||||
bool isMemberLine = false; // true for enum member / bitfield member lines
|
||||
bool isHelperLine = false; // true for static helper node lines
|
||||
};
|
||||
|
||||
inline bool isSyntheticLine(const LineMeta& lm) {
|
||||
@@ -637,13 +647,16 @@ namespace cmd {
|
||||
struct ChangeOffset { uint64_t nodeId; int oldOffset, newOffset; };
|
||||
struct ChangeEnumMembers { uint64_t nodeId;
|
||||
QVector<QPair<QString, int64_t>> oldMembers, newMembers; };
|
||||
struct ChangeOffsetExpr { uint64_t nodeId; QString oldExpr, newExpr; };
|
||||
struct ToggleHelper { uint64_t nodeId; bool oldVal, newVal; };
|
||||
}
|
||||
|
||||
using Command = std::variant<
|
||||
cmd::ChangeKind, cmd::Rename, cmd::Collapse,
|
||||
cmd::Insert, cmd::Remove, cmd::ChangeBase, cmd::WriteBytes,
|
||||
cmd::ChangeArrayMeta, cmd::ChangePointerRef, cmd::ChangeStructTypeName,
|
||||
cmd::ChangeClassKeyword, cmd::ChangeOffset, cmd::ChangeEnumMembers
|
||||
cmd::ChangeClassKeyword, cmd::ChangeOffset, cmd::ChangeEnumMembers,
|
||||
cmd::ChangeOffsetExpr, cmd::ToggleHelper
|
||||
>;
|
||||
|
||||
// ── Column spans (for inline editing) ──
|
||||
@@ -656,7 +669,7 @@ struct ColumnSpan {
|
||||
|
||||
enum class EditTarget { Name, Type, Value, BaseAddress, Source, ArrayIndex, ArrayCount,
|
||||
ArrayElementType, ArrayElementCount, PointerTarget,
|
||||
RootClassType, RootClassName, TypeSelector };
|
||||
RootClassType, RootClassName, TypeSelector, HelperExpr };
|
||||
|
||||
// Column layout constants (shared with format.cpp span computation)
|
||||
inline constexpr int kFoldCol = 3; // 3-char fold indicator prefix per line
|
||||
@@ -734,6 +747,17 @@ inline ColumnSpan memberValueSpanFor(const LineMeta& lm, const QString& lineText
|
||||
return {valStart, valEnd, true};
|
||||
}
|
||||
|
||||
// Helper expression span: locates text between "= " and " →" (or end of line)
|
||||
inline ColumnSpan helperExprSpanFor(const LineMeta& /*lm*/, const QString& lineText) {
|
||||
int eq = lineText.indexOf(QLatin1String("= "));
|
||||
if (eq < 0) return {};
|
||||
int exprStart = eq + 2;
|
||||
int arrow = lineText.indexOf(QChar(0x2192), exprStart); // →
|
||||
int exprEnd = (arrow > exprStart) ? arrow - 1 : lineText.size();
|
||||
while (exprEnd > exprStart && lineText[exprEnd - 1] == ' ') exprEnd--;
|
||||
return {exprStart, exprEnd, true};
|
||||
}
|
||||
|
||||
inline ColumnSpan commentSpanFor(const LineMeta& lm, int lineLength, int typeW = kColType, int nameW = kColName) {
|
||||
if (lm.lineKind == LineKind::Header || lm.lineKind == LineKind::Footer) return {};
|
||||
int ind = kFoldCol + lm.depth * 3;
|
||||
|
||||
@@ -503,6 +503,19 @@ RcxEditor::RcxEditor(QWidget* parent) : QWidget(parent) {
|
||||
if (m_updatingComment) return; // Skip queuing during comment update
|
||||
if (m_editState.target == EditTarget::Value)
|
||||
QTimer::singleShot(0, this, &RcxEditor::validateEditLive);
|
||||
|
||||
// Autocomplete for helper expressions — show field names as user types
|
||||
if (m_editState.target == EditTarget::HelperExpr && !m_helperCompletions.isEmpty()) {
|
||||
// Get word at cursor
|
||||
long pos = m_sci->SendScintilla(QsciScintillaBase::SCI_GETCURRENTPOS);
|
||||
long wordStart = m_sci->SendScintilla(QsciScintillaBase::SCI_WORDSTARTPOSITION, pos, (long)1);
|
||||
int wordLen = (int)(pos - wordStart);
|
||||
if (wordLen >= 1) {
|
||||
QByteArray list = m_helperCompletions.join(' ').toUtf8();
|
||||
m_sci->SendScintilla(QsciScintillaBase::SCI_AUTOCSETSEPARATOR, (long)' ');
|
||||
m_sci->SendScintilla(QsciScintillaBase::SCI_AUTOCSHOW, (uintptr_t)wordLen, list.constData());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_sci, &QsciScintilla::selectionChanged,
|
||||
@@ -1599,6 +1612,10 @@ bool RcxEditor::resolvedSpanFor(int line, EditTarget t,
|
||||
s = arrayElemCountSpanFor(*lm, lineText); break;
|
||||
case EditTarget::PointerTarget:
|
||||
s = pointerTargetSpanFor(*lm, lineText); break;
|
||||
case EditTarget::HelperExpr:
|
||||
if (lm->isHelperLine)
|
||||
s = helperExprSpanFor(*lm, lineText);
|
||||
break;
|
||||
case EditTarget::Source: break;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
bool isEditing() const { return m_editState.active; }
|
||||
bool beginInlineEdit(EditTarget target, int line = -1, int col = -1);
|
||||
void cancelInlineEdit();
|
||||
void setHelperCompletions(const QStringList& words) { m_helperCompletions = words; }
|
||||
|
||||
void applySelectionOverlay(const QSet<uint64_t>& selIds);
|
||||
void setCommandRowText(const QString& line);
|
||||
@@ -133,6 +134,7 @@ private:
|
||||
bool lastValidationOk = true; // track state to avoid redundant updates
|
||||
};
|
||||
InlineEditState m_editState;
|
||||
QStringList m_helperCompletions; // autocomplete words for HelperExpr editing
|
||||
|
||||
// ── Tab cycling state ──
|
||||
EditTarget m_lastTabTarget = EditTarget::Value;
|
||||
|
||||
@@ -172,7 +172,14 @@ static void emitStructBody(GenContext& ctx, uint64_t structId,
|
||||
int structSize = tree.structSpan(structId, &ctx.childMap);
|
||||
QString ind = indent(depth);
|
||||
|
||||
QVector<int> children = ctx.childMap.value(structId);
|
||||
QVector<int> allChildren = ctx.childMap.value(structId);
|
||||
QVector<int> children, helperIdxs;
|
||||
for (int ci : allChildren) {
|
||||
if (tree.nodes[ci].isHelper)
|
||||
helperIdxs.append(ci);
|
||||
else
|
||||
children.append(ci);
|
||||
}
|
||||
std::sort(children.begin(), children.end(), [&](int a, int b) {
|
||||
return tree.nodes[a].offset < tree.nodes[b].offset;
|
||||
});
|
||||
@@ -310,6 +317,14 @@ static void emitStructBody(GenContext& ctx, uint64_t structId,
|
||||
// Tail padding (skip for unions)
|
||||
if (!isUnion && cursor < structSize)
|
||||
emitPadRun(cursor, structSize - cursor);
|
||||
|
||||
// Emit helper comments (helpers are runtime-only, not part of struct layout)
|
||||
for (int hi : helperIdxs) {
|
||||
const Node& h = tree.nodes[hi];
|
||||
QString hType = h.structTypeName.isEmpty() ? ctx.cType(h.kind) : h.structTypeName;
|
||||
ctx.output += ind + QStringLiteral("// helper: %1 %2 @ %3\n")
|
||||
.arg(hType, sanitizeIdent(h.name), h.offsetExpr);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Emit a complete top-level struct definition (Vergilius-style) ──
|
||||
|
||||
@@ -51,6 +51,8 @@
|
||||
<file alias="chevron-down.svg">vsicons/chevron-down.svg</file>
|
||||
<file alias="folder.svg">vsicons/folder.svg</file>
|
||||
<file alias="symbol-enum.svg">vsicons/symbol-enum.svg</file>
|
||||
<file alias="symbol-class.svg">vsicons/symbol-class.svg</file>
|
||||
<file alias="symbol-variable.svg">vsicons/symbol-variable.svg</file>
|
||||
<file alias="server-process.svg">vsicons/server-process.svg</file>
|
||||
<file alias="remote.svg">vsicons/remote.svg</file>
|
||||
<file alias="plug.svg">vsicons/plug.svg</file>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@
|
||||
#include <QFont>
|
||||
#include <QVector>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <cstdint>
|
||||
#include "core.h"
|
||||
|
||||
@@ -26,13 +27,19 @@ enum class TypePopupMode { Root, FieldType, ArrayElement, PointerTarget };
|
||||
|
||||
struct TypeEntry {
|
||||
enum Kind { Primitive, Composite, Section };
|
||||
enum Category { CatPrimitive, CatType, CatEnum };
|
||||
|
||||
Kind entryKind = Primitive;
|
||||
Category category = CatPrimitive;
|
||||
NodeKind primitiveKind = NodeKind::Hex8; // valid when entryKind==Primitive
|
||||
uint64_t structId = 0; // valid when entryKind==Composite
|
||||
QString displayName;
|
||||
QString classKeyword; // "struct", "class", "enum" (Composite only)
|
||||
bool enabled = true; // false = grayed out (visible but not selectable)
|
||||
int sizeBytes = 0; // size in bytes (for display)
|
||||
int alignment = 0; // natural alignment in bytes
|
||||
int fieldCount = 0; // child field count (composite only)
|
||||
QStringList fieldSummary; // first ~6 fields: "0x00: float x"
|
||||
};
|
||||
|
||||
// ── Parsed type spec (shared between popup filter and inline edit) ──
|
||||
@@ -58,16 +65,21 @@ public:
|
||||
void setMode(TypePopupMode mode);
|
||||
void applyTheme(const Theme& theme);
|
||||
void setCurrentNodeSize(int bytes);
|
||||
void setPointerSize(int bytes);
|
||||
void setModifier(int modId, int arrayCount = 0);
|
||||
void setTypes(const QVector<TypeEntry>& types, const TypeEntry* current = nullptr);
|
||||
void popup(const QPoint& globalPos);
|
||||
|
||||
/// Show popup instantly with skeleton placeholders; call setTypes() to fill content.
|
||||
void popupLoading(const QPoint& globalPos);
|
||||
|
||||
/// Force native window creation to avoid cold-start delay.
|
||||
void warmUp();
|
||||
|
||||
signals:
|
||||
void typeSelected(const TypeEntry& entry, const QString& fullText);
|
||||
void createNewTypeRequested();
|
||||
void saveRequested();
|
||||
void dismissed();
|
||||
|
||||
protected:
|
||||
@@ -78,27 +90,35 @@ private:
|
||||
QLabel* m_titleLabel = nullptr;
|
||||
QToolButton* m_escLabel = nullptr;
|
||||
QToolButton* m_createBtn = nullptr;
|
||||
QToolButton* m_saveBtn = nullptr;
|
||||
QLineEdit* m_filterEdit = nullptr;
|
||||
QLabel* m_previewLabel = nullptr;
|
||||
QListView* m_listView = nullptr;
|
||||
QStringListModel* m_model = nullptr;
|
||||
QFrame* m_separator = nullptr;
|
||||
|
||||
// Modifier toggles
|
||||
QWidget* m_modRow = nullptr;
|
||||
QToolButton* m_btnPlain = nullptr;
|
||||
QToolButton* m_btnPtr = nullptr;
|
||||
QToolButton* m_btnDblPtr = nullptr;
|
||||
QToolButton* m_btnArray = nullptr;
|
||||
QLineEdit* m_arrayCountEdit = nullptr;
|
||||
QButtonGroup* m_modGroup = nullptr;
|
||||
|
||||
// Category filter checkboxes
|
||||
QWidget* m_chipRow = nullptr;
|
||||
QToolButton* m_chipPrim = nullptr;
|
||||
QToolButton* m_chipTypes = nullptr;
|
||||
QToolButton* m_chipEnums = nullptr;
|
||||
QLabel* m_statusLabel = nullptr;
|
||||
|
||||
QVector<TypeEntry> m_allTypes;
|
||||
QVector<TypeEntry> m_filteredTypes;
|
||||
QVector<QVector<int>> m_matchPositions;
|
||||
TypeEntry m_currentEntry;
|
||||
bool m_hasCurrent = false;
|
||||
TypePopupMode m_mode = TypePopupMode::FieldType;
|
||||
int m_currentNodeSize = 0;
|
||||
int m_pointerSize = 8;
|
||||
bool m_loading = false;
|
||||
QFont m_font;
|
||||
|
||||
void applyFilter(const QString& text);
|
||||
|
||||
Reference in New Issue
Block a user