| 500 | } |
| 501 | |
| 502 | static void build_def_props(char *buf, size_t bufsize, const CBMDefinition *def) { |
| 503 | /* Complexity/loop/recursion metrics are meaningful only for Function/Method. |
| 504 | * Gate the block so the millions of Macro/Field/Variable/Class/Enum nodes |
| 505 | * keep a lean properties blob (lossless — those fields are always zero for |
| 506 | * non-functions). Cuts RAM, gbuf-merge copy and dump volume. Mirrors |
| 507 | * pass_definitions.c::build_def_props — keep both in sync. */ |
| 508 | const bool is_fn = |
| 509 | def->label && (strcmp(def->label, "Function") == 0 || strcmp(def->label, "Method") == 0); |
| 510 | const char *test_role = def->test_role == CBM_TEST_ROLE_CASE ? ",\"test_role\":\"case\"" |
| 511 | : def->test_role == CBM_TEST_ROLE_SUITE ? ",\"test_role\":\"suite\"" |
| 512 | : ""; |
| 513 | int n; |
| 514 | if (is_fn) { |
| 515 | n = snprintf(buf, bufsize, |
| 516 | "{\"complexity\":%d,\"cognitive\":%d,\"loop_count\":%d,\"loop_depth\":%d," |
| 517 | "\"self_recursive\":%s,\"param_count\":%d,\"max_access_depth\":%d," |
| 518 | "\"linear_scan_in_loop\":%d,\"alloc_in_loop\":%d,\"recursion_in_loop\":%s," |
| 519 | "\"unguarded_recursion\":%s," |
| 520 | "\"lines\":%d,\"is_exported\":%s,\"is_test\":%s,\"is_entry_point\":%s%s", |
| 521 | def->complexity, def->cognitive, def->loop_count, def->loop_depth, |
| 522 | def->is_recursive ? "true" : "false", def->param_count, def->max_access_depth, |
| 523 | def->linear_scan_in_loop, def->alloc_in_loop, |
| 524 | def->recursion_in_loop ? "true" : "false", |
| 525 | def->unguarded_recursion ? "true" : "false", def->lines, |
| 526 | def->is_exported ? "true" : "false", def->is_test ? "true" : "false", |
| 527 | def->is_entry_point ? "true" : "false", test_role); |
| 528 | } else { |
| 529 | n = snprintf(buf, bufsize, |
| 530 | "{\"complexity\":%d,\"lines\":%d,\"is_exported\":%s,\"is_test\":%s," |
| 531 | "\"is_entry_point\":%s%s", |
| 532 | def->complexity, def->lines, def->is_exported ? "true" : "false", |
| 533 | def->is_test ? "true" : "false", def->is_entry_point ? "true" : "false", |
| 534 | test_role); |
| 535 | } |
| 536 | if (n <= 0 || (size_t)n >= bufsize) { |
| 537 | buf[0] = '\0'; |
| 538 | return; |
| 539 | } |
| 540 | size_t pos = (size_t)n; |
| 541 | append_json_string(buf, bufsize, &pos, "docstring", def->docstring); |
| 542 | /* Right after the docstring: the buffer is sized for exactly these three |
| 543 | * uncapped fields (pp_props_buf), so none can be squeezed out. */ |
| 544 | append_json_raw(buf, bufsize, &pos, "variants", def->variants); |
| 545 | append_json_string(buf, bufsize, &pos, "variant_key", def->variant_key); |
| 546 | append_json_string(buf, bufsize, &pos, "signature", def->signature); |
| 547 | append_json_string(buf, bufsize, &pos, "return_type", def->return_type); |
| 548 | append_json_string(buf, bufsize, &pos, "parent_class", def->parent_class); |
| 549 | append_json_str_array(buf, bufsize, &pos, "decorators", def->decorators); |
| 550 | append_json_str_array(buf, bufsize, &pos, "base_classes", def->base_classes); |
| 551 | append_json_str_array(buf, bufsize, &pos, "param_names", def->param_names); |
| 552 | append_json_str_array(buf, bufsize, &pos, "param_types", def->param_types); |
| 553 | append_json_string(buf, bufsize, &pos, "route_path", def->route_path); |
| 554 | append_json_string(buf, bufsize, &pos, "route_method", def->route_method); |
| 555 | append_json_string(buf, bufsize, &pos, "http_client", def->http_client); |
| 556 | append_json_string(buf, bufsize, &pos, "http_base_url", def->http_base_url); |
| 557 | /* A document definition's facts (an ADR's id, status, date, ...): key, value pairs. */ |
| 558 | for (const char **kv = def->extra_props; kv && kv[0] && kv[SKIP_ONE]; kv += PAIR_LEN) { |
| 559 | append_json_string(buf, bufsize, &pos, kv[0], kv[SKIP_ONE]); |
no test coverage detected