| 84 | } |
| 85 | |
| 86 | static bool surface_add_python_namespace(yyjson_mut_doc *doc, yyjson_mut_val *root, |
| 87 | const CBMFileResult *result, CBMLanguage language, |
| 88 | const char *rel_path) { |
| 89 | if (language != CBM_LANG_PYTHON) { |
| 90 | return yyjson_mut_obj_add_null(doc, root, "py"); |
| 91 | } |
| 92 | if (!result || !result->module_qn || !result->module_qn[0] || !rel_path || !rel_path[0] || |
| 93 | result->py_namespace.status != CBM_PY_NS_COMPLETE || |
| 94 | result->py_namespace.language != CBM_LANG_PYTHON || |
| 95 | !cbm_py_namespace_facts_valid(&result->py_namespace)) { |
| 96 | return false; |
| 97 | } |
| 98 | const CBMPyNamespaceFacts *facts = &result->py_namespace; |
| 99 | yyjson_mut_val *py = yyjson_mut_obj(doc); |
| 100 | yyjson_mut_val *events = yyjson_mut_arr(doc); |
| 101 | if (!py || !events || !yyjson_mut_obj_add_uint(doc, py, "v", facts->version) || |
| 102 | !yyjson_mut_obj_add_int(doc, py, "lang", (int)facts->language) || |
| 103 | !yyjson_mut_obj_add_str(doc, py, "module", result->module_qn) || |
| 104 | !yyjson_mut_obj_add_str(doc, py, "path", rel_path) || |
| 105 | !yyjson_mut_obj_add_int(doc, py, "status", (int)facts->status) || |
| 106 | !yyjson_mut_obj_add_int(doc, py, "failure", (int)facts->failure)) { |
| 107 | return false; |
| 108 | } |
| 109 | for (int i = 0; i < facts->count; i++) { |
| 110 | const CBMPyNamespaceFact *f = &facts->items[i]; |
| 111 | yyjson_mut_val *event = yyjson_mut_obj(doc); |
| 112 | yyjson_mut_val *names = yyjson_mut_arr(doc); |
| 113 | if (!event || !names || !yyjson_mut_obj_add_int(doc, event, "k", (int)f->kind) || |
| 114 | !yyjson_mut_obj_add_int(doc, event, "d", (int)f->def_kind) || |
| 115 | !yyjson_mut_obj_add_int(doc, event, "s", (int)f->sequence_kind) || |
| 116 | !yyjson_mut_obj_add_int(doc, event, "r", (int)f->reason) || |
| 117 | !yyjson_mut_obj_add_uint(doc, event, "f", f->flags) || |
| 118 | !yyjson_mut_obj_add_uint(doc, event, "l", f->relative_level) || |
| 119 | !surface_py_add_nullable(doc, event, "n", f->local_name) || |
| 120 | !surface_py_add_nullable(doc, event, "m", f->module_name) || |
| 121 | !surface_py_add_nullable(doc, event, "i", f->member_name)) { |
| 122 | return false; |
| 123 | } |
| 124 | for (int j = 0; j < f->name_count; j++) { |
| 125 | if (!yyjson_mut_arr_add_str(doc, names, f->names[j])) { |
| 126 | return false; |
| 127 | } |
| 128 | } |
| 129 | if (!yyjson_mut_obj_add_val(doc, event, "a", names) || |
| 130 | !yyjson_mut_arr_add_val(events, event)) { |
| 131 | return false; |
| 132 | } |
| 133 | } |
| 134 | return yyjson_mut_obj_add_val(doc, py, "events", events) && |
| 135 | yyjson_mut_obj_add_val(doc, root, "py", py); |
| 136 | } |
| 137 | |
| 138 | /* Reject duplicate fields rather than letting object lookup choose one. */ |
| 139 | static yyjson_val *surface_unique_field(yyjson_val *obj, const char *name) { |
no test coverage detected