One module directory, its files `paths[0..n)`: parse each (read from the * repository) into its declarations, calls and references. */
| 826 | /* One module directory, its files `paths[0..n)`: parse each (read from the |
| 827 | * repository) into its declarations, calls and references. */ |
| 828 | static tf_mod_t *tf_mod_parse(cbm_pipeline_ctx_t *ctx, CBMArena *arena, TSParser *parser, |
| 829 | const char *const *paths, int n) { |
| 830 | tf_mod_t *m = cbm_calloc(CBM_MEM_CLASS_OTHER, sizeof(*m)); |
| 831 | if (!m) { |
| 832 | return NULL; |
| 833 | } |
| 834 | const char *slash = strrchr(paths[0], '/'); |
| 835 | *m = (tf_mod_t){.ctx = ctx, |
| 836 | .arena = arena, |
| 837 | .decls = cbm_ht_create(0), |
| 838 | .calls = cbm_ht_create(0), |
| 839 | .dir = |
| 840 | cbm_arena_strndup(arena, paths[0], slash ? (size_t)(slash - paths[0]) : 0)}; |
| 841 | if (!m->decls || !m->calls || !m->dir) { |
| 842 | tf_mod_free(m); |
| 843 | return NULL; |
| 844 | } |
| 845 | for (int i = 0; i < n; i++) { |
| 846 | char path[CBM_SZ_2K]; |
| 847 | snprintf(path, sizeof(path), "%s/%s", ctx->repo_path, paths[i]); |
| 848 | size_t len = 0; |
| 849 | char *src = tf_read(path, &len); |
| 850 | TSTree *tree = src ? ts_parser_parse_string(parser, NULL, src, (uint32_t)len) : NULL; |
| 851 | if (tree) { |
| 852 | m->src = src; |
| 853 | m->file = cbm_arena_strdup(arena, paths[i]); |
| 854 | tf_mod_file(m, ts_tree_root_node(tree)); |
| 855 | ts_tree_delete(tree); |
| 856 | } |
| 857 | m->src = NULL; |
| 858 | cbm_free(CBM_MEM_CLASS_OTHER, src); |
| 859 | } |
| 860 | return m; |
| 861 | } |
| 862 | |
| 863 | /* path -> node, over the nodes of one label (Folder, File). */ |
| 864 | static CBMHashTable *tf_label_index(cbm_pipeline_ctx_t *ctx, const char *label) { |
no test coverage detected