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

Function extract_cpp_branch_views

internal/cbm/cbm.c:3367–3415  ·  view source on GitHub ↗

Haskell: the scanner parses the first branch of an #if group and swallows * the rest up to #endif as one token, so what is written once per * configuration (a definition, an import, a call in the other branch) was * seen in its first variant only. Every further branch is parsed as its own * view (cpp_branch_views.h: same bytes and lines, the other branches and the * conditional lines blanked)

Source from the content-addressed store, hash-verified

3365 * duplicates, which the pipeline dedups by caller and callee. The raw parse
3366 * alone decides the file's parse status. */
3367static void extract_cpp_branch_views(const CBMExtractCtx *raw, const TSLanguage *ts_lang,
3368 int64_t timeout_micros) {
3369 int views = cbm_cpp_branch_view_count(raw->arena, raw->source, raw->source_len);
3370 for (int v = 1; v <= views; v++) {
3371 char *view = cbm_cpp_branch_view(raw->arena, raw->source, raw->source_len, v);
3372 TSParser *parser = view ? get_thread_parser(ts_lang, raw->language) : NULL;
3373 if (!parser) {
3374 return;
3375 }
3376 ts_parser_reset(parser);
3377 TSParseOptions opts = {0};
3378 CBMParseBudget budget = {0}; // cppcheck-suppress unreadVariable
3379 if (timeout_micros > 0) {
3380 uint64_t budget_ns = (uint64_t)timeout_micros * USEC_TO_NSEC;
3381 budget.cpu_deadline_ns = cbm_thread_cpu_time_ns() + budget_ns;
3382 budget.wall_ceiling_ns = now_ns() + budget_ns * CBM_PARSE_WALL_CEILING_FACTOR;
3383 opts.payload = &budget;
3384 opts.progress_callback = cbm_timeout_cb;
3385 }
3386 /* A view keeps the raw source's length and line structure, so it is
3387 * parsed under the same terminated-last-line rule (#2078). */
3388 TSTree *tree = cbm_parse_source(parser, view, (uint32_t)raw->source_len, opts);
3389 if (!tree) {
3390 return;
3391 }
3392 CBMExtractCtx vctx = {
3393 .arena = raw->arena,
3394 .scratch = raw->scratch,
3395 .result = raw->result,
3396 .source = view,
3397 .source_len = raw->source_len,
3398 .language = raw->language,
3399 .project = raw->project,
3400 .rel_path = raw->rel_path,
3401 .module_qn = raw->module_qn,
3402 .root = ts_tree_root_node(tree),
3403 .macro_table = raw->macro_table,
3404 .return_type_table = raw->return_type_table,
3405 .walk_budget_nodes = cbm_walk_max_nodes(),
3406 };
3407 int defs_before = raw->result->defs.count;
3408 int imports_before = raw->result->imports.count;
3409 cbm_extract_definitions(&vctx);
3410 cbm_extract_imports(&vctx);
3411 cbm_extract_unified(&vctx);
3412 cpp_view_drop_seen(raw->result, defs_before, imports_before);
3413 ts_tree_delete(tree);
3414 }
3415}
3416
3417/* ── Innermost enclosing Function/Method per call (#1527) ──────────────
3418 * The call-context metrics attribute each call to the Function/Method def with

Callers 1

extract_file_ex_bodyFunction · 0.85

Calls 11

cbm_cpp_branch_viewFunction · 0.85
get_thread_parserFunction · 0.85
cbm_thread_cpu_time_nsFunction · 0.85
cbm_parse_sourceFunction · 0.85
cbm_walk_max_nodesFunction · 0.85
cbm_extract_definitionsFunction · 0.85
cbm_extract_importsFunction · 0.85
cbm_extract_unifiedFunction · 0.85
cpp_view_drop_seenFunction · 0.85
now_nsFunction · 0.70

Tested by

no test coverage detected