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

Function mk_assign

src/pipeline/pass_shell.c:3082–3119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3080}
3081
3082static void mk_assign(mk_t *m, TSNode n, bool cond) {
3083 TSNode name = ts_node_child_by_field_name(n, TS_FIELD("name"));
3084 TSNode value = ts_node_child_by_field_name(n, TS_FIELD("value"));
3085 if (ts_node_is_null(name)) {
3086 return;
3087 }
3088 uint32_t nb = ts_node_start_byte(name);
3089 const char *nm = mk_trim(m->a, m->src + nb, ts_node_end_byte(name) - nb);
3090 const char *raw = "";
3091 if (!ts_node_is_null(value)) {
3092 uint32_t vb = ts_node_start_byte(value);
3093 raw = mk_fold(m->a, m->src + vb, ts_node_end_byte(value) - vb);
3094 }
3095 const char *op = "=";
3096 for (uint32_t i = 0; i < ts_node_child_count(n); i++) {
3097 TSNode c = ts_node_child(n, i);
3098 if (!ts_node_is_named(c) && strchr(ts_node_type(c), '=')) {
3099 op = ts_node_type(c);
3100 }
3101 }
3102 if (!nm || !raw) {
3103 return;
3104 }
3105 mk_var_t *old = cbm_ht_get(m->vars, nm);
3106 if (strcmp(op, "?=") == 0 && old) {
3107 return;
3108 }
3109 mk_var_t *v = cbm_arena_alloc(m->a, sizeof(*v));
3110 if (!v) {
3111 return;
3112 }
3113 *v = (mk_var_t){raw, NULL, !cond && strcmp(op, "!=") != 0, false};
3114 if (strcmp(op, "+=") == 0 && old) {
3115 v->known = v->known && old->known;
3116 v->raw = cbm_arena_sprintf(m->a, "%s %s", old->raw, raw);
3117 }
3118 cbm_ht_set(m->vars, nm, v);
3119}
3120
3121/* Variables and recipe lines of a makefile; `cond`: under a conditional. */
3122/* The recipe lines in the bytes of a recipe_line node, split as make splits

Callers 1

mk_collect_oneFunction · 0.85

Calls 6

mk_trimFunction · 0.85
mk_foldFunction · 0.85
cbm_ht_getFunction · 0.85
cbm_ht_setFunction · 0.85
cbm_arena_allocFunction · 0.50
cbm_arena_sprintfFunction · 0.50

Tested by

no test coverage detected