aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 794ff231d..5e04aea17 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -108,6 +108,30 @@ Token ast_token(Ast *node) {
return empty_token;
}
+
+gb_global gbAtomic64 total_allocated_node_memory = {0};
+gb_global gbAtomic64 total_subtype_node_memory_test = {0};
+
+isize ast_node_size(AstKind kind) {
+ return align_formula_isize(gb_size_of(AstCommonStuff) + ast_variant_sizes[kind], gb_align_of(void *));
+
+}
+// NOTE(bill): And this below is why is I/we need a new language! Discriminated unions are a pain in C/C++
+Ast *alloc_ast_node(AstFile *f, AstKind kind) {
+ gbAllocator a = ast_allocator(f);
+
+ isize size = ast_node_size(kind);
+
+ gb_atomic64_fetch_add(&total_allocated_node_memory, cast(i64)(gb_size_of(Ast)));
+ gb_atomic64_fetch_add(&total_subtype_node_memory_test, cast(i64)(gb_size_of(AstCommonStuff) + ast_variant_sizes[kind]));
+
+ // Ast *node = gb_alloc_item(a, Ast);
+ Ast *node = cast(Ast *)gb_alloc(a, size);
+ node->kind = kind;
+ node->file = f;
+ return node;
+}
+
Ast *clone_ast(Ast *node);
Array<Ast *> clone_ast_array(Array<Ast *> array) {
Array<Ast *> result = {};
@@ -125,7 +149,7 @@ Ast *clone_ast(Ast *node) {
return nullptr;
}
Ast *n = alloc_ast_node(node->file, node->kind);
- gb_memmove(n, node, gb_size_of(Ast));
+ gb_memmove(n, node, ast_node_size(node->kind));
switch (n->kind) {
default: GB_PANIC("Unhandled Ast %.*s", LIT(ast_strings[n->kind])); break;
@@ -463,23 +487,6 @@ bool ast_node_expect(Ast *node, AstKind kind) {
return true;
}
-
-gb_global gbAtomic64 total_allocated_node_memory = {0};
-gb_global gbAtomic64 total_subtype_node_memory_test = {0};
-
-// NOTE(bill): And this below is why is I/we need a new language! Discriminated unions are a pain in C/C++
-Ast *alloc_ast_node(AstFile *f, AstKind kind) {
- gbAllocator a = ast_allocator(f);
-
- gb_atomic64_fetch_add(&total_allocated_node_memory, cast(i64)(gb_size_of(Ast)));
- gb_atomic64_fetch_add(&total_subtype_node_memory_test, cast(i64)(gb_size_of(AstCommonStuff) + ast_variant_sizes[kind]));
-
- Ast *node = gb_alloc_item(a, Ast);
- node->kind = kind;
- node->file = f;
- return node;
-}
-
Ast *ast_bad_expr(AstFile *f, Token begin, Token end) {
Ast *result = alloc_ast_node(f, Ast_BadExpr);
result->BadExpr.begin = begin;