File utilities and datatype implementation for a C-based code generator (#5)

Co-authored-by: Abdelrahman Said <said.abdelrahman@flawlessai.com>
Reviewed-on: #5
Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com>
Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
This commit is contained in:
2025-09-20 13:48:08 +00:00
committed by Abdelrahman Said
parent 09e96f8112
commit 14bd6ce5fd
52 changed files with 3814 additions and 944 deletions

View File

@@ -1,17 +1,15 @@
/**
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN.
*/
#include "./dbl_list.h"
#include "../../common/assert/assert.h"
#include "../../common/aliases/aliases.h"
#include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h"
#include <stddef.h>
#include <assert.h>
internal Str8List str8_node_to_list(Str8Node *node);
internal VoidPList void_ptr_node_to_list(VoidPNode *node);
internal Str8List str8_node_to_list(Str8Node *node);
internal B32List b32_node_to_list(B32Node *node);
internal CharList char_node_to_list(CharNode *node);
internal C8List c8_node_to_list(C8Node *node);
@@ -31,179 +29,6 @@ internal F128List f128_node_to_list(F128Node *node);
internal IptrList iptr_node_to_list(IptrNode *node);
internal UptrList uptr_node_to_list(UptrNode *node);
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds");
Str8Node *output = NULL;
Str8Node *current = list->first;
for (u64 i = 1; i <= index; ++i) {
current = current->next;
}
output = current;
return output;
}
void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
Str8List node_list = str8_node_to_list(node);
if (list->node_count == 0) {
*list = node_list;
return;
}
list->node_count += node_list.node_count;
Str8Node *first = list->first;
if (first) {
first->prev = node_list.last;
}
list->first = node_list.first;
node_list.last->next = first;
}
void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
Str8List node_list = str8_node_to_list(node);
if (list->node_count == 0) {
*list = node_list;
return;
}
list->node_count += node_list.node_count;
Str8Node *last = list->last;
if (last) {
last->next = node_list.first;
}
list->last = node_list.last;
node_list.first->prev = last;
}
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
if (index == 0) {
wapp_str8_list_push_front(list, node);
return;
} else if (index == list->node_count) {
wapp_str8_list_push_back(list, node);
return;
}
Str8Node *dst_node = wapp_str8_list_get(list, index);
if (!dst_node) {
return;
}
Str8List node_list = str8_node_to_list(node);
list->node_count += node_list.node_count;
Str8Node *prev = dst_node->prev;
dst_node->prev = node_list.last;
prev->next = node_list.first;
node_list.first->prev = prev;
node_list.last->next = dst_node;
}
Str8Node *wapp_str8_list_pop_front(Str8List *list) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
Str8Node *output = NULL;
if (list->node_count == 0) {
goto RETURN_STR8_LIST_POP_FRONT;
}
output = list->first;
if (list->node_count == 1) {
*list = (Str8List){0};
goto RETURN_STR8_LIST_POP_FRONT;
}
--(list->node_count);
list->first = output->next;
output->prev = output->next = NULL;
RETURN_STR8_LIST_POP_FRONT:
return output;
}
Str8Node *wapp_str8_list_pop_back(Str8List *list) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
Str8Node *output = NULL;
if (list->node_count == 0) {
goto RETURN_STR8_LIST_POP_BACK;
}
output = list->last;
if (list->node_count == 1) {
*list = (Str8List){0};
goto RETURN_STR8_LIST_POP_BACK;
}
--(list->node_count);
list->last = output->prev;
output->prev = output->next = NULL;
RETURN_STR8_LIST_POP_BACK:
return output;
}
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
Str8Node *output = NULL;
if (index == 0) {
output = wapp_str8_list_pop_front(list);
goto RETURN_STR8_LIST_REMOVE;
} else if (index == list->node_count) {
output = wapp_str8_list_pop_back(list);
goto RETURN_STR8_LIST_REMOVE;
}
output = wapp_str8_list_get(list, index);
if (!output) {
goto RETURN_STR8_LIST_REMOVE;
}
output->prev->next = output->next;
output->next->prev = output->prev;
--(list->node_count);
output->prev = output->next = NULL;
RETURN_STR8_LIST_REMOVE:
return output;
}
void wapp_str8_list_empty(Str8List *list) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
u64 count = list->node_count;
for (u64 i = 0; i < count; ++i) {
wapp_str8_list_pop_back(list);
}
}
VoidPNode *wapp_void_ptr_list_get(const VoidPList *list, u64 index) {
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds");
@@ -377,6 +202,179 @@ void wapp_void_ptr_list_empty(VoidPList *list) {
}
}
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds");
Str8Node *output = NULL;
Str8Node *current = list->first;
for (u64 i = 1; i <= index; ++i) {
current = current->next;
}
output = current;
return output;
}
void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
Str8List node_list = str8_node_to_list(node);
if (list->node_count == 0) {
*list = node_list;
return;
}
list->node_count += node_list.node_count;
Str8Node *first = list->first;
if (first) {
first->prev = node_list.last;
}
list->first = node_list.first;
node_list.last->next = first;
}
void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
Str8List node_list = str8_node_to_list(node);
if (list->node_count == 0) {
*list = node_list;
return;
}
list->node_count += node_list.node_count;
Str8Node *last = list->last;
if (last) {
last->next = node_list.first;
}
list->last = node_list.last;
node_list.first->prev = last;
}
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
if (index == 0) {
wapp_str8_list_push_front(list, node);
return;
} else if (index == list->node_count) {
wapp_str8_list_push_back(list, node);
return;
}
Str8Node *dst_node = wapp_str8_list_get(list, index);
if (!dst_node) {
return;
}
Str8List node_list = str8_node_to_list(node);
list->node_count += node_list.node_count;
Str8Node *prev = dst_node->prev;
dst_node->prev = node_list.last;
prev->next = node_list.first;
node_list.first->prev = prev;
node_list.last->next = dst_node;
}
Str8Node *wapp_str8_list_pop_front(Str8List *list) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
Str8Node *output = NULL;
if (list->node_count == 0) {
goto RETURN_STR8_LIST_POP_FRONT;
}
output = list->first;
if (list->node_count == 1) {
*list = (Str8List){0};
goto RETURN_STR8_LIST_POP_FRONT;
}
--(list->node_count);
list->first = output->next;
output->prev = output->next = NULL;
RETURN_STR8_LIST_POP_FRONT:
return output;
}
Str8Node *wapp_str8_list_pop_back(Str8List *list) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
Str8Node *output = NULL;
if (list->node_count == 0) {
goto RETURN_STR8_LIST_POP_BACK;
}
output = list->last;
if (list->node_count == 1) {
*list = (Str8List){0};
goto RETURN_STR8_LIST_POP_BACK;
}
--(list->node_count);
list->last = output->prev;
output->prev = output->next = NULL;
RETURN_STR8_LIST_POP_BACK:
return output;
}
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
Str8Node *output = NULL;
if (index == 0) {
output = wapp_str8_list_pop_front(list);
goto RETURN_STR8_LIST_REMOVE;
} else if (index == list->node_count) {
output = wapp_str8_list_pop_back(list);
goto RETURN_STR8_LIST_REMOVE;
}
output = wapp_str8_list_get(list, index);
if (!output) {
goto RETURN_STR8_LIST_REMOVE;
}
output->prev->next = output->next;
output->next->prev = output->prev;
--(list->node_count);
output->prev = output->next = NULL;
RETURN_STR8_LIST_REMOVE:
return output;
}
void wapp_str8_list_empty(Str8List *list) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
u64 count = list->node_count;
for (u64 i = 0; i < count; ++i) {
wapp_str8_list_pop_back(list);
}
}
B32Node *wapp_b32_list_get(const B32List *list, u64 index) {
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds");
@@ -3491,8 +3489,8 @@ void wapp_uptr_list_empty(UptrList *list) {
}
}
internal Str8List str8_node_to_list(Str8Node *node) {
Str8List output = {.first = node, .last = node, .node_count = 1};
internal VoidPList void_ptr_node_to_list(VoidPNode *node) {
VoidPList output = {.first = node, .last = node, .node_count = 1};
while (output.first->prev != NULL) {
output.first = output.first->prev;
@@ -3507,8 +3505,8 @@ internal Str8List str8_node_to_list(Str8Node *node) {
return output;
}
internal VoidPList void_ptr_node_to_list(VoidPNode *node) {
VoidPList output = {.first = node, .last = node, .node_count = 1};
internal Str8List str8_node_to_list(Str8Node *node) {
Str8List output = {.first = node, .last = node, .node_count = 1};
while (output.first->prev != NULL) {
output.first = output.first->prev;