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

Function dg_element

internal/cbm/diagram.c:251–300  ·  view source on GitHub ↗

The element `id` (made on first sight), its label set when it has none. */

Source from the content-addressed store, hash-verified

249
250/* The element `id` (made on first sight), its label set when it has none. */
251static const char *dg_element(dg_t *dg, dg_str_t id, dg_str_t label, const char *kind,
252 uint32_t line) {
253 id = dg_trim(id);
254 if (!id.n || dg->oom) {
255 return NULL;
256 }
257 char key[DG_ID_MAX];
258 size_t kn = dg_id_key(id, key);
259 char text[DG_LABEL_MAX];
260 size_t tl = dg_label_text(dg_unquote(label), text, sizeof(text));
261 CBMDefArray *defs = &dg->ctx->result->defs;
262 void *v = cbm_ht_get(dg->ids, key);
263 if (v) {
264 CBMDefinition *d = &defs->items[(uintptr_t)v - SKIP_ONE];
265 if (tl && d->name == d->extra_props[SKIP_ONE]) { /* still named by its id */
266 d->name = dg_dup(dg, text, tl);
267 dg_doc_add(dg, text, tl);
268 }
269 return d->qualified_name;
270 }
271 const char *qn = dg_element_qn(dg, dg_s(key, kn));
272 const char *idc = dg_dup(dg, id.p, id.n);
273 if (!qn || !idc) {
274 return NULL;
275 }
276 CBMDefinition def;
277 memset(&def, 0, sizeof(def));
278 def.name = tl ? dg_dup(dg, text, tl) : idc;
279 def.qualified_name = qn;
280 def.label = "DiagramElement";
281 def.file_path = dg->ctx->rel_path;
282 def.start_line = line;
283 def.end_line = line;
284 def.parent_class = dg->qn;
285 /* the kind may live in a parser buffer (a JSON value, a draw.io cell) */
286 const char *kindc = dg_dup(dg, kind, strlen(kind));
287 def.extra_props = dg_props(dg, "element_id", idc, "element_kind", kindc);
288 if (dg->oom || !def.name) {
289 return NULL;
290 }
291 cbm_defs_push(defs, dg->ctx->arena, def);
292 const char *k = dg_dup(dg, key, kn);
293 if (k) {
294 cbm_ht_set(dg->ids, k, (void *)(uintptr_t)defs->count);
295 }
296 if (tl) {
297 dg_doc_add(dg, text, tl);
298 }
299 return qn;
300}
301
302static void dg_arrow(dg_t *dg, dg_str_t from, dg_str_t to, dg_str_t label, const char *style,
303 uint32_t line) {

Callers 15

dg_arrowFunction · 0.85
dg_flow_groupFunction · 0.85
dg_mermaid_clickFunction · 0.85
dg_flow_statementFunction · 0.85
dg_sequenceFunction · 0.85
dg_class_relationFunction · 0.85
dg_classdiagramFunction · 0.85
dg_erdiagramFunction · 0.85
dg_statediagramFunction · 0.85
dg_c4_lineFunction · 0.85
dg_architectureFunction · 0.85
dg_puml_relationFunction · 0.85

Calls 12

dg_trimFunction · 0.85
dg_id_keyFunction · 0.85
dg_label_textFunction · 0.85
dg_unquoteFunction · 0.85
cbm_ht_getFunction · 0.85
dg_dupFunction · 0.85
dg_doc_addFunction · 0.85
dg_element_qnFunction · 0.85
dg_sFunction · 0.85
dg_propsFunction · 0.85
cbm_defs_pushFunction · 0.85
cbm_ht_setFunction · 0.85

Tested by

no test coverage detected