| 3830 | return out; |
| 3831 | } |
| 3832 | static bool st_context_eval(cbm_msb_eval_context_t *context, const char *project_rel, |
| 3833 | cbm_msb_result_t *out) { |
| 3834 | memset(out, 0, sizeof(*out)); |
| 3835 | const cbm_msb_t *m = context->m; |
| 3836 | msb_state_t *s = context->state; |
| 3837 | if (s->generation != m->generation) { |
| 3838 | context_drop_items(context); |
| 3839 | st_state_clear(s); |
| 3840 | context_clear_nearest(context); |
| 3841 | if (!st_state_epoch(s, m)) { |
| 3842 | st_state_clear(s); |
| 3843 | return false; |
| 3844 | } |
| 3845 | } |
| 3846 | int project = project_rel ? msb_file_index(m, project_rel) : CBM_NOT_FOUND; |
| 3847 | if (project < 0 || !s->symbols || !s->components) |
| 3848 | return false; |
| 3849 | msb_eval_t ev = {.m = m, .state = s, .main_project = project}; |
| 3850 | msb_live_t live = {.owners = {&ev, &context->item_owner}, |
| 3851 | .metadata_bytes = &context->nearest_bytes, |
| 3852 | .state_bytes = &s->bytes, |
| 3853 | .state_names = &s->names}; |
| 3854 | ev.live = &live; |
| 3855 | /* One call-local arena pair; components never acquire an arena pair. */ |
| 3856 | cbm_arena_init(&ev.arena); |
| 3857 | cbm_arena_init(&ev.scratch); |
| 3858 | ev_peak(&ev); |
| 3859 | msb_seed(&ev, project); |
| 3860 | cbm_arena_reset(&ev.scratch); |
| 3861 | int props = |
| 3862 | !ev.oom ? context_nearest(context, &ev, m->files[project].dir, false) : CBM_NOT_FOUND; |
| 3863 | st_component_t *prefix = st_run(&ev, props); |
| 3864 | st_component_t *local = st_run(&ev, project); |
| 3865 | int targets = |
| 3866 | !ev.oom ? context_nearest(context, &ev, m->files[project].dir, true) : CBM_NOT_FOUND; |
| 3867 | st_component_t *target = st_run(&ev, targets); |
| 3868 | bool ok = false; |
| 3869 | if (!ev.oom) { |
| 3870 | st_rope_t *a = prefix ? prefix->items : NULL, *b = target ? target->items : NULL; |
| 3871 | if (s->item_a != a || s->item_b != b) { |
| 3872 | context_drop_items(context); |
| 3873 | st_rope_drop(s, s->item_a); |
| 3874 | st_rope_drop(s, s->item_b); |
| 3875 | s->item_a = st_rope_hold(a); |
| 3876 | s->item_b = st_rope_hold(b); |
| 3877 | } |
| 3878 | s->capture_a = a; |
| 3879 | s->capture_b = b; |
| 3880 | msb_ulist_t inc = {0}, rem = {0}; |
| 3881 | const char *const *implicit = msb_implicit(&ev, project); |
| 3882 | for (int i = 0; !ev.oom && implicit && implicit[i]; i++) |
| 3883 | ulist_add(&ev, &inc, 'n', "", implicit[i]); |
| 3884 | ok = !ev.oom && apply_items(context, &ev, &inc, &rem); |
| 3885 | if (ok) { |
| 3886 | st_eval_rope(&ev, local ? local->items : NULL, &inc, &rem); |
| 3887 | ok = !ev.oom && msb_result(&ev, &inc, &rem, out); |
| 3888 | } |
| 3889 | s->capture_a = s->capture_b = NULL; |
no test coverage detected