The identifier a Python parameter node binds. Handles the bare, typed, * defaulted, keyword-only, *args and **kwargs shapes. */
| 266 | /* The identifier a Python parameter node binds. Handles the bare, typed, |
| 267 | * defaulted, keyword-only, *args and **kwargs shapes. */ |
| 268 | static const char *py_parameter_name(CBMExtractCtx *ctx, TSNode param) { |
| 269 | if (ts_node_is_null(param)) { |
| 270 | return NULL; |
| 271 | } |
| 272 | if (strcmp(ts_node_type(param), "identifier") == 0) { |
| 273 | return cbm_node_text(ctx->arena, param, ctx->source); |
| 274 | } |
| 275 | TSNode name = ts_node_child_by_field_name(param, TS_FIELD("name")); |
| 276 | if (!ts_node_is_null(name) && strcmp(ts_node_type(name), "identifier") == 0) { |
| 277 | return cbm_node_text(ctx->arena, name, ctx->source); |
| 278 | } |
| 279 | /* `*args` / `**kwargs`, and any typed shape without a `name` field: the |
| 280 | * bound identifier is the first named child. */ |
| 281 | TSNode first = ts_node_named_child(param, 0); |
| 282 | if (!ts_node_is_null(first) && strcmp(ts_node_type(first), "identifier") == 0) { |
| 283 | return cbm_node_text(ctx->arena, first, ctx->source); |
| 284 | } |
| 285 | return NULL; |
| 286 | } |
| 287 | |
| 288 | /* Bind this node's parameters into the frame just pushed for it. Called after |
| 289 | * every push in push_boundary_scopes, so the top frame is this node's own and |
no test coverage detected