summaryrefslogtreecommitdiff
path: root/src/compiler/ast-tree.c
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-24 02:59:57 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-24 02:59:57 +0330
commit7847178e34d567eb566d71b551a82dd36d15ea99 (patch)
tree5f678f9a4411b9c0b836a4cea4d80b1666dc6ca1 /src/compiler/ast-tree.c
parent07e5fc400493093cd03493ef469b9b97fa1fe87a (diff)
fix circular imports
Diffstat (limited to 'src/compiler/ast-tree.c')
-rw-r--r--src/compiler/ast-tree.c41
1 files changed, 13 insertions, 28 deletions
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index 2a44e39..ac046f0 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -1266,15 +1266,12 @@ AstTreeVariables copyAstTreeVariables(AstTreeVariables variables,
}
AstTreeRoots makeAstTree(const char *filePath) {
- char **filePathes = a404m_malloc(0 * sizeof(*filePathes));
-
- size_t roots_size = 0;
AstTreeRoots roots = {
- .data = a404m_malloc(roots_size * sizeof(*roots.data)),
+ .data = a404m_malloc(0 * sizeof(*roots.data)),
.size = 0,
};
- if (getAstTreeRoot(strClone(filePath), &roots, &filePathes) == NULL) {
+ if (getAstTreeRoot(strClone(filePath), &roots) == NULL) {
goto RETURN_ERROR;
}
@@ -1285,32 +1282,20 @@ AstTreeRoots makeAstTree(const char *filePath) {
}
}
- free(filePathes);
-
return roots;
RETURN_ERROR:
return AST_TREE_ROOTS_ERROR;
}
-AstTreeRoot *getAstTreeRoot(char *filePath, AstTreeRoots *roots,
- char ***filePathes) {
+AstTreeRoot *getAstTreeRoot(char *filePath, AstTreeRoots *roots) {
for (size_t i = 0; i < roots->size; ++i) {
- if (strcmp(*filePathes[i], filePath) == 0) {
+ if (strcmp(roots->data[i]->filePath, filePath) == 0) {
free(filePath);
return roots->data[i];
}
}
- const size_t filePathes_size =
- a404m_malloc_usable_size(*filePathes) / sizeof(**filePathes);
- if (filePathes_size == roots->size) {
- *filePathes =
- a404m_realloc(*filePathes, (filePathes_size + filePathes_size / 2 + 1) *
- sizeof(**filePathes));
- }
- *filePathes[roots->size] = filePath;
-
ParserNode *parserNode = parserFromPath(filePath);
if (parserNode == NULL) {
goto RETURN_ERROR;
@@ -1321,6 +1306,14 @@ AstTreeRoot *getAstTreeRoot(char *filePath, AstTreeRoots *roots,
goto RETURN_ERROR;
}
+ const size_t roots_size =
+ a404m_malloc_usable_size(roots->data) / sizeof(*roots->data);
+ if (roots_size == roots->size) {
+ roots->data = a404m_realloc(roots->data, (roots_size + roots_size / 2 + 1) *
+ sizeof(*roots->data));
+ }
+ roots->data[roots->size++] = root;
+
for (size_t i = 0; i < root->trees.size; ++i) {
AstTree *tree = root->trees.data[i];
if (tree->token == AST_TREE_TOKEN_FUNCTION_CALL) {
@@ -1377,7 +1370,7 @@ AstTreeRoot *getAstTreeRoot(char *filePath, AstTreeRoots *roots,
}
AstTreeRoot *import =
- getAstTreeRoot(joinToPathOf(filePath, str), roots, filePathes);
+ getAstTreeRoot(joinToPathOf(filePath, str), roots);
free(str);
if (import == NULL) {
@@ -1392,14 +1385,6 @@ AstTreeRoot *getAstTreeRoot(char *filePath, AstTreeRoots *roots,
}
}
- const size_t roots_size =
- a404m_malloc_usable_size(roots->data) / sizeof(*roots->data);
- if (roots_size == roots->size) {
- roots->data = a404m_realloc(roots->data, (roots_size + roots_size / 2 + 1) *
- sizeof(*roots->data));
- }
- roots->data[roots->size++] = root;
-
return root;
RETURN_ERROR: