Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Merge origin/main into java-external-gate

Martin Vogel5808426aca46
diff --cc src/pipeline/pass_calls.c
index e087b6073,a673e7539..a8c75bea2
--- a/src/pipeline/pass_calls.c
+++ b/src/pipeline/pass_calls.c
@@@ -868,6 -892,203 +892,208 @@@ static const cbm_gbuf_node_t *calls_fin
return src;
}
+ static CBMCallEvidence *calls_evidence_at(CBMCallEvidence *evidence, int index,
+ CBMCallEvidence *fallback) {
+ if (evidence) {
+ return &evidence[index];
+ }
+ return fallback;
+ }
+
+ static CBMCallEvidence *calls_evidence_new(cbm_pipeline_t *pipeline, const CBMFileResult *result) {
+ CBMCallEvidence *evidence =
+ cbm_calloc(CBM_MEM_CLASS_RESOLVE, (size_t)result->calls.count * sizeof(*evidence));
+ if (!evidence) {
+ cbm_pipeline_mark_unresolved_capture_failed(pipeline);
+ }
+ return evidence;
+ }
+
+ /* Report whether a service spelling handled this call, independently of
+ * whether its classified edge is CALLS and therefore covers the occurrence. */
+ static bool calls_emit_service_call(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const cbm_gbuf_node_t *source_node, cbm_svc_kind_t svc,
+ const cbm_resolution_t *resolved, CBMCallEvidence *evidence) {
+ if (svc != CBM_SVC_HTTP && svc != CBM_SVC_ASYNC) {
+ return false;
+ }
+ const char *url = call->first_string_arg;
+ if (!url || !url[0]) {
+ return false;
+ }
+ bool has_url_or_topic = url[0] == '/' || strstr(url, "://") != NULL ||
+ (svc == CBM_SVC_ASYNC && strlen(url) > PAIR_LEN);
+ if (!has_url_or_topic) {
+ return false;
+ }
+ cbm_resolution_t fallback = {.qualified_name = call->callee_name,
+ .confidence = PC_SVC_PATTERN_CONF,
+ .strategy = "service_pattern",
+ .candidate_count = 0};
+ const cbm_resolution_t *res = resolved ? resolved : &fallback;
+ evidence->calls_emitted |= emit_http_async_edge(ctx, call, source_node, NULL, res, svc, false);
+ return true;
+ }
+
+ /* Route registration counts as handled even when its edge is not CALLS. */
+ static bool calls_emit_route_call(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const cbm_gbuf_node_t *source_node, const char *module_qn,
+ const char **imp_keys, const char **imp_vals, int imp_count,
+ const char *route_mount, CBMLanguage lang,
+ CBMCallEvidence *evidence) {
+ if (cbm_service_pattern_route_method(call->callee_name) == NULL ||
+ route_reg_path(call, lang) == NULL) {
+ return false;
+ }
+ evidence->calls_emitted |= handle_route_registration(
+ ctx, call, source_node, module_qn, imp_keys, imp_vals, imp_count, route_mount, lang);
+ return true;
+ }
+
+ /* An external callee can still register a route or address an HTTP/async service. */
+ static int calls_emit_unresolved_service(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const cbm_gbuf_node_t *source_node, const char *module_qn,
+ const char **imp_keys, const char **imp_vals,
+ int imp_count, const char *route_mount, CBMLanguage lang,
+ CBMCallEvidence *evidence) {
+ if (calls_emit_route_call(ctx, call, source_node, module_qn, imp_keys, imp_vals, imp_count,
+ route_mount, lang, evidence)) {
+ return SKIP_ONE;
+ }
+ cbm_svc_kind_t svc = cbm_service_pattern_match(call->callee_name);
+ if (svc == CBM_SVC_NONE && cbm_service_pattern_is_global_fetch(call->callee_name)) {
+ svc = CBM_SVC_HTTP;
+ }
+ return calls_emit_service_call(ctx, call, source_node, svc, NULL, evidence);
+ }
+
+ /* Apply the field-call policy after a registry target has been found. */
+ static const cbm_gbuf_node_t *calls_field_target(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const CBMResolvedCallArray *lsp_calls,
+ CBMLanguage lang, const char *rel,
+ const cbm_gbuf_node_t *source_node,
+ const cbm_gbuf_node_t *target_node,
+ bool arrow_bound, cbm_resolution_t *res) {
+ switch (cbm_call_onto_field_policy(lang, call->callee_name, target_node->label,
+ target_node->file_path)) {
+ case CBM_FIELD_CALL_DROP:
+ return NULL;
+ case CBM_FIELD_CALL_BY_OWNER:
+ /* An arrow call was already bound this way by registry resolution. */
+ if (!arrow_bound) {
+ target_node = cbm_pipeline_c_member_call_resolve(
+ lsp_calls, NULL, ctx->gbuf, ctx->registry, ctx->project_name,
+ call->enclosing_func_qn, call->callee_name, cbm_c_member_rule_file(lang, rel), res);
+ }
+ if (!target_node || source_node->id == target_node->id) {
+ return NULL;
+ }
+ break;
+ case CBM_FIELD_CALL_KEEP:
+ break;
+ }
+ return target_node;
+ }
+
+ static bool calls_emit_lsp_target(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
- const CBMResolvedCall *lsp, bool allow_tail, CBMLanguage lang,
- const CBMImportArray *imports, const cbm_gbuf_node_t *source_node,
- const char *module_qn, const char **imp_keys,
- const char **imp_vals, int imp_count, const char *route_mount,
- CBMCallEvidence *evidence) {
++ const CBMResolvedCall *lsp, bool allow_tail, bool java_external,
++ CBMLanguage lang, const CBMImportArray *imports,
++ const cbm_gbuf_node_t *source_node, const char *module_qn,
++ const char **imp_keys, const char **imp_vals, int imp_count,
++ const char *route_mount, CBMCallEvidence *evidence) {
+ if (!lsp) {
+ return false;
+ }
+ bool exact_external_target =
+ call->requires_lsp_resolution && cbm_pipeline_kotlin_external_target(lang, lsp->callee_qn);
++ /* A Java call on a JDK/library type binds its exact QN only: no tail
++ * match onto a same-named project method. MUST match pass_parallel.c. */
+ const cbm_gbuf_node_t *target_node =
- exact_external_target ? cbm_pipeline_lsp_target_node_strict(ctx->gbuf, ctx->project_name,
- lsp->callee_qn, allow_tail)
- : cbm_pipeline_lsp_target_node(ctx->gbuf, ctx->project_name,
- lsp->callee_qn, allow_tail);
++ java_external ? cbm_pipeline_lsp_target_node_strict(ctx->gbuf, ctx->project_name,
++ lsp->callee_qn, false)
++ : exact_external_target ? cbm_pipeline_lsp_target_node_strict(ctx->gbuf, ctx->project_name,
++ lsp->callee_qn, allow_tail)
++ : cbm_pipeline_lsp_target_node(ctx->gbuf, ctx->project_name,
++ lsp->callee_qn, allow_tail);
+ if (!target_node || source_node->id == target_node->id) {
+ return false;
+ }
+ /* LSP textual fallbacks can also name data, as with static imports. The
+ * call is handled: no edge, and no registry fallback after it. */
+ if (cbm_java_suppress_call_to_data_member(lang == CBM_LANG_JAVA, target_node->label)) {
+ return true;
+ }
+ cbm_resolution_t res = {0};
+ /* Keep the canonical graph QN, including project prefixes added by fallback. */
+ res.qualified_name = target_node->qualified_name;
+ res.confidence = lsp->confidence;
+ res.strategy = lsp->strategy;
+ res.candidate_count = PC_SINGLE_CANDIDATE_COUNT;
+ evidence->candidate_qn = target_node->qualified_name;
+ /* Synthetic builtins can still denote a spawn; keep the parallel pass policy. */
+ cbm_pipeline_spawn_t spawn;
+ if (cbm_pipeline_spawn_site(ctx->gbuf, lang, call, imports, &res, &spawn)) {
+ cbm_pipeline_emit_spawn(ctx->gbuf, source_node, call, &spawn);
+ return true;
+ }
+ evidence->calls_emitted |=
+ emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys,
+ imp_vals, imp_count, false, route_mount, lang);
+ return true;
+ }
+
-/* Vendor receivers and cross-language name guesses cannot bind project calls.
- * Keep the registry policy shared with the parallel resolver. */
++/* Vendor receivers, Java library receivers and cross-language name guesses
++ * cannot bind project calls. Keep the registry policy shared with the
++ * parallel resolver. */
+ static cbm_resolution_t calls_registry_resolution(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const char *module_qn, const char **imp_keys,
+ const char **imp_vals, int imp_count,
+ CBMLanguage lang, bool rust_external,
- bool php_vendor_call) {
++ bool php_vendor_call, bool java_external) {
+ cbm_resolution_t res = {0};
- if (!rust_external && !php_vendor_call) {
++ if (!rust_external && !php_vendor_call && !java_external) {
+ /* Python LEGB fallback first (MUST match pass_parallel.c). */
+ res =
+ cbm_registry_resolve_call_scoped(ctx->registry, call->callee_name, module_qn, imp_keys,
+ imp_vals, imp_count, lang, call->enclosing_func_qn);
+ /* Cross-language veto: a name-only guess never binds another
+ * language's symbol (a JS app.get must not become Python's
+ * builtins.dict.get). The vetoed answer becomes EMPTY here, before
+ * the fallbacks below, so the route/HTTP classification still runs.
+ * MUST match pass_parallel.c. */
+ if (cbm_registry_name_guess_vetoed(ctx->registry, lang, &res)) {
+ res = (cbm_resolution_t){0};
+ }
+ }
+ return res;
+ }
+
+ static int calls_emit_import_service(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const cbm_gbuf_node_t *source_node, const char *rel,
+ CBMLanguage lang, const CBMImportArray *imports,
+ cbm_external_import_index_t *ext_imports,
+ CBMCallEvidence *evidence) {
+ /* A callee an import binds to an external client library
+ * (`send` under `from paho.mqtt import publish as send`): spelled
+ * through its import, then classified. MUST match pass_parallel.c. */
+ char spelled[CBM_SZ_512];
+ cbm_svc_kind_t isvc =
+ cbm_pipeline_external_import_service(ext_imports, ctx->gbuf, ctx->project_name, rel, lang,
+ imports, call, spelled, sizeof(spelled));
+ if (isvc != CBM_SVC_NONE) {
+ CBMCall through = *call;
+ through.callee_name = spelled;
+ cbm_resolution_t imp_res = {.qualified_name = spelled,
+ .confidence = PC_SVC_PATTERN_CONF,
+ .strategy = "import_binding",
+ .candidate_count = 0};
+ evidence->calls_emitted |=
+ emit_http_async_edge(ctx, &through, source_node, NULL, &imp_res, isvc, false);
+ return SKIP_ONE;
+ }
+ return 0;
+ }
+
/* Resolve one call and emit the appropriate edge. Returns 1 if resolved, 0 if not. */
static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBMFileResult *result,
const char *rel, const char *module_qn, const char **imp_keys,
@@@ -892,41 -1114,9 +1119,13 @@@
* Service/route classification below still runs. Mirrors pass_parallel.c. */
bool php_vendor_call = cbm_pipeline_php_vendor_call(php_vendor, result, call) ||
cbm_pipeline_lsp_external_receiver(lsp);
- if (calls_emit_lsp_target(ctx, call, lsp, allow_tail, lang, imports, source_node, module_qn,
- imp_keys, imp_vals, imp_count, route_mount, evidence)) {
+ /* A Java call on a JDK/library type is never bound to a project method
+ * found by name (no tail match, no registry guess). MUST match
+ * pass_parallel.c. */
+ bool java_external = cbm_pipeline_java_external_target(lang, lsp);
- if (lsp) {
- bool exact_external_target = call->requires_lsp_resolution &&
- cbm_pipeline_kotlin_external_target(lang, lsp->callee_qn);
- const cbm_gbuf_node_t *target_node =
- java_external ? cbm_pipeline_lsp_target_node_strict(ctx->gbuf, ctx->project_name,
- lsp->callee_qn, false)
- : exact_external_target ? cbm_pipeline_lsp_target_node_strict(
- ctx->gbuf, ctx->project_name, lsp->callee_qn, allow_tail)
- : cbm_pipeline_lsp_target_node(ctx->gbuf, ctx->project_name,
- lsp->callee_qn, allow_tail);
- if (target_node && source_node->id != target_node->id) {
- cbm_resolution_t res = {0};
- /* Use the gbuf node's QN so downstream edge props show the canonical
- * project-qualified form even when fallback prefixed the project. */
- res.qualified_name = target_node->qualified_name;
- res.confidence = lsp->confidence;
- res.strategy = lsp->strategy;
- res.candidate_count = 1;
- /* An LSP answer on a synthetic builtin (`<python-builtins>`) is
- * not project code: a spawn spelling still spawns. The parallel
- * pass keeps the LSP answer in `res` and asks the same question.
- * MUST match pass_parallel.c. */
- cbm_pipeline_spawn_t spawn;
- if (cbm_pipeline_spawn_site(ctx->gbuf, lang, call, imports, &res, &spawn)) {
- cbm_pipeline_emit_spawn(ctx->gbuf, source_node, call, &spawn);
- return SKIP_ONE;
- }
- emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys,
- imp_vals, imp_count, false, route_mount, lang);
- return SKIP_ONE;
- }
++ if (calls_emit_lsp_target(ctx, call, lsp, allow_tail, java_external, lang, imports, source_node,
++ module_qn, imp_keys, imp_vals, imp_count, route_mount, evidence)) {
+ return SKIP_ONE;
}
/* Synthetic semantic candidates (currently implicit C++ operators) are
@@@ -993,21 -1177,8 +1186,9 @@@
* classify the call. MUST match pass_parallel.c. */
bool rust_external = lsp && cbm_pipeline_rust_external_target(
lang, lsp->strategy, lsp->callee_qn, ctx->project_name);
- cbm_resolution_t res = {0};
- if (!rust_external && !php_vendor_call && !java_external) {
- /* Python LEGB fallback first (MUST match pass_parallel.c). */
- res =
- cbm_registry_resolve_call_scoped(ctx->registry, call->callee_name, module_qn, imp_keys,
- imp_vals, imp_count, lang, call->enclosing_func_qn);
- /* Cross-language veto: a name-only guess never binds another
- * language's symbol (a JS app.get must not become Python's
- * builtins.dict.get). The vetoed answer becomes EMPTY here, before
- * the fallbacks below, so the route/HTTP classification still runs.
- * MUST match pass_parallel.c. */
- if (cbm_registry_name_guess_vetoed(ctx->registry, lang, &res)) {
- res = (cbm_resolution_t){0};
- }
- }
- cbm_resolution_t res = calls_registry_resolution(
- ctx, call, module_qn, imp_keys, imp_vals, imp_count, lang, rust_external, php_vendor_call);
++ cbm_resolution_t res =
++ calls_registry_resolution(ctx, call, module_qn, imp_keys, imp_vals, imp_count, lang,
++ rust_external, php_vendor_call, java_external);
/* `p->open(fd)`: the registry does not split a callee on the arrow, and a
* member is not a name it could resolve anyway. The object's type decides,
* exactly as for the dot call handled further down. MUST match