Begin minimizing Ast size

This commit is contained in:
gingerBill
2021-11-14 15:12:37 +00:00
parent b9701340b8
commit 3f038428a7
10 changed files with 51 additions and 38 deletions

View File

@@ -65,7 +65,7 @@ Ast *alloc_ast_node(AstFile *f, AstKind kind) {
Ast *node = cast(Ast *)gb_alloc(a, size);
node->kind = kind;
node->file = f;
node->file_id = f ? f->id : 0;
return node;
}
@@ -95,7 +95,8 @@ Ast *clone_ast(Ast *node) {
if (node == nullptr) {
return nullptr;
}
Ast *n = alloc_ast_node(node->file, node->kind);
AstFile *f = get_ast_file_from_id(node->file_id);
Ast *n = alloc_ast_node(f, node->kind);
gb_memmove(n, node, ast_node_size(node->kind));
switch (n->kind) {
@@ -399,8 +400,9 @@ void error(Ast *node, char const *fmt, ...) {
va_start(va, fmt);
error_va(token.pos, end_pos, fmt, va);
va_end(va);
if (node != nullptr && node->file != nullptr) {
node->file->error_count += 1;
if (node != nullptr && node->file_id != 0) {
AstFile *f = get_ast_file_from_id(node->file_id);
f->error_count += 1;
}
}
@@ -413,8 +415,9 @@ void error_no_newline(Ast *node, char const *fmt, ...) {
va_start(va, fmt);
error_no_newline_va(token.pos, fmt, va);
va_end(va);
if (node != nullptr && node->file != nullptr) {
node->file->error_count += 1;
if (node != nullptr && node->file_id != 0) {
AstFile *f = get_ast_file_from_id(node->file_id);
f->error_count += 1;
}
}
@@ -442,8 +445,9 @@ void syntax_error(Ast *node, char const *fmt, ...) {
va_start(va, fmt);
syntax_error_va(token.pos, end_pos, fmt, va);
va_end(va);
if (node != nullptr && node->file != nullptr) {
node->file->error_count += 1;
if (node != nullptr && node->file_id != 0) {
AstFile *f = get_ast_file_from_id(node->file_id);
f->error_count += 1;
}
}