mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-17 19:32:23 -07:00
Begin minimizing Ast size
This commit is contained in:
+3
-3
@@ -8413,14 +8413,14 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
||||
if (check_is_assignable_to(c, &z, first_type)) {
|
||||
// NOTE(bill): AST GENERATION HACK!
|
||||
Token op = {Token_Pointer};
|
||||
first_arg = ast_deref_expr(first_arg->file, first_arg, op);
|
||||
first_arg = ast_deref_expr(first_arg->file(), first_arg, op);
|
||||
} else if (y.mode == Addressing_Variable) {
|
||||
Operand w = y;
|
||||
w.type = alloc_type_pointer(y.type);
|
||||
if (check_is_assignable_to(c, &w, first_type)) {
|
||||
// NOTE(bill): AST GENERATION HACK!
|
||||
Token op = {Token_And};
|
||||
first_arg = ast_unary_expr(first_arg->file, op, first_arg);
|
||||
first_arg = ast_unary_expr(first_arg->file(), op, first_arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8443,7 +8443,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
||||
}
|
||||
if (!fail && first_is_field_value) {
|
||||
Token op = {Token_Eq};
|
||||
AstFile *f = first_arg->file;
|
||||
AstFile *f = first_arg->file();
|
||||
first_arg = ast_field_value(f, ast_ident(f, make_token_ident(first_arg_name)), first_arg, op);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1616,7 +1616,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
}
|
||||
Operand lhs = {Addressing_Invalid};
|
||||
Operand rhs = {Addressing_Invalid};
|
||||
Ast *binary_expr = alloc_ast_node(node->file, Ast_BinaryExpr);
|
||||
Ast *binary_expr = alloc_ast_node(node->file(), Ast_BinaryExpr);
|
||||
ast_node(be, BinaryExpr, binary_expr);
|
||||
be->op = op;
|
||||
be->op.kind = cast(TokenKind)(cast(i32)be->op.kind - (Token_AddEq - Token_Add));
|
||||
|
||||
+3
-2
@@ -1939,8 +1939,9 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node,
|
||||
error(proc_type_node, "A procedure type with the #optional_second tag requires 2 return values, got %td", result_count);
|
||||
} else {
|
||||
bool ok = false;
|
||||
if (proc_type_node->file && proc_type_node->file->pkg) {
|
||||
ok = proc_type_node->file->pkg->scope == ctx->info->runtime_package->scope;
|
||||
AstFile *file = proc_type_node->file();
|
||||
if (file && file->pkg) {
|
||||
ok = file->pkg->scope == ctx->info->runtime_package->scope;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
|
||||
+1
-1
@@ -3712,7 +3712,7 @@ String path_to_entity_name(String name, String fullpath, bool strip_extension=tr
|
||||
#if 1
|
||||
|
||||
void add_import_dependency_node(Checker *c, Ast *decl, PtrMap<AstPackage *, ImportGraphNode *> *M) {
|
||||
AstPackage *parent_pkg = decl->file->pkg;
|
||||
AstPackage *parent_pkg = decl->file()->pkg;
|
||||
|
||||
switch (decl->kind) {
|
||||
case_ast_node(id, ImportDecl, decl);
|
||||
|
||||
@@ -454,7 +454,7 @@ lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, A
|
||||
token.kind = Token_Ident;
|
||||
token.string = name;
|
||||
Entity *e = alloc_entity_procedure(nullptr, token, type, pl->tags);
|
||||
e->file = expr->file;
|
||||
e->file = expr->file();
|
||||
e->decl_info = pl->decl;
|
||||
e->code_gen_module = m;
|
||||
e->flags |= EntityFlag_ProcBodyChecked;
|
||||
@@ -1278,8 +1278,8 @@ void lb_generate_code(lbGenerator *gen) {
|
||||
|
||||
if (Entity *entry_point = m->info->entry_point) {
|
||||
if (Ast *ident = entry_point->identifier.load()) {
|
||||
if (ident->file) {
|
||||
init_file = ident->file;
|
||||
if (ident->file_id) {
|
||||
init_file = ident->file();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ LLVMMetadataRef lb_get_llvm_file_metadata_from_node(lbModule *m, Ast *node) {
|
||||
if (node == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return lb_get_llvm_metadata(m, node->file);
|
||||
return lb_get_llvm_metadata(m, node->file());
|
||||
}
|
||||
|
||||
LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) {
|
||||
@@ -660,7 +660,7 @@ void lb_debug_complete_types(lbModule *m) {
|
||||
case Type_Struct:
|
||||
if (file == nullptr) {
|
||||
if (bt->Struct.node) {
|
||||
file = lb_get_llvm_metadata(m, bt->Struct.node->file);
|
||||
file = lb_get_llvm_metadata(m, bt->Struct.node->file());
|
||||
line_number = cast(unsigned)ast_token(bt->Struct.node).pos.line;
|
||||
}
|
||||
}
|
||||
@@ -741,7 +741,7 @@ void lb_debug_complete_types(lbModule *m) {
|
||||
{
|
||||
if (file == nullptr) {
|
||||
GB_ASSERT(bt->Union.node != nullptr);
|
||||
file = lb_get_llvm_metadata(m, bt->Union.node->file);
|
||||
file = lb_get_llvm_metadata(m, bt->Union.node->file());
|
||||
line_number = cast(unsigned)ast_token(bt->Union.node).pos.line;
|
||||
}
|
||||
|
||||
@@ -801,7 +801,7 @@ void lb_debug_complete_types(lbModule *m) {
|
||||
{
|
||||
if (file == nullptr) {
|
||||
GB_ASSERT(bt->BitSet.node != nullptr);
|
||||
file = lb_get_llvm_metadata(m, bt->BitSet.node->file);
|
||||
file = lb_get_llvm_metadata(m, bt->BitSet.node->file());
|
||||
line_number = cast(unsigned)ast_token(bt->BitSet.node).pos.line;
|
||||
}
|
||||
|
||||
@@ -929,7 +929,7 @@ void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, T
|
||||
}
|
||||
|
||||
|
||||
AstFile *file = p->body->file;
|
||||
AstFile *file = p->body->file();
|
||||
|
||||
LLVMMetadataRef llvm_scope = lb_get_current_debug_scope(p);
|
||||
LLVMMetadataRef llvm_file = lb_get_llvm_metadata(m, file);
|
||||
@@ -975,7 +975,7 @@ void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx) {
|
||||
}
|
||||
TokenPos pos = {};
|
||||
|
||||
pos.file_id = p->body->file ? p->body->file->id : 0;
|
||||
pos.file_id = p->body->file_id;
|
||||
pos.line = LLVMDILocationGetLine(loc);
|
||||
pos.column = LLVMDILocationGetColumn(loc);
|
||||
|
||||
|
||||
@@ -258,8 +258,8 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body)
|
||||
if (entity->file != nullptr) {
|
||||
file = lb_get_llvm_metadata(m, entity->file);
|
||||
scope = file;
|
||||
} else if (ident != nullptr && ident->file != nullptr) {
|
||||
file = lb_get_llvm_metadata(m, ident->file);
|
||||
} else if (ident != nullptr && ident->file_id != 0) {
|
||||
file = lb_get_llvm_metadata(m, ident->file());
|
||||
scope = file;
|
||||
} else if (entity->scope != nullptr) {
|
||||
file = lb_get_llvm_metadata(m, entity->scope->file);
|
||||
|
||||
@@ -212,8 +212,9 @@ void lb_open_scope(lbProcedure *p, Scope *s) {
|
||||
unsigned column = cast(unsigned)token.pos.column;
|
||||
|
||||
LLVMMetadataRef file = nullptr;
|
||||
if (s->node->file != nullptr) {
|
||||
file = lb_get_llvm_metadata(m, s->node->file);
|
||||
AstFile *ast_file = s->node->file();
|
||||
if (ast_file != nullptr) {
|
||||
file = lb_get_llvm_metadata(m, ast_file);
|
||||
}
|
||||
LLVMMetadataRef scope = nullptr;
|
||||
if (p->scope_stack.count > 0) {
|
||||
|
||||
+12
-8
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-10
@@ -255,14 +255,14 @@ ProcCallingConvention default_calling_convention(void) {
|
||||
return ProcCC_Odin;
|
||||
}
|
||||
|
||||
enum StateFlag : u16 {
|
||||
enum StateFlag : u8 {
|
||||
StateFlag_bounds_check = 1<<0,
|
||||
StateFlag_no_bounds_check = 1<<1,
|
||||
|
||||
StateFlag_BeenHandled = 1<<15,
|
||||
StateFlag_BeenHandled = 1<<7,
|
||||
};
|
||||
|
||||
enum ViralStateFlag : u16 {
|
||||
enum ViralStateFlag : u8 {
|
||||
ViralStateFlag_ContainsDeferredProcedure = 1<<0,
|
||||
};
|
||||
|
||||
@@ -666,7 +666,7 @@ AST_KIND(_TypeBegin, "", bool) \
|
||||
}) \
|
||||
AST_KIND(_TypeEnd, "", bool)
|
||||
|
||||
enum AstKind {
|
||||
enum AstKind : u16 {
|
||||
Ast_Invalid,
|
||||
#define AST_KIND(_kind_name_, ...) GB_JOIN2(Ast_, _kind_name_),
|
||||
AST_KINDS
|
||||
@@ -696,18 +696,18 @@ isize const ast_variant_sizes[] = {
|
||||
|
||||
struct AstCommonStuff {
|
||||
AstKind kind;
|
||||
u16 state_flags;
|
||||
u16 viral_state_flags;
|
||||
AstFile * file;
|
||||
u8 state_flags;
|
||||
u8 viral_state_flags;
|
||||
i32 file_id;
|
||||
Scope * scope;
|
||||
TypeAndValue tav; // TODO(bill): Make this a pointer to minimize pointer size
|
||||
};
|
||||
|
||||
struct Ast {
|
||||
AstKind kind;
|
||||
u16 state_flags;
|
||||
u16 viral_state_flags;
|
||||
AstFile * file;
|
||||
u8 state_flags;
|
||||
u8 viral_state_flags;
|
||||
i32 file_id;
|
||||
Scope * scope;
|
||||
TypeAndValue tav; // TODO(bill): Make this a pointer to minimize pointer size
|
||||
|
||||
@@ -717,6 +717,13 @@ struct Ast {
|
||||
AST_KINDS
|
||||
#undef AST_KIND
|
||||
};
|
||||
|
||||
|
||||
// NOTE(bill): I know I dislike methods but this is hopefully a temporary thing
|
||||
// for refactoring purposes
|
||||
AstFile *file() const {
|
||||
return get_ast_file_from_id(this->file_id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user