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

Function tf_mod_parse

src/pipeline/pass_terraform.c:828–861  ·  view source on GitHub ↗

One module directory, its files `paths[0..n)`: parse each (read from the * repository) into its declarations, calls and references. */

Source from the content-addressed store, hash-verified

826/* One module directory, its files `paths[0..n)`: parse each (read from the
827 * repository) into its declarations, calls and references. */
828static 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). */
864static CBMHashTable *tf_label_index(cbm_pipeline_ctx_t *ctx, const char *label) {

Callers 1

tf_link_repoFunction · 0.85

Calls 8

cbm_callocFunction · 0.85
cbm_ht_createFunction · 0.85
tf_mod_freeFunction · 0.85
tf_readFunction · 0.85
tf_mod_fileFunction · 0.85
cbm_freeFunction · 0.85
cbm_arena_strndupFunction · 0.50
cbm_arena_strdupFunction · 0.50

Tested by

no test coverage detected