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

Function php_substitute_template

internal/cbm/lsp/php_lsp.c:3443–3474  ·  view source on GitHub ↗

Substitute the type parameters in `t` according to a parallel * (param_names, args) mapping, returning a new arena-allocated CBMType. */

Source from the content-addressed store, hash-verified

3441/* Substitute the type parameters in `t` according to a parallel
3442 * (param_names, args) mapping, returning a new arena-allocated CBMType. */
3443static const CBMType *php_substitute_template(CBMArena *arena, const CBMType *t,
3444 const char *const *param_names,
3445 const CBMType *const *args) {
3446 if (!t || !param_names || !args)
3447 return t;
3448 if (t->kind == CBM_TYPE_NAMED && t->data.named.qualified_name) {
3449 const char *qn = t->data.named.qualified_name;
3450 for (int i = 0; param_names[i]; i++) {
3451 if (strcmp(qn, param_names[i]) == 0) {
3452 return args[i] ? args[i] : t;
3453 }
3454 }
3455 return t;
3456 }
3457 if (t->kind == CBM_TYPE_TEMPLATE) {
3458 /* Recurse into args. */
3459 int n = t->data.template_type.arg_count;
3460 if (n <= 0 || !t->data.template_type.template_args)
3461 return t;
3462 const CBMType **new_args =
3463 (const CBMType **)cbm_arena_alloc(arena, (size_t)(n + 1) * sizeof(*new_args));
3464 if (!new_args)
3465 return t;
3466 for (int i = 0; i < n; i++) {
3467 new_args[i] = php_substitute_template(arena, t->data.template_type.template_args[i],
3468 param_names, args);
3469 }
3470 new_args[n] = NULL;
3471 return cbm_type_template(arena, t->data.template_type.template_name, new_args, n);
3472 }
3473 return t;
3474}
3475
3476static void apply_phpdoc_class_tags(PHPLSPContext *ctx, CBMTypeRegistry *reg, const char *class_qn,
3477 const char *docstring, php_class_fields_t *out_fields) {

Callers 1

eval_member_call_typeFunction · 0.85

Calls 2

cbm_type_templateFunction · 0.85
cbm_arena_allocFunction · 0.50

Tested by

no test coverage detected