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

Function rst_contexts

internal/cbm/doclink_rst.c:1083–1161  ·  view source on GitHub ↗

H3 _contexts: the module, C namespace and class in force on every line. */

Source from the content-addressed store, hash-verified

1081
1082/* H3 _contexts: the module, C namespace and class in force on every line. */
1083static void rst_contexts(rst_doc_t *d) {
1084 int n = d->n;
1085 d->mod_at = (const char **)cbm_arena_alloc(d->scratch, (size_t)n * sizeof(char *));
1086 d->ns_at = (const char **)cbm_arena_alloc(d->scratch, (size_t)n * sizeof(char *));
1087 d->cls_at = (const char **)cbm_arena_alloc(d->scratch, (size_t)n * sizeof(char *));
1088 if (!d->mod_at || !d->ns_at || !d->cls_at) {
1089 d->failed = true;
1090 return;
1091 }
1092 memset(d->cls_at, 0, (size_t)n * sizeof(char *));
1093 const char *cm = NULL;
1094 const char *cn = NULL;
1095 int k = 0;
1096 /* directives are in line order (the scan appends them so) */
1097 for (int di = 0; di <= d->ndirs; di++) {
1098 int upto = di < d->ndirs ? d->dirs[di].line : n;
1099 for (; k < upto; k++) {
1100 d->mod_at[k] = cm;
1101 d->ns_at[k] = cn;
1102 }
1103 if (di == d->ndirs) {
1104 break;
1105 }
1106 const rst_dir_t *dir = &d->dirs[di];
1107 const char *v = dir->nargs ? dir->args[0] : NULL;
1108 if (strcmp(dir->dom, "py") == 0 &&
1109 (strcmp(dir->dname, "module") == 0 || strcmp(dir->dname, "currentmodule") == 0)) {
1110 cm = (!v || !v[0] || strcmp(v, "None") == 0) ? NULL : v;
1111 }
1112 if (strcmp(dir->dom, "c") == 0 &&
1113 (strcmp(dir->dname, "namespace") == 0 || strcmp(dir->dname, "namespace-push") == 0)) {
1114 cn = (!v || !v[0] || strcmp(v, "NULL") == 0) ? NULL : v;
1115 }
1116 if (strcmp(dir->dom, "c") == 0 && strcmp(dir->dname, "namespace-pop") == 0) {
1117 cn = NULL;
1118 }
1119 }
1120 for (int di = 0; di < d->ndirs && !d->failed; di++) {
1121 const rst_dir_t *dir = &d->dirs[di];
1122 if (strcmp(dir->dom, "py") != 0 || !rst_in(dir->dname, PY_OBJ) ||
1123 strcmp(dir->dname, "module") == 0 || dir->cs >= dir->ce) {
1124 continue;
1125 }
1126 const char *outer = d->cls_at[dir->line];
1127 const char **sigs = NULL;
1128 int ns = rst_join_sigs(d, dir, &sigs);
1129 const char *content_cls = outer;
1130 const char *prefix;
1131 const char *name;
1132 if (ns > 0 && rst_py_sig(d, sigs[ns - 1], &prefix, &name)) {
1133 const char *full;
1134 const char *rem;
1135 rst_py_fullname(d, prefix, name, outer, &full, &rem);
1136 if (strcmp(dir->dname, "class") == 0 || strcmp(dir->dname, "exception") == 0) {
1137 content_cls = full;
1138 } else if (rem[0]) {
1139 size_t rl = strlen(rem);
1140 const char *r = rem;

Callers 1

Calls 7

rst_inFunction · 0.85
rst_join_sigsFunction · 0.85
rst_py_sigFunction · 0.85
rst_py_fullnameFunction · 0.85
rst_optFunction · 0.85
cbm_arena_allocFunction · 0.70
cbm_arena_strndupFunction · 0.70

Tested by

no test coverage detected