MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / resolve_write_lhs_node

Function resolve_write_lhs_node

internal/cbm/extract_semantic.c:207–252  ·  view source on GitHub ↗

Resolve the write target of a node in an assignment_node_types set. For a plain assignment the target is the "left" field (or first child). For an increment/decrement unary expression (`x++`, `++x`, C# postfix_/prefix_unary_expression) there is no "left" field and the operand may sit on either side of the operator token, so scan named children for the first identifier / member-style operand. Re

Source from the content-addressed store, hash-verified

205// first identifier / member-style operand. Returns a null node when no simple
206// target is found.
207static TSNode resolve_write_lhs_node(TSNode node) {
208 TSNode left = ts_node_child_by_field_name(node, TS_FIELD("left"));
209 if (!ts_node_is_null(left)) {
210 return left;
211 }
212 const char *nk = ts_node_type(node);
213 if (strcmp(nk, "postfix_unary_expression") == 0 || strcmp(nk, "prefix_unary_expression") == 0 ||
214 strcmp(nk, "update_expression") == 0) {
215 // Only ++/-- mutate their operand. Other unary postfix/prefix forms
216 // (C# null-forgiving `x!`, address-of `&x`, deref `*x`, logical `!x`)
217 // READ the operand — never treat them as writes.
218 bool is_incdec = false;
219 uint32_t total = ts_node_child_count(node);
220 for (uint32_t i = 0; i < total; i++) {
221 TSNode c = ts_node_child(node, i);
222 if (ts_node_is_named(c)) {
223 continue; // operator is an anonymous token
224 }
225 const char *op = ts_node_type(c);
226 if (strcmp(op, "++") == 0 || strcmp(op, "--") == 0) {
227 is_incdec = true;
228 break;
229 }
230 }
231 if (!is_incdec) {
232 return (TSNode){0};
233 }
234 uint32_t cnc = ts_node_named_child_count(node);
235 for (uint32_t i = 0; i < cnc; i++) {
236 TSNode c = ts_node_named_child(node, i);
237 const char *ck = ts_node_type(c);
238 if (strcmp(ck, "identifier") == 0 || strcmp(ck, "simple_identifier") == 0 ||
239 strcmp(ck, "member_access_expression") == 0 ||
240 strcmp(ck, "field_expression") == 0 || strcmp(ck, "field_access") == 0 ||
241 strcmp(ck, "selector_expression") == 0 || strcmp(ck, "subscript_expression") == 0 ||
242 strcmp(ck, "index_expression") == 0) {
243 return c;
244 }
245 }
246 return (TSNode){0};
247 }
248 if (ts_node_child_count(node) > 0) {
249 return ts_node_child(node, 0);
250 }
251 return (TSNode){0};
252}
253
254// Try to emit a write for an assignment node.
255static void try_emit_assignment_write(CBMExtractCtx *ctx, TSNode node, const char *func_qn) {

Callers 2

handle_readwritesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected