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

Function cs_emit_items

internal/cbm/doclink_cs.c:2906–2967  ·  view source on GitHub ↗

Place every collected declaration in the block that holds it and write * its record. */

Source from the content-addressed store, hash-verified

2904/* Place every collected declaration in the block that holds it and write
2905 * its record. */
2906static void cs_emit_items(cs_scan_t *s) {
2907 cs_stack_t *st = (cs_stack_t *)cs_tmp_alloc(s, sizeof(*st));
2908 if (!st) {
2909 return;
2910 }
2911 st->sp = 0;
2912 st->frames[st->sp++] = (cs_frame_t){.item = CBM_NOT_FOUND,
2913 .end = UINT32_MAX,
2914 .inner_depth = 0,
2915 .region = 0,
2916 .ns_segments = 0,
2917 .type = CBM_NOT_FOUND,
2918 .type_depth = 0,
2919 .is_type = false,
2920 .bad = false};
2921 for (int i = 0; i < s->nitems && !s->failed && !s->sb.failed; i++) {
2922 const cs_item_t *it = &s->items[i];
2923 /* leave the blocks that ended; with parse errors also those the
2924 * braces say this item is not in (an #else branch re-opening the
2925 * block its #if branch opened) */
2926 int depth = s->lexical ? cs_depth_at(s, it->start) : 0;
2927 while (st->sp > SKIP_ONE &&
2928 (st->frames[st->sp - SKIP_ONE].end <= it->start ||
2929 (s->lexical && st->frames[st->sp - SKIP_ONE].inner_depth > depth))) {
2930 st->sp--;
2931 }
2932 const cs_frame_t top = st->frames[st->sp - SKIP_ONE];
2933 bool trusted = !top.bad;
2934 if (trusted && s->lexical) {
2935 trusted = it->start < s->untrusted && depth == top.inner_depth;
2936 }
2937 switch (it->tag) {
2938 case 'U':
2939 if (trusted && !top.is_type) {
2940 cs_emit_using(s, it->node, top.region);
2941 }
2942 break;
2943 case 'N':
2944 case 'F':
2945 cs_place_namespace(s, st, it, trusted);
2946 break;
2947 case 'T':
2948 cs_place_type(s, st, it, trusted);
2949 break;
2950 case 'M':
2951 /* the braces decide whose member it is when the tree has errors */
2952 if (trusted && top.is_type && (s->lexical || it->owner == top.item)) {
2953 cs_member_rec_t rec = {.line = cs_line(it->node),
2954 .kind = it->kind,
2955 .explicit_impl = it->explicit_impl,
2956 .is_static = it->is_static,
2957 .type = top.type,
2958 .name = it->text_name ? it->text_name
2959 : cs_name_dup(s, it->name)};
2960 cs_emit_member(s, &rec, it->tparams, it->params);
2961 }
2962 break;
2963 default:

Callers 1

Calls 8

cs_tmp_allocFunction · 0.85
cs_depth_atFunction · 0.85
cs_emit_usingFunction · 0.85
cs_place_namespaceFunction · 0.85
cs_place_typeFunction · 0.85
cs_lineFunction · 0.85
cs_name_dupFunction · 0.85
cs_emit_memberFunction · 0.85

Tested by

no test coverage detected