refactor: rename helpers to static fields, block-style rendering, sibling insert

Rename isHelper/ToggleHelper to isStatic/ToggleStatic across core, compose,
controller, editor, and generator. Static fields now render with block syntax
(static Type name { return expr } → 0xADDR) and support collapsed/expanded
display. Add "Add Static Field" context menu for sibling nodes. Update
expression span parser, completions, C++ generator comments, and all tests.
This commit is contained in:
IChooseYou
2026-02-28 08:21:00 -07:00
committed by IChooseYou
parent 6a51c904de
commit 95faf027a9
12 changed files with 685 additions and 367 deletions

View File

@@ -397,11 +397,11 @@ void composeParent(ComposeState& state, const NodeTree& tree,
const QVector<int>& allChildren = childIndices(state, node.id);
// Split children into regular nodes and helpers (helpers render at the end)
QVector<int> regular, helperIdxs;
// Split children into regular nodes and static fields (static fields render at the end)
QVector<int> regular, staticIdxs;
for (int ci : allChildren) {
if (tree.nodes[ci].isHelper)
helperIdxs.append(ci);
if (tree.nodes[ci].isStatic)
staticIdxs.append(ci);
else
regular.append(ci);
}
@@ -523,24 +523,9 @@ void composeParent(ComposeState& state, const NodeTree& tree,
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
// ── Static fields: render after regular children, before footer ──
if (!staticIdxs.isEmpty() && !node.collapsed) {
// Build identifier resolver for static field expressions
auto makeResolver = [&](uint64_t parentAbsAddr) {
AddressParserCallbacks cbs;
cbs.resolveIdentifier = [&tree, &prov, &regular, parentAbsAddr]
@@ -582,92 +567,143 @@ void composeParent(ComposeState& state, const NodeTree& tree,
auto cbs = makeResolver(absAddr);
for (int hi : helperIdxs) {
const Node& helper = tree.nodes[hi];
for (int si : staticIdxs) {
const Node& sf = tree.nodes[si];
// Evaluate expression → absolute address
uint64_t helperAddr = 0;
uint64_t staticAddr = 0;
bool exprOk = false;
if (!helper.offsetExpr.isEmpty()) {
auto result = AddressParser::evaluate(helper.offsetExpr, 8, &cbs);
if (!sf.offsetExpr.isEmpty()) {
auto result = AddressParser::evaluate(sf.offsetExpr, 8, &cbs);
exprOk = result.ok;
if (result.ok)
helperAddr = result.value;
staticAddr = result.value;
}
// Format: "▸ type name = expr → 0xADDR" (or "= expr (error)" on failure)
int typeW = state.effectiveTypeW(node.id);
int nameW = state.effectiveNameW(node.id);
// Resolve type name
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));
if (sf.kind == NodeKind::Struct)
typeName = fmt::structTypeName(sf);
else if (sf.kind == NodeKind::Pointer64 || sf.kind == NodeKind::Pointer32)
typeName = fmt::pointerTypeName(sf.kind, resolvePointerTarget(tree, sf.refId));
else
typeName = fmt::typeNameRaw(helper.kind);
typeName = fmt::typeNameRaw(sf.kind);
bool overflow = state.compactColumns && typeName.size() > typeW;
QString type = overflow ? typeName : typeName.leftJustified(typeW);
QString name = overflow ? helper.name : helper.name.leftJustified(nameW);
bool isCollapsed = sf.collapsed;
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);
// ── Header line: "static <type> <name> {" or collapsed: "static <type> <name> { return <expr>; }"
QString headerLine;
if (isCollapsed) {
QString exprPart;
if (!sf.offsetExpr.isEmpty()) {
if (exprOk)
exprPart = QStringLiteral("return %1 } \u2192 0x%2")
.arg(sf.offsetExpr)
.arg(QString::number(staticAddr, 16).toUpper());
else
exprPart = QStringLiteral("return %1 } (error)").arg(sf.offsetExpr);
} else {
exprPart = QStringLiteral("}");
}
headerLine = fmt::indent(childDepth)
+ QStringLiteral("static ") + typeName
+ QStringLiteral(" ") + sf.name
+ QStringLiteral(" { ") + exprPart;
} else {
headerLine = fmt::indent(childDepth)
+ QStringLiteral("static ") + typeName
+ QStringLiteral(" ") + sf.name
+ QStringLiteral(" {");
}
QString line = fmt::indent(childDepth) + type
+ QStringLiteral(" ") + name
+ QStringLiteral(" ") + exprPart;
LineMeta lm;
lm.nodeIdx = hi;
lm.nodeId = helper.id;
lm.nodeIdx = si;
lm.nodeId = sf.id;
lm.depth = childDepth;
lm.lineKind = LineKind::Header;
lm.nodeKind = helper.kind;
lm.nodeKind = sf.kind;
lm.foldHead = true;
lm.foldCollapsed = true; // helpers always start collapsed
lm.isHelperLine = true;
lm.foldCollapsed = isCollapsed;
lm.isStaticLine = true;
lm.foldLevel = computeFoldLevel(childDepth, true);
lm.markerMask = (1u << M_STRUCT_BG);
lm.offsetText = QStringLiteral("~") + QString::number(helperAddr, 16)
lm.offsetText = QStringLiteral("~") + QString::number(staticAddr, 16)
.toUpper().rightJustified(state.offsetHexDigits - 1, '0');
lm.offsetAddr = helperAddr;
lm.offsetAddr = staticAddr;
lm.ptrBase = state.currentPtrBase;
lm.effectiveTypeW = overflow ? typeName.size() : typeW;
lm.effectiveNameW = nameW;
state.emitLine(line, lm);
lm.effectiveTypeW = typeName.size() + 7; // "static " prefix
lm.effectiveNameW = sf.name.size();
state.emitLine(headerLine, 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);
// ── Body + children (only when expanded) ──
if (!isCollapsed) {
// Body line: " return <expr> → 0xADDR"
{
QString bodyLine;
if (!sf.offsetExpr.isEmpty()) {
if (exprOk)
bodyLine = fmt::indent(childDepth + 1)
+ QStringLiteral("return %1").arg(sf.offsetExpr);
else
bodyLine = fmt::indent(childDepth + 1)
+ QStringLiteral("return %1 (error)").arg(sf.offsetExpr);
} else {
bodyLine = fmt::indent(childDepth + 1)
+ QStringLiteral("return 0");
}
// Helper footer
// Right-align resolved address
if (exprOk && !sf.offsetExpr.isEmpty()) {
bodyLine += QStringLiteral(" \u2192 0x")
+ QString::number(staticAddr, 16).toUpper();
}
LineMeta blm;
blm.nodeIdx = si;
blm.nodeId = sf.id;
blm.depth = childDepth + 1;
blm.lineKind = LineKind::Field;
blm.nodeKind = sf.kind;
blm.isStaticLine = true;
blm.foldLevel = computeFoldLevel(childDepth + 1, false);
blm.markerMask = 0;
blm.offsetText = QString(state.offsetHexDigits, QChar(' '));
blm.offsetAddr = staticAddr;
blm.ptrBase = state.currentPtrBase;
state.emitLine(bodyLine, blm);
}
// If struct/array, compose children at evaluated address
if (exprOk && (sf.kind == NodeKind::Struct || sf.kind == NodeKind::Array)) {
const QVector<int>& staticKids = childIndices(state, sf.id);
for (int sci : staticKids) {
composeNode(state, tree, prov, sci, childDepth + 1,
staticAddr, sf.id, false, sf.id);
}
}
// Footer line: "};"
{
LineMeta flm;
flm.nodeIdx = hi;
flm.nodeId = helper.id;
flm.nodeIdx = si;
flm.nodeId = sf.id;
flm.depth = childDepth;
flm.lineKind = LineKind::Footer;
flm.nodeKind = helper.kind;
flm.nodeKind = sf.kind;
flm.isStaticLine = true;
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;
if (exprOk && (sf.kind == NodeKind::Struct || sf.kind == NodeKind::Array)) {
int sSpan = tree.structSpan(sf.id, &state.childMap);
flm.offsetText = fmt::fmtOffsetMargin(staticAddr + sSpan, false,
state.offsetHexDigits);
flm.offsetAddr = staticAddr + sSpan;
} else {
flm.offsetText = QString(state.offsetHexDigits, QChar(' '));
flm.offsetAddr = staticAddr;
}
flm.ptrBase = state.currentPtrBase;
state.emitLine(fmt::fmtStructFooter(helper, childDepth, hSpan), flm);
state.emitLine(fmt::indent(childDepth) + QStringLiteral("};"), flm);
}
}
}

View File

@@ -481,10 +481,10 @@ void RcxController::connectEditor(RcxEditor* editor) {
}
break;
}
case EditTarget::HelperExpr: {
case EditTarget::StaticExpr: {
if (nodeIdx >= 0 && nodeIdx < m_doc->tree.nodes.size()) {
const Node& node = m_doc->tree.nodes[nodeIdx];
if (node.isHelper && text != node.offsetExpr) {
if (node.isStatic && text != node.offsetExpr) {
m_doc->undoStack.push(new RcxCommand(this,
cmd::ChangeOffsetExpr{node.id, node.offsetExpr, text}));
}
@@ -1191,10 +1191,10 @@ void RcxController::applyCommand(const Command& command, bool isUndo) {
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>) {
} else if constexpr (std::is_same_v<T, cmd::ToggleStatic>) {
int idx = tree.indexOfId(c.nodeId);
if (idx >= 0)
tree.nodes[idx].isHelper = isUndo ? c.oldVal : c.newVal;
tree.nodes[idx].isStatic = isUndo ? c.oldVal : c.newVal;
}
}, command);
@@ -1849,18 +1849,18 @@ 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");
// Add Static Field — inserts a static field child
menu.addAction("Add Static Field", [this, nodeId]() {
Node sf;
sf.id = m_doc->tree.m_nextId++;
sf.kind = NodeKind::Hex64;
sf.name = QStringLiteral("static_field");
sf.parentId = nodeId;
sf.offset = 0;
sf.isStatic = true;
sf.offsetExpr = QStringLiteral("base");
m_doc->undoStack.push(new RcxCommand(this,
cmd::Insert{helper, {}}));
cmd::Insert{sf, {}}));
});
if (node.collapsed) {
menu.addAction(icon("expand-all.svg"), "&Expand", [this, nodeId]() {
@@ -1876,8 +1876,29 @@ void RcxController::showContextMenu(RcxEditor* editor, int line, int nodeIdx,
}
// Helper-specific: Edit Expression inline
if (node.isHelper) {
// Add Static Field as sibling (for child nodes of a struct)
if (node.parentId != 0 && node.kind != NodeKind::Struct && node.kind != NodeKind::Array) {
uint64_t parentId = node.parentId;
int pi = m_doc->tree.indexOfId(parentId);
if (pi >= 0 && (m_doc->tree.nodes[pi].kind == NodeKind::Struct
|| m_doc->tree.nodes[pi].kind == NodeKind::Array)) {
menu.addAction("Add Static Field", [this, parentId]() {
Node sf;
sf.id = m_doc->tree.m_nextId++;
sf.kind = NodeKind::Hex64;
sf.name = QStringLiteral("static_field");
sf.parentId = parentId;
sf.offset = 0;
sf.isStatic = true;
sf.offsetExpr = QStringLiteral("base");
m_doc->undoStack.push(new RcxCommand(this,
cmd::Insert{sf, {}}));
});
}
}
// Static field: Edit Expression inline
if (node.isStatic) {
menu.addAction("Edit E&xpression", [this, editor, line, nodeId]() {
// Build completions list: "base" + sibling field names
QStringList completions;
@@ -1886,12 +1907,12 @@ void RcxController::showContextMenu(RcxEditor* editor, int line, int nodeIdx,
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())
if (sib.parentId == parentId && !sib.isStatic && !sib.name.isEmpty())
completions << sib.name;
}
}
editor->setHelperCompletions(completions);
editor->beginInlineEdit(EditTarget::HelperExpr, line);
editor->setStaticCompletions(completions);
editor->beginInlineEdit(EditTarget::StaticExpr, line);
});
}
@@ -1948,6 +1969,27 @@ void RcxController::showContextMenu(RcxEditor* editor, int line, int nodeIdx,
// ── Always-available actions ──
// Add Static Field to current view root (struct)
if (m_viewRootId != 0) {
int ri = m_doc->tree.indexOfId(m_viewRootId);
if (ri >= 0 && (m_doc->tree.nodes[ri].kind == NodeKind::Struct
|| m_doc->tree.nodes[ri].kind == NodeKind::Array)) {
uint64_t rootId = m_viewRootId;
menu.addAction("Add Static Field", [this, rootId]() {
Node sf;
sf.id = m_doc->tree.m_nextId++;
sf.kind = NodeKind::Hex64;
sf.name = QStringLiteral("static_field");
sf.parentId = rootId;
sf.offset = 0;
sf.isStatic = true;
sf.offsetExpr = QStringLiteral("base");
m_doc->undoStack.push(new RcxCommand(this,
cmd::Insert{sf, {}}));
});
}
}
menu.addAction(icon("diff-added.svg"), "Append bytes...", [this, &menu]() {
bool ok;
QString input = QInputDialog::getText(menu.parentWidget(),
@@ -2359,12 +2401,12 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
e.sizeBytes = m_doc->tree.structSpan(n.id);
QVector<int> kids = m_doc->tree.childrenOf(n.id);
int nonHelperCount = 0;
int nonStaticCount = 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++;
if (child.isStatic) continue;
nonStaticCount++;
int childAlign = alignmentFor(child.kind);
if (childAlign > maxAlign) maxAlign = childAlign;
if (e.fieldSummary.size() < 6) {
@@ -2384,7 +2426,7 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
.arg(typeName, child.name);
}
}
e.fieldCount = nonHelperCount;
e.fieldCount = nonStaticCount;
e.alignment = maxAlign;
entries.append(e);

View File

@@ -197,8 +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)
bool isStatic = false; // static field — excluded from struct layout
QString offsetExpr; // C/C++ expression → absolute address (static fields only)
int arrayLen = 1; // Array: element count
int strLen = 64;
bool collapsed = false;
@@ -240,8 +240,8 @@ struct Node {
o["classKeyword"] = classKeyword;
o["parentId"] = QString::number(parentId);
o["offset"] = offset;
if (isHelper)
o["isHelper"] = true;
if (isStatic)
o["isStatic"] = true;
if (!offsetExpr.isEmpty())
o["offsetExpr"] = offsetExpr;
o["arrayLen"] = arrayLen;
@@ -283,7 +283,7 @@ 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.isStatic = o["isStatic"].toBool(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);
@@ -445,7 +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
if (c.isStatic) continue; // static fields 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;
@@ -600,7 +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
bool isStaticLine = false; // true for static field node lines
};
inline bool isSyntheticLine(const LineMeta& lm) {
@@ -648,7 +648,7 @@ namespace cmd {
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; };
struct ToggleStatic { uint64_t nodeId; bool oldVal, newVal; };
}
using Command = std::variant<
@@ -656,7 +656,7 @@ using Command = std::variant<
cmd::Insert, cmd::Remove, cmd::ChangeBase, cmd::WriteBytes,
cmd::ChangeArrayMeta, cmd::ChangePointerRef, cmd::ChangeStructTypeName,
cmd::ChangeClassKeyword, cmd::ChangeOffset, cmd::ChangeEnumMembers,
cmd::ChangeOffsetExpr, cmd::ToggleHelper
cmd::ChangeOffsetExpr, cmd::ToggleStatic
>;
// ── Column spans (for inline editing) ──
@@ -669,7 +669,7 @@ struct ColumnSpan {
enum class EditTarget { Name, Type, Value, BaseAddress, Source, ArrayIndex, ArrayCount,
ArrayElementType, ArrayElementCount, PointerTarget,
RootClassType, RootClassName, TypeSelector, HelperExpr };
RootClassType, RootClassName, TypeSelector, StaticExpr };
// Column layout constants (shared with format.cpp span computation)
inline constexpr int kFoldCol = 3; // 3-char fold indicator prefix per line
@@ -747,13 +747,20 @@ 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();
// Static field expression span: locates text between "return " and "→" / "(error)" / end
inline ColumnSpan staticExprSpanFor(const LineMeta& /*lm*/, const QString& lineText) {
int ret = lineText.indexOf(QLatin1String("return "));
if (ret < 0) return {};
int exprStart = ret + 7;
// End: before arrow, before "(error)", or line end
int exprEnd = lineText.size();
int arrow = lineText.indexOf(QChar(0x2192), exprStart);
if (arrow > exprStart) exprEnd = arrow;
int err = lineText.indexOf(QLatin1String("(error)"), exprStart);
if (err > exprStart && err < exprEnd) exprEnd = err;
// Also stop at " }" for collapsed format
int brace = lineText.indexOf(QLatin1String(" }"), exprStart);
if (brace > exprStart && brace < exprEnd) exprEnd = brace;
while (exprEnd > exprStart && lineText[exprEnd - 1] == ' ') exprEnd--;
return {exprStart, exprEnd, true};
}

View File

@@ -504,14 +504,14 @@ RcxEditor::RcxEditor(QWidget* parent) : QWidget(parent) {
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()) {
// Autocomplete for static field expressions — show field names as user types
if (m_editState.target == EditTarget::StaticExpr && !m_staticCompletions.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();
QByteArray list = m_staticCompletions.join(' ').toUtf8();
m_sci->SendScintilla(QsciScintillaBase::SCI_AUTOCSETSEPARATOR, (long)' ');
m_sci->SendScintilla(QsciScintillaBase::SCI_AUTOCSHOW, (uintptr_t)wordLen, list.constData());
}
@@ -1501,6 +1501,20 @@ static ColumnSpan headerTypeNameSpan(const LineMeta& lm, const QString& lineText
};
if (kKeywords.contains(typeCol)) return {};
// Static field headers: "static hex64 target {" — skip "static " prefix
if (lm.isStaticLine) {
int cursor = ind;
while (cursor < typeEnd && lineText[cursor] == ' ') cursor++;
if (lineText.mid(cursor, 7) == QLatin1String("static "))
cursor += 7;
while (cursor < typeEnd && lineText[cursor] == ' ') cursor++;
int tStart = cursor;
while (cursor < typeEnd && lineText[cursor] != ' ') cursor++;
if (cursor > tStart)
return {tStart, cursor, true};
return {};
}
// Named struct: entire type column is the type name (e.g. "_MMPTE")
// Find the actual text bounds within the padded column
int start = ind;
@@ -1586,7 +1600,8 @@ bool RcxEditor::resolvedSpanFor(int line, EditTarget t,
if (lm->nodeIdx < 0) return false;
// Hex nodes: only Type is editable (ASCII preview + hex bytes are display-only)
if ((t == EditTarget::Name || t == EditTarget::Value) && isHexNode(lm->nodeKind))
// Exception: static field names are always editable (they're function names)
if ((t == EditTarget::Name || t == EditTarget::Value) && isHexNode(lm->nodeKind) && !lm->isStaticLine)
return false;
QString lineText = getLineText(m_sci, line);
@@ -1612,9 +1627,9 @@ 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);
case EditTarget::StaticExpr:
if (lm->isStaticLine)
s = staticExprSpanFor(*lm, lineText);
break;
case EditTarget::Source: break;
}
@@ -2245,7 +2260,8 @@ bool RcxEditor::beginInlineEdit(EditTarget target, int line, int col) {
|| target == EditTarget::RootClassType || target == EditTarget::RootClassName)))
return false;
// Hex nodes: only Type is editable (ASCII preview + hex bytes are display-only)
if ((target == EditTarget::Name || target == EditTarget::Value) && isHexNode(lm->nodeKind))
// Exception: static field names are always editable (they're function names, not hex labels)
if ((target == EditTarget::Name || target == EditTarget::Value) && isHexNode(lm->nodeKind) && !lm->isStaticLine)
return false;
QString lineText;

View File

@@ -45,7 +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 setStaticCompletions(const QStringList& words) { m_staticCompletions = words; }
void applySelectionOverlay(const QSet<uint64_t>& selIds);
void setCommandRowText(const QString& line);
@@ -134,7 +134,7 @@ private:
bool lastValidationOk = true; // track state to avoid redundant updates
};
InlineEditState m_editState;
QStringList m_helperCompletions; // autocomplete words for HelperExpr editing
QStringList m_staticCompletions; // autocomplete words for StaticExpr editing
// ── Tab cycling state ──
EditTarget m_lastTabTarget = EditTarget::Value;

View File

@@ -173,10 +173,10 @@ static void emitStructBody(GenContext& ctx, uint64_t structId,
QString ind = indent(depth);
QVector<int> allChildren = ctx.childMap.value(structId);
QVector<int> children, helperIdxs;
QVector<int> children, staticIdxs;
for (int ci : allChildren) {
if (tree.nodes[ci].isHelper)
helperIdxs.append(ci);
if (tree.nodes[ci].isStatic)
staticIdxs.append(ci);
else
children.append(ci);
}
@@ -318,12 +318,12 @@ static void emitStructBody(GenContext& ctx, uint64_t structId,
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 static field comments (static fields are runtime-only, not part of struct layout)
for (int si : staticIdxs) {
const Node& sf = tree.nodes[si];
QString sfType = sf.structTypeName.isEmpty() ? ctx.cType(sf.kind) : sf.structTypeName;
ctx.output += ind + QStringLiteral("// static: %1 %2 @ %3\n")
.arg(sfType, sanitizeIdent(sf.name), sf.offsetExpr);
}
}