aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-11-14 15:12:37 +0000
committergingerBill <bill@gingerbill.org>2021-11-14 15:12:37 +0000
commit3f038428a7f282468011415db76da4bf08ddb67c (patch)
tree70712155e0f94b43754fd8a28bf40939b8228d0f /src/parser.cpp
parentb9701340b8faff107fe6a515d5de429141508f48 (diff)
Begin minimizing `Ast` size
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 12888a52d..ba5df1f27 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -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;
}
}