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

Function kt_process_statement

internal/cbm/lsp/kotlin_lsp.c:3068–3187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3066}
3067
3068static void kt_process_statement(KotlinLSPContext *ctx, TSNode stmt) {
3069 if (ts_node_is_null(stmt)) {
3070 return;
3071 }
3072 const char *kind = ts_node_type(stmt);
3073 /* Newer tree-sitter-kotlin wraps a body's statements in a `statements`
3074 * node (where older grammars used `block`/bare children). Unwrap either so
3075 * each real statement is bound + resolved in order. */
3076 if (strcmp(kind, "statements") == 0 || strcmp(kind, "block") == 0) {
3077 kt_process_block_stmts(ctx, stmt);
3078 return;
3079 }
3080 if (strcmp(kind, "property_declaration") == 0) {
3081 kt_bind_property_to_scope(ctx, stmt);
3082 /* Resolve calls within initializer */
3083 kt_resolve_calls_in_node(ctx, stmt);
3084 return;
3085 }
3086 if (strcmp(kind, "function_declaration") == 0) {
3087 /* Local function — register and recurse */
3088 TSNode name = kt_field_named(stmt, "name");
3089 if (ts_node_is_null(name)) {
3090 name = kt_child_kind_named(stmt, "simple_identifier");
3091 }
3092 if (ts_node_is_null(name)) {
3093 name = kt_name_child(stmt);
3094 }
3095 char *fname = kt_node_text(ctx, name);
3096 if (!fname) {
3097 return;
3098 }
3099 /* Register the local fn so call sites in the enclosing scope
3100 * can resolve it via kotlin_resolve_function_name. The QN is
3101 * "<enclosing_func_qn>.<fname>" so it's distinct from a top-level
3102 * function with the same short name. */
3103 const char *prev_func = ctx->enclosing_func_qn;
3104 const char *new_qn = kt_join_dot(ctx->arena, prev_func ? prev_func : ctx->module_qn, fname);
3105 {
3106 CBMRegisteredFunc lrf = {0};
3107 lrf.qualified_name = new_qn;
3108 lrf.short_name = fname;
3109 lrf.min_params = 0;
3110 cbm_registry_add_func((CBMTypeRegistry *)ctx->registry, lrf);
3111 /* Also register a same-package alias so bare `inner()` calls
3112 * succeed via the same-package fallback in
3113 * kotlin_resolve_function_name. */
3114 if (ctx->package_qn && *ctx->package_qn) {
3115 CBMRegisteredFunc alias = lrf;
3116 alias.qualified_name = kt_join_dot(ctx->arena, ctx->package_qn, fname);
3117 cbm_registry_add_func((CBMTypeRegistry *)ctx->registry, alias);
3118 } else {
3119 /* No package — register at root. */
3120 CBMRegisteredFunc alias = lrf;
3121 alias.qualified_name = cbm_arena_strdup(ctx->arena, fname);
3122 cbm_registry_add_func((CBMTypeRegistry *)ctx->registry, alias);
3123 }
3124 }
3125 ctx->enclosing_func_qn = new_qn;

Callers 2

kt_process_block_stmtsFunction · 0.85
kt_process_lambdaFunction · 0.85

Calls 15

kt_process_block_stmtsFunction · 0.85
kt_resolve_calls_in_nodeFunction · 0.85
kt_field_namedFunction · 0.85
kt_child_kind_namedFunction · 0.85
kt_name_childFunction · 0.85
kt_node_textFunction · 0.85
kt_join_dotFunction · 0.85
cbm_registry_add_funcFunction · 0.85
kt_child_kindFunction · 0.85
cbm_scope_pushFunction · 0.85
kt_bind_function_paramsFunction · 0.85

Tested by

no test coverage detected