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

Function node_prop

src/cypher/cypher.c:2247–2329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2245static void node_fields_free(cbm_node_t *n); /* defined below; used by the stub re-fetch */
2246
2247static const char *node_prop(const cbm_node_t *n, const char *prop, cbm_store_t *store) {
2248 if (!n || !prop) {
2249 return "";
2250 }
2251 const char *str = node_string_field(n, prop);
2252 if (str && str[0]) {
2253 return str;
2254 }
2255 /* Note: a string field that exists but is empty ("") falls through here so a
2256 * WITH-aggregation node stub (below) can re-fetch it. */
2257 /* Computed and JSON-derived values live in rotating thread-local buffers:
2258 * a single row (or an ORDER-BY comparison) reads several of these before any
2259 * of them is copied out, so returning one shared static buffer would alias
2260 * every column to the last value read. Mirrors edge_prop's rotation. */
2261 static _Thread_local char bufs[CYP_BUF_8][CBM_SZ_512];
2262 static _Thread_local int buf_idx = 0;
2263 char *out = bufs[buf_idx];
2264 buf_idx = (buf_idx + SKIP_ONE) % CYP_BUF_8;
2265
2266 if (strcmp(prop, "start_line") == 0) {
2267 snprintf(out, CBM_SZ_512, "%d", n->start_line);
2268 return out;
2269 }
2270 if (strcmp(prop, "end_line") == 0) {
2271 snprintf(out, CBM_SZ_512, "%d", n->end_line);
2272 return out;
2273 }
2274 /* Virtual computed properties: in_degree/out_degree via CALLS edges.
2275 * Enables Cypher dead-code detection: WHERE n.in_degree = '0'. */
2276 if (store && (strcmp(prop, "in_degree") == 0 || strcmp(prop, "out_degree") == 0)) {
2277 int in_deg = 0;
2278 int out_deg = 0;
2279 cbm_store_node_degree(store, n->id, &in_deg, &out_deg);
2280 int val = (strcmp(prop, "in_degree") == 0) ? in_deg : out_deg;
2281 snprintf(out, CBM_SZ_512, "%d", val);
2282 return out;
2283 }
2284 /* Fall back to any value stored in the node's properties JSON — exposes the
2285 * extraction metrics (complexity, cognitive, loop_count, loop_depth,
2286 * transitive_loop_depth, recursive) and any other persisted property to
2287 * WHERE/RETURN, e.g. WHERE n.loop_depth >= 2. */
2288 if (n->properties_json && n->properties_json[0] == '{') {
2289 const char *v = json_extract_prop(n->properties_json, prop, out, CBM_SZ_512);
2290 if (v && v[0]) {
2291 return v;
2292 }
2293 }
2294 /* WITH aggregation carries a node group var by id + name only (the group key
2295 * is the node name), so every other property is absent on the stub. Detect
2296 * the stub (id set, but the full string fields were never populated) and
2297 * re-fetch the node so RETURN g.file_path / g.label / g.<metric> project
2298 * correctly instead of returning blank. The gate is heuristic, not an exact
2299 * stub discriminator: a real bound node with NULL label AND file_path would
2300 * also match, but in that case the worst case is one redundant indexed fetch
2301 * that returns the same value — never a wrong result. */
2302 if (store && n->id > 0 && !n->file_path && !n->label) {
2303 cbm_node_t full = {0};
2304 if (cbm_store_find_node_by_id(store, n->id, &full) == CBM_STORE_OK) {

Callers 3

resolve_condition_valueFunction · 0.85
check_inline_propsFunction · 0.85
binding_get_virtualFunction · 0.85

Calls 5

node_string_fieldFunction · 0.85
cbm_store_node_degreeFunction · 0.85
json_extract_propFunction · 0.85
node_fields_freeFunction · 0.85

Tested by

no test coverage detected