From c2ca24a486319c0e8b9a5cd0c377a9d66eb036d3 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 17 Jun 2018 10:58:59 +0100 Subject: [PATCH] Big renaming: `AstNode` to `Ast` --- src/check_decl.cpp | 70 +-- src/check_expr.cpp | 308 +++++------ src/check_stmt.cpp | 190 +++---- src/check_type.cpp | 178 +++--- src/checker.cpp | 250 ++++----- src/checker.hpp | 80 +-- src/docs.cpp | 14 +- src/entity.cpp | 12 +- src/exact_value.cpp | 10 +- src/ir.cpp | 266 ++++----- src/ir_print.cpp | 8 +- src/parser.cpp | 1258 +++++++++++++++++++++---------------------- src/parser.hpp | 502 ++++++++--------- src/types.cpp | 10 +- 14 files changed, 1578 insertions(+), 1578 deletions(-) diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 9580af157..37a5c2249 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -1,5 +1,5 @@ -bool check_is_terminating(AstNode *node); -void check_stmt (CheckerContext *ctx, AstNode *node, u32 flags); +bool check_is_terminating(Ast *node); +void check_stmt (CheckerContext *ctx, Ast *node, u32 flags); // NOTE(bill): 'content_name' is for debugging and error messages Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, String context_name) { @@ -89,7 +89,7 @@ Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, Stri return e->type; } -void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array const &inits, String context_name) { +void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array const &inits, String context_name) { if ((lhs == nullptr || lhs_count == 0) && inits.count == 0) { return; } @@ -168,14 +168,14 @@ void check_init_constant(CheckerContext *ctx, Entity *e, Operand *operand) { } -bool is_type_distinct(AstNode *node) { +bool is_type_distinct(Ast *node) { for (;;) { if (node == nullptr) { return false; } - if (node->kind == AstNode_ParenExpr) { + if (node->kind == Ast_ParenExpr) { node = node->ParenExpr.expr; - } else if (node->kind == AstNode_HelperType) { + } else if (node->kind == Ast_HelperType) { node = node->HelperType.type; } else { break; @@ -183,33 +183,33 @@ bool is_type_distinct(AstNode *node) { } switch (node->kind) { - case AstNode_DistinctType: + case Ast_DistinctType: return true; - case AstNode_StructType: - case AstNode_UnionType: - case AstNode_EnumType: - case AstNode_BitFieldType: - case AstNode_ProcType: + case Ast_StructType: + case Ast_UnionType: + case Ast_EnumType: + case Ast_BitFieldType: + case Ast_ProcType: return true; - case AstNode_PointerType: - case AstNode_ArrayType: - case AstNode_DynamicArrayType: - case AstNode_MapType: + case Ast_PointerType: + case Ast_ArrayType: + case Ast_DynamicArrayType: + case Ast_MapType: return false; } return false; } -AstNode *remove_type_alias_clutter(AstNode *node) { +Ast *remove_type_alias_clutter(Ast *node) { for (;;) { if (node == nullptr) { return nullptr; } - if (node->kind == AstNode_ParenExpr) { + if (node->kind == Ast_ParenExpr) { node = node->ParenExpr.expr; - } else if (node->kind == AstNode_DistinctType) { + } else if (node->kind == Ast_DistinctType) { node = node->DistinctType.type; } else { return node; @@ -217,7 +217,7 @@ AstNode *remove_type_alias_clutter(AstNode *node) { } } -void check_type_decl(CheckerContext *ctx, Entity *e, AstNode *type_expr, Type *def) { +void check_type_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Type *def) { GB_ASSERT(e->type == nullptr); DeclInfo *decl = decl_info_of_entity(e); @@ -228,7 +228,7 @@ void check_type_decl(CheckerContext *ctx, Entity *e, AstNode *type_expr, Type *d bool is_distinct = is_type_distinct(type_expr); - AstNode *te = remove_type_alias_clutter(type_expr); + Ast *te = remove_type_alias_clutter(type_expr); e->type = t_invalid; String name = e->token.string; Type *named = alloc_type_named(name, nullptr, e); @@ -263,7 +263,7 @@ void override_entity_in_scope(Entity *original_entity, Entity *new_entity) { map_set(&found_scope->elements, hash_string(original_name), new_entity); } -void check_const_decl(CheckerContext *ctx, Entity *e, AstNode *type_expr, AstNode *init, Type *named_type) { +void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init, Type *named_type) { GB_ASSERT(e->type == nullptr); GB_ASSERT(e->kind == Entity_Constant); @@ -289,9 +289,9 @@ void check_const_decl(CheckerContext *ctx, Entity *e, AstNode *type_expr, AstNod if (init != nullptr) { Entity *entity = nullptr; - if (init->kind == AstNode_Ident) { + if (init->kind == Ast_Ident) { entity = check_ident(ctx, &operand, init, nullptr, e->type, true); - } else if (init->kind == AstNode_SelectorExpr) { + } else if (init->kind == Ast_SelectorExpr) { entity = check_selector(ctx, &operand, init, e->type); } else { check_expr_or_type(ctx, &operand, init, e->type); @@ -413,7 +413,7 @@ bool are_signatures_similar_enough(Type *a_, Type *b_) { } void init_entity_foreign_library(CheckerContext *ctx, Entity *e) { - AstNode *ident = nullptr; + Ast *ident = nullptr; Entity **foreign_library = nullptr; switch (e->kind) { @@ -431,7 +431,7 @@ void init_entity_foreign_library(CheckerContext *ctx, Entity *e) { if (ident == nullptr) { error(e->token, "foreign entiies must declare which library they are from"); - } else if (ident->kind != AstNode_Ident) { + } else if (ident->kind != Ast_Ident) { error(ident, "foreign library names must be an identifier"); } else { String name = ident->Ident.token.string; @@ -472,7 +472,7 @@ String handle_link_name(CheckerContext *ctx, Token token, String link_name, Stri void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) { GB_ASSERT(e->type == nullptr); - if (d->proc_lit->kind != AstNode_ProcLit) { + if (d->proc_lit->kind != Ast_ProcLit) { // TOOD(bill): Better error message error(d->proc_lit, "Expected a procedure to check"); return; @@ -556,7 +556,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) { d->scope = ctx->scope; - GB_ASSERT(pl->body->kind == AstNode_BlockStmt); + GB_ASSERT(pl->body->kind == Ast_BlockStmt); if (!pt->is_polymorphic) { check_procedure_later(ctx->checker, ctx->file, e->token, d, proc_type, pl->body, pl->tags); } @@ -640,7 +640,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) { } } -void check_var_decl(CheckerContext *ctx, Entity *e, Entity **entities, isize entity_count, AstNode *type_expr, Array const &init_expr_list) { +void check_var_decl(CheckerContext *ctx, Entity *e, Entity **entities, isize entity_count, Ast *type_expr, Array const &init_expr_list) { GB_ASSERT(e->type == nullptr); GB_ASSERT(e->kind == Entity_Variable); @@ -749,16 +749,16 @@ void check_proc_group_decl(CheckerContext *ctx, Entity *pg_entity, DeclInfo *d) ptr_set_init(&entity_set, heap_allocator(), 2*pg->args.count); for_array(i, pg->args) { - AstNode *arg = pg->args[i]; + Ast *arg = pg->args[i]; Entity *e = nullptr; Operand o = {}; - if (arg->kind == AstNode_Ident) { + if (arg->kind == Ast_Ident) { e = check_ident(ctx, &o, arg, nullptr, nullptr, true); - } else if (arg->kind == AstNode_SelectorExpr) { + } else if (arg->kind == Ast_SelectorExpr) { e = check_selector(ctx, &o, arg, nullptr); } if (e == nullptr) { - error(arg, "Expected a valid entity name in procedure group, got %.*s", LIT(ast_node_strings[arg->kind])); + error(arg, "Expected a valid entity name in procedure group, got %.*s", LIT(ast_strings[arg->kind])); continue; } if (e->kind == Entity_Variable) { @@ -919,11 +919,11 @@ void check_entity_decl(CheckerContext *ctx, Entity *e, DeclInfo *d, Type *named_ -void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *type, AstNode *body) { +void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *type, Ast *body) { if (body == nullptr) { return; } - GB_ASSERT(body->kind == AstNode_BlockStmt); + GB_ASSERT(body->kind == Ast_BlockStmt); String proc_name = {}; if (token.kind == Token_Ident) { diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 6d00087e2..c171446c9 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -45,40 +45,40 @@ int valid_index_and_score_cmp(void const *a, void const *b) { -#define CALL_ARGUMENT_CHECKER(name) CallArgumentError name(CheckerContext *c, AstNode *call, Type *proc_type, Entity *entity, Array operands, CallArgumentErrorMode show_error_mode, CallArgumentData *data) +#define CALL_ARGUMENT_CHECKER(name) CallArgumentError name(CheckerContext *c, Ast *call, Type *proc_type, Entity *entity, Array operands, CallArgumentErrorMode show_error_mode, CallArgumentData *data) typedef CALL_ARGUMENT_CHECKER(CallArgumentCheckerType); -void check_expr (CheckerContext *c, Operand *operand, AstNode *expression); -void check_multi_expr (CheckerContext *c, Operand *operand, AstNode *expression); -void check_expr_or_type (CheckerContext *c, Operand *operand, AstNode *expression, Type *type_hint = nullptr); -ExprKind check_expr_base (CheckerContext *c, Operand *operand, AstNode *expression, Type *type_hint); -void check_expr_with_type_hint (CheckerContext *c, Operand *o, AstNode *e, Type *t); -Type * check_type (CheckerContext *c, AstNode *expression); -Type * check_type_expr (CheckerContext *c, AstNode *expression, Type *named_type); +void check_expr (CheckerContext *c, Operand *operand, Ast *expression); +void check_multi_expr (CheckerContext *c, Operand *operand, Ast *expression); +void check_expr_or_type (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint = nullptr); +ExprKind check_expr_base (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint); +void check_expr_with_type_hint (CheckerContext *c, Operand *o, Ast *e, Type *t); +Type * check_type (CheckerContext *c, Ast *expression); +Type * check_type_expr (CheckerContext *c, Ast *expression, Type *named_type); Type * make_optional_ok_type (Type *value); -void check_type_decl (CheckerContext *c, Entity *e, AstNode *type_expr, Type *def); -Entity * check_selector (CheckerContext *c, Operand *operand, AstNode *node, Type *type_hint); -Entity * check_ident (CheckerContext *c, Operand *o, AstNode *n, Type *named_type, Type *type_hint, bool allow_import_name); +void check_type_decl (CheckerContext *c, Entity *e, Ast *type_expr, Type *def); +Entity * check_selector (CheckerContext *c, Operand *operand, Ast *node, Type *type_hint); +Entity * check_ident (CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name); Entity * find_polymorphic_struct_entity (CheckerContext *c, Type *original_type, isize param_count, Array ordered_operands); void check_not_tuple (CheckerContext *c, Operand *operand); void convert_to_typed (CheckerContext *c, Operand *operand, Type *target_type); -gbString expr_to_string (AstNode *expression); +gbString expr_to_string (Ast *expression); void check_entity_decl (CheckerContext *c, Entity *e, DeclInfo *decl, Type *named_type); -void check_const_decl (CheckerContext *c, Entity *e, AstNode *type_expr, AstNode *init_expr, Type *named_type); -void check_proc_body (CheckerContext *c, Token token, DeclInfo *decl, Type *type, AstNode *body); -void update_expr_type (CheckerContext *c, AstNode *e, Type *type, bool final); -bool check_is_terminating (AstNode *node); -bool check_has_break (AstNode *stmt, bool implicit); -void check_stmt (CheckerContext *c, AstNode *node, u32 flags); -void check_stmt_list (CheckerContext *c, Array const &stmts, u32 flags); +void check_const_decl (CheckerContext *c, Entity *e, Ast *type_expr, Ast *init_expr, Type *named_type); +void check_proc_body (CheckerContext *c, Token token, DeclInfo *decl, Type *type, Ast *body); +void update_expr_type (CheckerContext *c, Ast *e, Type *type, bool final); +bool check_is_terminating (Ast *node); +bool check_has_break (Ast *stmt, bool implicit); +void check_stmt (CheckerContext *c, Ast *node, u32 flags); +void check_stmt_list (CheckerContext *c, Array const &stmts, u32 flags); void check_init_constant (CheckerContext *c, Entity *e, Operand *operand); bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value); -bool check_procedure_type (CheckerContext *c, Type *type, AstNode *proc_type_node, Array *operands = nullptr); -void check_struct_type (CheckerContext *c, Type *struct_type, AstNode *node, Array *poly_operands, +bool check_procedure_type (CheckerContext *c, Type *type, Ast *proc_type_node, Array *operands = nullptr); +void check_struct_type (CheckerContext *c, Type *struct_type, Ast *node, Array *poly_operands, Type *named_type = nullptr, Type *original_type_for_poly = nullptr); -CallArgumentData check_call_arguments (CheckerContext *c, Operand *operand, Type *proc_type, AstNode *call); +CallArgumentData check_call_arguments (CheckerContext *c, Operand *operand, Type *proc_type, Ast *call); Type * check_init_variable (CheckerContext *c, Entity *e, Operand *operand, String context_name); @@ -95,8 +95,8 @@ void error_operand_not_expression(Operand *o) { void error_operand_no_value(Operand *o) { if (o->mode == Addressing_NoValue) { gbString err = expr_to_string(o->expr); - AstNode *x = unparen_expr(o->expr); - if (x->kind == AstNode_CallExpr) { + Ast *x = unparen_expr(o->expr); + if (x->kind == Ast_CallExpr) { error(o->expr, "'%s' call does not return a value and cannot be used as a value", err); } else { error(o->expr, "'%s' used as a value", err); @@ -107,7 +107,7 @@ void error_operand_no_value(Operand *o) { } -void check_scope_decls(CheckerContext *c, Array const &nodes, isize reserve_size) { +void check_scope_decls(CheckerContext *c, Array const &nodes, isize reserve_size) { Scope *s = c->scope; GB_ASSERT(s->package == nullptr); @@ -166,7 +166,7 @@ bool check_is_assignable_to_using_subtype(Type *src, Type *dst) { } bool find_or_generate_polymorphic_procedure(CheckerContext *c, Entity *base_entity, Type *type, - Array *param_operands, AstNode *poly_def_node, PolyProcData *poly_proc_data) { + Array *param_operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { /////////////////////////////////////////////////////////////////////////////// // // // TODO CLEANUP(bill): This procedure is very messy and hacky. Clean this!!! // @@ -316,7 +316,7 @@ bool find_or_generate_polymorphic_procedure(CheckerContext *c, Entity *base_enti - AstNode *proc_lit = clone_ast_node(a, old_decl->proc_lit); + Ast *proc_lit = clone_ast_node(a, old_decl->proc_lit); ast_node(pl, ProcLit, proc_lit); // NOTE(bill): Associate the scope declared above withinth this procedure declaration's type add_scope(&nctx, pl->type, final_proc_type->Proc.scope); @@ -335,7 +335,7 @@ bool find_or_generate_polymorphic_procedure(CheckerContext *c, Entity *base_enti } u64 tags = base_entity->Procedure.tags; - AstNode *ident = clone_ast_node(a, base_entity->identifier); + Ast *ident = clone_ast_node(a, base_entity->identifier); Token token = ident->Ident.token; DeclInfo *d = make_decl_info(nctx.allocator, scope, old_decl->parent); d->gen_proc_type = final_proc_type; @@ -390,14 +390,14 @@ bool find_or_generate_polymorphic_procedure(CheckerContext *c, Entity *base_enti return true; } -bool check_polymorphic_procedure_assignment(CheckerContext *c, Operand *operand, Type *type, AstNode *poly_def_node, PolyProcData *poly_proc_data) { +bool check_polymorphic_procedure_assignment(CheckerContext *c, Operand *operand, Type *type, Ast *poly_def_node, PolyProcData *poly_proc_data) { if (operand->expr == nullptr) return false; Entity *base_entity = entity_of_ident(operand->expr); if (base_entity == nullptr) return false; return find_or_generate_polymorphic_procedure(c, base_entity, type, nullptr, poly_def_node, poly_proc_data); } -bool find_or_generate_polymorphic_procedure_from_parameters(CheckerContext *c, Entity *base_entity, Array *operands, AstNode *poly_def_node, PolyProcData *poly_proc_data) { +bool find_or_generate_polymorphic_procedure_from_parameters(CheckerContext *c, Entity *base_entity, Array *operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { return find_or_generate_polymorphic_procedure(c, base_entity, nullptr, operands, poly_def_node, poly_proc_data); } @@ -590,8 +590,8 @@ i64 check_distance_between_types(CheckerContext *c, Operand *operand, Type *type } } - AstNode *expr = unparen_expr(operand->expr); - if (expr != nullptr && expr->kind == AstNode_AutoCast) { + Ast *expr = unparen_expr(operand->expr); + if (expr != nullptr && expr->kind == Ast_AutoCast) { Operand x = *operand; x.expr = expr->AutoCast.expr; bool ok = check_cast_internal(c, &x, type); @@ -940,8 +940,8 @@ bool check_cycle(CheckerContext *c, Entity *curr, bool report) { } -Entity *check_ident(CheckerContext *c, Operand *o, AstNode *n, Type *named_type, Type *type_hint, bool allow_import_name) { - GB_ASSERT(n->kind == AstNode_Ident); +Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name) { + GB_ASSERT(n->kind == Ast_Ident); o->mode = Addressing_Invalid; o->expr = n; String name = n->Ident.token.string; @@ -1381,8 +1381,8 @@ void check_is_expressible(CheckerContext *c, Operand *o, Type *type) { bool check_is_not_addressable(CheckerContext *c, Operand *o) { if (o->mode == Addressing_OptionalOk) { - AstNode *expr = unselector_expr(o->expr); - if (expr->kind != AstNode_TypeAssertion) { + Ast *expr = unselector_expr(o->expr); + if (expr->kind != Ast_TypeAssertion) { return true; } ast_node(ta, TypeAssertion, expr); @@ -1409,11 +1409,11 @@ bool check_is_not_addressable(CheckerContext *c, Operand *o) { return false; } -void check_unary_expr(CheckerContext *c, Operand *o, Token op, AstNode *node) { +void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *node) { switch (op.kind) { case Token_And: { // Pointer address if (check_is_not_addressable(c, o)) { - if (ast_node_expect(node, AstNode_UnaryExpr)) { + if (ast_node_expect(node, Ast_UnaryExpr)) { ast_node(ue, UnaryExpr, node); gbString str = expr_to_string(ue->expr); error(op, "Cannot take the pointer address of '%s'", str); @@ -1594,8 +1594,8 @@ void check_comparison(CheckerContext *c, Operand *x, Operand *y, TokenKind op) { } -void check_shift(CheckerContext *c, Operand *x, Operand *y, AstNode *node) { - GB_ASSERT(node->kind == AstNode_BinaryExpr); +void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *node) { + GB_ASSERT(node->kind == Ast_BinaryExpr); ast_node(be, BinaryExpr, node); ExactValue x_val = {}; @@ -1663,7 +1663,7 @@ void check_shift(CheckerContext *c, Operand *x, Operand *y, AstNode *node) { return; } - TokenPos pos = ast_node_token(x->expr).pos; + TokenPos pos = ast_token(x->expr).pos; if (x_is_untyped) { ExprInfo *info = check_get_expr_info(&c->checker->info, x->expr); if (info != nullptr) { @@ -1693,8 +1693,8 @@ void check_shift(CheckerContext *c, Operand *x, Operand *y, AstNode *node) { } -Operand check_ptr_addition(CheckerContext *c, TokenKind op, Operand *ptr, Operand *offset, AstNode *node) { - GB_ASSERT(node->kind == AstNode_BinaryExpr); +Operand check_ptr_addition(CheckerContext *c, TokenKind op, Operand *ptr, Operand *offset, Ast *node) { + GB_ASSERT(node->kind == Ast_BinaryExpr); ast_node(be, BinaryExpr, node); GB_ASSERT(is_type_pointer(ptr->type)); GB_ASSERT(is_type_integer(offset->type)); @@ -1933,7 +1933,7 @@ void check_cast(CheckerContext *c, Operand *x, Type *type) { x->type = type; } -bool check_transmute(CheckerContext *c, AstNode *node, Operand *o, Type *t) { +bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type *t) { if (!is_operand_value(*o)) { error(o->expr, "'transmute' can only be applied to values"); o->mode = Addressing_Invalid; @@ -1988,8 +1988,8 @@ bool check_binary_array_expr(CheckerContext *c, Token op, Operand *x, Operand *y } -void check_binary_expr(CheckerContext *c, Operand *x, AstNode *node) { - GB_ASSERT(node->kind == AstNode_BinaryExpr); +void check_binary_expr(CheckerContext *c, Operand *x, Ast *node) { + GB_ASSERT(node->kind == Ast_BinaryExpr); Operand y_ = {}, *y = &y_; ast_node(be, BinaryExpr, node); @@ -2176,7 +2176,7 @@ void check_binary_expr(CheckerContext *c, Operand *x, AstNode *node) { } -void update_expr_type(CheckerContext *c, AstNode *e, Type *type, bool final) { +void update_expr_type(CheckerContext *c, Ast *e, Type *type, bool final) { ExprInfo *found = check_get_expr_info(&c->checker->info, e); if (found == nullptr) { return; @@ -2235,7 +2235,7 @@ void update_expr_type(CheckerContext *c, AstNode *e, Type *type, bool final) { add_type_and_value(&c->checker->info, e, old.mode, type, old.value); } -void update_expr_value(CheckerContext *c, AstNode *e, ExactValue value) { +void update_expr_value(CheckerContext *c, Ast *e, ExactValue value) { ExprInfo *found = check_get_expr_info(&c->checker->info, e); if (found) { found->value = value; @@ -2473,7 +2473,7 @@ void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) { update_expr_type(c, operand->expr, target_type, true); } -bool check_index_value(CheckerContext *c, bool open_range, AstNode *index_value, i64 max_count, i64 *value) { +bool check_index_value(CheckerContext *c, bool open_range, Ast *index_value, i64 max_count, i64 *value) { Operand operand = {Addressing_Invalid}; check_expr(c, &operand, index_value); if (operand.mode == Addressing_Invalid) { @@ -2531,7 +2531,7 @@ bool check_index_value(CheckerContext *c, bool open_range, AstNode *index_value, return true; } -Entity *check_selector(CheckerContext *c, Operand *operand, AstNode *node, Type *type_hint) { +Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *type_hint) { ast_node(se, SelectorExpr, node); bool check_op_expr = true; @@ -2541,30 +2541,30 @@ Entity *check_selector(CheckerContext *c, Operand *operand, AstNode *node, Type operand->expr = node; - AstNode *op_expr = se->expr; - AstNode *selector = unparen_expr(se->selector); + Ast *op_expr = se->expr; + Ast *selector = unparen_expr(se->selector); if (selector == nullptr) { operand->mode = Addressing_Invalid; operand->expr = node; return nullptr; } - if (selector->kind != AstNode_Ident) { - // if (selector->kind != AstNode_Ident) { - error(selector, "Illegal selector kind: '%.*s'", LIT(ast_node_strings[selector->kind])); + if (selector->kind != Ast_Ident) { + // if (selector->kind != Ast_Ident) { + error(selector, "Illegal selector kind: '%.*s'", LIT(ast_strings[selector->kind])); operand->mode = Addressing_Invalid; operand->expr = node; return nullptr; } - if (op_expr->kind == AstNode_Ident) { + if (op_expr->kind == Ast_Ident) { String op_name = op_expr->Ident.token.string; Entity *e = scope_lookup(c->scope, op_name); add_entity_use(c, op_expr, e); expr_entity = e; Entity *original_e = e; - if (e != nullptr && e->kind == Entity_ImportName && selector->kind == AstNode_Ident) { + if (e != nullptr && e->kind == Entity_ImportName && selector->kind == Ast_Ident) { // IMPORTANT NOTE(bill): This is very sloppy code but it's also very fragile // It pretty much needs to be in this order and this way // If you can clean this up, please do but be really careful @@ -2659,7 +2659,7 @@ Entity *check_selector(CheckerContext *c, Operand *operand, AstNode *node, Type } - if (entity == nullptr && selector->kind == AstNode_Ident) { + if (entity == nullptr && selector->kind == Ast_Ident) { String field_name = selector->Ident.token.string; if (is_type_dynamic_array(type_deref(operand->type))) { init_mem_allocator(c->checker); @@ -2749,8 +2749,8 @@ Entity *check_selector(CheckerContext *c, Operand *operand, AstNode *node, Type return entity; } -bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, i32 id) { - GB_ASSERT(call->kind == AstNode_CallExpr); +bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 id) { + GB_ASSERT(call->kind == Ast_CallExpr); ast_node(ce, CallExpr, call); BuiltinProc *bp = &builtin_procs[id]; { @@ -2772,7 +2772,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, } if (ce->args.count > 0) { - if (ce->args[0]->kind == AstNode_FieldValue) { + if (ce->args[0]->kind == Ast_FieldValue) { error(call, "'field = value' calling is not allowed on built-in procedures"); return false; } @@ -2816,12 +2816,12 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, error(ce->args[0], "'#location' expects either 0 or 1 arguments, got %td", ce->args.count); } if (ce->args.count > 0) { - AstNode *arg = ce->args[0]; + Ast *arg = ce->args[0]; Entity *e = nullptr; Operand o = {}; - if (arg->kind == AstNode_Ident) { + if (arg->kind == Ast_Ident) { e = check_ident(c, &o, arg, nullptr, nullptr, true); - } else if (arg->kind == AstNode_SelectorExpr) { + } else if (arg->kind == Ast_SelectorExpr) { e = check_selector(c, &o, arg, nullptr); } if (e == nullptr) { @@ -3069,7 +3069,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, return false; } - AstNode *capacity = ce->args[1]; + Ast *capacity = ce->args[1]; Operand op = {}; check_expr(c, &op, capacity); if (op.mode == Addressing_Invalid) { @@ -3169,7 +3169,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, Type *key = base_type(type)->Map.key; Operand x = {Addressing_Invalid}; - AstNode *key_node = ce->args[1]; + Ast *key_node = ce->args[1]; Operand op = {}; check_expr(c, &op, key_node); if (op.mode == Addressing_Invalid) { @@ -3245,9 +3245,9 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, return false; } - AstNode *field_arg = unparen_expr(ce->args[1]); + Ast *field_arg = unparen_expr(ce->args[1]); if (field_arg == nullptr || - field_arg->kind != AstNode_Ident) { + field_arg->kind != Ast_Ident) { error(field_arg, "Expected an identifier for field argument"); return false; } @@ -3284,7 +3284,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, case BuiltinProc_type_of: { // proc type_of(val: Type) -> type(Type) - AstNode *expr = ce->args[0]; + Ast *expr = ce->args[0]; Operand o = {}; check_expr_or_type(c, &o, expr); @@ -3325,7 +3325,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, // NOTE(bill): The type information may not be setup yet init_core_type_info(c->checker); - AstNode *expr = ce->args[0]; + Ast *expr = ce->args[0]; Operand o = {}; check_expr_or_type(c, &o, expr); if (o.mode == Addressing_Invalid) { @@ -3360,7 +3360,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, // NOTE(bill): The type information may not be setup yet init_core_type_info(c->checker); - AstNode *expr = ce->args[0]; + Ast *expr = ce->args[0]; Operand o = {}; check_expr_or_type(c, &o, expr); if (o.mode == Addressing_Invalid) { @@ -3408,7 +3408,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call, if (i == 0) { continue; } - AstNode *arg = ce->args[i]; + Ast *arg = ce->args[i]; Operand op = {}; check_expr(c, &op, arg); if (op.mode == Addressing_Invalid) { @@ -3672,7 +3672,7 @@ break; return false; } - AstNode *other_arg = ce->args[1]; + Ast *other_arg = ce->args[1]; Operand a = *operand; Operand b = {}; check_expr(c, &b, other_arg); @@ -3749,7 +3749,7 @@ break; return false; } - AstNode *other_arg = ce->args[1]; + Ast *other_arg = ce->args[1]; Operand a = *operand; Operand b = {}; check_expr(c, &b, other_arg); @@ -3871,8 +3871,8 @@ break; return false; } - AstNode *min_arg = ce->args[1]; - AstNode *max_arg = ce->args[2]; + Ast *min_arg = ce->args[1]; + Ast *max_arg = ce->args[2]; Operand x = *operand; Operand y = {}; Operand z = {}; @@ -3972,7 +3972,7 @@ break; error(ce->args[0], "Expected a type for 'transmute'"); return false; } - AstNode *expr = ce->args[1]; + Ast *expr = ce->args[1]; Operand *o = operand; check_expr(c, o, expr); if (o->mode == Addressing_Invalid) { @@ -4040,7 +4040,7 @@ isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs } -void check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array *operands, Array const &rhs, bool allow_ok, bool *optional_ok_ = nullptr) { +void check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array *operands, Array const &rhs, bool allow_ok, bool *optional_ok_ = nullptr) { bool optional_ok = false; isize tuple_index = 0; for_array(i, rhs) { @@ -4304,13 +4304,13 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { return err; } -bool is_call_expr_field_value(AstNodeCallExpr *ce) { +bool is_call_expr_field_value(AstCallExpr *ce) { GB_ASSERT(ce != nullptr); if (ce->args.count == 0) { return false; } - return ce->args[0]->kind == AstNode_FieldValue; + return ce->args[0]->kind == Ast_FieldValue; } isize lookup_procedure_parameter(TypeProc *pt, String parameter_name) { @@ -4359,9 +4359,9 @@ CALL_ARGUMENT_CHECKER(check_named_call_arguments) { defer (array_free(&ordered_operands)); for_array(i, ce->args) { - AstNode *arg = ce->args[i]; + Ast *arg = ce->args[i]; ast_node(fv, FieldValue, arg); - if (fv->field->kind != AstNode_Ident) { + if (fv->field->kind != Ast_Ident) { if (show_error) { gbString expr_str = expr_to_string(fv->field); error(arg, "Invalid parameter name '%s' in procedure call", expr_str); @@ -4483,7 +4483,7 @@ CALL_ARGUMENT_CHECKER(check_named_call_arguments) { return err; } -CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type *proc_type, AstNode *call) { +CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type *proc_type, Ast *call) { ast_node(ce, CallExpr, call); CallArgumentCheckerType *call_checker = check_call_arguments_internal; @@ -4497,7 +4497,7 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type operands = array_make(heap_allocator(), ce->args.count); for_array(i, ce->args) { - AstNode *arg = ce->args[i]; + Ast *arg = ce->args[i]; ast_node(fv, FieldValue, arg); check_expr_or_type(c, &operands[i], fv->value); } @@ -4637,9 +4637,9 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type } result_type = t_invalid; } else { - AstNode *ident = operand->expr; - while (ident->kind == AstNode_SelectorExpr) { - AstNode *s = ident->SelectorExpr.selector; + Ast *ident = operand->expr; + while (ident->kind == Ast_SelectorExpr) { + Ast *s = ident->SelectorExpr.selector; ident = s; } @@ -4654,9 +4654,9 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type return data; } } else { - AstNode *ident = operand->expr; - while (ident->kind == AstNode_SelectorExpr) { - AstNode *s = ident->SelectorExpr.selector; + Ast *ident = operand->expr; + while (ident->kind == Ast_SelectorExpr) { + Ast *s = ident->SelectorExpr.selector; ident = s; } @@ -4694,7 +4694,7 @@ isize lookup_polymorphic_struct_parameter(TypeStruct *st, String parameter_name) } -CallArgumentError check_polymorphic_struct_type(CheckerContext *c, Operand *operand, AstNode *call) { +CallArgumentError check_polymorphic_struct_type(CheckerContext *c, Operand *operand, Ast *call) { ast_node(ce, CallExpr, call); Type *original_type = operand->type; @@ -4714,7 +4714,7 @@ CallArgumentError check_polymorphic_struct_type(CheckerContext *c, Operand *oper named_fields = true; operands = array_make(heap_allocator(), ce->args.count); for_array(i, ce->args) { - AstNode *arg = ce->args[i]; + Ast *arg = ce->args[i]; ast_node(fv, FieldValue, arg); check_expr_or_type(c, &operands[i], fv->value); } @@ -4742,9 +4742,9 @@ CallArgumentError check_polymorphic_struct_type(CheckerContext *c, Operand *oper ordered_operands = array_make(c->allocator, param_count); for_array(i, ce->args) { - AstNode *arg = ce->args[i]; + Ast *arg = ce->args[i]; ast_node(fv, FieldValue, arg); - if (fv->field->kind != AstNode_Ident) { + if (fv->field->kind != Ast_Ident) { if (show_error) { gbString expr_str = expr_to_string(fv->field); error(arg, "Invalid parameter name '%s' in polymorphic type call", expr_str); @@ -4867,7 +4867,7 @@ CallArgumentError check_polymorphic_struct_type(CheckerContext *c, Operand *oper String generated_name = make_string_c(expr_to_string(call)); Type *named_type = alloc_type_named(generated_name, nullptr, nullptr); - AstNode *node = clone_ast_node(a, st->node); + Ast *node = clone_ast_node(a, st->node); Type *struct_type = alloc_type_struct(); struct_type->Struct.node = node; struct_type->Struct.polymorphic_parent = original_type; @@ -4884,10 +4884,10 @@ CallArgumentError check_polymorphic_struct_type(CheckerContext *c, Operand *oper } -ExprKind check_call_expr(CheckerContext *c, Operand *operand, AstNode *call) { +ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call) { ast_node(ce, CallExpr, call); if (ce->proc != nullptr && - ce->proc->kind == AstNode_BasicDirective) { + ce->proc->kind == Ast_BasicDirective) { ast_node(bd, BasicDirective, ce->proc); String name = bd->name; if (name == "location" || name == "assert") { @@ -4905,14 +4905,14 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, AstNode *call) { if (ce->args.count > 0) { bool fail = false; - bool first_is_field_value = (ce->args[0]->kind == AstNode_FieldValue); + bool first_is_field_value = (ce->args[0]->kind == Ast_FieldValue); for_array(i, ce->args) { - AstNode *arg = ce->args[i]; + Ast *arg = ce->args[i]; bool mix = false; if (first_is_field_value) { - mix = arg->kind != AstNode_FieldValue; + mix = arg->kind != Ast_FieldValue; } else { - mix = arg->kind == AstNode_FieldValue; + mix = arg->kind == Ast_FieldValue; } if (mix) { error(arg, "Mixture of 'field = value' and value elements in a procedure all is not allowed"); @@ -4929,8 +4929,8 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, AstNode *call) { if (operand->mode == Addressing_Invalid) { for_array(i, ce->args) { - AstNode *arg = ce->args[i]; - if (arg->kind == AstNode_FieldValue) { + Ast *arg = ce->args[i]; + if (arg->kind == Ast_FieldValue) { arg = arg->FieldValue.value; } check_expr_base(c, operand, arg, nullptr); @@ -4945,9 +4945,9 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, AstNode *call) { if (is_type_polymorphic_struct(t)) { auto err = check_polymorphic_struct_type(c, operand, call); if (err == 0) { - AstNode *ident = operand->expr; - while (ident->kind == AstNode_SelectorExpr) { - AstNode *s = ident->SelectorExpr.selector; + Ast *ident = operand->expr; + while (ident->kind == Ast_SelectorExpr) { + Ast *s = ident->SelectorExpr.selector; ident = s; } Type *ot = operand->type; GB_ASSERT(ot->kind == Type_Named); @@ -4968,8 +4968,8 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, AstNode *call) { case 0: error(call, "Missing argument in conversion to '%s'", str); break; default: error(call, "Too many arguments in conversion to '%s'", str); break; case 1: { - AstNode *arg = ce->args[0]; - if (arg->kind == AstNode_FieldValue) { + Ast *arg = ce->args[0]; + if (arg->kind == Ast_FieldValue) { error(call, "'field = value' cannot be used in a type conversion"); arg = arg->FieldValue.value; // NOTE(bill): Carry on the cast regardless @@ -5000,7 +5000,7 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, AstNode *call) { bool valid_type = (proc_type != nullptr) && is_type_proc(proc_type); bool valid_mode = is_operand_value(*operand); if (!valid_type || !valid_mode) { - AstNode *e = operand->expr; + Ast *e = operand->expr; gbString str = expr_to_string(e); gbString type_str = type_to_string(operand->type); error(e, "Cannot call a non-procedure: '%s' of type '%s'", str, type_str); @@ -5061,7 +5061,7 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, AstNode *call) { } -void check_expr_with_type_hint(CheckerContext *c, Operand *o, AstNode *e, Type *t) { +void check_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *t) { check_expr_base(c, o, e, t); check_not_tuple(c, o); char *err_str = nullptr; @@ -5145,7 +5145,7 @@ bool ternary_compare_types(Type *x, Type *y) { return are_types_identical(x, y); } -ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, Type *type_hint) { +ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Stmt; o->mode = Addressing_Invalid; @@ -5387,9 +5387,9 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, type = nullptr; // [?]Type - if (cl->type->kind == AstNode_ArrayType && cl->type->ArrayType.count != nullptr) { - AstNode *count = cl->type->ArrayType.count; - if (count->kind == AstNode_UnaryExpr && + if (cl->type->kind == Ast_ArrayType && cl->type->ArrayType.count != nullptr) { + Ast *count = cl->type->ArrayType.count; + if (count->kind == Ast_UnaryExpr && count->UnaryExpr.op.kind == Token_Question) { type = alloc_type_array(check_type(c, cl->type->ArrayType.elem), -1); is_to_be_determined_array_count = true; @@ -5452,17 +5452,17 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, } } - if (cl->elems[0]->kind == AstNode_FieldValue) { + if (cl->elems[0]->kind == Ast_FieldValue) { bool *fields_visited = gb_alloc_array(c->allocator, bool, field_count); for_array(i, cl->elems) { - AstNode *elem = cl->elems[i]; - if (elem->kind != AstNode_FieldValue) { + Ast *elem = cl->elems[i]; + if (elem->kind != Ast_FieldValue) { error(elem, "Mixture of 'field = value' and value elements in a literal is not allowed"); continue; } ast_node(fv, FieldValue, elem); - if (fv->field->kind != AstNode_Ident) { + if (fv->field->kind != Ast_Ident) { gbString expr_str = expr_to_string(fv->field); error(elem, "Invalid field name '%s' in structure literal", expr_str); gb_string_free(expr_str); @@ -5508,8 +5508,8 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, for_array(index, cl->elems) { Entity *field = nullptr; - AstNode *elem = cl->elems[index]; - if (elem->kind == AstNode_FieldValue) { + Ast *elem = cl->elems[index]; + if (elem->kind == Ast_FieldValue) { seen_field_value = true; // error(elem, "Mixture of 'field = value' and value elements in a literal is not allowed"); // continue; @@ -5592,13 +5592,13 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, } for (; index < cl->elems.count; index++) { - AstNode *e = cl->elems[index]; + Ast *e = cl->elems[index]; if (e == nullptr) { error(node, "Invalid literal element"); continue; } - if (e->kind == AstNode_FieldValue) { + if (e->kind == Ast_FieldValue) { error(e, "'field = value' is only allowed in struct literals"); continue; } @@ -5640,17 +5640,17 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, { // Checker values Type *field_types[2] = {t_rawptr, t_typeid}; isize field_count = 2; - if (cl->elems[0]->kind == AstNode_FieldValue) { + if (cl->elems[0]->kind == Ast_FieldValue) { bool fields_visited[2] = {}; for_array(i, cl->elems) { - AstNode *elem = cl->elems[i]; - if (elem->kind != AstNode_FieldValue) { + Ast *elem = cl->elems[i]; + if (elem->kind != Ast_FieldValue) { error(elem, "Mixture of 'field = value' and value elements in a 'any' literal is not allowed"); continue; } ast_node(fv, FieldValue, elem); - if (fv->field->kind != AstNode_Ident) { + if (fv->field->kind != Ast_Ident) { gbString expr_str = expr_to_string(fv->field); error(elem, "Invalid field name '%s' in 'any' literal", expr_str); gb_string_free(expr_str); @@ -5681,8 +5681,8 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, } } else { for_array(index, cl->elems) { - AstNode *elem = cl->elems[index]; - if (elem->kind == AstNode_FieldValue) { + Ast *elem = cl->elems[index]; + if (elem->kind == Ast_FieldValue) { error(elem, "Mixture of 'field = value' and value elements in a 'any' literal is not allowed"); continue; } @@ -5715,8 +5715,8 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, is_constant = false; { // Checker values for_array(i, cl->elems) { - AstNode *elem = cl->elems[i]; - if (elem->kind != AstNode_FieldValue) { + Ast *elem = cl->elems[i]; + if (elem->kind != Ast_FieldValue) { error(elem, "Only 'field = value' elements are allowed in a map literal"); continue; } @@ -6067,7 +6067,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, TokenKind interval_kind = se->interval.kind; i64 indices[2] = {}; - AstNode *nodes[2] = {se->low, se->high}; + Ast *nodes[2] = {se->low, se->high}; for (isize i = 0; i < gb_count_of(nodes); i++) { i64 index = max_count; if (nodes[i] != nullptr) { @@ -6128,17 +6128,17 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, } case_end; - case AstNode_TypeType: - case AstNode_PolyType: - case AstNode_ProcType: - case AstNode_PointerType: - case AstNode_ArrayType: - case AstNode_DynamicArrayType: - case AstNode_StructType: - case AstNode_UnionType: - // case AstNode_RawUnionType: - case AstNode_EnumType: - case AstNode_MapType: + case Ast_TypeType: + case Ast_PolyType: + case Ast_ProcType: + case Ast_PointerType: + case Ast_ArrayType: + case Ast_DynamicArrayType: + case Ast_StructType: + case Ast_UnionType: + // case Ast_RawUnionType: + case Ast_EnumType: + case Ast_MapType: o->mode = Addressing_Type; o->type = check_type(c, node); break; @@ -6149,7 +6149,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node, return kind; } -ExprKind check_expr_base(CheckerContext *c, Operand *o, AstNode *node, Type *type_hint) { +ExprKind check_expr_base(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = check_expr_base_internal(c, o, node, type_hint); Type *type = nullptr; ExactValue value = {ExactValue_Invalid}; @@ -6179,7 +6179,7 @@ ExprKind check_expr_base(CheckerContext *c, Operand *o, AstNode *node, Type *typ -void check_multi_expr(CheckerContext *c, Operand *o, AstNode *e) { +void check_multi_expr(CheckerContext *c, Operand *o, Ast *e) { check_expr_base(c, o, e, nullptr); switch (o->mode) { default: @@ -6207,22 +6207,22 @@ void check_not_tuple(CheckerContext *c, Operand *o) { } } -void check_expr(CheckerContext *c, Operand *o, AstNode *e) { +void check_expr(CheckerContext *c, Operand *o, Ast *e) { check_multi_expr(c, o, e); check_not_tuple(c, o); } -void check_expr_or_type(CheckerContext *c, Operand *o, AstNode *e, Type *type_hint) { +void check_expr_or_type(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) { check_expr_base(c, o, e, type_hint); check_not_tuple(c, o); error_operand_no_value(o); } -gbString write_expr_to_string(gbString str, AstNode *node); +gbString write_expr_to_string(gbString str, Ast *node); -gbString write_struct_fields_to_string(gbString str, Array const ¶ms) { +gbString write_struct_fields_to_string(gbString str, Array const ¶ms) { for_array(i, params) { if (i > 0) { str = gb_string_appendc(str, ", "); @@ -6245,11 +6245,11 @@ gbString string_append_token(gbString str, Token token) { } -gbString write_expr_to_string(gbString str, AstNode *node) { +gbString write_expr_to_string(gbString str, Ast *node) { if (node == nullptr) return str; - if (is_ast_node_stmt(node)) { + if (is_ast_stmt(node)) { GB_ASSERT("stmt passed to write_expr_to_string"); } @@ -6423,7 +6423,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) { case_ast_node(at, ArrayType, node); str = gb_string_append_rune(str, '['); if (at->count != nullptr && - at->count->kind == AstNode_UnaryExpr && + at->count->kind == Ast_UnaryExpr && at->count->UnaryExpr.op.kind == Token_Question) { str = gb_string_appendc(str, "?"); } else { @@ -6457,7 +6457,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) { } for_array(i, f->names) { - AstNode *name = f->names[i]; + Ast *name = f->names[i]; if (i > 0) str = gb_string_appendc(str, ", "); str = write_expr_to_string(str, name); } @@ -6533,7 +6533,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) { str = gb_string_appendc(str, "("); for_array(i, ce->args) { - AstNode *arg = ce->args[i]; + Ast *arg = ce->args[i]; if (i > 0) { str = gb_string_appendc(str, ", "); } @@ -6598,6 +6598,6 @@ gbString write_expr_to_string(gbString str, AstNode *node) { return str; } -gbString expr_to_string(AstNode *expression) { +gbString expr_to_string(Ast *expression) { return write_expr_to_string(gb_string_make(heap_allocator(), ""), expression); } diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index b5c88ab14..a98b86250 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1,4 +1,4 @@ -void check_stmt_list(CheckerContext *ctx, Array const &stmts, u32 flags) { +void check_stmt_list(CheckerContext *ctx, Array const &stmts, u32 flags) { if (stmts.count == 0) { return; } @@ -12,14 +12,14 @@ void check_stmt_list(CheckerContext *ctx, Array const &stmts, u32 fla isize max = stmts.count; for (isize i = stmts.count-1; i >= 0; i--) { - if (stmts[i]->kind != AstNode_EmptyStmt) { + if (stmts[i]->kind != Ast_EmptyStmt) { break; } max--; } for (isize i = 0; i < max; i++) { - AstNode *n = stmts[i]; - if (n->kind == AstNode_EmptyStmt) { + Ast *n = stmts[i]; + if (n->kind == Ast_EmptyStmt) { continue; } u32 new_flags = flags; @@ -29,11 +29,11 @@ void check_stmt_list(CheckerContext *ctx, Array const &stmts, u32 fla if (i+1 < max) { switch (n->kind) { - case AstNode_ReturnStmt: + case Ast_ReturnStmt: error(n, "Statements after this 'return' are never execu"); break; - case AstNode_BranchStmt: + case Ast_BranchStmt: error(n, "Statements after this '%.*s' are never executed", LIT(n->BranchStmt.token.string)); break; } @@ -43,11 +43,11 @@ void check_stmt_list(CheckerContext *ctx, Array const &stmts, u32 fla } } -bool check_is_terminating_list(Array const &stmts) { +bool check_is_terminating_list(Array const &stmts) { // Iterate backwards for (isize n = stmts.count-1; n >= 0; n--) { - AstNode *stmt = stmts[n]; - if (stmt->kind != AstNode_EmptyStmt) { + Ast *stmt = stmts[n]; + if (stmt->kind != Ast_EmptyStmt) { return check_is_terminating(stmt); } } @@ -55,9 +55,9 @@ bool check_is_terminating_list(Array const &stmts) { return false; } -bool check_has_break_list(Array const &stmts, bool implicit) { +bool check_has_break_list(Array const &stmts, bool implicit) { for_array(i, stmts) { - AstNode *stmt = stmts[i]; + Ast *stmt = stmts[i]; if (check_has_break(stmt, implicit)) { return true; } @@ -66,24 +66,24 @@ bool check_has_break_list(Array const &stmts, bool implicit) { } -bool check_has_break(AstNode *stmt, bool implicit) { +bool check_has_break(Ast *stmt, bool implicit) { switch (stmt->kind) { - case AstNode_BranchStmt: + case Ast_BranchStmt: if (stmt->BranchStmt.token.kind == Token_break) { return implicit; } break; - case AstNode_BlockStmt: + case Ast_BlockStmt: return check_has_break_list(stmt->BlockStmt.stmts, implicit); - case AstNode_IfStmt: + case Ast_IfStmt: if (check_has_break(stmt->IfStmt.body, implicit) || (stmt->IfStmt.else_stmt != nullptr && check_has_break(stmt->IfStmt.else_stmt, implicit))) { return true; } break; - case AstNode_CaseClause: + case Ast_CaseClause: return check_has_break_list(stmt->CaseClause.stmts, implicit); } @@ -94,7 +94,7 @@ bool check_has_break(AstNode *stmt, bool implicit) { // NOTE(bill): The last expression has to be a 'return' statement // TODO(bill): This is a mild hack and should be probably handled properly -bool check_is_terminating(AstNode *node) { +bool check_is_terminating(Ast *node) { switch (node->kind) { case_ast_node(rs, ReturnStmt, node); return true; @@ -139,7 +139,7 @@ bool check_is_terminating(AstNode *node) { case_ast_node(ss, SwitchStmt, node); bool has_default = false; for_array(i, ss->body->BlockStmt.stmts) { - AstNode *clause = ss->body->BlockStmt.stmts[i]; + Ast *clause = ss->body->BlockStmt.stmts[i]; ast_node(cc, CaseClause, clause); if (cc->list.count == 0) { has_default = true; @@ -155,7 +155,7 @@ bool check_is_terminating(AstNode *node) { case_ast_node(ss, TypeSwitchStmt, node); bool has_default = false; for_array(i, ss->body->BlockStmt.stmts) { - AstNode *clause = ss->body->BlockStmt.stmts[i]; + Ast *clause = ss->body->BlockStmt.stmts[i]; ast_node(cc, CaseClause, clause); if (cc->list.count == 0) { has_default = true; @@ -186,7 +186,7 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) return nullptr; } - AstNode *node = unparen_expr(lhs->expr); + Ast *node = unparen_expr(lhs->expr); // NOTE(bill): Ignore assignments to '_' if (is_blank_ident(node)) { @@ -234,7 +234,7 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) rhs->proc_group = nullptr; } } else { - if (node->kind == AstNode_Ident) { + if (node->kind == Ast_Ident) { ast_node(i, Ident, node); e = scope_lookup(ctx->scope, i->token.string); if (e != nullptr && e->kind == Entity_Variable) { @@ -289,9 +289,9 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) } case Addressing_MapIndex: { - AstNode *ln = unparen_expr(lhs->expr); - if (ln->kind == AstNode_IndexExpr) { - AstNode *x = ln->IndexExpr.expr; + Ast *ln = unparen_expr(lhs->expr); + if (ln->kind == Ast_IndexExpr) { + Ast *x = ln->IndexExpr.expr; TypeAndValue tav = type_and_value_of_expr(&ctx->checker->info, x); GB_ASSERT(tav.mode != Addressing_Invalid); if (tav.mode != Addressing_Variable) { @@ -308,7 +308,7 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) } default: { - if (lhs->expr->kind == AstNode_SelectorExpr) { + if (lhs->expr->kind == Ast_SelectorExpr) { // NOTE(bill): Extra error checks Operand op_c = {Addressing_Invalid}; ast_node(se, SelectorExpr, lhs->expr); @@ -342,8 +342,8 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) } -void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags); -void check_stmt(CheckerContext *ctx, AstNode *node, u32 flags) { +void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags); +void check_stmt(CheckerContext *ctx, Ast *node, u32 flags) { u32 prev_stmt_state_flags = ctx->stmt_state_flags; if (node->stmt_state_flags != 0) { @@ -368,14 +368,14 @@ void check_stmt(CheckerContext *ctx, AstNode *node, u32 flags) { } -void check_when_stmt(CheckerContext *ctx, AstNodeWhenStmt *ws, u32 flags) { +void check_when_stmt(CheckerContext *ctx, AstWhenStmt *ws, u32 flags) { Operand operand = {Addressing_Invalid}; check_expr(ctx, &operand, ws->cond); if (operand.mode != Addressing_Constant || !is_type_boolean(operand.type)) { error(ws->cond, "Non-constant boolean 'when' condition"); return; } - if (ws->body == nullptr || ws->body->kind != AstNode_BlockStmt) { + if (ws->body == nullptr || ws->body->kind != Ast_BlockStmt) { error(ws->cond, "Invalid body for 'when' statement"); return; } @@ -384,10 +384,10 @@ void check_when_stmt(CheckerContext *ctx, AstNodeWhenStmt *ws, u32 flags) { check_stmt_list(ctx, ws->body->BlockStmt.stmts, flags); } else if (ws->else_stmt) { switch (ws->else_stmt->kind) { - case AstNode_BlockStmt: + case Ast_BlockStmt: check_stmt_list(ctx, ws->else_stmt->BlockStmt.stmts, flags); break; - case AstNode_WhenStmt: + case Ast_WhenStmt: check_when_stmt(ctx, &ws->else_stmt->WhenStmt, flags); break; default: @@ -397,12 +397,12 @@ void check_when_stmt(CheckerContext *ctx, AstNodeWhenStmt *ws, u32 flags) { } } -void check_label(CheckerContext *ctx, AstNode *label) { +void check_label(CheckerContext *ctx, Ast *label) { if (label == nullptr) { return; } ast_node(l, Label, label); - if (l->name->kind != AstNode_Ident) { + if (l->name->kind != Ast_Ident) { error(l->name, "A label's name must be an identifier"); return; } @@ -440,7 +440,7 @@ void check_label(CheckerContext *ctx, AstNode *label) { } // Returns 'true' for 'continue', 'false' for 'return' -bool check_using_stmt_entity(CheckerContext *ctx, AstNodeUsingStmt *us, AstNode *expr, bool is_selector, Entity *e) { +bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, bool is_selector, Entity *e) { if (e == nullptr) { error(us->token, "'using' applied to an unknown entity"); return true; @@ -596,11 +596,11 @@ void add_constant_switch_case(CheckerContext *ctx, Map *seen, Oper } } - TypeAndToken tap = {operand.type, ast_node_token(operand.expr)}; + TypeAndToken tap = {operand.type, ast_token(operand.expr)}; multi_map_insert(seen, key, tap); } -void check_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { +void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { ast_node(ss, SwitchStmt, node); Operand x = {}; @@ -623,21 +623,21 @@ void check_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { x.value = exact_value_bool(true); Token token = {}; - token.pos = ast_node_token(ss->body).pos; + token.pos = ast_token(ss->body).pos; token.string = str_lit("true"); - x.expr = gb_alloc_item(ctx->allocator, AstNode); - x.expr->kind = AstNode_Ident; + x.expr = gb_alloc_item(ctx->allocator, Ast); + x.expr->kind = Ast_Ident; x.expr->Ident.token = token; } // NOTE(bill): Check for multiple defaults - AstNode *first_default = nullptr; + Ast *first_default = nullptr; ast_node(bs, BlockStmt, ss->body); for_array(i, bs->stmts) { - AstNode *stmt = bs->stmts[i]; - AstNode *default_stmt = nullptr; - if (stmt->kind == AstNode_CaseClause) { + Ast *stmt = bs->stmts[i]; + Ast *default_stmt = nullptr; + if (stmt->kind == Ast_CaseClause) { ast_node(cc, CaseClause, stmt); if (cc->list.count == 0) { default_stmt = stmt; @@ -648,7 +648,7 @@ void check_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { if (default_stmt != nullptr) { if (first_default != nullptr) { - TokenPos pos = ast_node_token(first_default).pos; + TokenPos pos = ast_token(first_default).pos; error(stmt, "multiple default clauses\n" "\tfirst at %.*s(%td:%td)", @@ -673,17 +673,17 @@ void check_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { defer (map_destroy(&seen)); for_array(stmt_index, bs->stmts) { - AstNode *stmt = bs->stmts[stmt_index]; - if (stmt->kind != AstNode_CaseClause) { + Ast *stmt = bs->stmts[stmt_index]; + if (stmt->kind != Ast_CaseClause) { // NOTE(bill): error handled by above multiple default checker continue; } ast_node(cc, CaseClause, stmt); for_array(j, cc->list) { - AstNode *expr = unparen_expr(cc->list[j]); + Ast *expr = unparen_expr(cc->list[j]); - if (is_ast_node_a_range(expr)) { + if (is_ast_range(expr)) { ast_node(ie, BinaryExpr, expr); Operand lhs = {}; Operand rhs = {}; @@ -838,7 +838,7 @@ TypeSwitchKind check_valid_type_switch_type(Type *type) { return TypeSwitch_Invalid; } -void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { +void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { ast_node(ss, TypeSwitchStmt, node); Operand x = {}; @@ -848,13 +848,13 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { check_label(ctx, ss->label); // TODO(bill): What should the label's "scope" be? - if (ss->tag->kind != AstNode_AssignStmt) { + if (ss->tag->kind != Ast_AssignStmt) { error(ss->tag, "Expected an 'in' assignment for this type switch statement"); return; } ast_node(as, AssignStmt, ss->tag); - Token as_token = ast_node_token(ss->tag); + Token as_token = ast_token(ss->tag); if (as->lhs.count != 1) { syntax_error(as_token, "Expected 1 name before 'in'"); return; @@ -863,8 +863,8 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { syntax_error(as_token, "Expected 1 expression after 'in'"); return; } - AstNode *lhs = as->lhs[0]; - AstNode *rhs = as->rhs[0]; + Ast *lhs = as->lhs[0]; + Ast *rhs = as->rhs[0]; check_expr(ctx, &x, rhs); check_assignment(ctx, &x, nullptr, str_lit("type switch expression")); @@ -889,12 +889,12 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { bool is_ptr = is_type_pointer(x.type); // NOTE(bill): Check for multiple defaults - AstNode *first_default = nullptr; + Ast *first_default = nullptr; ast_node(bs, BlockStmt, ss->body); for_array(i, bs->stmts) { - AstNode *stmt = bs->stmts[i]; - AstNode *default_stmt = nullptr; - if (stmt->kind == AstNode_CaseClause) { + Ast *stmt = bs->stmts[i]; + Ast *default_stmt = nullptr; + if (stmt->kind == Ast_CaseClause) { ast_node(cc, CaseClause, stmt); if (cc->list.count == 0) { default_stmt = stmt; @@ -905,7 +905,7 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { if (default_stmt != nullptr) { if (first_default != nullptr) { - TokenPos pos = ast_node_token(first_default).pos; + TokenPos pos = ast_token(first_default).pos; error(stmt, "Multiple default clauses\n" "\tfirst at %.*s(%td:%td)", @@ -916,8 +916,8 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { } } - if (lhs->kind != AstNode_Ident) { - error(rhs, "Expected an identifier, got '%.*s'", LIT(ast_node_strings[rhs->kind])); + if (lhs->kind != Ast_Ident) { + error(rhs, "Expected an identifier, got '%.*s'", LIT(ast_strings[rhs->kind])); return; } @@ -926,8 +926,8 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { defer (ptr_set_destroy(&seen)); for_array(i, bs->stmts) { - AstNode *stmt = bs->stmts[i]; - if (stmt->kind != AstNode_CaseClause) { + Ast *stmt = bs->stmts[i]; + if (stmt->kind != Ast_CaseClause) { // NOTE(bill): error handled by above multiple default checker continue; } @@ -938,7 +938,7 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { Type *case_type = nullptr; for_array(type_index, cc->list) { - AstNode *type_expr = cc->list[type_index]; + Ast *type_expr = cc->list[type_index]; if (type_expr != nullptr) { // Otherwise it's a default expression Operand y = {}; check_expr_or_type(ctx, &y, type_expr); @@ -1046,7 +1046,7 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) { } } -void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { +void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { u32 mod_flags = flags & (~Stmt_FallthroughAllowed); switch (node->kind) { case_ast_node(_, EmptyStmt, node); case_end; @@ -1070,8 +1070,8 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { if (kind == Expr_Stmt) { return; } - if (operand.expr->kind == AstNode_CallExpr) { - AstNodeCallExpr *ce = &operand.expr->CallExpr; + if (operand.expr->kind == Ast_CallExpr) { + AstCallExpr *ce = &operand.expr->CallExpr; Type *t = type_of_expr(&ctx->checker->info, ce->proc); if (is_type_proc(t)) { if (t->Proc.require_results) { @@ -1157,7 +1157,7 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { } Operand lhs = {Addressing_Invalid}; Operand rhs = {Addressing_Invalid}; - AstNode binary_expr = {AstNode_BinaryExpr}; + Ast binary_expr = {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)); @@ -1201,8 +1201,8 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { if (is->else_stmt != nullptr) { switch (is->else_stmt->kind) { - case AstNode_IfStmt: - case AstNode_BlockStmt: + case Ast_IfStmt: + case Ast_BlockStmt: check_stmt(ctx, is->else_stmt, mod_flags); break; default: @@ -1277,8 +1277,8 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { if (fs->post != nullptr) { check_stmt(ctx, fs->post, 0); - if (fs->post->kind != AstNode_AssignStmt && - fs->post->kind != AstNode_IncDecStmt) { + if (fs->post->kind != Ast_AssignStmt && + fs->post->kind != Ast_IncDecStmt) { error(fs->post, "'for' statement post statement must be a simple statement"); } } @@ -1299,10 +1299,10 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { isize entity_count = 0; bool is_map = false; - AstNode *expr = unparen_expr(rs->expr); + Ast *expr = unparen_expr(rs->expr); - if (is_ast_node_a_range(expr)) { + if (is_ast_range(expr)) { ast_node(ie, BinaryExpr, expr); Operand x = {Addressing_Invalid}; Operand y = {Addressing_Invalid}; @@ -1447,18 +1447,18 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { } skip_expr:; // NOTE(zhiayang): again, declaring a variable immediately after a label... weird. - AstNode *lhs[2] = {rs->val0, rs->val1}; + Ast *lhs[2] = {rs->val0, rs->val1}; Type * rhs[2] = {val0, val1}; for (isize i = 0; i < 2; i++) { if (lhs[i] == nullptr) { continue; } - AstNode *name = lhs[i]; + Ast *name = lhs[i]; Type * type = rhs[i]; Entity *entity = nullptr; - if (name->kind == AstNode_Ident) { + if (name->kind == Ast_Ident) { Token token = name->Ident.token; String str = token.string; Entity *found = nullptr; @@ -1483,7 +1483,7 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { } if (entity == nullptr) { - entity = alloc_entity_dummy_variable(universal_scope, ast_node_token(name)); + entity = alloc_entity_dummy_variable(universal_scope, ast_token(name)); } entities[entity_count++] = entity; @@ -1513,7 +1513,7 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { case_ast_node(ds, DeferStmt, node); - if (is_ast_node_decl(ds->stmt)) { + if (is_ast_decl(ds->stmt)) { error(ds->token, "You cannot defer a declaration"); } else { bool out_in_defer = ctx->in_defer; @@ -1547,11 +1547,11 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { } if (bs->label != nullptr) { - if (bs->label->kind != AstNode_Ident) { + if (bs->label->kind != Ast_Ident) { error(bs->label, "A branch statement's label name must be an identifier"); return; } - AstNode *ident = bs->label; + Ast *ident = bs->label; String name = ident->Ident.token.string; Operand o = {}; Entity *e = check_ident(ctx, &o, ident, nullptr, nullptr, false); @@ -1574,24 +1574,24 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { return; } for_array(i, us->list) { - AstNode *expr = unparen_expr(us->list[0]); + Ast *expr = unparen_expr(us->list[0]); Entity *e = nullptr; bool is_selector = false; Operand o = {}; switch (expr->kind) { - case AstNode_Ident: + case Ast_Ident: e = check_ident(ctx, &o, expr, nullptr, nullptr, true); break; - case AstNode_SelectorExpr: + case Ast_SelectorExpr: e = check_selector(ctx, &o, expr, nullptr); is_selector = true; break; - case AstNode_Implicit: + case Ast_Implicit: error(us->token, "'using' applied to an implicit value"); continue; default: - error(us->token, "'using' can only be applied to an entity, got %.*s", LIT(ast_node_strings[expr->kind])); + error(us->token, "'using' can only be applied to an entity, got %.*s", LIT(ast_strings[expr->kind])); continue; } @@ -1609,9 +1609,9 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { case_end; case_ast_node(fb, ForeignBlockDecl, node); - AstNode *foreign_library = fb->foreign_library; + Ast *foreign_library = fb->foreign_library; CheckerContext c = *ctx; - if (foreign_library->kind != AstNode_Ident) { + if (foreign_library->kind != Ast_Ident) { error(foreign_library, "foreign library name must be an identifier"); } else { c.foreign_context.curr_library = foreign_library; @@ -1622,8 +1622,8 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { ast_node(block, BlockStmt, fb->body); for_array(i, block->stmts) { - AstNode *decl = block->stmts[i]; - if (decl->kind == AstNode_ValueDecl && decl->ValueDecl.is_mutable) { + Ast *decl = block->stmts[i]; + if (decl->kind == Ast_ValueDecl && decl->ValueDecl.is_mutable) { check_stmt(&c, decl, flags); } } @@ -1636,9 +1636,9 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { isize new_name_count = 0; for_array(i, vd->names) { - AstNode *name = vd->names[i]; + Ast *name = vd->names[i]; Entity *entity = nullptr; - if (name->kind != AstNode_Ident) { + if (name->kind != Ast_Ident) { error(name, "A variable declaration must be an identifier"); } else { Token token = name->Ident.token; @@ -1653,9 +1653,9 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { entity = alloc_entity_variable(ctx->scope, token, nullptr, false); entity->identifier = name; - AstNode *fl = ctx->foreign_context.curr_library; + Ast *fl = ctx->foreign_context.curr_library; if (fl != nullptr) { - GB_ASSERT(fl->kind == AstNode_Ident); + GB_ASSERT(fl->kind == Ast_Ident); entity->Variable.is_foreign = true; entity->Variable.foreign_library_ident = fl; } @@ -1669,7 +1669,7 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { } } if (entity == nullptr) { - entity = alloc_entity_dummy_variable(universal_scope, ast_node_token(name)); + entity = alloc_entity_dummy_variable(universal_scope, ast_token(name)); } entity->parent_proc_decl = ctx->curr_proc_decl; entities[entity_count++] = entity; @@ -1766,7 +1766,7 @@ void check_stmt_internal(CheckerContext *ctx, AstNode *node, u32 flags) { } if (vd->is_using != 0) { - Token token = ast_node_token(node); + Token token = ast_token(node); if (vd->type != nullptr && entity_count > 1) { error(token, "'using' can only be applied to one variable of the same type"); // TODO(bill): Should a 'continue' happen here? diff --git a/src/check_type.cpp b/src/check_type.cpp index 9a2493aed..6058fb859 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1,5 +1,5 @@ -void populate_using_entity_scope(CheckerContext *ctx, AstNode *node, Type *t) { +void populate_using_entity_scope(CheckerContext *ctx, Ast *node, Type *t) { t = base_type(type_deref(t)); gbString str = nullptr; defer (gb_string_free(str)); @@ -31,16 +31,16 @@ void populate_using_entity_scope(CheckerContext *ctx, AstNode *node, Type *t) { } -void check_struct_fields(CheckerContext *ctx, AstNode *node, Array *fields, Array const ¶ms, +void check_struct_fields(CheckerContext *ctx, Ast *node, Array *fields, Array const ¶ms, isize init_field_capacity, Type *named_type, String context) { *fields = array_make(heap_allocator(), 0, init_field_capacity); - GB_ASSERT(node->kind == AstNode_StructType); + GB_ASSERT(node->kind == Ast_StructType); isize variable_count = 0; for_array(i, params) { - AstNode *field = params[i]; - if (ast_node_expect(field, AstNode_Field)) { + Ast *field = params[i]; + if (ast_node_expect(field, Ast_Field)) { ast_node(f, Field, field); variable_count += gb_max(f->names.count, 1); } @@ -48,12 +48,12 @@ void check_struct_fields(CheckerContext *ctx, AstNode *node, Array *fi i32 field_src_index = 0; for_array(i, params) { - AstNode *param = params[i]; - if (param->kind != AstNode_Field) { + Ast *param = params[i]; + if (param->kind != Ast_Field) { continue; } ast_node(p, Field, param); - AstNode *type_expr = p->type; + Ast *type_expr = p->type; Type *type = nullptr; bool detemine_type_from_operand = false; @@ -80,8 +80,8 @@ void check_struct_fields(CheckerContext *ctx, AstNode *node, Array *fi bool is_using = (p->flags&FieldFlag_using) != 0; for_array(j, p->names) { - AstNode *name = p->names[j]; - if (!ast_node_expect(name, AstNode_Ident)) { + Ast *name = p->names[j]; + if (!ast_node_expect(name, Ast_Ident)) { continue; } @@ -101,7 +101,7 @@ void check_struct_fields(CheckerContext *ctx, AstNode *node, Array *fi if (!is_type_struct(t) && !is_type_raw_union(t) && !is_type_bit_field(t) && p->names.count >= 1 && - p->names[0]->kind == AstNode_Ident) { + p->names[0]->kind == Ast_Ident) { Token name_token = p->names[0]->Ident.token; gbString type_str = type_to_string(first_type); error(name_token, "'using' cannot be applied to the field '%.*s' of type '%s'", LIT(name_token.string), type_str); @@ -122,7 +122,7 @@ Entity *make_names_field_for_struct(CheckerContext *ctx, Scope *scope) { return e; } -bool check_custom_align(CheckerContext *ctx, AstNode *node, i64 *align_) { +bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) { GB_ASSERT(align_ != nullptr); Operand o = {}; check_expr(ctx, &o, node); @@ -197,18 +197,18 @@ Entity *find_polymorphic_struct_entity(CheckerContext *ctx, Type *original_type, } -void add_polymorphic_struct_entity(CheckerContext *ctx, AstNode *node, Type *named_type, Type *original_type) { +void add_polymorphic_struct_entity(CheckerContext *ctx, Ast *node, Type *named_type, Type *original_type) { GB_ASSERT(is_type_named(named_type)); gbAllocator a = heap_allocator(); Scope *s = ctx->scope->parent; Entity *e = nullptr; { - Token token = ast_node_token(node); + Token token = ast_token(node); token.kind = Token_String; token.string = named_type->Named.name; - AstNode *node = ast_ident(nullptr, token); + Ast *node = ast_ident(nullptr, token); e = alloc_entity_type_name(s, token, named_type); e->state = EntityState_Resolved; @@ -228,7 +228,7 @@ void add_polymorphic_struct_entity(CheckerContext *ctx, AstNode *node, Type *nam } } -void check_struct_type(CheckerContext *ctx, Type *struct_type, AstNode *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { +void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { GB_ASSERT(is_type_struct(struct_type)); ast_node(st, StructType, node); @@ -236,7 +236,7 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, AstNode *node, Ar isize min_field_count = 0; for_array(field_index, st->fields) { - AstNode *field = st->fields[field_index]; + Ast *field = st->fields[field_index]; switch (field->kind) { case_ast_node(f, ValueDecl, field); min_field_count += f->names.count; @@ -259,12 +259,12 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, AstNode *node, Ar if (st->polymorphic_params != nullptr) { ast_node(field_list, FieldList, st->polymorphic_params); - Array params = field_list->list; + Array params = field_list->list; if (params.count != 0) { isize variable_count = 0; for_array(i, params) { - AstNode *field = params[i]; - if (ast_node_expect(field, AstNode_Field)) { + Ast *field = params[i]; + if (ast_node_expect(field, Ast_Field)) { ast_node(f, Field, field); variable_count += gb_max(f->names.count, 1); } @@ -273,12 +273,12 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, AstNode *node, Ar auto entities = array_make(ctx->allocator, 0, variable_count); for_array(i, params) { - AstNode *param = params[i]; - if (param->kind != AstNode_Field) { + Ast *param = params[i]; + if (param->kind != Ast_Field) { continue; } ast_node(p, Field, param); - AstNode *type_expr = p->type; + Ast *type_expr = p->type; Type *type = nullptr; bool is_type_param = false; bool is_type_polymorphic_type = false; @@ -286,15 +286,15 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, AstNode *node, Ar error(param, "Expected a type for this parameter"); continue; } - if (type_expr->kind == AstNode_Ellipsis) { + if (type_expr->kind == Ast_Ellipsis) { type_expr = type_expr->Ellipsis.expr; error(param, "A polymorphic parameter cannot be variadic"); } - if (type_expr->kind == AstNode_TypeType) { + if (type_expr->kind == Ast_TypeType) { is_type_param = true; Type *specialization = nullptr; if (type_expr->TypeType.specialization != nullptr) { - AstNode *s = type_expr->TypeType.specialization; + Ast *s = type_expr->TypeType.specialization; specialization = check_type(ctx, s); // if (!is_type_polymorphic_struct(specialization)) { // gbString str = type_to_string(specialization); @@ -339,8 +339,8 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, AstNode *node, Ar Scope *scope = ctx->scope; for_array(j, p->names) { - AstNode *name = p->names[j]; - if (!ast_node_expect(name, AstNode_Ident)) { + Ast *name = p->names[j]; + if (!ast_node_expect(name, Ast_Ident)) { continue; } Entity *e = nullptr; @@ -431,7 +431,7 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, AstNode *node, Ar } } } -void check_union_type(CheckerContext *ctx, Type *union_type, AstNode *node) { +void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node) { GB_ASSERT(is_type_union(union_type)); ast_node(ut, UnionType, node); @@ -444,7 +444,7 @@ void check_union_type(CheckerContext *ctx, Type *union_type, AstNode *node) { union_type->Union.scope = ctx->scope; for_array(i, ut->variants) { - AstNode *node = ut->variants[i]; + Ast *node = ut->variants[i]; Type *t = check_type_expr(ctx, node, nullptr); if (t != nullptr && t != t_invalid) { bool ok = true; @@ -485,7 +485,7 @@ void check_union_type(CheckerContext *ctx, Type *union_type, AstNode *node) { } } -void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, AstNode *node) { +void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast *node) { ast_node(et, EnumType, node); GB_ASSERT(is_type_enum(enum_type)); @@ -521,18 +521,18 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast scope_reserve(ctx->scope, et->fields.count); for_array(i, et->fields) { - AstNode *field = et->fields[i]; - AstNode *ident = nullptr; - AstNode *init = nullptr; - if (field->kind == AstNode_FieldValue) { + Ast *field = et->fields[i]; + Ast *ident = nullptr; + Ast *init = nullptr; + if (field->kind == Ast_FieldValue) { ast_node(fv, FieldValue, field); - if (fv->field == nullptr || fv->field->kind != AstNode_Ident) { + if (fv->field == nullptr || fv->field->kind != Ast_Ident) { error(field, "An enum field's name must be an identifier"); continue; } ident = fv->field; init = fv->value; - } else if (field->kind == AstNode_Ident) { + } else if (field->kind == Ast_Ident) { ident = field; } else { error(field, "An enum field's name must be an identifier"); @@ -634,7 +634,7 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast } -void check_bit_field_type(CheckerContext *ctx, Type *bit_field_type, AstNode *node) { +void check_bit_field_type(CheckerContext *ctx, Type *bit_field_type, Ast *node) { ast_node(bft, BitFieldType, node); GB_ASSERT(is_type_bit_field(bit_field_type)); @@ -646,12 +646,12 @@ void check_bit_field_type(CheckerContext *ctx, Type *bit_field_type, AstNode *no u32 curr_offset = 0; for_array(i, bft->fields) { - AstNode *field = bft->fields[i]; - GB_ASSERT(field->kind == AstNode_FieldValue); - AstNode *ident = field->FieldValue.field; - AstNode *value = field->FieldValue.value; + Ast *field = bft->fields[i]; + GB_ASSERT(field->kind == Ast_FieldValue); + Ast *ident = field->FieldValue.field; + Ast *value = field->FieldValue.value; - if (ident->kind != AstNode_Ident) { + if (ident->kind != Ast_Ident) { error(field, "A bit field value's name must be an identifier"); continue; } @@ -786,7 +786,7 @@ Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Oper } -Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool *is_variadic_, isize *variadic_index_, bool *success_, isize *specialization_count_, Array *operands) { +Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is_variadic_, isize *variadic_index_, bool *success_, isize *specialization_count_, Array *operands) { if (_params == nullptr) { return nullptr; } @@ -795,7 +795,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool bool success = true; ast_node(field_list, FieldList, _params); - Array params = field_list->list; + Array params = field_list->list; if (params.count == 0) { if (success_) *success_ = success; @@ -806,16 +806,16 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool isize variable_count = 0; for_array(i, params) { - AstNode *field = params[i]; - if (ast_node_expect(field, AstNode_Field)) { + Ast *field = params[i]; + if (ast_node_expect(field, Ast_Field)) { ast_node(f, Field, field); variable_count += gb_max(f->names.count, 1); } } isize min_variable_count = variable_count; for (isize i = params.count-1; i >= 0; i--) { - AstNode *field = params[i]; - if (field->kind == AstNode_Field) { + Ast *field = params[i]; + if (field->kind == Ast_Field) { ast_node(f, Field, field); if (f->default_value == nullptr) { break; @@ -830,14 +830,14 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool bool is_c_vararg = false; auto variables = array_make(ctx->allocator, 0, variable_count); for_array(i, params) { - AstNode *param = params[i]; - if (param->kind != AstNode_Field) { + Ast *param = params[i]; + if (param->kind != Ast_Field) { continue; } ast_node(p, Field, param); - AstNode *type_expr = p->type; + Ast *type_expr = p->type; Type *type = nullptr; - AstNode *default_value = unparen_expr(p->default_value); + Ast *default_value = unparen_expr(p->default_value); ExactValue value = {}; bool default_is_nil = false; bool default_is_location = false; @@ -849,7 +849,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool bool is_using = (p->flags&FieldFlag_using) != 0; if (type_expr == nullptr) { - if (default_value->kind == AstNode_BasicDirective && + if (default_value->kind == Ast_BasicDirective && default_value->BasicDirective.name == "caller_location") { init_core_source_code_location(ctx->checker); default_is_location = true; @@ -860,15 +860,15 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool if (is_operand_nil(o)) { default_is_nil = true; } else if (o.mode != Addressing_Constant) { - if (default_value->kind == AstNode_ProcLit) { + if (default_value->kind == Ast_ProcLit) { value = exact_value_procedure(default_value); } else { Entity *e = nullptr; if (o.mode == Addressing_Value && is_type_proc(o.type)) { Operand x = {}; - if (default_value->kind == AstNode_Ident) { + if (default_value->kind == Ast_Ident) { e = check_ident(ctx, &x, default_value, nullptr, nullptr, false); - } else if (default_value->kind == AstNode_SelectorExpr) { + } else if (default_value->kind == Ast_SelectorExpr) { e = check_selector(ctx, &x, default_value, nullptr); } } @@ -888,7 +888,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool type = default_type(o.type); } } else { - if (type_expr->kind == AstNode_Ellipsis) { + if (type_expr->kind == Ast_Ellipsis) { type_expr = type_expr->Ellipsis.expr; #if 1 is_variadic = true; @@ -906,7 +906,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool } #endif } - if (type_expr->kind == AstNode_TypeType) { + if (type_expr->kind == Ast_TypeType) { ast_node(tt, TypeType, type_expr); is_type_param = true; specialization = check_type(ctx, tt->specialization); @@ -942,12 +942,12 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool } if (default_value != nullptr) { - if (type_expr->kind == AstNode_TypeType) { + if (type_expr->kind == Ast_TypeType) { error(default_value, "A type parameter may not have a default value"); continue; } else { Operand o = {}; - if (default_value->kind == AstNode_BasicDirective && + if (default_value->kind == Ast_BasicDirective && default_value->BasicDirective.name == "caller_location") { init_core_source_code_location(ctx->checker); default_is_location = true; @@ -959,15 +959,15 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool if (is_operand_nil(o)) { default_is_nil = true; } else if (o.mode != Addressing_Constant) { - if (default_value->kind == AstNode_ProcLit) { + if (default_value->kind == Ast_ProcLit) { value = exact_value_procedure(default_value); } else { Entity *e = nullptr; if (o.mode == Addressing_Value && is_type_proc(o.type)) { Operand x = {}; - if (default_value->kind == AstNode_Ident) { + if (default_value->kind == Ast_Ident) { e = check_ident(ctx, &x, default_value, nullptr, nullptr, false); - } else if (default_value->kind == AstNode_SelectorExpr) { + } else if (default_value->kind == Ast_SelectorExpr) { e = check_selector(ctx, &x, default_value, nullptr); } } @@ -1010,7 +1010,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool if (p->flags&FieldFlag_c_vararg) { if (p->type == nullptr || - p->type->kind != AstNode_Ellipsis) { + p->type->kind != Ast_Ellipsis) { error(param, "'#c_vararg' can only be applied to variadic type fields"); p->flags &= ~FieldFlag_c_vararg; // Remove the flag } else { @@ -1031,8 +1031,8 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool bool is_in = (p->flags&FieldFlag_in) != 0; for_array(j, p->names) { - AstNode *name = p->names[j]; - if (!ast_node_expect(name, AstNode_Ident)) { + Ast *name = p->names[j]; + if (!ast_node_expect(name, Ast_Ident)) { continue; } @@ -1150,12 +1150,12 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool return tuple; } -Type *check_get_results(CheckerContext *ctx, Scope *scope, AstNode *_results) { +Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) { if (_results == nullptr) { return nullptr; } ast_node(field_list, FieldList, _results); - Array results = field_list->list; + Array results = field_list->list; if (results.count == 0) { return nullptr; @@ -1164,8 +1164,8 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, AstNode *_results) { isize variable_count = 0; for_array(i, results) { - AstNode *field = results[i]; - if (ast_node_expect(field, AstNode_Field)) { + Ast *field = results[i]; + if (ast_node_expect(field, Ast_Field)) { ast_node(f, Field, field); variable_count += gb_max(f->names.count, 1); } @@ -1174,7 +1174,7 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, AstNode *_results) { auto variables = array_make(ctx->allocator, 0, variable_count); for_array(i, results) { ast_node(field, Field, results[i]); - AstNode *default_value = unparen_expr(field->default_value); + Ast *default_value = unparen_expr(field->default_value); ExactValue value = {}; bool default_is_nil = false; @@ -1220,7 +1220,7 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, AstNode *_results) { if (field->names.count == 0) { - Token token = ast_node_token(field->type); + Token token = ast_token(field->type); token.string = str_lit(""); Entity *param = alloc_entity_param(scope, token, type, false, false); param->Variable.default_value = value; @@ -1228,14 +1228,14 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, AstNode *_results) { array_add(&variables, param); } else { for_array(j, field->names) { - Token token = ast_node_token(results[i]); + Token token = ast_token(results[i]); if (field->type != nullptr) { - token = ast_node_token(field->type); + token = ast_token(field->type); } token.string = str_lit(""); - AstNode *name = field->names[j]; - if (name->kind != AstNode_Ident) { + Ast *name = field->names[j]; + if (name->kind != Ast_Ident) { error(name, "Expected an identifer for as the field name"); } else { token = name->Ident.token; @@ -1466,7 +1466,7 @@ bool abi_compat_return_by_value(gbAllocator a, ProcCallingConvention cc, Type *a } // NOTE(bill): 'operands' is for generating non generic procedure type -bool check_procedure_type(CheckerContext *ctx, Type *type, AstNode *proc_type_node, Array *operands) { +bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, Array *operands) { ast_node(pt, ProcType, proc_type_node); if (ctx->polymorphic_scope == nullptr && ctx->allow_polymorphic_types) { @@ -1572,11 +1572,11 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, AstNode *proc_type_no } -i64 check_array_count(CheckerContext *ctx, Operand *o, AstNode *e) { +i64 check_array_count(CheckerContext *ctx, Operand *o, Ast *e) { if (e == nullptr) { return 0; } - if (e->kind == AstNode_UnaryExpr && + if (e->kind == Ast_UnaryExpr && e->UnaryExpr.op.kind == Token_Ellipsis) { return -1; } @@ -1641,7 +1641,7 @@ void init_map_entry_type(Type *type) { value: Value; } */ - AstNode *dummy_node = alloc_ast_node(nullptr, AstNode_Invalid); + Ast *dummy_node = alloc_ast_node(nullptr, Ast_Invalid); Scope *s = create_scope(universal_scope, a); auto fields = array_make(a, 0, 3); @@ -1676,7 +1676,7 @@ void init_map_internal_types(Type *type) { } */ gbAllocator a = heap_allocator(); - AstNode *dummy_node = alloc_ast_node(nullptr, AstNode_Invalid); + Ast *dummy_node = alloc_ast_node(nullptr, Ast_Invalid); Scope *s = create_scope(universal_scope, a); Type *hashes_type = alloc_type_dynamic_array(t_int); @@ -1695,7 +1695,7 @@ void init_map_internal_types(Type *type) { type->Map.lookup_result_type = make_optional_ok_type(value); } -void check_map_type(CheckerContext *ctx, Type *type, AstNode *node) { +void check_map_type(CheckerContext *ctx, Type *type, Ast *node) { GB_ASSERT(type->kind == Type_Map); ast_node(mt, MapType, node); @@ -1728,7 +1728,7 @@ void check_map_type(CheckerContext *ctx, Type *type, AstNode *node) { -bool check_type_internal(CheckerContext *ctx, AstNode *e, Type **type, Type *named_type) { +bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_type) { GB_ASSERT_NOT_NULL(type); if (e == nullptr) { *type = t_invalid; @@ -1792,8 +1792,8 @@ bool check_type_internal(CheckerContext *ctx, AstNode *e, Type **type, Type *nam case_end; case_ast_node(pt, PolyType, e); - AstNode *ident = pt->type; - if (ident->kind != AstNode_Ident) { + Ast *ident = pt->type; + if (ident->kind != Ast_Ident) { error(ident, "Expected an identifier after the $"); *type = t_invalid; return false; @@ -1805,7 +1805,7 @@ bool check_type_internal(CheckerContext *ctx, AstNode *e, Type **type, Type *nam CheckerContext c = *ctx; c.in_polymorphic_specialization = true; - AstNode *s = pt->specialization; + Ast *s = pt->specialization; specific = check_type(&c, s); } Type *t = alloc_type_generic(ctx->scope, 0, token.string, specific); @@ -2009,7 +2009,7 @@ bool check_type_internal(CheckerContext *ctx, AstNode *e, Type **type, Type *nam return false; } -Type *check_type(CheckerContext *ctx, AstNode *e) { +Type *check_type(CheckerContext *ctx, Ast *e) { CheckerContext c = *ctx; c.type_path = new_checker_type_path(); defer (destroy_checker_type_path(c.type_path)); @@ -2017,7 +2017,7 @@ Type *check_type(CheckerContext *ctx, AstNode *e) { return check_type_expr(&c, e, nullptr); } -Type *check_type_expr(CheckerContext *ctx, AstNode *e, Type *named_type) { +Type *check_type_expr(CheckerContext *ctx, Ast *e, Type *named_type) { Type *type = nullptr; bool ok = check_type_internal(ctx, e, &type, named_type); diff --git a/src/checker.cpp b/src/checker.cpp index a59592e46..4efbcab45 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1,7 +1,7 @@ #include "entity.cpp" #include "types.cpp" -void check_expr(CheckerContext *c, Operand *operand, AstNode *expression); +void check_expr(CheckerContext *c, Operand *operand, Ast *expression); bool is_operand_value(Operand o) { @@ -165,10 +165,10 @@ void import_graph_node_swap(ImportGraphNode **data, isize i, isize j) { } GB_COMPARE_PROC(ast_node_cmp) { - AstNode *x = *cast(AstNode **)a; - AstNode *y = *cast(AstNode **)b; - Token i = ast_node_token(x); - Token j = ast_node_token(y); + Ast *x = *cast(Ast **)a; + Ast *y = *cast(Ast **)b; + Token i = ast_token(x); + Token j = ast_token(y); return token_pos_cmp(i.pos, j.pos); } @@ -307,7 +307,7 @@ void destroy_scope(Scope *scope) { } -void add_scope(CheckerContext *c, AstNode *node, Scope *scope) { +void add_scope(CheckerContext *c, Ast *node, Scope *scope) { GB_ASSERT(node != nullptr); GB_ASSERT(scope != nullptr); scope->node = node; @@ -315,20 +315,20 @@ void add_scope(CheckerContext *c, AstNode *node, Scope *scope) { } -void check_open_scope(CheckerContext *c, AstNode *node) { +void check_open_scope(CheckerContext *c, Ast *node) { node = unparen_expr(node); - GB_ASSERT(node->kind == AstNode_Invalid || - is_ast_node_stmt(node) || - is_ast_node_type(node)); + GB_ASSERT(node->kind == Ast_Invalid || + is_ast_stmt(node) || + is_ast_type(node)); Scope *scope = create_scope(c->scope, c->allocator); add_scope(c, node, scope); switch (node->kind) { - case AstNode_ProcType: + case Ast_ProcType: scope->is_proc = true; break; - case AstNode_StructType: - case AstNode_EnumType: - case AstNode_UnionType: + case Ast_StructType: + case Ast_EnumType: + case Ast_UnionType: scope->is_struct = true; break; } @@ -662,26 +662,26 @@ void destroy_checker(Checker *c) { } -Entity *entity_of_ident(AstNode *identifier) { - if (identifier->kind == AstNode_Ident) { +Entity *entity_of_ident(Ast *identifier) { + if (identifier->kind == Ast_Ident) { return identifier->Ident.entity; } return nullptr; } -TypeAndValue type_and_value_of_expr(CheckerInfo *i, AstNode *expr) { +TypeAndValue type_and_value_of_expr(CheckerInfo *i, Ast *expr) { TypeAndValue result = {}; TypeAndValue *found = map_get(&i->types, hash_node(expr)); if (found) result = *found; return result; } -Type *type_of_expr(CheckerInfo *i, AstNode *expr) { +Type *type_of_expr(CheckerInfo *i, Ast *expr) { TypeAndValue tav = type_and_value_of_expr(i, expr); if (tav.mode != Addressing_Invalid) { return tav.type; } - if (expr->kind == AstNode_Ident) { + if (expr->kind == Ast_Ident) { Entity *entity = entity_of_ident(expr); if (entity) { return entity->type; @@ -691,12 +691,12 @@ Type *type_of_expr(CheckerInfo *i, AstNode *expr) { return nullptr; } -Entity *implicit_entity_of_node(CheckerInfo *i, AstNode *clause) { +Entity *implicit_entity_of_node(CheckerInfo *i, Ast *clause) { // Entity **found = map_get(&i->implicits, hash_node(clause)); // if (found != nullptr) { // return *found; // } - if (clause->kind == AstNode_CaseClause) { + if (clause->kind == Ast_CaseClause) { return clause->CaseClause.implicit_entity; } return nullptr; @@ -707,15 +707,15 @@ bool is_entity_implicitly_imported(Entity *import_name, Entity *e) { } // Will return nullptr if not found -Entity *entity_of_node(CheckerInfo *i, AstNode *expr) { +Entity *entity_of_node(CheckerInfo *i, Ast *expr) { expr = unparen_expr(expr); switch (expr->kind) { case_ast_node(ident, Ident, expr); return entity_of_ident(expr); case_end; case_ast_node(se, SelectorExpr, expr); - AstNode *s = unselector_expr(se->selector); - if (s->kind == AstNode_Ident) { + Ast *s = unselector_expr(se->selector); + if (s->kind == Ast_Ident) { return entity_of_ident(s); } case_end; @@ -734,7 +734,7 @@ DeclInfo *decl_info_of_entity(Entity *e) { return nullptr; } -DeclInfo *decl_info_of_ident(AstNode *ident) { +DeclInfo *decl_info_of_ident(Ast *ident) { return decl_info_of_entity(entity_of_ident(ident)); } @@ -745,16 +745,16 @@ AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { } return nullptr; } -Scope *scope_of_node(AstNode *node) { +Scope *scope_of_node(Ast *node) { return node->scope; } -ExprInfo *check_get_expr_info(CheckerInfo *i, AstNode *expr) { +ExprInfo *check_get_expr_info(CheckerInfo *i, Ast *expr) { return map_get(&i->untyped, hash_node(expr)); } -void check_set_expr_info(CheckerInfo *i, AstNode *expr, ExprInfo info) { +void check_set_expr_info(CheckerInfo *i, Ast *expr, ExprInfo info) { map_set(&i->untyped, hash_node(expr), info); } -void check_remove_expr_info(CheckerInfo *i, AstNode *expr) { +void check_remove_expr_info(CheckerInfo *i, Ast *expr) { map_remove(&i->untyped, hash_node(expr)); } @@ -794,7 +794,7 @@ isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { } -void add_untyped(CheckerInfo *i, AstNode *expression, bool lhs, AddressingMode mode, Type *type, ExactValue value) { +void add_untyped(CheckerInfo *i, Ast *expression, bool lhs, AddressingMode mode, Type *type, ExactValue value) { if (expression == nullptr) { return; } @@ -807,7 +807,7 @@ void add_untyped(CheckerInfo *i, AstNode *expression, bool lhs, AddressingMode m map_set(&i->untyped, hash_node(expression), make_expr_info(mode, type, value, lhs)); } -void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode, Type *type, ExactValue value) { +void add_type_and_value(CheckerInfo *i, Ast *expression, AddressingMode mode, Type *type, ExactValue value) { if (expression == nullptr) { return; } @@ -825,9 +825,9 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode map_set(&i->types, hash_node(expression), tv); } -void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) { +void add_entity_definition(CheckerInfo *i, Ast *identifier, Entity *entity) { GB_ASSERT(identifier != nullptr); - GB_ASSERT(identifier->kind == AstNode_Ident); + GB_ASSERT(identifier->kind == Ast_Ident); if (is_blank_ident(identifier)) { return; } @@ -842,7 +842,7 @@ void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) array_add(&i->definitions, entity); } -bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) { +bool add_entity(Checker *c, Scope *scope, Ast *identifier, Entity *entity) { if (scope == nullptr) { return false; } @@ -883,12 +883,12 @@ bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) { return true; } -void add_entity_use(CheckerContext *c, AstNode *identifier, Entity *entity) { +void add_entity_use(CheckerContext *c, Ast *identifier, Entity *entity) { if (entity == nullptr) { return; } if (identifier != nullptr) { - if (identifier->kind != AstNode_Ident) { + if (identifier->kind != Ast_Ident) { return; } if (entity->identifier == nullptr) { @@ -906,8 +906,8 @@ void add_entity_use(CheckerContext *c, AstNode *identifier, Entity *entity) { } -void add_entity_and_decl_info(CheckerContext *c, AstNode *identifier, Entity *e, DeclInfo *d) { - GB_ASSERT(identifier->kind == AstNode_Ident); +void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d) { + GB_ASSERT(identifier->kind == Ast_Ident); GB_ASSERT(e != nullptr && d != nullptr); GB_ASSERT(identifier->Ident.token.string == e->token.string); @@ -931,10 +931,10 @@ void add_entity_and_decl_info(CheckerContext *c, AstNode *identifier, Entity *e, } -void add_implicit_entity(CheckerContext *c, AstNode *clause, Entity *e) { +void add_implicit_entity(CheckerContext *c, Ast *clause, Entity *e) { GB_ASSERT(clause != nullptr); GB_ASSERT(e != nullptr); - GB_ASSERT(clause->kind == AstNode_CaseClause); + GB_ASSERT(clause->kind == Ast_CaseClause); clause->CaseClause.implicit_entity = e; } @@ -1098,7 +1098,7 @@ void check_procedure_later(Checker *c, ProcInfo info) { array_add(&c->procs_to_check, info); } -void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *decl, Type *type, AstNode *body, u64 tags) { +void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *decl, Type *type, Ast *body, u64 tags) { ProcInfo info = {}; info.file = file; info.token = token; @@ -1798,7 +1798,7 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) { -void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac) { +void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac) { if (attributes.count == 0) return; String original_link_prefix = {}; @@ -1811,19 +1811,19 @@ void check_decl_attributes(CheckerContext *c, Array const &attributes defer (string_set_destroy(&set)); for_array(i, attributes) { - AstNode *attr = attributes[i]; - if (attr->kind != AstNode_Attribute) continue; + Ast *attr = attributes[i]; + if (attr->kind != Ast_Attribute) continue; for_array(j, attr->Attribute.elems) { - AstNode *elem = attr->Attribute.elems[j]; + Ast *elem = attr->Attribute.elems[j]; String name = {}; - AstNode *value = nullptr; + Ast *value = nullptr; switch (elem->kind) { case_ast_node(i, Ident, elem); name = i->token.string; case_end; case_ast_node(fv, FieldValue, elem); - GB_ASSERT(fv->field->kind == AstNode_Ident); + GB_ASSERT(fv->field->kind == Ast_Ident); name = fv->field->Ident.token.string; value = fv->value; case_end; @@ -1869,7 +1869,7 @@ void check_decl_attributes(CheckerContext *c, Array const &attributes } -bool check_arity_match(CheckerContext *c, AstNodeValueDecl *vd, bool is_global) { +bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global) { isize lhs = vd->names.count; isize rhs = vd->values.count; @@ -1880,7 +1880,7 @@ bool check_arity_match(CheckerContext *c, AstNodeValueDecl *vd, bool is_global) } } else if (lhs < rhs) { if (lhs < vd->values.count) { - AstNode *n = vd->values[lhs]; + Ast *n = vd->values[lhs]; gbString str = expr_to_string(n); error(n, "Extra initial expression '%s'", str); gb_string_free(str); @@ -1890,13 +1890,13 @@ bool check_arity_match(CheckerContext *c, AstNodeValueDecl *vd, bool is_global) return false; } else if (lhs > rhs) { if (!is_global && rhs != 1) { - AstNode *n = vd->names[rhs]; + Ast *n = vd->names[rhs]; gbString str = expr_to_string(n); error(n, "Missing expression for '%s'", str); gb_string_free(str); return false; } else if (is_global) { - AstNode *n = vd->values[rhs-1]; + Ast *n = vd->values[rhs-1]; error(n, "Expected %td expressions on the right hand side, got %td", lhs, rhs); return false; } @@ -1905,7 +1905,7 @@ bool check_arity_match(CheckerContext *c, AstNodeValueDecl *vd, bool is_global) return true; } -void check_collect_entities_from_when_stmt(CheckerContext *c, AstNodeWhenStmt *ws) { +void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws) { Operand operand = {Addressing_Invalid}; if (!ws->is_cond_determined) { check_expr(c, &operand, ws->cond); @@ -1920,17 +1920,17 @@ void check_collect_entities_from_when_stmt(CheckerContext *c, AstNodeWhenStmt *w ws->determined_cond = operand.value.kind == ExactValue_Bool && operand.value.value_bool; } - if (ws->body == nullptr || ws->body->kind != AstNode_BlockStmt) { + if (ws->body == nullptr || ws->body->kind != Ast_BlockStmt) { error(ws->cond, "Invalid body for 'when' statement"); } else { if (ws->determined_cond) { check_collect_entities(c, ws->body->BlockStmt.stmts); } else if (ws->else_stmt) { switch (ws->else_stmt->kind) { - case AstNode_BlockStmt: + case Ast_BlockStmt: check_collect_entities(c, ws->else_stmt->BlockStmt.stmts); break; - case AstNode_WhenStmt: + case Ast_WhenStmt: check_collect_entities_from_when_stmt(c, &ws->else_stmt->WhenStmt); break; default: @@ -1941,7 +1941,7 @@ void check_collect_entities_from_when_stmt(CheckerContext *c, AstNodeWhenStmt *w } } -void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array *attributes) { +void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array *attributes) { switch (e->kind) { case Entity_ProcGroup: case Entity_Procedure: @@ -1956,19 +1956,19 @@ void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array * } for_array(j, *attributes) { - AstNode *attr = (*attributes)[j]; - if (attr->kind != AstNode_Attribute) continue; + Ast *attr = (*attributes)[j]; + if (attr->kind != Ast_Attribute) continue; for (isize k = 0; k < attr->Attribute.elems.count; k++) { - AstNode *elem = attr->Attribute.elems[k]; + Ast *elem = attr->Attribute.elems[k]; String name = {}; - AstNode *value = nullptr; + Ast *value = nullptr; switch (elem->kind) { case_ast_node(i, Ident, elem); name = i->token.string; case_end; case_ast_node(fv, FieldValue, elem); - GB_ASSERT(fv->field->kind == AstNode_Ident); + GB_ASSERT(fv->field->kind == Ast_Ident); name = fv->field->Ident.token.string; value = fv->value; case_end; @@ -1991,8 +1991,8 @@ void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array * } for (isize i = 0; i < attributes->count; i++) { - AstNode *attr = (*attributes)[i]; - if (attr->kind != AstNode_Attribute) continue; + Ast *attr = (*attributes)[i]; + if (attr->kind != Ast_Attribute) continue; if (attr->Attribute.elems.count == 0) { (*attributes)[i] = (*attributes)[attributes->count-1]; attributes->count--; @@ -2001,7 +2001,7 @@ void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array * } } -void check_collect_value_decl(CheckerContext *c, AstNode *decl) { +void check_collect_value_decl(CheckerContext *c, Ast *decl) { if (decl->been_handled) return; decl->been_handled = true; @@ -2027,13 +2027,13 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) { } for_array(i, vd->names) { - AstNode *name = vd->names[i]; - AstNode *value = nullptr; + Ast *name = vd->names[i]; + Ast *value = nullptr; if (i < vd->values.count) { value = vd->values[i]; } - if (name->kind != AstNode_Ident) { - error(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind])); + if (name->kind != Ast_Ident) { + error(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_strings[name->kind])); continue; } Entity *e = alloc_entity_variable(c->scope, name->Ident.token, nullptr, false); @@ -2044,9 +2044,9 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) { error(name, "'using' is not allowed at the file scope"); } - AstNode *fl = c->foreign_context.curr_library; + Ast *fl = c->foreign_context.curr_library; if (fl != nullptr) { - GB_ASSERT(fl->kind == AstNode_Ident); + GB_ASSERT(fl->kind == Ast_Ident); e->Variable.is_foreign = true; e->Variable.foreign_library_ident = fl; @@ -2060,7 +2060,7 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) { DeclInfo *d = di; if (d == nullptr || i > 0) { - AstNode *init_expr = value; + Ast *init_expr = value; d = make_decl_info(heap_allocator(), e->scope, c->decl); d->type_expr = vd->type; d->init_expr = init_expr; @@ -2077,13 +2077,13 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) { check_arity_match(c, vd, true); } else { for_array(i, vd->names) { - AstNode *name = vd->names[i]; - if (name->kind != AstNode_Ident) { - error(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind])); + Ast *name = vd->names[i]; + if (name->kind != Ast_Ident) { + error(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_strings[name->kind])); continue; } - AstNode *init = unparen_expr(vd->values[i]); + Ast *init = unparen_expr(vd->values[i]); if (init == nullptr) { error(name, "Expected a value for this constant value declaration"); continue; @@ -2091,21 +2091,21 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) { Token token = name->Ident.token; - AstNode *fl = c->foreign_context.curr_library; + Ast *fl = c->foreign_context.curr_library; DeclInfo *d = make_decl_info(c->allocator, c->scope, c->decl); Entity *e = nullptr; d->attributes = vd->attributes; - if (is_ast_node_type(init) || - (vd->type != nullptr && vd->type->kind == AstNode_TypeType)) { + if (is_ast_type(init) || + (vd->type != nullptr && vd->type->kind == Ast_TypeType)) { e = alloc_entity_type_name(d->scope, token, nullptr); if (vd->type != nullptr) { error(name, "A type declaration cannot have an type parameter"); } d->type_expr = init; d->init_expr = init; - } else if (init->kind == AstNode_ProcLit) { + } else if (init->kind == Ast_ProcLit) { if (c->scope->is_struct) { error(name, "Procedure declarations are not allowed within a struct"); continue; @@ -2113,11 +2113,11 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) { ast_node(pl, ProcLit, init); e = alloc_entity_procedure(d->scope, token, nullptr, pl->tags); if (fl != nullptr) { - GB_ASSERT(fl->kind == AstNode_Ident); + GB_ASSERT(fl->kind == Ast_Ident); e->Procedure.foreign_library_ident = fl; e->Procedure.is_foreign = true; - GB_ASSERT(pl->type->kind == AstNode_ProcType); + GB_ASSERT(pl->type->kind == Ast_ProcType); auto cc = pl->type->ProcType.calling_convention; if (cc == ProcCC_ForeignBlockDefault) { cc = ProcCC_CDecl; @@ -2135,7 +2135,7 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) { } d->proc_lit = init; d->type_expr = pl->type; - } else if (init->kind == AstNode_ProcGroup) { + } else if (init->kind == Ast_ProcGroup) { ast_node(pg, ProcGroup, init); e = alloc_entity_proc_group(d->scope, token, nullptr); if (fl != nullptr) { @@ -2151,9 +2151,9 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) { if (e->kind != Entity_Procedure) { if (fl != nullptr || c->foreign_context.in_export) { - AstNodeKind kind = init->kind; - error(name, "Only procedures and variables are allowed to be in a foreign block, got %.*s", LIT(ast_node_strings[kind])); - if (kind == AstNode_ProcType) { + AstKind kind = init->kind; + error(name, "Only procedures and variables are allowed to be in a foreign block, got %.*s", LIT(ast_strings[kind])); + if (kind == Ast_ProcType) { gb_printf_err("\tDid you forget to append '---' to the procedure?\n"); } } @@ -2168,17 +2168,17 @@ void check_collect_value_decl(CheckerContext *c, AstNode *decl) { } } -void check_add_foreign_block_decl(CheckerContext *ctx, AstNode *decl) { +void check_add_foreign_block_decl(CheckerContext *ctx, Ast *decl) { if (decl->been_handled) return; decl->been_handled = true; ast_node(fb, ForeignBlockDecl, decl); - AstNode *foreign_library = fb->foreign_library; + Ast *foreign_library = fb->foreign_library; CheckerContext c = *ctx; - if (foreign_library->kind == AstNode_Ident) { + if (foreign_library->kind == Ast_Ident) { c.foreign_context.curr_library = foreign_library; - } else if (foreign_library->kind == AstNode_Implicit && foreign_library->Implicit.kind == Token_export) { + } else if (foreign_library->kind == Ast_Implicit && foreign_library->Implicit.kind == Token_export) { c.foreign_context.in_export = true; } else { error(foreign_library, "Foreign block name must be an identifier or 'export'"); @@ -2193,13 +2193,13 @@ void check_add_foreign_block_decl(CheckerContext *ctx, AstNode *decl) { } // NOTE(bill): If file_scopes == nullptr, this will act like a local scope -void check_collect_entities(CheckerContext *c, Array const &nodes) { +void check_collect_entities(CheckerContext *c, Array const &nodes) { for_array(decl_index, nodes) { - AstNode *decl = nodes[decl_index]; - if (!is_ast_node_decl(decl) && !is_ast_node_when_stmt(decl)) { - if (c->scope->is_file && decl->kind == AstNode_ExprStmt) { - AstNode *expr = decl->ExprStmt.expr; - if (expr->kind == AstNode_CallExpr && expr->CallExpr.proc->kind == AstNode_BasicDirective) { + Ast *decl = nodes[decl_index]; + if (!is_ast_decl(decl) && !is_ast_when_stmt(decl)) { + if (c->scope->is_file && decl->kind == Ast_ExprStmt) { + Ast *expr = decl->ExprStmt.expr; + if (expr->kind == Ast_CallExpr && expr->CallExpr.proc->kind == Ast_BasicDirective) { if (c->collect_delayed_decls) { array_add(&c->scope->delayed_directives, expr); } @@ -2259,7 +2259,7 @@ void check_collect_entities(CheckerContext *c, Array const &nodes) { // declared after this stmt in source if (!c->scope->is_file || c->collect_delayed_decls) { for_array(i, nodes) { - AstNode *node = nodes[i]; + Ast *node = nodes[i]; switch (node->kind) { case_ast_node(ws, WhenStmt, node); check_collect_entities_from_when_stmt(c, ws); @@ -2378,7 +2378,7 @@ String path_to_entity_name(String name, String fullpath) { #if 1 -void add_import_dependency_node(Checker *c, AstNode *decl, Map *M) { +void add_import_dependency_node(Checker *c, Ast *decl, Map *M) { AstPackage *parent_pkg = decl->file->pkg; switch (decl->kind) { @@ -2391,7 +2391,7 @@ void add_import_dependency_node(Checker *c, AstNode *decl, Mapinfo.packages.entries[pkg_index].value; gb_printf_err("%.*s\n", LIT(pkg->fullpath)); } - Token token = ast_node_token(decl); + Token token = ast_token(decl); gb_printf_err("%.*s(%td:%td)\n", LIT(token.pos.file), token.pos.line, token.pos.column); GB_PANIC("Unable to find package: %.*s", LIT(path)); } @@ -2428,7 +2428,7 @@ void add_import_dependency_node(Checker *c, AstNode *decl, Mapelse_stmt != nullptr) { switch (ws->else_stmt->kind) { - case AstNode_BlockStmt: { + case Ast_BlockStmt: { auto stmts = ws->else_stmt->BlockStmt.stmts; for_array(i, stmts) { add_import_dependency_node(c, stmts[i], M); @@ -2436,7 +2436,7 @@ void add_import_dependency_node(Checker *c, AstNode *decl, Mapelse_stmt, M); break; } @@ -2462,7 +2462,7 @@ Array generate_import_dependency_graph(Checker *c) { for_array(j, p->files) { AstFile *f = p->files[j]; for_array(k, f->decls) { - AstNode *decl = f->decls[k]; + Ast *decl = f->decls[k]; add_import_dependency_node(c, decl, &M); } } @@ -2484,7 +2484,7 @@ Array generate_import_dependency_graph(Checker *c) { struct ImportPathItem { AstPackage *pkg; - AstNode * decl; + Ast * decl; }; Array find_import_path(Checker *c, AstPackage *start, AstPackage *end, PtrSet *visited) { @@ -2507,8 +2507,8 @@ Array find_import_path(Checker *c, AstPackage *start, AstPackage AstFile *f = pkg->files[i]; for_array(j, f->imports) { AstPackage *pkg = nullptr; - AstNode *decl = f->imports[j]; - if (decl->kind == AstNode_ImportDecl) { + Ast *decl = f->imports[j]; + if (decl->kind == Ast_ImportDecl) { pkg = decl->ImportDecl.package; } else { continue; @@ -2537,7 +2537,7 @@ Array find_import_path(Checker *c, AstPackage *start, AstPackage return empty_path; } #endif -void check_add_import_decl(CheckerContext *ctx, AstNode *decl) { +void check_add_import_decl(CheckerContext *ctx, Ast *decl) { if (decl->been_handled) return; decl->been_handled = true; @@ -2624,7 +2624,7 @@ void check_add_import_decl(CheckerContext *ctx, AstNode *decl) { } -void check_add_foreign_import_decl(CheckerContext *ctx, AstNode *decl) { +void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) { if (decl->been_handled) return; decl->been_handled = true; @@ -2667,10 +2667,10 @@ void check_add_foreign_import_decl(CheckerContext *ctx, AstNode *decl) { add_entity(ctx->checker, parent_scope, nullptr, e); } -bool collect_checked_packages_from_decl_list(Checker *c, Array const &decls) { +bool collect_checked_packages_from_decl_list(Checker *c, Array const &decls) { bool new_files = false; for_array(i, decls) { - AstNode *decl = decls[i]; + Ast *decl = decls[i]; switch (decl->kind) { case_ast_node(id, ImportDecl, decl); HashKey key = hash_string(id->fullpath); @@ -2690,10 +2690,10 @@ bool collect_checked_packages_from_decl_list(Checker *c, Array const } // Returns true if a new package is present -bool collect_file_decls(CheckerContext *ctx, Array const &decls); -bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstNodeWhenStmt *ws); +bool collect_file_decls(CheckerContext *ctx, Array const &decls); +bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws); -bool collect_when_stmt_from_file(CheckerContext *ctx, AstNodeWhenStmt *ws) { +bool collect_when_stmt_from_file(CheckerContext *ctx, AstWhenStmt *ws) { Operand operand = {Addressing_Invalid}; if (!ws->is_cond_determined) { check_expr(ctx, &operand, ws->cond); @@ -2708,16 +2708,16 @@ bool collect_when_stmt_from_file(CheckerContext *ctx, AstNodeWhenStmt *ws) { ws->determined_cond = operand.value.kind == ExactValue_Bool && operand.value.value_bool; } - if (ws->body == nullptr || ws->body->kind != AstNode_BlockStmt) { + if (ws->body == nullptr || ws->body->kind != Ast_BlockStmt) { error(ws->cond, "Invalid body for 'when' statement"); } else { if (ws->determined_cond) { return collect_checked_packages_from_decl_list(ctx->checker, ws->body->BlockStmt.stmts); } else if (ws->else_stmt) { switch (ws->else_stmt->kind) { - case AstNode_BlockStmt: + case Ast_BlockStmt: return collect_checked_packages_from_decl_list(ctx->checker, ws->else_stmt->BlockStmt.stmts); - case AstNode_WhenStmt: + case Ast_WhenStmt: return collect_when_stmt_from_file(ctx, &ws->else_stmt->WhenStmt); default: error(ws->else_stmt, "Invalid 'else' statement in 'when' statement"); @@ -2729,7 +2729,7 @@ bool collect_when_stmt_from_file(CheckerContext *ctx, AstNodeWhenStmt *ws) { return false; } -bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstNodeWhenStmt *ws) { +bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws) { Operand operand = {Addressing_Invalid}; if (!ws->is_cond_determined) { check_expr(ctx, &operand, ws->cond); @@ -2744,16 +2744,16 @@ bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstNodeWhenStmt *ws) ws->determined_cond = operand.value.kind == ExactValue_Bool && operand.value.value_bool; } - if (ws->body == nullptr || ws->body->kind != AstNode_BlockStmt) { + if (ws->body == nullptr || ws->body->kind != Ast_BlockStmt) { error(ws->cond, "Invalid body for 'when' statement"); } else { if (ws->determined_cond) { return collect_file_decls(ctx, ws->body->BlockStmt.stmts); } else if (ws->else_stmt) { switch (ws->else_stmt->kind) { - case AstNode_BlockStmt: + case Ast_BlockStmt: return collect_file_decls(ctx, ws->else_stmt->BlockStmt.stmts); - case AstNode_WhenStmt: + case Ast_WhenStmt: return collect_file_decls_from_when_stmt(ctx, &ws->else_stmt->WhenStmt); default: error(ws->else_stmt, "Invalid 'else' statement in 'when' statement"); @@ -2765,7 +2765,7 @@ bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstNodeWhenStmt *ws) return false; } -bool collect_file_decls(CheckerContext *ctx, Array const &decls) { +bool collect_file_decls(CheckerContext *ctx, Array const &decls) { GB_ASSERT(ctx->scope->is_file); if (collect_checked_packages_from_decl_list(ctx->checker, decls)) { @@ -2773,7 +2773,7 @@ bool collect_file_decls(CheckerContext *ctx, Array const &decls) { } for_array(i, decls) { - AstNode *decl = decls[i]; + Ast *decl = decls[i]; switch (decl->kind) { case_ast_node(vd, ValueDecl, decl); check_collect_value_decl(ctx, decl); @@ -2814,7 +2814,7 @@ bool collect_file_decls(CheckerContext *ctx, Array const &decls) { case_end; case_ast_node(ce, CallExpr, decl); - if (ce->proc->kind == AstNode_BasicDirective) { + if (ce->proc->kind == Ast_BasicDirective) { Operand o = {}; check_expr(ctx, &o, decl); } @@ -2975,11 +2975,11 @@ void check_import_entities(Checker *c) { add_curr_ast_file(&ctx, f); for_array(j, f->scope->delayed_imports) { - AstNode *decl = f->scope->delayed_imports[j]; + Ast *decl = f->scope->delayed_imports[j]; check_add_import_decl(&ctx, decl); } for_array(j, f->scope->delayed_directives) { - AstNode *expr = f->scope->delayed_directives[j]; + Ast *expr = f->scope->delayed_directives[j]; Operand o = {}; check_expr(&ctx, &o, expr); } @@ -3139,7 +3139,7 @@ void check_proc_info(Checker *c, ProcInfo pi) { if (pt->is_polymorphic && !pt->is_poly_specialized) { Token token = pi.token; if (pi.poly_def_node != nullptr) { - token = ast_node_token(pi.poly_def_node); + token = ast_token(pi.poly_def_node); } error(token, "Unspecialized polymorphic procedure '%.*s'", LIT(name)); return; @@ -3260,7 +3260,7 @@ void check_parsed_files(Checker *c) { for_array(i, c->info.untyped.entries) { auto *entry = &c->info.untyped.entries[i]; HashKey key = entry->key; - AstNode *expr = cast(AstNode *)key.ptr; + Ast *expr = cast(Ast *)key.ptr; ExprInfo *info = &entry->value; if (info != nullptr && expr != nullptr) { if (is_type_typed(info->type)) { diff --git a/src/checker.hpp b/src/checker.hpp index 4ead1c6cc..4defc7d31 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -167,7 +167,7 @@ struct Operand { AddressingMode mode; Type * type; ExactValue value; - AstNode * expr; + Ast * expr; BuiltinProcId builtin_id; Entity * proc_group; }; @@ -175,7 +175,7 @@ struct Operand { struct BlockLabel { String name; - AstNode *label; // AstNode_Label; + Ast *label; // Ast_Label; }; struct AttributeContext { @@ -192,10 +192,10 @@ AttributeContext make_attribute_context(String link_prefix) { return ac; } -#define DECL_ATTRIBUTE_PROC(_name) bool _name(CheckerContext *c, AstNode *elem, String name, ExactValue value, AttributeContext *ac) +#define DECL_ATTRIBUTE_PROC(_name) bool _name(CheckerContext *c, Ast *elem, String name, ExactValue value, AttributeContext *ac) typedef DECL_ATTRIBUTE_PROC(DeclAttributeProc); -void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac); +void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac); // DeclInfo is used to store information of certain declarations to allow for "any order" usage @@ -206,11 +206,11 @@ struct DeclInfo { Entity ** entities; isize entity_count; - AstNode * type_expr; - AstNode * init_expr; - Array init_expr_list; - Array attributes; - AstNode * proc_lit; // AstNode_ProcLit + Ast * type_expr; + Ast * init_expr; + Array init_expr_list; + Array attributes; + Ast * proc_lit; // Ast_ProcLit Type * gen_proc_type; // Precalculated PtrSet deps; @@ -224,16 +224,16 @@ struct ProcInfo { Token token; DeclInfo *decl; Type * type; // Type_Procedure - AstNode * body; // AstNode_BlockStmt + Ast * body; // Ast_BlockStmt u64 tags; bool generated_from_polymorphic; - AstNode * poly_def_node; + Ast * poly_def_node; }; struct Scope { - AstNode * node; + Ast * node; Scope * parent; Scope * prev, *next; Scope * first_child; @@ -242,8 +242,8 @@ struct Scope { PtrSet implicit; // Scope * shared; - Array delayed_directives; - Array delayed_imports; + Array delayed_directives; + Array delayed_imports; PtrSet imported; bool is_proc; bool is_global; @@ -290,7 +290,7 @@ struct ImportGraphNode { struct ForeignContext { - AstNode * curr_library; + Ast * curr_library; ProcCallingConvention default_cc; String link_prefix; bool in_export; @@ -301,8 +301,8 @@ typedef Array CheckerPolyPath; // CheckerInfo stores all the symbol information for a type-checked program struct CheckerInfo { - Map types; // Key: AstNode * | Expression -> Type (and value) - Map untyped; // Key: AstNode * | Expression -> ExprInfo + Map types; // Key: Ast * | Expression -> Type (and value) + Map untyped; // Key: Ast * | Expression -> ExprInfo Map files; // Key: String (full path) Map packages; // Key: String (full path) Map foreigns; // Key: String @@ -310,7 +310,7 @@ struct CheckerInfo { Array entities; Array variable_init_order; - Map > gen_procs; // Key: AstNode * | Identifier -> Entity + Map > gen_procs; // Key: Ast * | Identifier -> Entity Map > gen_types; // Key: Type * Array type_info_types; @@ -368,7 +368,7 @@ struct Checker { -HashKey hash_node (AstNode *node) { return hash_pointer(node); } +HashKey hash_node (Ast *node) { return hash_pointer(node); } HashKey hash_ast_file (AstFile *file) { return hash_pointer(file); } HashKey hash_entity (Entity *e) { return hash_pointer(e); } HashKey hash_type (Type *t) { return hash_pointer(t); } @@ -377,19 +377,19 @@ HashKey hash_decl_info(DeclInfo *decl) { return hash_pointer(decl); } // CheckerInfo API -TypeAndValue type_and_value_of_expr (CheckerInfo *i, AstNode *expr); -Type * type_of_expr (CheckerInfo *i, AstNode *expr); -Entity * entity_of_ident (AstNode *identifier); -Entity * implicit_entity_of_node(CheckerInfo *i, AstNode *clause); -Scope * scope_of_node (AstNode *node); -DeclInfo * decl_info_of_ident (AstNode *ident); +TypeAndValue type_and_value_of_expr (CheckerInfo *i, Ast *expr); +Type * type_of_expr (CheckerInfo *i, Ast *expr); +Entity * entity_of_ident (Ast *identifier); +Entity * implicit_entity_of_node(CheckerInfo *i, Ast *clause); +Scope * scope_of_node (Ast *node); +DeclInfo * decl_info_of_ident (Ast *ident); DeclInfo * decl_info_of_entity (Entity * e); AstFile * ast_file_of_filename (CheckerInfo *i, String filename); // IMPORTANT: Only to use once checking is done isize type_info_index (CheckerInfo *i, Type * type, bool error_on_failure = true); // Will return nullptr if not found -Entity *entity_of_node(CheckerInfo *i, AstNode *expr); +Entity *entity_of_node(CheckerInfo *i, Ast *expr); Entity *scope_lookup_current(Scope *s, String name); @@ -398,24 +398,24 @@ void scope_lookup_parent (Scope *s, String name, Scope **scope_, Entity **ent Entity *scope_insert (Scope *s, Entity *entity); -ExprInfo *check_get_expr_info (CheckerInfo *i, AstNode *expr); -void check_set_expr_info (CheckerInfo *i, AstNode *expr, ExprInfo info); -void check_remove_expr_info (CheckerInfo *i, AstNode *expr); -void add_untyped (CheckerInfo *i, AstNode *expression, bool lhs, AddressingMode mode, Type *basic_type, ExactValue value); -void add_type_and_value (CheckerInfo *i, AstNode *expression, AddressingMode mode, Type *type, ExactValue value); -void add_entity_use (CheckerContext *c, AstNode *identifier, Entity *entity); -void add_implicit_entity (CheckerContext *c, AstNode *node, Entity *e); -void add_entity_and_decl_info(CheckerContext *c, AstNode *identifier, Entity *e, DeclInfo *d); +ExprInfo *check_get_expr_info (CheckerInfo *i, Ast *expr); +void check_set_expr_info (CheckerInfo *i, Ast *expr, ExprInfo info); +void check_remove_expr_info (CheckerInfo *i, Ast *expr); +void add_untyped (CheckerInfo *i, Ast *expression, bool lhs, AddressingMode mode, Type *basic_type, ExactValue value); +void add_type_and_value (CheckerInfo *i, Ast *expression, AddressingMode mode, Type *type, ExactValue value); +void add_entity_use (CheckerContext *c, Ast *identifier, Entity *entity); +void add_implicit_entity (CheckerContext *c, Ast *node, Entity *e); +void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d); void add_type_info_type (CheckerContext *c, Type *t); -void check_add_import_decl(CheckerContext *c, AstNode *decl); -void check_add_foreign_import_decl(CheckerContext *c, AstNode *decl); +void check_add_import_decl(CheckerContext *c, Ast *decl); +void check_add_foreign_import_decl(CheckerContext *c, Ast *decl); -bool check_arity_match(CheckerContext *c, AstNodeValueDecl *vd, bool is_global = false); -void check_collect_entities(CheckerContext *c, Array const &nodes); -void check_collect_entities_from_when_stmt(CheckerContext *c, AstNodeWhenStmt *ws); -void check_delayed_file_import_entity(CheckerContext *c, AstNode *decl); +bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global = false); +void check_collect_entities(CheckerContext *c, Array const &nodes); +void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws); +void check_delayed_file_import_entity(CheckerContext *c, Ast *decl); CheckerTypePath *new_checker_type_path(); void destroy_checker_type_path(CheckerTypePath *tp); diff --git a/src/docs.cpp b/src/docs.cpp index bfc34232e..3bc0da649 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -1,6 +1,6 @@ // Generates Documentation -gbString expr_to_string(AstNode *expression); +gbString expr_to_string(Ast *expression); String alloc_comment_group_string(gbAllocator a, CommentGroup g) { isize len = 0; @@ -33,9 +33,9 @@ String alloc_comment_group_string(gbAllocator a, CommentGroup g) { } #if 0 -void print_type_spec(AstNode *spec) { +void print_type_spec(Ast *spec) { ast_node(ts, TypeSpec, spec); - GB_ASSERT(ts->name->kind == AstNode_Ident); + GB_ASSERT(ts->name->kind == Ast_Ident); String name = ts->name->Ident.string; if (name.len == 0) { return; @@ -46,8 +46,8 @@ void print_type_spec(AstNode *spec) { gb_printf("type %.*s\n", LIT(name)); } -void print_proc_decl(AstNodeProcDecl *pd) { - GB_ASSERT(pd->name->kind == AstNode_Ident); +void print_proc_decl(AstProcDecl *pd) { + GB_ASSERT(pd->name->kind == Ast_Ident); String name = pd->name->Ident.string; if (name.len == 0) { return; @@ -89,7 +89,7 @@ void print_proc_decl(AstNodeProcDecl *pd) { gb_printf("\n\n"); } #endif -void print_declaration(AstNode *decl) { +void print_declaration(Ast *decl) { } void generate_documentation(Parser *parser) { @@ -100,7 +100,7 @@ void generate_documentation(Parser *parser) { // gb_printf("%.*s\n", LIT(fullpath)); // for_array(decl_index, file->decls) { - // AstNode *decl = file->decls[decl_index]; + // Ast *decl = file->decls[decl_index]; // print_declaration(decl); // } // } diff --git a/src/entity.cpp b/src/entity.cpp index 2c0b99931..37bafc7d3 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -65,14 +65,14 @@ struct Entity { Token token; Scope * scope; Type * type; - AstNode * identifier; // Can be nullptr + Ast * identifier; // Can be nullptr DeclInfo * decl_info; DeclInfo * parent_proc_decl; // nullptr if in file/global scope AstPackage *pkg; // TODO(bill): Cleanup how `using` works for entities Entity * using_parent; - AstNode * using_expr; + Ast * using_expr; isize order_in_src; String deprecated_message; @@ -87,7 +87,7 @@ struct Entity { ExactValue default_value; String thread_local_model; Entity * foreign_library; - AstNode * foreign_library_ident; + Ast * foreign_library_ident; String link_name; String link_prefix; bool is_foreign; @@ -106,7 +106,7 @@ struct Entity { struct { u64 tags; Entity * foreign_library; - AstNode * foreign_library_ident; + Ast * foreign_library_ident; String link_name; String link_prefix; bool is_foreign; @@ -130,7 +130,7 @@ struct Entity { i32 Nil; struct { String name; - AstNode *node; + Ast *node; } Label; }; }; @@ -295,7 +295,7 @@ Entity *alloc_entity_nil(String name, Type *type) { return entity; } -Entity *alloc_entity_label(Scope *scope, Token token, Type *type, AstNode *node) { +Entity *alloc_entity_label(Scope *scope, Token token, Type *type, Ast *node) { Entity *entity = alloc_entity(Entity_Label, scope, token, type); entity->Label.node = node; entity->state = EntityState_Resolved; diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 7012d4db5..1f07e2ee6 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -3,7 +3,7 @@ // TODO(bill): Big numbers // IMPORTANT TODO(bill): This needs to be completely fixed!!!!!!!! -struct AstNode; +struct Ast; struct HashKey; struct Type; struct Entity; @@ -37,8 +37,8 @@ struct ExactValue { f64 value_float; i64 value_pointer; Complex128 value_complex; - AstNode * value_compound; - AstNode * value_procedure; + Ast * value_compound; + Ast * value_procedure; Entity * value_entity; }; }; @@ -73,7 +73,7 @@ HashKey hash_exact_value(ExactValue v) { } -ExactValue exact_value_compound(AstNode *node) { +ExactValue exact_value_compound(Ast *node) { ExactValue result = {ExactValue_Compound}; result.value_compound = node; return result; @@ -123,7 +123,7 @@ ExactValue exact_value_pointer(i64 ptr) { return result; } -ExactValue exact_value_procedure(AstNode *node) { +ExactValue exact_value_procedure(Ast *node) { ExactValue result = {ExactValue_Procedure}; result.value_procedure = node; return result; diff --git a/src/ir.cpp b/src/ir.cpp index 8eed0dc02..3ec4e5c37 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -24,7 +24,7 @@ struct irModule { Map members; // Key: String Map entity_names; // Key: Entity * of the typename Map debug_info; // Key: Unique pointer - Map anonymous_proc_lits; // Key: AstNode * + Map anonymous_proc_lits; // Key: Ast * irDebugInfo * debug_compile_unit; @@ -60,7 +60,7 @@ struct irBlock { i32 index; String label; irProcedure *proc; - AstNode * node; // Can be nullptr + Ast * node; // Can be nullptr Scope * scope; isize scope_index; irDomNode dom; @@ -95,7 +95,7 @@ struct irDefer { isize scope_index; irBlock * block; union { - AstNode *stmt; + Ast *stmt; // NOTE(bill): 'instr' will be copied every time to create a new one irValue *instr; }; @@ -103,7 +103,7 @@ struct irDefer { struct irBranchBlocks { - AstNode *label; + Ast *label; irBlock *break_; irBlock *continue_; }; @@ -122,8 +122,8 @@ struct irProcedure { irModule * module; String name; Type * type; - AstNode * type_expr; - AstNode * body; + Ast * type_expr; + Ast * body; u64 tags; ProcInlining inlining; bool is_foreign; @@ -244,7 +244,7 @@ struct irProcedure { IR_INSTR_KIND(StartupRuntime, i32) \ IR_INSTR_KIND(DebugDeclare, struct { \ irDebugInfo *scope; \ - AstNode * expr; \ + Ast * expr; \ Entity * entity; \ bool is_addr; \ irValue * value; \ @@ -758,7 +758,7 @@ Array *ir_value_referrers(irValue *v) { //////////////////////////////////////////////////////////////// void ir_module_add_value (irModule *m, Entity *e, irValue *v); -void ir_emit_zero_init (irProcedure *p, irValue *address, AstNode *expr); +void ir_emit_zero_init (irProcedure *p, irValue *address, Ast *expr); irValue *ir_emit_comment (irProcedure *p, String text); irValue *ir_emit_store (irProcedure *p, irValue *address, irValue *value); irValue *ir_emit_load (irProcedure *p, irValue *address); @@ -766,11 +766,11 @@ void ir_emit_jump (irProcedure *proc, irBlock *block); irValue *ir_emit_conv (irProcedure *proc, irValue *value, Type *t); irValue *ir_type_info (irProcedure *proc, Type *type); irValue *ir_typeid (irModule *m, Type *type); -irValue *ir_build_expr (irProcedure *proc, AstNode *expr); -void ir_build_stmt (irProcedure *proc, AstNode *node); -irValue *ir_build_cond (irProcedure *proc, AstNode *cond, irBlock *true_block, irBlock *false_block); +irValue *ir_build_expr (irProcedure *proc, Ast *expr); +void ir_build_stmt (irProcedure *proc, Ast *node); +irValue *ir_build_cond (irProcedure *proc, Ast *cond, irBlock *true_block, irBlock *false_block); void ir_build_defer_stmt (irProcedure *proc, irDefer d); -irAddr ir_build_addr (irProcedure *proc, AstNode *expr); +irAddr ir_build_addr (irProcedure *proc, Ast *expr); void ir_build_proc (irValue *value, irProcedure *parent); void ir_gen_global_type_name(irModule *m, Entity *e, String name); irValue *ir_get_type_info_ptr (irProcedure *proc, Type *type); @@ -1081,7 +1081,7 @@ irValue *ir_instr_comment(irProcedure *p, String text) { return v; } -irValue *ir_instr_debug_declare(irProcedure *p, irDebugInfo *scope, AstNode *expr, Entity *entity, bool is_addr, irValue *value) { +irValue *ir_instr_debug_declare(irProcedure *p, irDebugInfo *scope, Ast *expr, Entity *entity, bool is_addr, irValue *value) { irValue *v = ir_alloc_instr(p, irInstr_DebugDeclare); v->Instr.DebugDeclare.scope = scope; v->Instr.DebugDeclare.expr = expr; @@ -1159,7 +1159,7 @@ irValue *ir_const_string(gbAllocator a, String s) { return ir_value_constant(a, t_string, exact_value_string(s)); } -irValue *ir_value_procedure(gbAllocator a, irModule *m, Entity *entity, Type *type, AstNode *type_expr, AstNode *body, String name) { +irValue *ir_value_procedure(gbAllocator a, irModule *m, Entity *entity, Type *type, Ast *type_expr, Ast *body, String name) { irValue *v = ir_alloc_value(a, irValue_Proc); v->Proc.module = m; v->Proc.entity = entity; @@ -1196,11 +1196,11 @@ irValue *ir_generate_array(irModule *m, Type *elem_type, i64 count, String prefi return value; } -irBlock *ir_new_block(irProcedure *proc, AstNode *node, char *label) { +irBlock *ir_new_block(irProcedure *proc, Ast *node, char *label) { Scope *scope = nullptr; if (node != nullptr) { scope = scope_of_node(node); - GB_ASSERT_MSG(scope != nullptr, "Block scope not found for %.*s", LIT(ast_node_strings[node->kind])); + GB_ASSERT_MSG(scope != nullptr, "Block scope not found for %.*s", LIT(ast_strings[node->kind])); } irValue *v = ir_alloc_value(proc->module->allocator, irValue_Block); @@ -1244,7 +1244,7 @@ void ir_start_block(irProcedure *proc, irBlock *block) { -irDefer ir_add_defer_node(irProcedure *proc, isize scope_index, AstNode *stmt) { +irDefer ir_add_defer_node(irProcedure *proc, isize scope_index, Ast *stmt) { irDefer d = {irDefer_Node}; d.scope_index = scope_index; d.block = proc->curr_block; @@ -1355,7 +1355,7 @@ void ir_add_foreign_library_path(irModule *m, Entity *e) { -irValue *ir_add_local(irProcedure *proc, Entity *e, AstNode *expr, bool zero_initialized) { +irValue *ir_add_local(irProcedure *proc, Entity *e, Ast *expr, bool zero_initialized) { irBlock *b = proc->decl_block; // all variables must be in the first block irValue *instr = ir_instr_local(proc, e, true); instr->Instr.block = b; @@ -1375,7 +1375,7 @@ irValue *ir_add_local(irProcedure *proc, Entity *e, AstNode *expr, bool zero_ini return instr; } -irValue *ir_add_local_for_identifier(irProcedure *proc, AstNode *ident, bool zero_initialized) { +irValue *ir_add_local_for_identifier(irProcedure *proc, Ast *ident, bool zero_initialized) { Entity *e = entity_of_ident(ident); if (e != nullptr) { String name = e->token.string; @@ -1436,7 +1436,7 @@ irValue *ir_add_global_generated(irModule *m, Type *type, irValue *value) { } -irValue *ir_add_param(irProcedure *proc, Entity *e, AstNode *expr, Type *abi_type) { +irValue *ir_add_param(irProcedure *proc, Entity *e, Ast *expr, Type *abi_type) { irValue *v = ir_value_param(proc->module->allocator, proc, e, abi_type); irValueParam *p = &v->Param; @@ -1534,8 +1534,8 @@ irDebugInfo *ir_add_debug_info_proc(irProcedure *proc, Entity *entity, String na // //////////////////////////////////////////////////////////////// -irValue *ir_emit_runtime_call (irProcedure *proc, char const *name_, Array args, AstNode *expr = nullptr); -irValue *ir_emit_package_call(irProcedure *proc, char const *package_name_, char const *name_, Array args, AstNode *expr = nullptr); +irValue *ir_emit_runtime_call (irProcedure *proc, char const *name_, Array args, Ast *expr = nullptr); +irValue *ir_emit_package_call(irProcedure *proc, char const *package_name_, char const *name_, Array args, Ast *expr = nullptr); irValue *ir_emit_store(irProcedure *p, irValue *address, irValue *value) { @@ -1564,14 +1564,14 @@ irValue *ir_emit_select(irProcedure *p, irValue *cond, irValue *t, irValue *f) { return ir_emit(p, ir_instr_select(p, cond, t, f)); } -void ir_add_debug_location_to_value(irProcedure *proc, irValue *v, AstNode *e) { +void ir_add_debug_location_to_value(irProcedure *proc, irValue *v, Ast *e) { if (v != nullptr && e != nullptr) { v->loc.debug_scope = proc->debug_scope; - v->loc.pos = ast_node_token(e).pos; + v->loc.pos = ast_token(e).pos; } } -void ir_emit_zero_init(irProcedure *p, irValue *address, AstNode *expr) { +void ir_emit_zero_init(irProcedure *p, irValue *address, Ast *expr) { gbAllocator a = p->module->allocator; Type *t = type_deref(ir_type(address)); auto args = array_make(a, 2); @@ -1702,7 +1702,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array args) { return result; } -irValue *ir_emit_runtime_call(irProcedure *proc, char const *name_, Array args, AstNode *expr) { +irValue *ir_emit_runtime_call(irProcedure *proc, char const *name_, Array args, Ast *expr) { String name = make_string_c(cast(char *)name_); AstPackage *p = proc->module->info->runtime_package; @@ -1714,7 +1714,7 @@ irValue *ir_emit_runtime_call(irProcedure *proc, char const *name_, Array args, AstNode *expr) { +irValue *ir_emit_package_call(irProcedure *proc, char const *package_name_, char const *name_, Array args, Ast *expr) { String name = make_string_c(cast(char *)name_); String package_name = make_string_c(cast(char *)package_name_); @@ -1921,7 +1921,7 @@ Type *ir_addr_type(irAddr const &addr) { } irValue *ir_emit_source_code_location(irProcedure *proc, String procedure, TokenPos pos); -irValue *ir_emit_source_code_location(irProcedure *proc, AstNode *node); +irValue *ir_emit_source_code_location(irProcedure *proc, Ast *node); irValue *ir_emit_ptr_offset(irProcedure *proc, irValue *ptr, irValue *offset); irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *right, Type *type); @@ -2147,7 +2147,7 @@ irValue *ir_addr_get_ptr(irProcedure *proc, irAddr const &addr) { return addr.addr; } -irValue *ir_build_addr_ptr(irProcedure *proc, AstNode *expr) { +irValue *ir_build_addr_ptr(irProcedure *proc, Ast *expr) { irAddr const &addr = ir_build_addr(proc, expr); return ir_addr_get_ptr(proc, addr); } @@ -3628,7 +3628,7 @@ irValue *ir_typeid(irModule *m, Type *type) { } -irValue *ir_emit_logical_binary_expr(irProcedure *proc, TokenKind op, AstNode *left, AstNode *right, Type *type) { +irValue *ir_emit_logical_binary_expr(irProcedure *proc, TokenKind op, Ast *left, Ast *right, Type *type) { irBlock *rhs = ir_new_block(proc, nullptr, "logical.cmp.rhs"); irBlock *done = ir_new_block(proc, nullptr, "logical.cmp.done"); @@ -3666,7 +3666,7 @@ irValue *ir_emit_logical_binary_expr(irProcedure *proc, TokenKind op, AstNode *l return ir_emit(proc, ir_instr_phi(proc, edges, type)); } -irValue *ir_emit_logical_binary_expr(irProcedure *proc, AstNode *expr) { +irValue *ir_emit_logical_binary_expr(irProcedure *proc, Ast *expr) { ast_node(be, BinaryExpr, expr); irBlock *rhs = ir_new_block(proc, nullptr, "logical.cmp.rhs"); irBlock *done = ir_new_block(proc, nullptr, "logical.cmp.done"); @@ -3874,8 +3874,8 @@ void ir_mangle_add_sub_type_name(irModule *m, Entity *field, String parent) { } -irBranchBlocks ir_lookup_branch_blocks(irProcedure *proc, AstNode *ident) { - GB_ASSERT(ident->kind == AstNode_Ident); +irBranchBlocks ir_lookup_branch_blocks(irProcedure *proc, Ast *ident) { + GB_ASSERT(ident->kind == Ast_Ident); Entity *e = entity_of_ident(ident); GB_ASSERT(e->kind == Entity_Label); for_array(i, proc->branch_blocks) { @@ -3891,7 +3891,7 @@ irBranchBlocks ir_lookup_branch_blocks(irProcedure *proc, AstNode *ident) { } -void ir_push_target_list(irProcedure *proc, AstNode *label, irBlock *break_, irBlock *continue_, irBlock *fallthrough_) { +void ir_push_target_list(irProcedure *proc, Ast *label, irBlock *break_, irBlock *continue_, irBlock *fallthrough_) { irTargetList *tl = gb_alloc_item(proc->module->allocator, irTargetList); tl->prev = proc->target_list; tl->break_ = break_; @@ -3900,12 +3900,12 @@ void ir_push_target_list(irProcedure *proc, AstNode *label, irBlock *break_, irB proc->target_list = tl; if (label != nullptr) { // Set label blocks - GB_ASSERT(label->kind == AstNode_Label); + GB_ASSERT(label->kind == Ast_Label); for_array(i, proc->branch_blocks) { irBranchBlocks *b = &proc->branch_blocks[i]; GB_ASSERT(b->label != nullptr && label != nullptr); - GB_ASSERT(b->label->kind == AstNode_Label); + GB_ASSERT(b->label->kind == Ast_Label); if (b->label == label) { b->break_ = break_; b->continue_ = continue_; @@ -3923,7 +3923,7 @@ void ir_pop_target_list(irProcedure *proc) { -irValue *ir_gen_anonymous_proc_lit(irModule *m, String prefix_name, AstNode *expr, irProcedure *proc = nullptr) { +irValue *ir_gen_anonymous_proc_lit(irModule *m, String prefix_name, Ast *expr, irProcedure *proc = nullptr) { ast_node(pl, ProcLit, expr); // NOTE(bill): Generate a new name @@ -4095,7 +4095,7 @@ irValue *ir_find_global_variable(irProcedure *proc, String name) { return *value; } -void ir_build_stmt_list(irProcedure *proc, Array stmts); +void ir_build_stmt_list(irProcedure *proc, Array stmts); bool is_double_pointer(Type *t) { @@ -4121,14 +4121,14 @@ irValue *ir_emit_source_code_location(irProcedure *proc, String procedure, Token } -irValue *ir_emit_source_code_location(irProcedure *proc, AstNode *node) { +irValue *ir_emit_source_code_location(irProcedure *proc, Ast *node) { String proc_name = {}; if (proc->entity) { proc_name = proc->entity->token.string; } TokenPos pos = {}; if (node) { - pos = ast_node_token(node).pos; + pos = ast_token(node).pos; } return ir_emit_source_code_location(proc, proc_name, pos); } @@ -4140,7 +4140,7 @@ void ir_emit_increment(irProcedure *proc, irValue *addr) { } -void ir_init_data_with_defaults(irProcedure *proc, irValue *ptr, irValue *count, AstNode *expr) { +void ir_init_data_with_defaults(irProcedure *proc, irValue *ptr, irValue *count, Ast *expr) { Type *elem_type = type_deref(ir_type(ptr)); GB_ASSERT(is_type_struct(elem_type) || is_type_array(elem_type)); @@ -4172,7 +4172,7 @@ void ir_init_data_with_defaults(irProcedure *proc, irValue *ptr, irValue *count, } -irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv, BuiltinProcId id) { +irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, BuiltinProcId id) { ast_node(ce, CallExpr, expr); switch (id) { @@ -4181,10 +4181,10 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv String name = bd->name; GB_ASSERT(name == "location"); String procedure = proc->entity->token.string; - TokenPos pos = ast_node_token(ce->proc).pos; + TokenPos pos = ast_token(ce->proc).pos; if (ce->args.count > 0) { - AstNode *ident = unselector_expr(ce->args[0]); - GB_ASSERT(ident->kind == AstNode_Ident); + Ast *ident = unselector_expr(ce->args[0]); + GB_ASSERT(ident->kind == Ast_Ident); Entity *e = entity_of_ident(ident); GB_ASSERT(e != nullptr); @@ -4200,7 +4200,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv } case BuiltinProc_type_info_of: { - AstNode *arg = ce->args[0]; + Ast *arg = ce->args[0]; TypeAndValue tav = type_and_value_of_expr(proc->module->info, arg); if (tav.mode == Addressing_Type) { Type *t = default_type(type_of_expr(proc->module->info, arg)); @@ -4214,7 +4214,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv } case BuiltinProc_typeid_of: { - AstNode *arg = ce->args[0]; + Ast *arg = ce->args[0]; TypeAndValue tav = type_and_value_of_expr(proc->module->info, arg); if (tav.mode == Addressing_Type) { Type *t = default_type(type_of_expr(proc->module->info, arg)); @@ -4340,14 +4340,14 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv irValue *len = ir_emit_conv(proc, ir_build_expr(proc, ce->args[1]), t_int); - ir_emit_slice_bounds_check(proc, ast_node_token(ce->args[1]), v_zero, len, len, false); + ir_emit_slice_bounds_check(proc, ast_token(ce->args[1]), v_zero, len, len, false); irValue *slice_size = len; if (esz != 1) { slice_size = ir_emit_arith(proc, Token_Mul, elem_size, len, t_int); } - TokenPos pos = ast_node_token(ce->args[0]).pos; + TokenPos pos = ast_token(ce->args[0]).pos; auto args = array_make(proc->module->allocator, 3); args[0] = slice_size; @@ -4390,7 +4390,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv cap = ir_emit_conv(proc, ir_build_expr(proc, ce->args[2]), t_int); } - ir_emit_dynamic_array_bounds_check(proc, ast_node_token(ce->args[0]), v_zero, len, cap); + ir_emit_dynamic_array_bounds_check(proc, ast_token(ce->args[0]), v_zero, len, cap); irValue *array = ir_add_local_generated(proc, type); @@ -4413,7 +4413,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv gbAllocator a = proc->module->allocator; - AstNode *node = ce->args[0]; + Ast *node = ce->args[0]; TypeAndValue tav = type_and_value_of_expr(proc->module->info, node); Type *type = base_type(tav.type); @@ -4561,7 +4561,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv } Type *type = ir_type(array_ptr); { - TokenPos pos = ast_node_token(ce->args[0]).pos; + TokenPos pos = ast_token(ce->args[0]).pos; GB_ASSERT_MSG(is_type_pointer(type), "%.*s(%td) %s", LIT(pos.file), pos.line, type_to_string(type)); @@ -4586,7 +4586,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv isize arg_index = 0; isize arg_count = 0; for_array(i, ce->args) { - AstNode *a = ce->args[i]; + Ast *a = ce->args[i]; Type *at = base_type(type_of_expr(proc->module->info, a)); if (at->kind == Type_Tuple) { arg_count += at->Tuple.variable_count; @@ -4829,15 +4829,15 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv return nullptr; } -irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr); +irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr); -irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { +irValue *ir_build_expr(irProcedure *proc, Ast *expr) { irValue *v = ir_build_expr_internal(proc, expr); ir_add_debug_location_to_value(proc, v, expr); return v; } -irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { +irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { expr = unparen_expr(expr); TypeAndValue tv = type_and_value_of_expr(proc->module->info, expr); @@ -4900,7 +4900,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { Entity *e = entity_of_ident(expr); GB_ASSERT_MSG(e != nullptr, "%s", expr_to_string(expr)); if (e->kind == Entity_Builtin) { - Token token = ast_node_token(expr); + Token token = ast_token(expr); GB_PANIC("TODO(bill): ir_build_expr Entity_Builtin '%.*s'\n" "\t at %.*s(%td:%td)", LIT(builtin_procs[e->Builtin.id].name), LIT(token.pos.file), token.pos.line, token.pos.column); @@ -4974,7 +4974,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { case_end; case_ast_node(ta, TypeAssertion, expr); - TokenPos pos = ast_node_token(expr).pos; + TokenPos pos = ast_token(expr).pos; Type *type = tv.type; irValue *e = ir_build_expr(proc, ta->expr); Type *t = type_deref(ir_type(e)); @@ -5007,15 +5007,15 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { case_ast_node(ue, UnaryExpr, expr); switch (ue->op.kind) { case Token_And: { - AstNode *ue_expr = unparen_expr(ue->expr); - if (ue_expr->kind == AstNode_TypeAssertion) { + Ast *ue_expr = unparen_expr(ue->expr); + if (ue_expr->kind == Ast_TypeAssertion) { gbAllocator a = proc->module->allocator; GB_ASSERT(is_type_pointer(tv.type)); ast_node(ta, TypeAssertion, ue_expr); - TokenPos pos = ast_node_token(expr).pos; + TokenPos pos = ast_token(expr).pos; Type *type = type_of_expr(proc->module->info, ue_expr); GB_ASSERT(!is_type_tuple(type)); @@ -5147,7 +5147,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { return y; } - AstNode *p = unparen_expr(ce->proc); + Ast *p = unparen_expr(ce->proc); if (proc_mode == Addressing_Builtin) { Entity *e = entity_of_ident(p); BuiltinProcId id = BuiltinProc_Invalid; @@ -5170,9 +5170,9 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { auto args = array_make(proc->module->allocator, pt->param_count); for_array(arg_index, ce->args) { - AstNode *arg = ce->args[arg_index]; + Ast *arg = ce->args[arg_index]; ast_node(fv, FieldValue, arg); - GB_ASSERT(fv->field->kind == AstNode_Ident); + GB_ASSERT(fv->field->kind == Ast_Ident); String name = fv->field->Ident.token.string; isize index = lookup_procedure_parameter(pt, name); GB_ASSERT(index >= 0); @@ -5210,7 +5210,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { isize arg_count = 0; for_array(i, ce->args) { - AstNode *arg = ce->args[i]; + Ast *arg = ce->args[i]; TypeAndValue tav = type_and_value_of_expr(proc->module->info, arg); GB_ASSERT_MSG(tav.mode != Addressing_Invalid, "%s", expr_to_string(arg)); GB_ASSERT_MSG(tav.mode != Addressing_ProcGroup, "%s", expr_to_string(arg)); @@ -5238,7 +5238,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { if (proc->entity != nullptr) { proc_name = proc->entity->token.string; } - TokenPos pos = ast_node_token(ce->proc).pos; + TokenPos pos = ast_token(ce->proc).pos; TypeTuple *param_tuple = nullptr; if (pt->params) { @@ -5247,7 +5247,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { } for_array(i, ce->args) { - AstNode *arg = ce->args[i]; + Ast *arg = ce->args[i]; TypeAndValue arg_tv = type_and_value_of_expr(proc->module->info, arg); if (arg_tv.mode == Addressing_Type) { args[arg_index++] = ir_value_nil(proc->module->allocator, arg_tv.type); @@ -5394,7 +5394,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) { case_end; } - GB_PANIC("Unexpected expression: %.*s", LIT(ast_node_strings[expr->kind])); + GB_PANIC("Unexpected expression: %.*s", LIT(ast_strings[expr->kind])); return nullptr; } @@ -5417,11 +5417,11 @@ irValue *ir_get_using_variable(irProcedure *proc, Entity *e) { return ir_emit_deep_field_gep(proc, v, sel); } -bool ir_is_elem_const(irModule *m, AstNode *elem, Type *elem_type) { +bool ir_is_elem_const(irModule *m, Ast *elem, Type *elem_type) { if (!elem_type_can_be_constant(elem_type)) { return false; } - if (elem->kind == AstNode_FieldValue) { + if (elem->kind == Ast_FieldValue) { elem = elem->FieldValue.value; } TypeAndValue tav = type_and_value_of_expr(m->info, elem); @@ -5429,7 +5429,7 @@ bool ir_is_elem_const(irModule *m, AstNode *elem, Type *elem_type) { return tav.value.kind != ExactValue_Invalid; } -irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, AstNode *expr) { +irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, Ast *expr) { GB_ASSERT(e != nullptr); GB_ASSERT(e->kind != Entity_Constant); @@ -5452,7 +5452,7 @@ irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, AstNode *expr) { return ir_addr(v); } -irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { +irAddr ir_build_addr(irProcedure *proc, Ast *expr) { switch (expr->kind) { case_ast_node(i, Implicit, expr); irValue *v = nullptr; @@ -5483,8 +5483,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { case_ast_node(se, SelectorExpr, expr); ir_emit_comment(proc, str_lit("SelectorExpr")); - AstNode *sel = unparen_expr(se->selector); - if (sel->kind == AstNode_Ident) { + Ast *sel = unparen_expr(se->selector); + if (sel->kind == Ast_Ident) { String selector = sel->Ident.token.string; TypeAndValue tav = type_and_value_of_expr(proc->module->info, se->expr); @@ -5568,7 +5568,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { case_ast_node(ta, TypeAssertion, expr); gbAllocator a = proc->module->allocator; - TokenPos pos = ast_node_token(expr).pos; + TokenPos pos = ast_token(expr).pos; irValue *e = ir_build_expr(proc, ta->expr); Type *t = type_deref(ir_type(e)); if (is_type_union(t)) { @@ -5644,7 +5644,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { auto index_tv = type_and_value_of_expr(proc->module->info, ie->index); if (index_tv.mode != Addressing_Constant) { irValue *len = ir_const_int(a, t->Array.count); - ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); + ir_emit_bounds_check(proc, ast_token(ie->index), index, len); } return ir_addr(elem); break; @@ -5663,7 +5663,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *elem = ir_slice_elem(proc, slice); irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); irValue *len = ir_slice_len(proc, slice); - ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); + ir_emit_bounds_check(proc, ast_token(ie->index), index, len); irValue *v = ir_emit_ptr_offset(proc, elem, index); return ir_addr(v); break; @@ -5682,7 +5682,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *elem = ir_dynamic_array_elem(proc, dynamic_array); irValue *len = ir_dynamic_array_len(proc, dynamic_array); irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); - ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); + ir_emit_bounds_check(proc, ast_token(ie->index), index, len); irValue *v = ir_emit_ptr_offset(proc, elem, index); return ir_addr(v); break; @@ -5707,7 +5707,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { len = ir_string_len(proc, str); index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); - ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); + ir_emit_bounds_check(proc, ast_token(ie->index), index, len); return ir_addr(ir_emit_ptr_offset(proc, elem, index)); break; @@ -5845,7 +5845,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { if (proc->entity) { proc_name = proc->entity->token.string; } - TokenPos pos = ast_node_token(expr).pos; + TokenPos pos = ast_token(expr).pos; switch (bt->kind) { default: GB_PANIC("Unknown CompoundLit type: %s", type_to_string(type)); break; @@ -5860,13 +5860,13 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { if (cl->elems.count > 0) { ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, exact_value_compound(expr))); for_array(field_index, cl->elems) { - AstNode *elem = cl->elems[field_index]; + Ast *elem = cl->elems[field_index]; irValue *field_expr = nullptr; Entity *field = nullptr; isize index = field_index; - if (elem->kind == AstNode_FieldValue) { + if (elem->kind == Ast_FieldValue) { ast_node(fv, FieldValue, elem); String name = fv->field->Ident.token.string; Selection sel = lookup_field(bt, name, false); @@ -5909,7 +5909,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { ir_emit_runtime_call(proc, "__dynamic_map_reserve", args); } for_array(field_index, cl->elems) { - AstNode *elem = cl->elems[field_index]; + Ast *elem = cl->elems[field_index]; ast_node(fv, FieldValue, elem); irValue *key = ir_build_expr(proc, fv->field); @@ -5941,7 +5941,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *items = ir_generate_array(proc->module, elem, item_count, str_lit("__dacl$"), cast(i64)cast(intptr)expr); for_array(field_index, cl->elems) { - AstNode *f = cl->elems[field_index]; + Ast *f = cl->elems[field_index]; irValue *value = ir_emit_conv(proc, ir_build_expr(proc, f), elem); irValue *ep = ir_emit_array_epi(proc, items, cast(i32)field_index); ir_emit_store(proc, ep, value); @@ -5964,7 +5964,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { if (cl->elems.count > 0) { ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, exact_value_compound(expr))); for_array(i, cl->elems) { - AstNode *elem = cl->elems[i]; + Ast *elem = cl->elems[i]; if (ir_is_elem_const(proc->module, elem, et)) { continue; } @@ -5989,7 +5989,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *data = ir_emit_array_ep(proc, slice->ConstantSlice.backing_array, v_zero32); for_array(i, cl->elems) { - AstNode *elem = cl->elems[i]; + Ast *elem = cl->elems[i]; if (ir_is_elem_const(proc->module, elem, et)) { continue; } @@ -6022,12 +6022,12 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { }; for_array(field_index, cl->elems) { - AstNode *elem = cl->elems[field_index]; + Ast *elem = cl->elems[field_index]; irValue *field_expr = nullptr; isize index = field_index; - if (elem->kind == AstNode_FieldValue) { + if (elem->kind == Ast_FieldValue) { ast_node(fv, FieldValue, elem); Selection sel = lookup_field(bt, fv->field->Ident.token.string, false); index = sel.index[0]; @@ -6078,11 +6078,11 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { case_end; } - TokenPos token_pos = ast_node_token(expr).pos; + TokenPos token_pos = ast_token(expr).pos; GB_PANIC("Unexpected address expression\n" - "\tAstNode: %.*s @ " + "\tAst: %.*s @ " "%.*s(%td:%td)\n", - LIT(ast_node_strings[expr->kind]), + LIT(ast_strings[expr->kind]), LIT(token_pos.file), token_pos.line, token_pos.column); @@ -6103,7 +6103,7 @@ void ir_build_assign_op(irProcedure *proc, irAddr const &lhs, irValue *value, To ir_addr_store(proc, lhs, new_value); } -irValue *ir_build_cond(irProcedure *proc, AstNode *cond, irBlock *true_block, irBlock *false_block) { +irValue *ir_build_cond(irProcedure *proc, Ast *cond, irBlock *true_block, irBlock *false_block) { switch (cond->kind) { case_ast_node(pe, ParenExpr, cond); return ir_build_cond(proc, pe->expr, true_block, false_block); @@ -6136,7 +6136,7 @@ irValue *ir_build_cond(irProcedure *proc, AstNode *cond, irBlock *true_block, ir return v; } -void ir_build_nested_proc(irProcedure *proc, AstNodeProcLit *pd, Entity *e) { +void ir_build_nested_proc(irProcedure *proc, AstProcLit *pd, Entity *e) { GB_ASSERT(pd->body != nullptr); if (ir_min_dep_entity(proc->module, e) == false) { @@ -6173,14 +6173,14 @@ void ir_build_nested_proc(irProcedure *proc, AstNodeProcLit *pd, Entity *e) { } -void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) { +void ir_build_constant_value_decl(irProcedure *proc, AstValueDecl *vd) { if (vd == nullptr || vd->is_mutable) { return; } for_array(i, vd->names) { - AstNode *ident = vd->names[i]; - GB_ASSERT(ident->kind == AstNode_Ident); + Ast *ident = vd->names[i]; + GB_ASSERT(ident->kind == Ast_Ident); Entity *e = entity_of_ident(ident); GB_ASSERT(e != nullptr); switch (e->kind) { @@ -6276,10 +6276,10 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) { } } -void ir_build_stmt_list(irProcedure *proc, Array stmts) { +void ir_build_stmt_list(irProcedure *proc, Array stmts) { // NOTE(bill): Precollect constant entities for_array(i, stmts) { - AstNode *stmt = stmts[i]; + Ast *stmt = stmts[i]; switch (stmt->kind) { case_ast_node(vd, ValueDecl, stmt); ir_build_constant_value_decl(proc, vd); @@ -6295,8 +6295,8 @@ void ir_build_stmt_list(irProcedure *proc, Array stmts) { } } -void ir_build_stmt_internal(irProcedure *proc, AstNode *node); -void ir_build_stmt(irProcedure *proc, AstNode *node) { +void ir_build_stmt_internal(irProcedure *proc, Ast *node); +void ir_build_stmt(irProcedure *proc, Ast *node) { u64 prev_stmt_state_flags = proc->module->stmt_state_flags; if (node->stmt_state_flags != 0) { @@ -6319,7 +6319,7 @@ void ir_build_stmt(irProcedure *proc, AstNode *node) { proc->module->stmt_state_flags = prev_stmt_state_flags; } -void ir_build_when_stmt(irProcedure *proc, AstNodeWhenStmt *ws) { +void ir_build_when_stmt(irProcedure *proc, AstWhenStmt *ws) { irValue *cond = ir_build_expr(proc, ws->cond); GB_ASSERT(cond->kind == irValue_Constant && is_type_boolean(ir_type(cond))); @@ -6329,10 +6329,10 @@ void ir_build_when_stmt(irProcedure *proc, AstNodeWhenStmt *ws) { ir_build_stmt_list(proc, ws->body->BlockStmt.stmts); } else if (ws->else_stmt) { switch (ws->else_stmt->kind) { - case AstNode_BlockStmt: + case Ast_BlockStmt: ir_build_stmt_list(proc, ws->else_stmt->BlockStmt.stmts); break; - case AstNode_WhenStmt: + case Ast_WhenStmt: ir_build_when_stmt(proc, &ws->else_stmt->WhenStmt); break; default: @@ -6498,7 +6498,7 @@ void ir_build_range_string(irProcedure *proc, irValue *expr, Type *val_type, if (done_) *done_ = done; } -void ir_build_range_interval(irProcedure *proc, AstNodeBinaryExpr *node, Type *val_type, +void ir_build_range_interval(irProcedure *proc, AstBinaryExpr *node, Type *val_type, irValue **val_, irValue **idx_, irBlock **loop_, irBlock **done_) { // TODO(bill): How should the behaviour work for lower and upper bounds checking for iteration? // If 'lower' is changed, should 'val' do so or is that not typical behaviour? @@ -6556,14 +6556,14 @@ void ir_build_range_interval(irProcedure *proc, AstNodeBinaryExpr *node, Type *v if (done_) *done_ = done; } -void ir_store_type_case_implicit(irProcedure *proc, AstNode *clause, irValue *value) { +void ir_store_type_case_implicit(irProcedure *proc, Ast *clause, irValue *value) { Entity *e = implicit_entity_of_node(proc->module->info, clause); GB_ASSERT(e != nullptr); irValue *x = ir_add_local(proc, e, nullptr, false); ir_emit_store(proc, x, value); } -void ir_type_case_body(irProcedure *proc, AstNode *label, AstNode *clause, irBlock *body, irBlock *done) { +void ir_type_case_body(irProcedure *proc, Ast *label, Ast *clause, irBlock *body, irBlock *done) { ast_node(cc, CaseClause, clause); ir_push_target_list(proc, label, done, nullptr, nullptr); @@ -6575,7 +6575,7 @@ void ir_type_case_body(irProcedure *proc, AstNode *label, AstNode *clause, irBlo ir_emit_jump(proc, done); } -void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { +void ir_build_stmt_internal(irProcedure *proc, Ast *node) { switch (node->kind) { case_ast_node(bs, EmptyStmt, node); case_end; @@ -6586,8 +6586,8 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { case_ast_node(us, UsingStmt, node); for_array(i, us->list) { - AstNode *decl = unparen_expr(us->list[i]); - // if (decl->kind == AstNode_GenDecl) { + Ast *decl = unparen_expr(us->list[i]); + // if (decl->kind == Ast_GenDecl) { // ir_build_stmt(proc, decl); // } } @@ -6616,7 +6616,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { if (vd->values.count == 0) { // declared and zero-initialized for_array(i, vd->names) { - AstNode *name = vd->names[i]; + Ast *name = vd->names[i]; if (!is_blank_ident(name)) { ir_add_local_for_identifier(proc, name, true); } @@ -6626,7 +6626,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { auto inits = array_make(m->tmp_allocator, 0, vd->names.count); for_array(i, vd->names) { - AstNode *name = vd->names[i]; + Ast *name = vd->names[i]; irAddr lval = ir_addr(nullptr); if (!is_blank_ident(name)) { ir_add_local_for_identifier(proc, name, false); @@ -6668,7 +6668,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { auto lvals = array_make(m->tmp_allocator); for_array(i, as->lhs) { - AstNode *lhs = as->lhs[i]; + Ast *lhs = as->lhs[i]; irAddr lval = {}; if (!is_blank_ident(lhs)) { lval = ir_build_addr(proc, lhs); @@ -6678,7 +6678,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { if (as->lhs.count == as->rhs.count) { if (as->lhs.count == 1) { - AstNode *rhs = as->rhs[0]; + Ast *rhs = as->rhs[0]; irValue *init = ir_build_expr(proc, rhs); ir_addr_store(proc, lvals[0], init); } else { @@ -6749,7 +6749,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_emit_comment(proc, str_lit("DeferStmt")); isize scope_index = proc->scope_index; // TODO(bill): What was the original rationale behind this line? - // if (ds->stmt->kind == AstNode_BlockStmt) scope_index--; + // if (ds->stmt->kind == Ast_BlockStmt) scope_index--; ir_add_defer_node(proc, scope_index, ds->stmt); case_end; @@ -6929,15 +6929,15 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { irValue *key = nullptr; irBlock *loop = nullptr; irBlock *done = nullptr; - AstNode *expr = unparen_expr(rs->expr); + Ast *expr = unparen_expr(rs->expr); bool is_map = false; TypeAndValue tav = type_and_value_of_expr(proc->module->info, expr); - if (is_ast_node_a_range(expr)) { + if (is_ast_range(expr)) { ir_build_range_interval(proc, &expr->BinaryExpr, val0_type, &val, &key, &loop, &done); } else if (tav.mode == Addressing_Type) { - TokenPos pos = ast_node_token(expr).pos; + TokenPos pos = ast_token(expr).pos; gbAllocator a = proc->module->allocator; Type *t = tav.type; GB_ASSERT(is_type_enum(t)); @@ -7091,7 +7091,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ast_node(body, BlockStmt, ss->body); - Array default_stmts = {}; + Array default_stmts = {}; irBlock *default_fall = nullptr; irBlock *default_block = nullptr; @@ -7100,7 +7100,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { isize case_count = body->stmts.count; for_array(i, body->stmts) { - AstNode *clause = body->stmts[i]; + Ast *clause = body->stmts[i]; irBlock *body = fall; ast_node(cc, CaseClause, clause); @@ -7132,10 +7132,10 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { irBlock *next_cond = nullptr; for_array(j, cc->list) { - AstNode *expr = unparen_expr(cc->list[j]); + Ast *expr = unparen_expr(cc->list[j]); next_cond = ir_new_block(proc, clause, "switch.case.next"); irValue *cond = v_false; - if (is_ast_node_a_range(expr)) { + if (is_ast_range(expr)) { ast_node(ie, BinaryExpr, expr); TokenKind op = Token_Invalid; switch (ie->op.kind) { @@ -7220,14 +7220,14 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { // NOTE(bill): Append this later irBlock *done = ir_new_block(proc, node, "typeswitch.done"); - AstNode *default_ = nullptr; + Ast *default_ = nullptr; ast_node(body, BlockStmt, ss->body); gb_local_persist i32 weird_count = 0; for_array(i, body->stmts) { - AstNode *clause = body->stmts[i]; + Ast *clause = body->stmts[i]; ast_node(cc, CaseClause, clause); if (cc->list.count == 0) { default_ = clause; @@ -7439,13 +7439,13 @@ void ir_begin_procedure_body(irProcedure *proc) { for_array(i, params->variables) { ast_node(fl, FieldList, pt->params); GB_ASSERT(fl->list.count > 0); - GB_ASSERT(fl->list[0]->kind == AstNode_Field); + GB_ASSERT(fl->list[0]->kind == Ast_Field); if (q_index == fl->list[param_index]->Field.names.count) { q_index = 0; param_index++; } ast_node(field, Field, fl->list[param_index]); - AstNode *name = field->names[q_index++]; + Ast *name = field->names[q_index++]; Entity *e = params->variables[i]; if (e->kind != Entity_Variable) { @@ -7593,9 +7593,9 @@ void ir_build_proc(irValue *value, irProcedure *parent) { Entity *f = p->params->Tuple.variables[i]; if (f->kind == Entity_Variable) { if (f->Variable.default_value.kind == ExactValue_Procedure) { - AstNode *expr = f->Variable.default_value.value_procedure; + Ast *expr = f->Variable.default_value.value_procedure; GB_ASSERT(expr != nullptr); - if (expr->kind == AstNode_ProcLit) { + if (expr->kind == Ast_ProcLit) { ir_gen_anonymous_proc_lit(proc->module, proc->name, expr, proc); } } @@ -8461,7 +8461,7 @@ void ir_gen_tree(irGen *s) { case Entity_Procedure: { ast_node(pl, ProcLit, decl->proc_lit); String original_name = name; - AstNode *body = pl->body; + Ast *body = pl->body; if (e->Procedure.is_foreign) { name = e->token.string; // NOTE(bill): Don't use the mangled name @@ -8471,7 +8471,7 @@ void ir_gen_tree(irGen *s) { name = e->Procedure.link_name; } - AstNode *type_expr = pl->type; + Ast *type_expr = pl->type; irValue *p = ir_value_procedure(a, m, e, e->type, type_expr, body, name); p->Proc.tags = pl->tags; @@ -8551,7 +8551,7 @@ void ir_gen_tree(irGen *s) { } proc_type->Proc.abi_compat_result_type = proc_results->Tuple.variables[0]->type; - AstNode *body = alloc_ast_node(nullptr, AstNode_Invalid); + Ast *body = alloc_ast_node(nullptr, Ast_Invalid); Entity *e = alloc_entity_procedure(nullptr, make_token_ident(name), proc_type, 0); irValue *p = ir_value_procedure(a, m, e, proc_type, nullptr, body, name); @@ -8629,7 +8629,7 @@ void ir_gen_tree(irGen *s) { } proc_type->Proc.abi_compat_result_type = proc_results->Tuple.variables[0]->type; - AstNode *body = alloc_ast_node(nullptr, AstNode_Invalid); + Ast *body = alloc_ast_node(nullptr, Ast_Invalid); Entity *e = alloc_entity_procedure(nullptr, make_token_ident(name), proc_type, 0); irValue *p = ir_value_procedure(a, m, e, proc_type, nullptr, body, name); @@ -8693,7 +8693,7 @@ void ir_gen_tree(irGen *s) { proc_params, 4, proc_results, 1, false, ProcCC_Std); - AstNode *body = alloc_ast_node(nullptr, AstNode_Invalid); + Ast *body = alloc_ast_node(nullptr, Ast_Invalid); Entity *e = alloc_entity_procedure(a, nullptr, make_token_ident(name), proc_type, 0); irValue *p = ir_value_procedure(a, m, e, proc_type, nullptr, body, name); @@ -8719,7 +8719,7 @@ void ir_gen_tree(irGen *s) { nullptr, 0, nullptr, 0, false, ProcCC_Contextless); - AstNode *body = alloc_ast_node(nullptr, AstNode_Invalid); + Ast *body = alloc_ast_node(nullptr, Ast_Invalid); Entity *e = alloc_entity_procedure(nullptr, make_token_ident(name), proc_type, 0); irValue *p = ir_value_procedure(a, m, e, proc_type, nullptr, body, name); diff --git a/src/ir_print.cpp b/src/ir_print.cpp index ce5fcec9e..a1982479d 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -709,7 +709,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type * bool *visited = gb_alloc_array(m->tmp_allocator, bool, value_count); if (cl->elems.count > 0) { - if (cl->elems[0]->kind == AstNode_FieldValue) { + if (cl->elems[0]->kind == Ast_FieldValue) { isize elem_count = cl->elems.count; for (isize i = 0; i < elem_count; i++) { ast_node(fv, FieldValue, cl->elems[i]); @@ -765,13 +765,13 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type * } case ExactValue_Procedure: { irValue **found = nullptr; - AstNode *expr = value.value_procedure; + Ast *expr = value.value_procedure; GB_ASSERT(expr != nullptr); - if (expr->kind == AstNode_ProcLit) { + if (expr->kind == Ast_ProcLit) { found = map_get(&m->anonymous_proc_lits, hash_pointer(expr)); } else { - GB_ASSERT(expr->kind == AstNode_Ident); + GB_ASSERT(expr->kind == Ast_Ident); Entity *e = entity_of_ident(expr); GB_ASSERT(e != nullptr); found = map_get(&m->values, hash_entity(e)); diff --git a/src/parser.cpp b/src/parser.cpp index cc6bead02..666eb1f7a 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1,106 +1,106 @@ -Token ast_node_token(AstNode *node) { +Token ast_token(Ast *node) { switch (node->kind) { - case AstNode_Ident: return node->Ident.token; - case AstNode_Implicit: return node->Implicit; - case AstNode_Undef: return node->Undef; - case AstNode_BasicLit: return node->BasicLit.token; - case AstNode_BasicDirective: return node->BasicDirective.token; - case AstNode_ProcGroup: return node->ProcGroup.token; - case AstNode_ProcLit: return ast_node_token(node->ProcLit.type); - case AstNode_CompoundLit: + case Ast_Ident: return node->Ident.token; + case Ast_Implicit: return node->Implicit; + case Ast_Undef: return node->Undef; + case Ast_BasicLit: return node->BasicLit.token; + case Ast_BasicDirective: return node->BasicDirective.token; + case Ast_ProcGroup: return node->ProcGroup.token; + case Ast_ProcLit: return ast_token(node->ProcLit.type); + case Ast_CompoundLit: if (node->CompoundLit.type != nullptr) { - return ast_node_token(node->CompoundLit.type); + return ast_token(node->CompoundLit.type); } return node->CompoundLit.open; - case AstNode_TagExpr: return node->TagExpr.token; - case AstNode_RunExpr: return node->RunExpr.token; - case AstNode_BadExpr: return node->BadExpr.begin; - case AstNode_UnaryExpr: return node->UnaryExpr.op; - case AstNode_BinaryExpr: return ast_node_token(node->BinaryExpr.left); - case AstNode_ParenExpr: return node->ParenExpr.open; - case AstNode_CallExpr: return ast_node_token(node->CallExpr.proc); - case AstNode_SelectorExpr: + case Ast_TagExpr: return node->TagExpr.token; + case Ast_RunExpr: return node->RunExpr.token; + case Ast_BadExpr: return node->BadExpr.begin; + case Ast_UnaryExpr: return node->UnaryExpr.op; + case Ast_BinaryExpr: return ast_token(node->BinaryExpr.left); + case Ast_ParenExpr: return node->ParenExpr.open; + case Ast_CallExpr: return ast_token(node->CallExpr.proc); + case Ast_SelectorExpr: if (node->SelectorExpr.selector != nullptr) { - return ast_node_token(node->SelectorExpr.selector); + return ast_token(node->SelectorExpr.selector); } return node->SelectorExpr.token; - case AstNode_IndexExpr: return node->IndexExpr.open; - case AstNode_SliceExpr: return node->SliceExpr.open; - case AstNode_Ellipsis: return node->Ellipsis.token; - case AstNode_FieldValue: return node->FieldValue.eq; - case AstNode_DerefExpr: return node->DerefExpr.op; - case AstNode_TernaryExpr: return ast_node_token(node->TernaryExpr.cond); - case AstNode_TypeAssertion: return ast_node_token(node->TypeAssertion.expr); - case AstNode_TypeCast: return node->TypeCast.token; - case AstNode_AutoCast: return node->AutoCast.token; + case Ast_IndexExpr: return node->IndexExpr.open; + case Ast_SliceExpr: return node->SliceExpr.open; + case Ast_Ellipsis: return node->Ellipsis.token; + case Ast_FieldValue: return node->FieldValue.eq; + case Ast_DerefExpr: return node->DerefExpr.op; + case Ast_TernaryExpr: return ast_token(node->TernaryExpr.cond); + case Ast_TypeAssertion: return ast_token(node->TypeAssertion.expr); + case Ast_TypeCast: return node->TypeCast.token; + case Ast_AutoCast: return node->AutoCast.token; - case AstNode_BadStmt: return node->BadStmt.begin; - case AstNode_EmptyStmt: return node->EmptyStmt.token; - case AstNode_ExprStmt: return ast_node_token(node->ExprStmt.expr); - case AstNode_TagStmt: return node->TagStmt.token; - case AstNode_AssignStmt: return node->AssignStmt.op; - case AstNode_IncDecStmt: return ast_node_token(node->IncDecStmt.expr); - case AstNode_BlockStmt: return node->BlockStmt.open; - case AstNode_IfStmt: return node->IfStmt.token; - case AstNode_WhenStmt: return node->WhenStmt.token; - case AstNode_ReturnStmt: return node->ReturnStmt.token; - case AstNode_ForStmt: return node->ForStmt.token; - case AstNode_RangeStmt: return node->RangeStmt.token; - case AstNode_CaseClause: return node->CaseClause.token; - case AstNode_SwitchStmt: return node->SwitchStmt.token; - case AstNode_TypeSwitchStmt: return node->TypeSwitchStmt.token; - case AstNode_DeferStmt: return node->DeferStmt.token; - case AstNode_BranchStmt: return node->BranchStmt.token; - case AstNode_UsingStmt: return node->UsingStmt.token; - case AstNode_PushContext: return node->PushContext.token; + case Ast_BadStmt: return node->BadStmt.begin; + case Ast_EmptyStmt: return node->EmptyStmt.token; + case Ast_ExprStmt: return ast_token(node->ExprStmt.expr); + case Ast_TagStmt: return node->TagStmt.token; + case Ast_AssignStmt: return node->AssignStmt.op; + case Ast_IncDecStmt: return ast_token(node->IncDecStmt.expr); + case Ast_BlockStmt: return node->BlockStmt.open; + case Ast_IfStmt: return node->IfStmt.token; + case Ast_WhenStmt: return node->WhenStmt.token; + case Ast_ReturnStmt: return node->ReturnStmt.token; + case Ast_ForStmt: return node->ForStmt.token; + case Ast_RangeStmt: return node->RangeStmt.token; + case Ast_CaseClause: return node->CaseClause.token; + case Ast_SwitchStmt: return node->SwitchStmt.token; + case Ast_TypeSwitchStmt: return node->TypeSwitchStmt.token; + case Ast_DeferStmt: return node->DeferStmt.token; + case Ast_BranchStmt: return node->BranchStmt.token; + case Ast_UsingStmt: return node->UsingStmt.token; + case Ast_PushContext: return node->PushContext.token; - case AstNode_BadDecl: return node->BadDecl.begin; - case AstNode_Label: return node->Label.token; + case Ast_BadDecl: return node->BadDecl.begin; + case Ast_Label: return node->Label.token; - case AstNode_ValueDecl: return ast_node_token(node->ValueDecl.names[0]); - case AstNode_PackageDecl: return node->PackageDecl.token; - case AstNode_ImportDecl: return node->ImportDecl.token; - case AstNode_ForeignImportDecl: return node->ForeignImportDecl.token; + case Ast_ValueDecl: return ast_token(node->ValueDecl.names[0]); + case Ast_PackageDecl: return node->PackageDecl.token; + case Ast_ImportDecl: return node->ImportDecl.token; + case Ast_ForeignImportDecl: return node->ForeignImportDecl.token; - case AstNode_ForeignBlockDecl: return node->ForeignBlockDecl.token; + case Ast_ForeignBlockDecl: return node->ForeignBlockDecl.token; - case AstNode_Attribute: + case Ast_Attribute: return node->Attribute.token; - case AstNode_Field: + case Ast_Field: if (node->Field.names.count > 0) { - return ast_node_token(node->Field.names[0]); + return ast_token(node->Field.names[0]); } - return ast_node_token(node->Field.type); - case AstNode_FieldList: + return ast_token(node->Field.type); + case Ast_FieldList: return node->FieldList.token; - case AstNode_UnionField: - return ast_node_token(node->UnionField.name); + case Ast_UnionField: + return ast_token(node->UnionField.name); - case AstNode_TypeType: return node->TypeType.token; - case AstNode_HelperType: return node->HelperType.token; - case AstNode_DistinctType: return node->DistinctType.token; - case AstNode_PolyType: return node->PolyType.token; - case AstNode_ProcType: return node->ProcType.token; - case AstNode_PointerType: return node->PointerType.token; - case AstNode_ArrayType: return node->ArrayType.token; - case AstNode_DynamicArrayType: return node->DynamicArrayType.token; - case AstNode_StructType: return node->StructType.token; - case AstNode_UnionType: return node->UnionType.token; - case AstNode_EnumType: return node->EnumType.token; - case AstNode_BitFieldType: return node->BitFieldType.token; - case AstNode_MapType: return node->MapType.token; + case Ast_TypeType: return node->TypeType.token; + case Ast_HelperType: return node->HelperType.token; + case Ast_DistinctType: return node->DistinctType.token; + case Ast_PolyType: return node->PolyType.token; + case Ast_ProcType: return node->ProcType.token; + case Ast_PointerType: return node->PointerType.token; + case Ast_ArrayType: return node->ArrayType.token; + case Ast_DynamicArrayType: return node->DynamicArrayType.token; + case Ast_StructType: return node->StructType.token; + case Ast_UnionType: return node->UnionType.token; + case Ast_EnumType: return node->EnumType.token; + case Ast_BitFieldType: return node->BitFieldType.token; + case Ast_MapType: return node->MapType.token; } return empty_token; } -AstNode *clone_ast_node(gbAllocator a, AstNode *node); -Array clone_ast_node_array(gbAllocator a, Array array) { - Array result = {}; +Ast *clone_ast_node(gbAllocator a, Ast *node); +Array clone_ast_node_array(gbAllocator a, Array array) { + Array result = {}; if (array.count > 0) { - result = array_make(a, array.count); + result = array_make(a, array.count); for_array(i, array) { result[i] = clone_ast_node(a, array[i]); } @@ -108,248 +108,248 @@ Array clone_ast_node_array(gbAllocator a, Array array) { return result; } -AstNode *clone_ast_node(gbAllocator a, AstNode *node) { +Ast *clone_ast_node(gbAllocator a, Ast *node) { if (node == nullptr) { return nullptr; } - AstNode *n = alloc_ast_node(node->file, node->kind); - gb_memmove(n, node, gb_size_of(AstNode)); + Ast *n = alloc_ast_node(node->file, node->kind); + gb_memmove(n, node, gb_size_of(Ast)); switch (n->kind) { - default: GB_PANIC("Unhandled AstNode %.*s", LIT(ast_node_strings[n->kind])); break; + default: GB_PANIC("Unhandled Ast %.*s", LIT(ast_strings[n->kind])); break; - case AstNode_Invalid: break; - case AstNode_Ident: + case Ast_Invalid: break; + case Ast_Ident: n->Ident.entity = nullptr; break; - case AstNode_Implicit: break; - case AstNode_Undef: break; - case AstNode_BasicLit: break; - case AstNode_BasicDirective: break; + case Ast_Implicit: break; + case Ast_Undef: break; + case Ast_BasicLit: break; + case Ast_BasicDirective: break; - case AstNode_PolyType: + case Ast_PolyType: n->PolyType.type = clone_ast_node(a, n->PolyType.type); n->PolyType.specialization = clone_ast_node(a, n->PolyType.specialization); break; - case AstNode_Ellipsis: + case Ast_Ellipsis: n->Ellipsis.expr = clone_ast_node(a, n->Ellipsis.expr); break; - case AstNode_ProcGroup: + case Ast_ProcGroup: n->ProcGroup.args = clone_ast_node_array(a, n->ProcGroup.args); break; - case AstNode_ProcLit: + case Ast_ProcLit: n->ProcLit.type = clone_ast_node(a, n->ProcLit.type); n->ProcLit.body = clone_ast_node(a, n->ProcLit.body); break; - case AstNode_CompoundLit: + case Ast_CompoundLit: n->CompoundLit.type = clone_ast_node(a, n->CompoundLit.type); n->CompoundLit.elems = clone_ast_node_array(a, n->CompoundLit.elems); break; - case AstNode_BadExpr: break; - case AstNode_TagExpr: + case Ast_BadExpr: break; + case Ast_TagExpr: n->TagExpr.expr = clone_ast_node(a, n->TagExpr.expr); break; - case AstNode_RunExpr: + case Ast_RunExpr: n->RunExpr.expr = clone_ast_node(a, n->RunExpr.expr); break; - case AstNode_UnaryExpr: + case Ast_UnaryExpr: n->UnaryExpr.expr = clone_ast_node(a, n->UnaryExpr.expr); break; - case AstNode_BinaryExpr: + case Ast_BinaryExpr: n->BinaryExpr.left = clone_ast_node(a, n->BinaryExpr.left); n->BinaryExpr.right = clone_ast_node(a, n->BinaryExpr.right); break; - case AstNode_ParenExpr: + case Ast_ParenExpr: n->ParenExpr.expr = clone_ast_node(a, n->ParenExpr.expr); break; - case AstNode_SelectorExpr: + case Ast_SelectorExpr: n->SelectorExpr.expr = clone_ast_node(a, n->SelectorExpr.expr); n->SelectorExpr.selector = clone_ast_node(a, n->SelectorExpr.selector); break; - case AstNode_IndexExpr: + case Ast_IndexExpr: n->IndexExpr.expr = clone_ast_node(a, n->IndexExpr.expr); n->IndexExpr.index = clone_ast_node(a, n->IndexExpr.index); break; - case AstNode_DerefExpr: + case Ast_DerefExpr: n->DerefExpr.expr = clone_ast_node(a, n->DerefExpr.expr); break; - case AstNode_SliceExpr: + case Ast_SliceExpr: n->SliceExpr.expr = clone_ast_node(a, n->SliceExpr.expr); n->SliceExpr.low = clone_ast_node(a, n->SliceExpr.low); n->SliceExpr.high = clone_ast_node(a, n->SliceExpr.high); break; - case AstNode_CallExpr: + case Ast_CallExpr: n->CallExpr.proc = clone_ast_node(a, n->CallExpr.proc); n->CallExpr.args = clone_ast_node_array(a, n->CallExpr.args); break; - case AstNode_FieldValue: + case Ast_FieldValue: n->FieldValue.field = clone_ast_node(a, n->FieldValue.field); n->FieldValue.value = clone_ast_node(a, n->FieldValue.value); break; - case AstNode_TernaryExpr: + case Ast_TernaryExpr: n->TernaryExpr.cond = clone_ast_node(a, n->TernaryExpr.cond); n->TernaryExpr.x = clone_ast_node(a, n->TernaryExpr.x); n->TernaryExpr.y = clone_ast_node(a, n->TernaryExpr.y); break; - case AstNode_TypeAssertion: + case Ast_TypeAssertion: n->TypeAssertion.expr = clone_ast_node(a, n->TypeAssertion.expr); n->TypeAssertion.type = clone_ast_node(a, n->TypeAssertion.type); break; - case AstNode_TypeCast: + case Ast_TypeCast: n->TypeCast.type = clone_ast_node(a, n->TypeCast.type); n->TypeCast.expr = clone_ast_node(a, n->TypeCast.expr); break; - case AstNode_BadStmt: break; - case AstNode_EmptyStmt: break; - case AstNode_ExprStmt: + case Ast_BadStmt: break; + case Ast_EmptyStmt: break; + case Ast_ExprStmt: n->ExprStmt.expr = clone_ast_node(a, n->ExprStmt.expr); break; - case AstNode_TagStmt: + case Ast_TagStmt: n->TagStmt.stmt = clone_ast_node(a, n->TagStmt.stmt); break; - case AstNode_AssignStmt: + case Ast_AssignStmt: n->AssignStmt.lhs = clone_ast_node_array(a, n->AssignStmt.lhs); n->AssignStmt.rhs = clone_ast_node_array(a, n->AssignStmt.rhs); break; - case AstNode_IncDecStmt: + case Ast_IncDecStmt: n->IncDecStmt.expr = clone_ast_node(a, n->IncDecStmt.expr); break; - case AstNode_BlockStmt: + case Ast_BlockStmt: n->BlockStmt.stmts = clone_ast_node_array(a, n->BlockStmt.stmts); break; - case AstNode_IfStmt: + case Ast_IfStmt: n->IfStmt.init = clone_ast_node(a, n->IfStmt.init); n->IfStmt.cond = clone_ast_node(a, n->IfStmt.cond); n->IfStmt.body = clone_ast_node(a, n->IfStmt.body); n->IfStmt.else_stmt = clone_ast_node(a, n->IfStmt.else_stmt); break; - case AstNode_WhenStmt: + case Ast_WhenStmt: n->WhenStmt.cond = clone_ast_node(a, n->WhenStmt.cond); n->WhenStmt.body = clone_ast_node(a, n->WhenStmt.body); n->WhenStmt.else_stmt = clone_ast_node(a, n->WhenStmt.else_stmt); break; - case AstNode_ReturnStmt: + case Ast_ReturnStmt: n->ReturnStmt.results = clone_ast_node_array(a, n->ReturnStmt.results); break; - case AstNode_ForStmt: + case Ast_ForStmt: n->ForStmt.label = clone_ast_node(a, n->ForStmt.label); n->ForStmt.init = clone_ast_node(a, n->ForStmt.init); n->ForStmt.cond = clone_ast_node(a, n->ForStmt.cond); n->ForStmt.post = clone_ast_node(a, n->ForStmt.post); n->ForStmt.body = clone_ast_node(a, n->ForStmt.body); break; - case AstNode_RangeStmt: + case Ast_RangeStmt: n->RangeStmt.label = clone_ast_node(a, n->RangeStmt.label); n->RangeStmt.val0 = clone_ast_node(a, n->RangeStmt.val0); n->RangeStmt.val1 = clone_ast_node(a, n->RangeStmt.val1); n->RangeStmt.expr = clone_ast_node(a, n->RangeStmt.expr); n->RangeStmt.body = clone_ast_node(a, n->RangeStmt.body); break; - case AstNode_CaseClause: + case Ast_CaseClause: n->CaseClause.list = clone_ast_node_array(a, n->CaseClause.list); n->CaseClause.stmts = clone_ast_node_array(a, n->CaseClause.stmts); n->CaseClause.implicit_entity = nullptr; break; - case AstNode_SwitchStmt: + case Ast_SwitchStmt: n->SwitchStmt.label = clone_ast_node(a, n->SwitchStmt.label); n->SwitchStmt.init = clone_ast_node(a, n->SwitchStmt.init); n->SwitchStmt.tag = clone_ast_node(a, n->SwitchStmt.tag); n->SwitchStmt.body = clone_ast_node(a, n->SwitchStmt.body); break; - case AstNode_TypeSwitchStmt: + case Ast_TypeSwitchStmt: n->TypeSwitchStmt.label = clone_ast_node(a, n->TypeSwitchStmt.label); n->TypeSwitchStmt.tag = clone_ast_node(a, n->TypeSwitchStmt.tag); n->TypeSwitchStmt.body = clone_ast_node(a, n->TypeSwitchStmt.body); break; - case AstNode_DeferStmt: + case Ast_DeferStmt: n->DeferStmt.stmt = clone_ast_node(a, n->DeferStmt.stmt); break; - case AstNode_BranchStmt: + case Ast_BranchStmt: n->BranchStmt.label = clone_ast_node(a, n->BranchStmt.label); break; - case AstNode_UsingStmt: + case Ast_UsingStmt: n->UsingStmt.list = clone_ast_node_array(a, n->UsingStmt.list); break; - case AstNode_PushContext: + case Ast_PushContext: n->PushContext.expr = clone_ast_node(a, n->PushContext.expr); n->PushContext.body = clone_ast_node(a, n->PushContext.body); break; - case AstNode_BadDecl: break; + case Ast_BadDecl: break; - case AstNode_ForeignBlockDecl: + case Ast_ForeignBlockDecl: n->ForeignBlockDecl.foreign_library = clone_ast_node(a, n->ForeignBlockDecl.foreign_library); n->ForeignBlockDecl.body = clone_ast_node(a, n->ForeignBlockDecl.body); n->ForeignBlockDecl.attributes = clone_ast_node_array(a, n->ForeignBlockDecl.attributes); break; - case AstNode_Label: + case Ast_Label: n->Label.name = clone_ast_node(a, n->Label.name); break; - case AstNode_ValueDecl: + case Ast_ValueDecl: n->ValueDecl.names = clone_ast_node_array(a, n->ValueDecl.names); n->ValueDecl.type = clone_ast_node(a, n->ValueDecl.type); n->ValueDecl.values = clone_ast_node_array(a, n->ValueDecl.values); n->ValueDecl.attributes = clone_ast_node_array(a, n->ValueDecl.attributes); break; - case AstNode_Attribute: + case Ast_Attribute: n->Attribute.elems = clone_ast_node_array(a, n->Attribute.elems); break; - case AstNode_Field: + case Ast_Field: n->Field.names = clone_ast_node_array(a, n->Field.names); n->Field.type = clone_ast_node(a, n->Field.type); break; - case AstNode_FieldList: + case Ast_FieldList: n->FieldList.list = clone_ast_node_array(a, n->FieldList.list); break; - case AstNode_UnionField: + case Ast_UnionField: n->UnionField.name = clone_ast_node(a, n->UnionField.name); n->UnionField.list = clone_ast_node(a, n->UnionField.list); break; - case AstNode_TypeType: + case Ast_TypeType: n->TypeType.specialization = clone_ast_node(a, n->TypeType.specialization); break; - case AstNode_HelperType: + case Ast_HelperType: n->HelperType.type = clone_ast_node(a, n->HelperType.type); break; - case AstNode_DistinctType: + case Ast_DistinctType: n->DistinctType.type = clone_ast_node(a, n->DistinctType.type); break; - case AstNode_ProcType: + case Ast_ProcType: n->ProcType.params = clone_ast_node(a, n->ProcType.params); n->ProcType.results = clone_ast_node(a, n->ProcType.results); break; - case AstNode_PointerType: + case Ast_PointerType: n->PointerType.type = clone_ast_node(a, n->PointerType.type); break; - case AstNode_ArrayType: + case Ast_ArrayType: n->ArrayType.count = clone_ast_node(a, n->ArrayType.count); n->ArrayType.elem = clone_ast_node(a, n->ArrayType.elem); break; - case AstNode_DynamicArrayType: + case Ast_DynamicArrayType: n->DynamicArrayType.elem = clone_ast_node(a, n->DynamicArrayType.elem); break; - case AstNode_StructType: + case Ast_StructType: n->StructType.fields = clone_ast_node_array(a, n->StructType.fields); n->StructType.polymorphic_params = clone_ast_node(a, n->StructType.polymorphic_params); n->StructType.align = clone_ast_node(a, n->StructType.align); break; - case AstNode_UnionType: + case Ast_UnionType: n->UnionType.variants = clone_ast_node_array(a, n->UnionType.variants); break; - case AstNode_EnumType: + case Ast_EnumType: n->EnumType.base_type = clone_ast_node(a, n->EnumType.base_type); n->EnumType.fields = clone_ast_node_array(a, n->EnumType.fields); break; - case AstNode_BitFieldType: + case Ast_BitFieldType: n->BitFieldType.fields = clone_ast_node_array(a, n->BitFieldType.fields); n->BitFieldType.align = clone_ast_node(a, n->BitFieldType.align); - case AstNode_MapType: + case Ast_MapType: n->MapType.count = clone_ast_node(a, n->MapType.count); n->MapType.key = clone_ast_node(a, n->MapType.key); n->MapType.value = clone_ast_node(a, n->MapType.value); @@ -360,10 +360,10 @@ AstNode *clone_ast_node(gbAllocator a, AstNode *node) { } -void error(AstNode *node, char *fmt, ...) { +void error(Ast *node, char *fmt, ...) { Token token = {}; if (node != nullptr) { - token = ast_node_token(node); + token = ast_token(node); } va_list va; va_start(va, fmt); @@ -374,10 +374,10 @@ void error(AstNode *node, char *fmt, ...) { } } -void error_no_newline(AstNode *node, char *fmt, ...) { +void error_no_newline(Ast *node, char *fmt, ...) { Token token = {}; if (node != nullptr) { - token = ast_node_token(node); + token = ast_token(node); } va_list va; va_start(va, fmt); @@ -388,17 +388,17 @@ void error_no_newline(AstNode *node, char *fmt, ...) { } } -void warning(AstNode *node, char *fmt, ...) { +void warning(Ast *node, char *fmt, ...) { va_list va; va_start(va, fmt); - warning_va(ast_node_token(node), fmt, va); + warning_va(ast_token(node), fmt, va); va_end(va); } -void syntax_error(AstNode *node, char *fmt, ...) { +void syntax_error(Ast *node, char *fmt, ...) { va_list va; va_start(va, fmt); - syntax_error_va(ast_node_token(node), fmt, va); + syntax_error_va(ast_token(node), fmt, va); va_end(va); if (node != nullptr && node->file != nullptr) { node->file->error_count += 1; @@ -406,9 +406,9 @@ void syntax_error(AstNode *node, char *fmt, ...) { } -bool ast_node_expect(AstNode *node, AstNodeKind kind) { +bool ast_node_expect(Ast *node, AstKind kind) { if (node->kind != kind) { - syntax_error(node, "Expected %.*s, got %.*s", LIT(ast_node_strings[node->kind])); + syntax_error(node, "Expected %.*s, got %.*s", LIT(ast_strings[node->kind])); return false; } return true; @@ -416,31 +416,31 @@ bool ast_node_expect(AstNode *node, AstNodeKind kind) { // NOTE(bill): And this below is why is I/we need a new language! Discriminated unions are a pain in C/C++ -AstNode *alloc_ast_node(AstFile *f, AstNodeKind kind) { +Ast *alloc_ast_node(AstFile *f, AstKind kind) { gbAllocator a = ast_allocator(); - AstNode *node = gb_alloc_item(a, AstNode); + Ast *node = gb_alloc_item(a, Ast); node->kind = kind; node->file = f; return node; } -AstNode *ast_bad_expr(AstFile *f, Token begin, Token end) { - AstNode *result = alloc_ast_node(f, AstNode_BadExpr); +Ast *ast_bad_expr(AstFile *f, Token begin, Token end) { + Ast *result = alloc_ast_node(f, Ast_BadExpr); result->BadExpr.begin = begin; result->BadExpr.end = end; return result; } -AstNode *ast_tag_expr(AstFile *f, Token token, Token name, AstNode *expr) { - AstNode *result = alloc_ast_node(f, AstNode_TagExpr); +Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { + Ast *result = alloc_ast_node(f, Ast_TagExpr); result->TagExpr.token = token; result->TagExpr.name = name; result->TagExpr.expr = expr; return result; } -AstNode *ast_run_expr(AstFile *f, Token token, Token name, AstNode *expr) { - AstNode *result = alloc_ast_node(f, AstNode_RunExpr); +Ast *ast_run_expr(AstFile *f, Token token, Token name, Ast *expr) { + Ast *result = alloc_ast_node(f, Ast_RunExpr); result->RunExpr.token = token; result->RunExpr.name = name; result->RunExpr.expr = expr; @@ -448,23 +448,23 @@ AstNode *ast_run_expr(AstFile *f, Token token, Token name, AstNode *expr) { } -AstNode *ast_tag_stmt(AstFile *f, Token token, Token name, AstNode *stmt) { - AstNode *result = alloc_ast_node(f, AstNode_TagStmt); +Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { + Ast *result = alloc_ast_node(f, Ast_TagStmt); result->TagStmt.token = token; result->TagStmt.name = name; result->TagStmt.stmt = stmt; return result; } -AstNode *ast_unary_expr(AstFile *f, Token op, AstNode *expr) { - AstNode *result = alloc_ast_node(f, AstNode_UnaryExpr); +Ast *ast_unary_expr(AstFile *f, Token op, Ast *expr) { + Ast *result = alloc_ast_node(f, Ast_UnaryExpr); result->UnaryExpr.op = op; result->UnaryExpr.expr = expr; return result; } -AstNode *ast_binary_expr(AstFile *f, Token op, AstNode *left, AstNode *right) { - AstNode *result = alloc_ast_node(f, AstNode_BinaryExpr); +Ast *ast_binary_expr(AstFile *f, Token op, Ast *left, Ast *right) { + Ast *result = alloc_ast_node(f, Ast_BinaryExpr); if (left == nullptr) { syntax_error(op, "No lhs expression for binary expression '%.*s'", LIT(op.string)); @@ -482,16 +482,16 @@ AstNode *ast_binary_expr(AstFile *f, Token op, AstNode *left, AstNode *right) { return result; } -AstNode *ast_paren_expr(AstFile *f, AstNode *expr, Token open, Token close) { - AstNode *result = alloc_ast_node(f, AstNode_ParenExpr); +Ast *ast_paren_expr(AstFile *f, Ast *expr, Token open, Token close) { + Ast *result = alloc_ast_node(f, Ast_ParenExpr); result->ParenExpr.expr = expr; result->ParenExpr.open = open; result->ParenExpr.close = close; return result; } -AstNode *ast_call_expr(AstFile *f, AstNode *proc, Array args, Token open, Token close, Token ellipsis) { - AstNode *result = alloc_ast_node(f, AstNode_CallExpr); +Ast *ast_call_expr(AstFile *f, Ast *proc, Array args, Token open, Token close, Token ellipsis) { + Ast *result = alloc_ast_node(f, Ast_CallExpr); result->CallExpr.proc = proc; result->CallExpr.args = args; result->CallExpr.open = open; @@ -501,15 +501,15 @@ AstNode *ast_call_expr(AstFile *f, AstNode *proc, Array args, Token o } -AstNode *ast_selector_expr(AstFile *f, Token token, AstNode *expr, AstNode *selector) { - AstNode *result = alloc_ast_node(f, AstNode_SelectorExpr); +Ast *ast_selector_expr(AstFile *f, Token token, Ast *expr, Ast *selector) { + Ast *result = alloc_ast_node(f, Ast_SelectorExpr); result->SelectorExpr.expr = expr; result->SelectorExpr.selector = selector; return result; } -AstNode *ast_index_expr(AstFile *f, AstNode *expr, AstNode *index, Token open, Token close) { - AstNode *result = alloc_ast_node(f, AstNode_IndexExpr); +Ast *ast_index_expr(AstFile *f, Ast *expr, Ast *index, Token open, Token close) { + Ast *result = alloc_ast_node(f, Ast_IndexExpr); result->IndexExpr.expr = expr; result->IndexExpr.index = index; result->IndexExpr.open = open; @@ -518,8 +518,8 @@ AstNode *ast_index_expr(AstFile *f, AstNode *expr, AstNode *index, Token open, T } -AstNode *ast_slice_expr(AstFile *f, AstNode *expr, Token open, Token close, Token interval, AstNode *low, AstNode *high) { - AstNode *result = alloc_ast_node(f, AstNode_SliceExpr); +Ast *ast_slice_expr(AstFile *f, Ast *expr, Token open, Token close, Token interval, Ast *low, Ast *high) { + Ast *result = alloc_ast_node(f, Ast_SliceExpr); result->SliceExpr.expr = expr; result->SliceExpr.open = open; result->SliceExpr.close = close; @@ -529,8 +529,8 @@ AstNode *ast_slice_expr(AstFile *f, AstNode *expr, Token open, Token close, Toke return result; } -AstNode *ast_deref_expr(AstFile *f, AstNode *expr, Token op) { - AstNode *result = alloc_ast_node(f, AstNode_DerefExpr); +Ast *ast_deref_expr(AstFile *f, Ast *expr, Token op) { + Ast *result = alloc_ast_node(f, Ast_DerefExpr); result->DerefExpr.expr = expr; result->DerefExpr.op = op; return result; @@ -539,47 +539,47 @@ AstNode *ast_deref_expr(AstFile *f, AstNode *expr, Token op) { -AstNode *ast_ident(AstFile *f, Token token) { - AstNode *result = alloc_ast_node(f, AstNode_Ident); +Ast *ast_ident(AstFile *f, Token token) { + Ast *result = alloc_ast_node(f, Ast_Ident); result->Ident.token = token; return result; } -AstNode *ast_implicit(AstFile *f, Token token) { - AstNode *result = alloc_ast_node(f, AstNode_Implicit); +Ast *ast_implicit(AstFile *f, Token token) { + Ast *result = alloc_ast_node(f, Ast_Implicit); result->Implicit = token; return result; } -AstNode *ast_undef(AstFile *f, Token token) { - AstNode *result = alloc_ast_node(f, AstNode_Undef); +Ast *ast_undef(AstFile *f, Token token) { + Ast *result = alloc_ast_node(f, Ast_Undef); result->Undef = token; return result; } -AstNode *ast_basic_lit(AstFile *f, Token basic_lit) { - AstNode *result = alloc_ast_node(f, AstNode_BasicLit); +Ast *ast_basic_lit(AstFile *f, Token basic_lit) { + Ast *result = alloc_ast_node(f, Ast_BasicLit); result->BasicLit.token = basic_lit; return result; } -AstNode *ast_basic_directive(AstFile *f, Token token, String name) { - AstNode *result = alloc_ast_node(f, AstNode_BasicDirective); +Ast *ast_basic_directive(AstFile *f, Token token, String name) { + Ast *result = alloc_ast_node(f, Ast_BasicDirective); result->BasicDirective.token = token; result->BasicDirective.name = name; return result; } -AstNode *ast_ellipsis(AstFile *f, Token token, AstNode *expr) { - AstNode *result = alloc_ast_node(f, AstNode_Ellipsis); +Ast *ast_ellipsis(AstFile *f, Token token, Ast *expr) { + Ast *result = alloc_ast_node(f, Ast_Ellipsis); result->Ellipsis.token = token; result->Ellipsis.expr = expr; return result; } -AstNode *ast_proc_group(AstFile *f, Token token, Token open, Token close, Array args) { - AstNode *result = alloc_ast_node(f, AstNode_ProcGroup); +Ast *ast_proc_group(AstFile *f, Token token, Token open, Token close, Array args) { + Ast *result = alloc_ast_node(f, Ast_ProcGroup); result->ProcGroup.token = token; result->ProcGroup.open = open; result->ProcGroup.close = close; @@ -587,24 +587,24 @@ AstNode *ast_proc_group(AstFile *f, Token token, Token open, Token close, Array< return result; } -AstNode *ast_proc_lit(AstFile *f, AstNode *type, AstNode *body, u64 tags) { - AstNode *result = alloc_ast_node(f, AstNode_ProcLit); +Ast *ast_proc_lit(AstFile *f, Ast *type, Ast *body, u64 tags) { + Ast *result = alloc_ast_node(f, Ast_ProcLit); result->ProcLit.type = type; result->ProcLit.body = body; result->ProcLit.tags = tags; return result; } -AstNode *ast_field_value(AstFile *f, AstNode *field, AstNode *value, Token eq) { - AstNode *result = alloc_ast_node(f, AstNode_FieldValue); +Ast *ast_field_value(AstFile *f, Ast *field, Ast *value, Token eq) { + Ast *result = alloc_ast_node(f, Ast_FieldValue); result->FieldValue.field = field; result->FieldValue.value = value; result->FieldValue.eq = eq; return result; } -AstNode *ast_compound_lit(AstFile *f, AstNode *type, Array elems, Token open, Token close) { - AstNode *result = alloc_ast_node(f, AstNode_CompoundLit); +Ast *ast_compound_lit(AstFile *f, Ast *type, Array elems, Token open, Token close) { + Ast *result = alloc_ast_node(f, Ast_CompoundLit); result->CompoundLit.type = type; result->CompoundLit.elems = elems; result->CompoundLit.open = open; @@ -613,29 +613,29 @@ AstNode *ast_compound_lit(AstFile *f, AstNode *type, Array elems, Tok } -AstNode *ast_ternary_expr(AstFile *f, AstNode *cond, AstNode *x, AstNode *y) { - AstNode *result = alloc_ast_node(f, AstNode_TernaryExpr); +Ast *ast_ternary_expr(AstFile *f, Ast *cond, Ast *x, Ast *y) { + Ast *result = alloc_ast_node(f, Ast_TernaryExpr); result->TernaryExpr.cond = cond; result->TernaryExpr.x = x; result->TernaryExpr.y = y; return result; } -AstNode *ast_type_assertion(AstFile *f, AstNode *expr, Token dot, AstNode *type) { - AstNode *result = alloc_ast_node(f, AstNode_TypeAssertion); +Ast *ast_type_assertion(AstFile *f, Ast *expr, Token dot, Ast *type) { + Ast *result = alloc_ast_node(f, Ast_TypeAssertion); result->TypeAssertion.expr = expr; result->TypeAssertion.dot = dot; result->TypeAssertion.type = type; return result; } -AstNode *ast_type_cast(AstFile *f, Token token, AstNode *type, AstNode *expr) { - AstNode *result = alloc_ast_node(f, AstNode_TypeCast); +Ast *ast_type_cast(AstFile *f, Token token, Ast *type, Ast *expr) { + Ast *result = alloc_ast_node(f, Ast_TypeCast); result->TypeCast.token = token; result->TypeCast.type = type; result->TypeCast.expr = expr; return result; } -AstNode *ast_auto_cast(AstFile *f, Token token, AstNode *expr) { - AstNode *result = alloc_ast_node(f, AstNode_AutoCast); +Ast *ast_auto_cast(AstFile *f, Token token, Ast *expr) { + Ast *result = alloc_ast_node(f, Ast_AutoCast); result->AutoCast.token = token; result->AutoCast.expr = expr; return result; @@ -645,27 +645,27 @@ AstNode *ast_auto_cast(AstFile *f, Token token, AstNode *expr) { -AstNode *ast_bad_stmt(AstFile *f, Token begin, Token end) { - AstNode *result = alloc_ast_node(f, AstNode_BadStmt); +Ast *ast_bad_stmt(AstFile *f, Token begin, Token end) { + Ast *result = alloc_ast_node(f, Ast_BadStmt); result->BadStmt.begin = begin; result->BadStmt.end = end; return result; } -AstNode *ast_empty_stmt(AstFile *f, Token token) { - AstNode *result = alloc_ast_node(f, AstNode_EmptyStmt); +Ast *ast_empty_stmt(AstFile *f, Token token) { + Ast *result = alloc_ast_node(f, Ast_EmptyStmt); result->EmptyStmt.token = token; return result; } -AstNode *ast_expr_stmt(AstFile *f, AstNode *expr) { - AstNode *result = alloc_ast_node(f, AstNode_ExprStmt); +Ast *ast_expr_stmt(AstFile *f, Ast *expr) { + Ast *result = alloc_ast_node(f, Ast_ExprStmt); result->ExprStmt.expr = expr; return result; } -AstNode *ast_assign_stmt(AstFile *f, Token op, Array lhs, Array rhs) { - AstNode *result = alloc_ast_node(f, AstNode_AssignStmt); +Ast *ast_assign_stmt(AstFile *f, Token op, Array lhs, Array rhs) { + Ast *result = alloc_ast_node(f, Ast_AssignStmt); result->AssignStmt.op = op; result->AssignStmt.lhs = lhs; result->AssignStmt.rhs = rhs; @@ -673,8 +673,8 @@ AstNode *ast_assign_stmt(AstFile *f, Token op, Array lhs, ArrayIncDecStmt.op = op; result->IncDecStmt.expr = expr; return result; @@ -682,16 +682,16 @@ AstNode *ast_inc_dec_stmt(AstFile *f, Token op, AstNode *expr) { -AstNode *ast_block_stmt(AstFile *f, Array stmts, Token open, Token close) { - AstNode *result = alloc_ast_node(f, AstNode_BlockStmt); +Ast *ast_block_stmt(AstFile *f, Array stmts, Token open, Token close) { + Ast *result = alloc_ast_node(f, Ast_BlockStmt); result->BlockStmt.stmts = stmts; result->BlockStmt.open = open; result->BlockStmt.close = close; return result; } -AstNode *ast_if_stmt(AstFile *f, Token token, AstNode *init, AstNode *cond, AstNode *body, AstNode *else_stmt) { - AstNode *result = alloc_ast_node(f, AstNode_IfStmt); +Ast *ast_if_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *body, Ast *else_stmt) { + Ast *result = alloc_ast_node(f, Ast_IfStmt); result->IfStmt.token = token; result->IfStmt.init = init; result->IfStmt.cond = cond; @@ -700,8 +700,8 @@ AstNode *ast_if_stmt(AstFile *f, Token token, AstNode *init, AstNode *cond, AstN return result; } -AstNode *ast_when_stmt(AstFile *f, Token token, AstNode *cond, AstNode *body, AstNode *else_stmt) { - AstNode *result = alloc_ast_node(f, AstNode_WhenStmt); +Ast *ast_when_stmt(AstFile *f, Token token, Ast *cond, Ast *body, Ast *else_stmt) { + Ast *result = alloc_ast_node(f, Ast_WhenStmt); result->WhenStmt.token = token; result->WhenStmt.cond = cond; result->WhenStmt.body = body; @@ -710,16 +710,16 @@ AstNode *ast_when_stmt(AstFile *f, Token token, AstNode *cond, AstNode *body, As } -AstNode *ast_return_stmt(AstFile *f, Token token, Array results) { - AstNode *result = alloc_ast_node(f, AstNode_ReturnStmt); +Ast *ast_return_stmt(AstFile *f, Token token, Array results) { + Ast *result = alloc_ast_node(f, Ast_ReturnStmt); result->ReturnStmt.token = token; result->ReturnStmt.results = results; return result; } -AstNode *ast_for_stmt(AstFile *f, Token token, AstNode *init, AstNode *cond, AstNode *post, AstNode *body) { - AstNode *result = alloc_ast_node(f, AstNode_ForStmt); +Ast *ast_for_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *post, Ast *body) { + Ast *result = alloc_ast_node(f, Ast_ForStmt); result->ForStmt.token = token; result->ForStmt.init = init; result->ForStmt.cond = cond; @@ -728,8 +728,8 @@ AstNode *ast_for_stmt(AstFile *f, Token token, AstNode *init, AstNode *cond, Ast return result; } -AstNode *ast_range_stmt(AstFile *f, Token token, AstNode *val0, AstNode *val1, Token in_token, AstNode *expr, AstNode *body) { - AstNode *result = alloc_ast_node(f, AstNode_RangeStmt); +Ast *ast_range_stmt(AstFile *f, Token token, Ast *val0, Ast *val1, Token in_token, Ast *expr, Ast *body) { + Ast *result = alloc_ast_node(f, Ast_RangeStmt); result->RangeStmt.token = token; result->RangeStmt.val0 = val0; result->RangeStmt.val1 = val1; @@ -739,8 +739,8 @@ AstNode *ast_range_stmt(AstFile *f, Token token, AstNode *val0, AstNode *val1, T return result; } -AstNode *ast_switch_stmt(AstFile *f, Token token, AstNode *init, AstNode *tag, AstNode *body) { - AstNode *result = alloc_ast_node(f, AstNode_SwitchStmt); +Ast *ast_switch_stmt(AstFile *f, Token token, Ast *init, Ast *tag, Ast *body) { + Ast *result = alloc_ast_node(f, Ast_SwitchStmt); result->SwitchStmt.token = token; result->SwitchStmt.init = init; result->SwitchStmt.tag = tag; @@ -749,16 +749,16 @@ AstNode *ast_switch_stmt(AstFile *f, Token token, AstNode *init, AstNode *tag, A } -AstNode *ast_type_switch_stmt(AstFile *f, Token token, AstNode *tag, AstNode *body) { - AstNode *result = alloc_ast_node(f, AstNode_TypeSwitchStmt); +Ast *ast_type_switch_stmt(AstFile *f, Token token, Ast *tag, Ast *body) { + Ast *result = alloc_ast_node(f, Ast_TypeSwitchStmt); result->TypeSwitchStmt.token = token; result->TypeSwitchStmt.tag = tag; result->TypeSwitchStmt.body = body; return result; } -AstNode *ast_case_clause(AstFile *f, Token token, Array list, Array stmts) { - AstNode *result = alloc_ast_node(f, AstNode_CaseClause); +Ast *ast_case_clause(AstFile *f, Token token, Array list, Array stmts) { + Ast *result = alloc_ast_node(f, Ast_CaseClause); result->CaseClause.token = token; result->CaseClause.list = list; result->CaseClause.stmts = stmts; @@ -766,29 +766,29 @@ AstNode *ast_case_clause(AstFile *f, Token token, Array list, ArrayDeferStmt.token = token; result->DeferStmt.stmt = stmt; return result; } -AstNode *ast_branch_stmt(AstFile *f, Token token, AstNode *label) { - AstNode *result = alloc_ast_node(f, AstNode_BranchStmt); +Ast *ast_branch_stmt(AstFile *f, Token token, Ast *label) { + Ast *result = alloc_ast_node(f, Ast_BranchStmt); result->BranchStmt.token = token; result->BranchStmt.label = label; return result; } -AstNode *ast_using_stmt(AstFile *f, Token token, Array list) { - AstNode *result = alloc_ast_node(f, AstNode_UsingStmt); +Ast *ast_using_stmt(AstFile *f, Token token, Array list) { + Ast *result = alloc_ast_node(f, Ast_UsingStmt); result->UsingStmt.token = token; result->UsingStmt.list = list; return result; } -AstNode *ast_push_context(AstFile *f, Token token, AstNode *expr, AstNode *body) { - AstNode *result = alloc_ast_node(f, AstNode_PushContext); +Ast *ast_push_context(AstFile *f, Token token, Ast *expr, Ast *body) { + Ast *result = alloc_ast_node(f, Ast_PushContext); result->PushContext.token = token; result->PushContext.expr = expr; result->PushContext.body = body; @@ -798,16 +798,16 @@ AstNode *ast_push_context(AstFile *f, Token token, AstNode *expr, AstNode *body) -AstNode *ast_bad_decl(AstFile *f, Token begin, Token end) { - AstNode *result = alloc_ast_node(f, AstNode_BadDecl); +Ast *ast_bad_decl(AstFile *f, Token begin, Token end) { + Ast *result = alloc_ast_node(f, Ast_BadDecl); result->BadDecl.begin = begin; result->BadDecl.end = end; return result; } -AstNode *ast_field(AstFile *f, Array names, AstNode *type, AstNode *default_value, u32 flags, +Ast *ast_field(AstFile *f, Array names, Ast *type, Ast *default_value, u32 flags, CommentGroup *docs, CommentGroup *comment) { - AstNode *result = alloc_ast_node(f, AstNode_Field); + Ast *result = alloc_ast_node(f, Ast_Field); result->Field.names = names; result->Field.type = type; result->Field.default_value = default_value; @@ -817,44 +817,44 @@ AstNode *ast_field(AstFile *f, Array names, AstNode *type, AstNode *d return result; } -AstNode *ast_field_list(AstFile *f, Token token, Array list) { - AstNode *result = alloc_ast_node(f, AstNode_FieldList); +Ast *ast_field_list(AstFile *f, Token token, Array list) { + Ast *result = alloc_ast_node(f, Ast_FieldList); result->FieldList.token = token; result->FieldList.list = list; return result; } -AstNode *ast_union_field(AstFile *f, AstNode *name, AstNode *list) { - AstNode *result = alloc_ast_node(f, AstNode_UnionField); +Ast *ast_union_field(AstFile *f, Ast *name, Ast *list) { + Ast *result = alloc_ast_node(f, Ast_UnionField); result->UnionField.name = name; result->UnionField.list = list; return result; } -AstNode *ast_type_type(AstFile *f, Token token, AstNode *specialization) { - AstNode *result = alloc_ast_node(f, AstNode_TypeType); +Ast *ast_type_type(AstFile *f, Token token, Ast *specialization) { + Ast *result = alloc_ast_node(f, Ast_TypeType); result->TypeType.token = token; result->TypeType.specialization = specialization; return result; } -AstNode *ast_helper_type(AstFile *f, Token token, AstNode *type) { - AstNode *result = alloc_ast_node(f, AstNode_HelperType); +Ast *ast_helper_type(AstFile *f, Token token, Ast *type) { + Ast *result = alloc_ast_node(f, Ast_HelperType); result->HelperType.token = token; result->HelperType.type = type; return result; } -AstNode *ast_distinct_type(AstFile *f, Token token, AstNode *type) { - AstNode *result = alloc_ast_node(f, AstNode_DistinctType); +Ast *ast_distinct_type(AstFile *f, Token token, Ast *type) { + Ast *result = alloc_ast_node(f, Ast_DistinctType); result->DistinctType.token = token; result->DistinctType.type = type; return result; } -AstNode *ast_poly_type(AstFile *f, Token token, AstNode *type, AstNode *specialization) { - AstNode *result = alloc_ast_node(f, AstNode_PolyType); +Ast *ast_poly_type(AstFile *f, Token token, Ast *type, Ast *specialization) { + Ast *result = alloc_ast_node(f, Ast_PolyType); result->PolyType.token = token; result->PolyType.type = type; result->PolyType.specialization = specialization; @@ -862,8 +862,8 @@ AstNode *ast_poly_type(AstFile *f, Token token, AstNode *type, AstNode *speciali } -AstNode *ast_proc_type(AstFile *f, Token token, AstNode *params, AstNode *results, u64 tags, ProcCallingConvention calling_convention, bool generic) { - AstNode *result = alloc_ast_node(f, AstNode_ProcType); +Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags, ProcCallingConvention calling_convention, bool generic) { + Ast *result = alloc_ast_node(f, Ast_ProcType); result->ProcType.token = token; result->ProcType.params = params; result->ProcType.results = results; @@ -874,32 +874,32 @@ AstNode *ast_proc_type(AstFile *f, Token token, AstNode *params, AstNode *result } -AstNode *ast_pointer_type(AstFile *f, Token token, AstNode *type) { - AstNode *result = alloc_ast_node(f, AstNode_PointerType); +Ast *ast_pointer_type(AstFile *f, Token token, Ast *type) { + Ast *result = alloc_ast_node(f, Ast_PointerType); result->PointerType.token = token; result->PointerType.type = type; return result; } -AstNode *ast_array_type(AstFile *f, Token token, AstNode *count, AstNode *elem) { - AstNode *result = alloc_ast_node(f, AstNode_ArrayType); +Ast *ast_array_type(AstFile *f, Token token, Ast *count, Ast *elem) { + Ast *result = alloc_ast_node(f, Ast_ArrayType); result->ArrayType.token = token; result->ArrayType.count = count; result->ArrayType.elem = elem; return result; } -AstNode *ast_dynamic_array_type(AstFile *f, Token token, AstNode *elem) { - AstNode *result = alloc_ast_node(f, AstNode_DynamicArrayType); +Ast *ast_dynamic_array_type(AstFile *f, Token token, Ast *elem) { + Ast *result = alloc_ast_node(f, Ast_DynamicArrayType); result->DynamicArrayType.token = token; result->DynamicArrayType.elem = elem; return result; } -AstNode *ast_struct_type(AstFile *f, Token token, Array fields, isize field_count, - AstNode *polymorphic_params, bool is_packed, bool is_raw_union, - AstNode *align) { - AstNode *result = alloc_ast_node(f, AstNode_StructType); +Ast *ast_struct_type(AstFile *f, Token token, Array fields, isize field_count, + Ast *polymorphic_params, bool is_packed, bool is_raw_union, + Ast *align) { + Ast *result = alloc_ast_node(f, Ast_StructType); result->StructType.token = token; result->StructType.fields = fields; result->StructType.field_count = field_count; @@ -911,8 +911,8 @@ AstNode *ast_struct_type(AstFile *f, Token token, Array fields, isize } -AstNode *ast_union_type(AstFile *f, Token token, Array variants, AstNode *align) { - AstNode *result = alloc_ast_node(f, AstNode_UnionType); +Ast *ast_union_type(AstFile *f, Token token, Array variants, Ast *align) { + Ast *result = alloc_ast_node(f, Ast_UnionType); result->UnionType.token = token; result->UnionType.variants = variants; result->UnionType.align = align; @@ -920,8 +920,8 @@ AstNode *ast_union_type(AstFile *f, Token token, Array variants, AstN } -AstNode *ast_enum_type(AstFile *f, Token token, AstNode *base_type, bool is_export, Array fields) { - AstNode *result = alloc_ast_node(f, AstNode_EnumType); +Ast *ast_enum_type(AstFile *f, Token token, Ast *base_type, bool is_export, Array fields) { + Ast *result = alloc_ast_node(f, Ast_EnumType); result->EnumType.token = token; result->EnumType.base_type = base_type; result->EnumType.is_export = is_export; @@ -929,16 +929,16 @@ AstNode *ast_enum_type(AstFile *f, Token token, AstNode *base_type, bool is_expo return result; } -AstNode *ast_bit_field_type(AstFile *f, Token token, Array fields, AstNode *align) { - AstNode *result = alloc_ast_node(f, AstNode_BitFieldType); +Ast *ast_bit_field_type(AstFile *f, Token token, Array fields, Ast *align) { + Ast *result = alloc_ast_node(f, Ast_BitFieldType); result->BitFieldType.token = token; result->BitFieldType.fields = fields; result->BitFieldType.align = align; return result; } -AstNode *ast_map_type(AstFile *f, Token token, AstNode *key, AstNode *value) { - AstNode *result = alloc_ast_node(f, AstNode_MapType); +Ast *ast_map_type(AstFile *f, Token token, Ast *key, Ast *value) { + Ast *result = alloc_ast_node(f, Ast_MapType); result->MapType.token = token; result->MapType.key = key; result->MapType.value = value; @@ -946,9 +946,9 @@ AstNode *ast_map_type(AstFile *f, Token token, AstNode *key, AstNode *value) { } -AstNode *ast_foreign_block_decl(AstFile *f, Token token, AstNode *foreign_library, AstNode *body, +Ast *ast_foreign_block_decl(AstFile *f, Token token, Ast *foreign_library, Ast *body, CommentGroup *docs) { - AstNode *result = alloc_ast_node(f, AstNode_ForeignBlockDecl); + Ast *result = alloc_ast_node(f, Ast_ForeignBlockDecl); result->ForeignBlockDecl.token = token; result->ForeignBlockDecl.foreign_library = foreign_library; result->ForeignBlockDecl.body = body; @@ -958,16 +958,16 @@ AstNode *ast_foreign_block_decl(AstFile *f, Token token, AstNode *foreign_librar return result; } -AstNode *ast_label_decl(AstFile *f, Token token, AstNode *name) { - AstNode *result = alloc_ast_node(f, AstNode_Label); +Ast *ast_label_decl(AstFile *f, Token token, Ast *name) { + Ast *result = alloc_ast_node(f, Ast_Label); result->Label.token = token; result->Label.name = name; return result; } -AstNode *ast_value_decl(AstFile *f, Array names, AstNode *type, Array values, bool is_mutable, +Ast *ast_value_decl(AstFile *f, Array names, Ast *type, Array values, bool is_mutable, CommentGroup *docs, CommentGroup *comment) { - AstNode *result = alloc_ast_node(f, AstNode_ValueDecl); + Ast *result = alloc_ast_node(f, Ast_ValueDecl); result->ValueDecl.names = names; result->ValueDecl.type = type; result->ValueDecl.values = values; @@ -979,8 +979,8 @@ AstNode *ast_value_decl(AstFile *f, Array names, AstNode *type, Array return result; } -AstNode *ast_package_decl(AstFile *f, Token token, Token name, CommentGroup *docs, CommentGroup *comment) { - AstNode *result = alloc_ast_node(f, AstNode_PackageDecl); +Ast *ast_package_decl(AstFile *f, Token token, Token name, CommentGroup *docs, CommentGroup *comment) { + Ast *result = alloc_ast_node(f, Ast_PackageDecl); result->PackageDecl.token = token; result->PackageDecl.name = name; result->PackageDecl.docs = docs; @@ -988,9 +988,9 @@ AstNode *ast_package_decl(AstFile *f, Token token, Token name, CommentGroup *doc return result; } -AstNode *ast_import_decl(AstFile *f, Token token, bool is_using, Token relpath, Token import_name, +Ast *ast_import_decl(AstFile *f, Token token, bool is_using, Token relpath, Token import_name, CommentGroup *docs, CommentGroup *comment) { - AstNode *result = alloc_ast_node(f, AstNode_ImportDecl); + Ast *result = alloc_ast_node(f, Ast_ImportDecl); result->ImportDecl.token = token; result->ImportDecl.is_using = is_using; result->ImportDecl.relpath = relpath; @@ -1000,9 +1000,9 @@ AstNode *ast_import_decl(AstFile *f, Token token, bool is_using, Token relpath, return result; } -AstNode *ast_foreign_import_decl(AstFile *f, Token token, Token filepath, Token library_name, +Ast *ast_foreign_import_decl(AstFile *f, Token token, Token filepath, Token library_name, CommentGroup *docs, CommentGroup *comment) { - AstNode *result = alloc_ast_node(f, AstNode_ForeignImportDecl); + Ast *result = alloc_ast_node(f, Ast_ForeignImportDecl); result->ForeignImportDecl.token = token; result->ForeignImportDecl.filepath = filepath; result->ForeignImportDecl.library_name = library_name; @@ -1012,8 +1012,8 @@ AstNode *ast_foreign_import_decl(AstFile *f, Token token, Token filepath, Token } -AstNode *ast_attribute(AstFile *f, Token token, Token open, Token close, Array elems) { - AstNode *result = alloc_ast_node(f, AstNode_Attribute); +Ast *ast_attribute(AstFile *f, Token token, Token open, Token close, Array elems) { + Ast *result = alloc_ast_node(f, Ast_Attribute); result->Attribute.token = token; result->Attribute.open = open; result->Attribute.elems = elems; @@ -1183,8 +1183,8 @@ bool is_blank_ident(Token token) { } return false; } -bool is_blank_ident(AstNode *node) { - if (node->kind == AstNode_Ident) { +bool is_blank_ident(Ast *node) { + if (node->kind == Ast_Ident) { ast_node(i, Ident, node); return is_blank_ident(i->token.string); } @@ -1252,47 +1252,47 @@ Token expect_closing(AstFile *f, TokenKind kind, String context) { return expect_token(f, kind); } -bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) { +bool is_semicolon_optional_for_node(AstFile *f, Ast *s) { if (s == nullptr) { return false; } switch (s->kind) { - case AstNode_EmptyStmt: - case AstNode_BlockStmt: + case Ast_EmptyStmt: + case Ast_BlockStmt: return true; - case AstNode_IfStmt: - case AstNode_WhenStmt: - case AstNode_ForStmt: - case AstNode_RangeStmt: - case AstNode_SwitchStmt: - case AstNode_TypeSwitchStmt: - case AstNode_PushContext: + case Ast_IfStmt: + case Ast_WhenStmt: + case Ast_ForStmt: + case Ast_RangeStmt: + case Ast_SwitchStmt: + case Ast_TypeSwitchStmt: + case Ast_PushContext: return true; - case AstNode_HelperType: + case Ast_HelperType: return is_semicolon_optional_for_node(f, s->HelperType.type); - case AstNode_DistinctType: + case Ast_DistinctType: return is_semicolon_optional_for_node(f, s->DistinctType.type); - case AstNode_PointerType: + case Ast_PointerType: return is_semicolon_optional_for_node(f, s->PointerType.type); - case AstNode_StructType: - case AstNode_UnionType: - case AstNode_EnumType: - case AstNode_BitFieldType: + case Ast_StructType: + case Ast_UnionType: + case Ast_EnumType: + case Ast_BitFieldType: return true; - case AstNode_ProcLit: + case Ast_ProcLit: return true; - case AstNode_PackageDecl: - case AstNode_ImportDecl: - case AstNode_ForeignImportDecl: + case Ast_PackageDecl: + case Ast_ImportDecl: + case Ast_ForeignImportDecl: return true; - case AstNode_ValueDecl: + case Ast_ValueDecl: if (s->ValueDecl.is_mutable) { return false; } @@ -1301,14 +1301,14 @@ bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) { } break; - case AstNode_ForeignBlockDecl: + case Ast_ForeignBlockDecl: return is_semicolon_optional_for_node(f, s->ForeignBlockDecl.body); } return false; } -void expect_semicolon(AstFile *f, AstNode *s) { +void expect_semicolon(AstFile *f, Ast *s) { if (allow_token(f, Token_Semicolon)) { return; } @@ -1335,7 +1335,7 @@ void expect_semicolon(AstFile *f, AstNode *s) { return; } } - String node_string = ast_node_strings[s->kind]; + String node_string = ast_strings[s->kind]; syntax_error(prev_token, "Expected ';' after %.*s, got %.*s", LIT(node_string), LIT(token_strings[prev_token.kind])); } else { @@ -1345,16 +1345,16 @@ void expect_semicolon(AstFile *f, AstNode *s) { } -AstNode * parse_expr(AstFile *f, bool lhs); -AstNode * parse_proc_type(AstFile *f, Token proc_token); -Array parse_stmt_list(AstFile *f); -AstNode * parse_stmt(AstFile *f); -AstNode * parse_body(AstFile *f); -AstNode * parse_block_stmt(AstFile *f, b32 is_when); +Ast * parse_expr(AstFile *f, bool lhs); +Ast * parse_proc_type(AstFile *f, Token proc_token); +Array parse_stmt_list(AstFile *f); +Ast * parse_stmt(AstFile *f); +Ast * parse_body(AstFile *f); +Ast * parse_block_stmt(AstFile *f, b32 is_when); -AstNode *parse_ident(AstFile *f) { +Ast *parse_ident(AstFile *f) { Token token = f->curr_token; if (token.kind == Token_Ident) { advance_token(f); @@ -1365,46 +1365,46 @@ AstNode *parse_ident(AstFile *f) { return ast_ident(f, token); } -AstNode *parse_tag_expr(AstFile *f, AstNode *expression) { +Ast *parse_tag_expr(AstFile *f, Ast *expression) { Token token = expect_token(f, Token_Hash); Token name = expect_token(f, Token_Ident); return ast_tag_expr(f, token, name, expression); } -AstNode *unparen_expr(AstNode *node) { +Ast *unparen_expr(Ast *node) { for (;;) { if (node == nullptr) { return nullptr; } - if (node->kind != AstNode_ParenExpr) { + if (node->kind != Ast_ParenExpr) { return node; } node = node->ParenExpr.expr; } } -AstNode *unselector_expr(AstNode *node) { +Ast *unselector_expr(Ast *node) { node = unparen_expr(node); if (node == nullptr) { return nullptr; } - while (node->kind == AstNode_SelectorExpr) { + while (node->kind == Ast_SelectorExpr) { node = node->SelectorExpr.selector; } return node; } -AstNode *parse_value(AstFile *f); +Ast *parse_value(AstFile *f); -Array parse_element_list(AstFile *f) { - auto elems = array_make(heap_allocator()); +Array parse_element_list(AstFile *f) { + auto elems = array_make(heap_allocator()); while (f->curr_token.kind != Token_CloseBrace && f->curr_token.kind != Token_EOF) { - AstNode *elem = parse_value(f); + Ast *elem = parse_value(f); if (f->curr_token.kind == Token_Eq) { Token eq = expect_token(f, Token_Eq); - AstNode *value = parse_value(f); + Ast *value = parse_value(f); elem = ast_field_value(f, elem, value, eq); } @@ -1418,8 +1418,8 @@ Array parse_element_list(AstFile *f) { return elems; } -AstNode *parse_literal_value(AstFile *f, AstNode *type) { - Array elems = {}; +Ast *parse_literal_value(AstFile *f, Ast *type) { + Array elems = {}; Token open = expect_token(f, Token_OpenBrace); f->expr_level++; if (f->curr_token.kind != Token_CloseBrace) { @@ -1431,19 +1431,19 @@ AstNode *parse_literal_value(AstFile *f, AstNode *type) { return ast_compound_lit(f, type, elems, open, close); } -AstNode *parse_value(AstFile *f) { +Ast *parse_value(AstFile *f) { if (f->curr_token.kind == Token_OpenBrace) { return parse_literal_value(f, nullptr); } - AstNode *value = parse_expr(f, false); + Ast *value = parse_expr(f, false); return value; } -AstNode *parse_type_or_ident(AstFile *f); +Ast *parse_type_or_ident(AstFile *f); -void check_proc_add_tag(AstFile *f, AstNode *tag_expr, u64 *tags, ProcTag tag, String tag_name) { +void check_proc_add_tag(AstFile *f, Ast *tag_expr, u64 *tags, ProcTag tag, String tag_name) { if (*tags & tag) { syntax_error(tag_expr, "Procedure tag already used: %.*s", LIT(tag_name)); } @@ -1502,7 +1502,7 @@ void parse_proc_tags(AstFile *f, u64 *tags) { GB_ASSERT(tags != nullptr); while (f->curr_token.kind == Token_Hash) { - AstNode *tag_expr = parse_tag_expr(f, nullptr); + Ast *tag_expr = parse_tag_expr(f, nullptr); ast_node(te, TagExpr, tag_expr); String tag_name = te->name.string; @@ -1528,21 +1528,21 @@ void parse_proc_tags(AstFile *f, u64 *tags) { } -Array parse_lhs_expr_list (AstFile *f); -Array parse_rhs_expr_list (AstFile *f); -AstNode * parse_simple_stmt (AstFile *f, u32 flags); -AstNode * parse_type (AstFile *f); -AstNode * parse_call_expr (AstFile *f, AstNode *operand); -AstNode * parse_struct_field_list(AstFile *f, isize *name_count_); -AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_type_token); +Array parse_lhs_expr_list (AstFile *f); +Array parse_rhs_expr_list (AstFile *f); +Ast * parse_simple_stmt (AstFile *f, u32 flags); +Ast * parse_type (AstFile *f); +Ast * parse_call_expr (AstFile *f, Ast *operand); +Ast * parse_struct_field_list(AstFile *f, isize *name_count_); +Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_type_token); -AstNode *convert_stmt_to_expr(AstFile *f, AstNode *statement, String kind) { +Ast *convert_stmt_to_expr(AstFile *f, Ast *statement, String kind) { if (statement == nullptr) { return nullptr; } - if (statement->kind == AstNode_ExprStmt) { + if (statement->kind == Ast_ExprStmt) { return statement->ExprStmt.expr; } @@ -1554,18 +1554,18 @@ AstNode *convert_stmt_to_expr(AstFile *f, AstNode *statement, String kind) { return ast_bad_expr(f, f->curr_token, end); } -AstNode *convert_stmt_to_body(AstFile *f, AstNode *stmt) { - if (stmt->kind == AstNode_BlockStmt) { +Ast *convert_stmt_to_body(AstFile *f, Ast *stmt) { + if (stmt->kind == Ast_BlockStmt) { syntax_error(stmt, "Expected a normal statement rather than a block statement"); return stmt; } - if (stmt->kind == AstNode_EmptyStmt) { + if (stmt->kind == Ast_EmptyStmt) { syntax_error(stmt, "Expected a non-empty statement"); } - GB_ASSERT(is_ast_node_stmt(stmt) || is_ast_node_decl(stmt)); - Token open = ast_node_token(stmt); - Token close = ast_node_token(stmt); - auto stmts = array_make(heap_allocator(), 0, 1); + GB_ASSERT(is_ast_stmt(stmt) || is_ast_decl(stmt)); + Token open = ast_token(stmt); + Token close = ast_token(stmt); + auto stmts = array_make(heap_allocator(), 0, 1); array_add(&stmts, stmt); return ast_block_stmt(f, stmts, open, close); } @@ -1573,8 +1573,8 @@ AstNode *convert_stmt_to_body(AstFile *f, AstNode *stmt) { -AstNode *parse_operand(AstFile *f, bool lhs) { - AstNode *operand = nullptr; // Operand +Ast *parse_operand(AstFile *f, bool lhs) { + Ast *operand = nullptr; // Operand switch (f->curr_token.kind) { case Token_Ident: return parse_ident(f); @@ -1617,7 +1617,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) { case Token_distinct: { Token token = expect_token(f, Token_distinct); - AstNode *type = parse_type(f); + Ast *type = parse_type(f); return ast_distinct_type(f, token, type); } @@ -1628,9 +1628,9 @@ AstNode *parse_operand(AstFile *f, bool lhs) { } Token name = expect_token(f, Token_Ident); if (name.string == "run") { - AstNode *expr = parse_expr(f, false); + Ast *expr = parse_expr(f, false); operand = ast_run_expr(f, token, name, expr); - if (unparen_expr(expr)->kind != AstNode_CallExpr) { + if (unparen_expr(expr)->kind != Ast_CallExpr) { syntax_error(expr, "#run can only be applied to procedure calls"); operand = ast_bad_expr(f, token, f->curr_token); } @@ -1640,10 +1640,10 @@ AstNode *parse_operand(AstFile *f, bool lhs) { } else if (name.string == "procedure") { return ast_basic_directive(f, token, name.string); } else if (name.string == "caller_location") { return ast_basic_directive(f, token, name.string); } else if (name.string == "location") { - AstNode *tag = ast_basic_directive(f, token, name.string); + Ast *tag = ast_basic_directive(f, token, name.string); return parse_call_expr(f, tag); } else if (name.string == "assert") { - AstNode *tag = ast_basic_directive(f, token, name.string); + Ast *tag = ast_basic_directive(f, token, name.string); return parse_call_expr(f, tag); } else { operand = ast_tag_expr(f, token, name, parse_expr(f, false)); @@ -1655,9 +1655,9 @@ AstNode *parse_operand(AstFile *f, bool lhs) { case Token_no_inline: { Token token = advance_token(f); - AstNode *expr = parse_operand(f, false); - if (expr->kind != AstNode_ProcLit) { - syntax_error(expr, "%.*s must be followed by a procedure literal, got %.*s", LIT(token.string), LIT(ast_node_strings[expr->kind])); + Ast *expr = parse_operand(f, false); + if (expr->kind != Ast_ProcLit) { + syntax_error(expr, "%.*s must be followed by a procedure literal, got %.*s", LIT(token.string), LIT(ast_strings[expr->kind])); return ast_bad_expr(f, token, f->curr_token); } ProcInlining pi = ProcInlining_none; @@ -1684,11 +1684,11 @@ AstNode *parse_operand(AstFile *f, bool lhs) { if (f->curr_token.kind == Token_OpenBracket) { // ProcGroup Token open = expect_token(f, Token_OpenBracket); - auto args = array_make(heap_allocator()); + auto args = array_make(heap_allocator()); while (f->curr_token.kind != Token_CloseBracket && f->curr_token.kind != Token_EOF) { - AstNode *elem = parse_expr(f, false); + Ast *elem = parse_expr(f, false); array_add(&args, elem); if (!allow_token(f, Token_Comma)) { @@ -1705,7 +1705,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) { return ast_proc_group(f, token, open, close, args); } - AstNode *type = parse_proc_type(f, token); + Ast *type = parse_proc_type(f, token); if (f->allow_type && f->expr_level < 0) { return type; @@ -1716,16 +1716,16 @@ AstNode *parse_operand(AstFile *f, bool lhs) { if (allow_token(f, Token_Undef)) { return ast_proc_lit(f, type, nullptr, tags); } else if (f->curr_token.kind == Token_OpenBrace) { - AstNode *curr_proc = f->curr_proc; - AstNode *body = nullptr; + Ast *curr_proc = f->curr_proc; + Ast *body = nullptr; f->curr_proc = type; body = parse_body(f); f->curr_proc = curr_proc; return ast_proc_lit(f, type, body, tags); } else if (allow_token(f, Token_do)) { - AstNode *curr_proc = f->curr_proc; - AstNode *body = nullptr; + Ast *curr_proc = f->curr_proc; + Ast *body = nullptr; f->curr_proc = type; body = convert_stmt_to_body(f, parse_stmt(f)); f->curr_proc = curr_proc; @@ -1744,8 +1744,8 @@ AstNode *parse_operand(AstFile *f, bool lhs) { // Check for Types case Token_Dollar: { Token token = expect_token(f, Token_Dollar); - AstNode *type = parse_ident(f); - AstNode *specialization = nullptr; + Ast *type = parse_ident(f); + Ast *specialization = nullptr; if (allow_token(f, Token_Quo)) { specialization = parse_type(f); } @@ -1753,11 +1753,11 @@ AstNode *parse_operand(AstFile *f, bool lhs) { } break; case Token_type_of: { - AstNode *i = ast_implicit(f, expect_token(f, Token_type_of)); - AstNode *type = parse_call_expr(f, i); + Ast *i = ast_implicit(f, expect_token(f, Token_type_of)); + Ast *type = parse_call_expr(f, i); while (f->curr_token.kind == Token_Period) { Token token = advance_token(f); - AstNode *sel = parse_ident(f); + Ast *sel = parse_ident(f); type = ast_selector_expr(f, token, type, sel); } return type; @@ -1765,13 +1765,13 @@ AstNode *parse_operand(AstFile *f, bool lhs) { case Token_Pointer: { Token token = expect_token(f, Token_Pointer); - AstNode *elem = parse_type(f); + Ast *elem = parse_type(f); return ast_pointer_type(f, token, elem); } break; case Token_OpenBracket: { Token token = expect_token(f, Token_OpenBracket); - AstNode *count_expr = nullptr; + Ast *count_expr = nullptr; if (f->curr_token.kind == Token_Question) { count_expr = ast_unary_expr(f, expect_token(f, Token_Question), nullptr); } else if (allow_token(f, Token_dynamic)) { @@ -1788,8 +1788,8 @@ AstNode *parse_operand(AstFile *f, bool lhs) { case Token_map: { Token token = expect_token(f, Token_map); - AstNode *key = nullptr; - AstNode *value = nullptr; + Ast *key = nullptr; + Ast *value = nullptr; Token open, close; open = expect_token_after(f, Token_OpenBracket, "map"); @@ -1802,10 +1802,10 @@ AstNode *parse_operand(AstFile *f, bool lhs) { case Token_struct: { Token token = expect_token(f, Token_struct); - AstNode *polymorphic_params = nullptr; + Ast *polymorphic_params = nullptr; bool is_packed = false; bool is_raw_union = false; - AstNode *align = nullptr; + Ast *align = nullptr; if (allow_token(f, Token_OpenParen)) { isize param_count = 0; @@ -1852,12 +1852,12 @@ AstNode *parse_operand(AstFile *f, bool lhs) { Token open = expect_token_after(f, Token_OpenBrace, "struct"); isize name_count = 0; - AstNode *fields = parse_struct_field_list(f, &name_count); + Ast *fields = parse_struct_field_list(f, &name_count); Token close = expect_token(f, Token_CloseBrace); - Array decls = {}; + Array decls = {}; if (fields != nullptr) { - GB_ASSERT(fields->kind == AstNode_FieldList); + GB_ASSERT(fields->kind == Ast_FieldList); decls = fields->FieldList.list; } @@ -1867,8 +1867,8 @@ AstNode *parse_operand(AstFile *f, bool lhs) { case Token_union: { Token token = expect_token(f, Token_union); Token open = expect_token_after(f, Token_OpenBrace, "union"); - auto variants = array_make(heap_allocator()); - AstNode *align = nullptr; + auto variants = array_make(heap_allocator()); + Ast *align = nullptr; CommentGroup *docs = f->lead_comment; Token start_token = f->curr_token; @@ -1888,8 +1888,8 @@ AstNode *parse_operand(AstFile *f, bool lhs) { while (f->curr_token.kind != Token_CloseBrace && f->curr_token.kind != Token_EOF) { - AstNode *type = parse_type(f); - if (type->kind != AstNode_BadExpr) { + Ast *type = parse_type(f); + if (type->kind != Ast_BadExpr) { array_add(&variants, type); } if (!allow_token(f, Token_Comma)) { @@ -1905,7 +1905,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) { case Token_enum: { bool is_export = false; Token token = expect_token(f, Token_enum); - AstNode *base_type = nullptr; + Ast *base_type = nullptr; if (f->curr_token.kind != Token_OpenBrace) { if (f->curr_token.kind != Token_Hash) { base_type = parse_type(f); @@ -1927,7 +1927,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) { } Token open = expect_token(f, Token_OpenBrace); - Array values = parse_element_list(f); + Array values = parse_element_list(f); Token close = expect_token(f, Token_CloseBrace); return ast_enum_type(f, token, base_type, is_export, values); @@ -1935,8 +1935,8 @@ AstNode *parse_operand(AstFile *f, bool lhs) { case Token_bit_field: { Token token = expect_token(f, Token_bit_field); - auto fields = array_make(heap_allocator()); - AstNode *align = nullptr; + auto fields = array_make(heap_allocator()); + Ast *align = nullptr; Token open, close; isize prev_level = f->expr_level; @@ -1960,11 +1960,11 @@ AstNode *parse_operand(AstFile *f, bool lhs) { while (f->curr_token.kind != Token_EOF && f->curr_token.kind != Token_CloseBrace) { - AstNode *name = parse_ident(f); + Ast *name = parse_ident(f); Token colon = expect_token(f, Token_Colon); - AstNode *value = parse_expr(f, true); + Ast *value = parse_expr(f, true); - AstNode *field = ast_field_value(f, name, value, colon); + Ast *field = ast_field_value(f, name, value, colon); array_add(&fields, field); if (f->curr_token.kind != Token_Comma) { @@ -1980,12 +1980,12 @@ AstNode *parse_operand(AstFile *f, bool lhs) { default: { #if 0 - AstNode *type = parse_type_or_ident(f); + Ast *type = parse_type_or_ident(f); if (type != nullptr) { // TODO(bill): Is this correct??? // NOTE(bill): Sanity check as identifiers should be handled already - TokenPos pos = ast_node_token(type).pos; - GB_ASSERT_MSG(type->kind != AstNode_Ident, "Type cannot be identifier %.*s(%td:%td)", LIT(pos.file), pos.line, pos.column); + TokenPos pos = ast_token(type).pos; + GB_ASSERT_MSG(type->kind != Ast_Ident, "Type cannot be identifier %.*s(%td:%td)", LIT(pos.file), pos.line, pos.column); return type; } #endif @@ -1996,26 +1996,26 @@ AstNode *parse_operand(AstFile *f, bool lhs) { return nullptr; } -bool is_literal_type(AstNode *node) { +bool is_literal_type(Ast *node) { node = unparen_expr(node); switch (node->kind) { - case AstNode_BadExpr: - case AstNode_Ident: - case AstNode_SelectorExpr: - case AstNode_ArrayType: - case AstNode_StructType: - case AstNode_UnionType: - case AstNode_EnumType: - case AstNode_DynamicArrayType: - case AstNode_MapType: - case AstNode_CallExpr: + case Ast_BadExpr: + case Ast_Ident: + case Ast_SelectorExpr: + case Ast_ArrayType: + case Ast_StructType: + case Ast_UnionType: + case Ast_EnumType: + case Ast_DynamicArrayType: + case Ast_MapType: + case Ast_CallExpr: return true; } return false; } -AstNode *parse_call_expr(AstFile *f, AstNode *operand) { - auto args = array_make(heap_allocator()); +Ast *parse_call_expr(AstFile *f, Ast *operand) { + auto args = array_make(heap_allocator()); Token open_paren, close_paren; Token ellipsis = {}; @@ -2037,7 +2037,7 @@ AstNode *parse_call_expr(AstFile *f, AstNode *operand) { ellipsis = expect_token(f, Token_Ellipsis); } - AstNode *arg = parse_expr(f, false); + Ast *arg = parse_expr(f, false); if (f->curr_token.kind == Token_Eq) { Token eq = expect_token(f, Token_Eq); @@ -2045,7 +2045,7 @@ AstNode *parse_call_expr(AstFile *f, AstNode *operand) { syntax_error(ellipsis, "'...' must be applied to value rather than the field name"); } - AstNode *value = parse_value(f); + Ast *value = parse_value(f); arg = ast_field_value(f, arg, value, eq); @@ -2063,7 +2063,7 @@ AstNode *parse_call_expr(AstFile *f, AstNode *operand) { return ast_call_expr(f, operand, args, open_paren, close_paren, ellipsis); } -AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) { +Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { if (operand == nullptr) { if (f->allow_type) return nullptr; Token begin = f->curr_token; @@ -2090,7 +2090,7 @@ AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) { // break; case Token_OpenParen: { Token open = expect_token(f, Token_OpenParen); - AstNode *type = parse_type(f); + Ast *type = parse_type(f); Token close = expect_token(f, Token_CloseParen); operand = ast_type_assertion(f, operand, token, type); } break; @@ -2098,7 +2098,7 @@ AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) { default: syntax_error(f->curr_token, "Expected a selector"); advance_token(f); - operand = ast_bad_expr(f, ast_node_token(operand), f->curr_token); + operand = ast_bad_expr(f, ast_token(operand), f->curr_token); // operand = ast_selector_expr(f, f->curr_token, operand, nullptr); break; } @@ -2112,7 +2112,7 @@ AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) { f->allow_range = false; Token open = {}, close = {}, interval = {}; - AstNode *indices[2] = {}; + Ast *indices[2] = {}; Token ellipsis = {}; bool is_ellipsis = false; @@ -2173,21 +2173,21 @@ AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) { } -AstNode *parse_unary_expr(AstFile *f, bool lhs) { +Ast *parse_unary_expr(AstFile *f, bool lhs) { switch (f->curr_token.kind) { case Token_transmute: case Token_cast: { Token token = advance_token(f); expect_token(f, Token_OpenParen); - AstNode *type = parse_type(f); + Ast *type = parse_type(f); expect_token(f, Token_CloseParen); - AstNode *expr = parse_unary_expr(f, lhs); + Ast *expr = parse_unary_expr(f, lhs); return ast_type_cast(f, token, type, expr); } case Token_auto_cast: { Token token = advance_token(f); - AstNode *expr = parse_unary_expr(f, lhs); + Ast *expr = parse_unary_expr(f, lhs); return ast_auto_cast(f, token, expr); } @@ -2197,7 +2197,7 @@ AstNode *parse_unary_expr(AstFile *f, bool lhs) { case Token_Xor: case Token_And: { Token token = advance_token(f); - AstNode *expr = parse_unary_expr(f, lhs); + Ast *expr = parse_unary_expr(f, lhs); return ast_unary_expr(f, token, expr); } } @@ -2205,11 +2205,11 @@ AstNode *parse_unary_expr(AstFile *f, bool lhs) { return parse_atom_expr(f, parse_operand(f, lhs), lhs); } -bool is_ast_node_a_range(AstNode *expr) { +bool is_ast_range(Ast *expr) { if (expr == nullptr) { return false; } - if (expr->kind != AstNode_BinaryExpr) { + if (expr->kind != Ast_BinaryExpr) { return false; } TokenKind op = expr->BinaryExpr.op.kind; @@ -2261,8 +2261,8 @@ i32 token_precedence(AstFile *f, TokenKind t) { return 0; } -AstNode *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { - AstNode *expr = parse_unary_expr(f, lhs); +Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { + Ast *expr = parse_unary_expr(f, lhs); for (i32 prec = token_precedence(f, f->curr_token.kind); prec >= prec_in; prec--) { for (;;) { Token op = f->curr_token; @@ -2274,14 +2274,14 @@ AstNode *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { expect_operator(f); // NOTE(bill): error checks too if (op.kind == Token_Question) { - AstNode *cond = expr; + Ast *cond = expr; // Token_Question - AstNode *x = parse_expr(f, lhs); + Ast *x = parse_expr(f, lhs); Token token_c = expect_token(f, Token_Colon); - AstNode *y = parse_expr(f, lhs); + Ast *y = parse_expr(f, lhs); expr = ast_ternary_expr(f, cond, x, y); } else { - AstNode *right = parse_binary_expr(f, false, prec+1); + Ast *right = parse_binary_expr(f, false, prec+1); if (right == nullptr) { syntax_error(op, "Expected expression on the right-hand side of the binary operator"); } @@ -2294,15 +2294,15 @@ AstNode *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { return expr; } -AstNode *parse_expr(AstFile *f, bool lhs) { +Ast *parse_expr(AstFile *f, bool lhs) { return parse_binary_expr(f, lhs, 0+1); } -Array parse_expr_list(AstFile *f, bool lhs) { - auto list = array_make(heap_allocator()); +Array parse_expr_list(AstFile *f, bool lhs) { + auto list = array_make(heap_allocator()); for (;;) { - AstNode *e = parse_expr(f, lhs); + Ast *e = parse_expr(f, lhs); array_add(&list, e); if (f->curr_token.kind != Token_Comma || f->curr_token.kind == Token_EOF) { @@ -2314,16 +2314,16 @@ Array parse_expr_list(AstFile *f, bool lhs) { return list; } -Array parse_lhs_expr_list(AstFile *f) { +Array parse_lhs_expr_list(AstFile *f) { return parse_expr_list(f, true); } -Array parse_rhs_expr_list(AstFile *f) { +Array parse_rhs_expr_list(AstFile *f) { return parse_expr_list(f, false); } -Array parse_ident_list(AstFile *f) { - auto list = array_make(heap_allocator()); +Array parse_ident_list(AstFile *f) { + auto list = array_make(heap_allocator()); for (;;) { array_add(&list, parse_ident(f)); @@ -2337,8 +2337,8 @@ Array parse_ident_list(AstFile *f) { return list; } -AstNode *parse_type(AstFile *f) { - AstNode *type = parse_type_or_ident(f); +Ast *parse_type(AstFile *f) { + Ast *type = parse_type_or_ident(f); if (type == nullptr) { Token token = advance_token(f); syntax_error(token, "Expected a type"); @@ -2347,16 +2347,16 @@ AstNode *parse_type(AstFile *f) { return type; } -void parse_foreign_block_decl(AstFile *f, Array *decls) { - AstNode *decl = parse_stmt(f); +void parse_foreign_block_decl(AstFile *f, Array *decls) { + Ast *decl = parse_stmt(f); switch (decl->kind) { - case AstNode_EmptyStmt: - case AstNode_BadStmt: - case AstNode_BadDecl: + case Ast_EmptyStmt: + case Ast_BadStmt: + case Ast_BadDecl: return; - case AstNode_WhenStmt: - case AstNode_ValueDecl: + case Ast_WhenStmt: + case Ast_ValueDecl: array_add(decls, decl); return; @@ -2366,9 +2366,9 @@ void parse_foreign_block_decl(AstFile *f, Array *decls) { } } -AstNode *parse_foreign_block(AstFile *f, Token token) { +Ast *parse_foreign_block(AstFile *f, Token token) { CommentGroup *docs = f->lead_comment; - AstNode *foreign_library = nullptr; + Ast *foreign_library = nullptr; if (f->curr_token.kind == Token_export) { foreign_library = ast_implicit(f, expect_token(f, Token_export)); } else if (f->curr_token.kind == Token_OpenBrace) { @@ -2378,7 +2378,7 @@ AstNode *parse_foreign_block(AstFile *f, Token token) { } Token open = {}; Token close = {}; - auto decls = array_make(heap_allocator()); + auto decls = array_make(heap_allocator()); bool prev_in_foreign_block = f->in_foreign_block; defer (f->in_foreign_block = prev_in_foreign_block); @@ -2394,18 +2394,18 @@ AstNode *parse_foreign_block(AstFile *f, Token token) { close = expect_token(f, Token_CloseBrace); - AstNode *body = ast_block_stmt(f, decls, open, close); + Ast *body = ast_block_stmt(f, decls, open, close); - AstNode *decl = ast_foreign_block_decl(f, token, foreign_library, body, docs); + Ast *decl = ast_foreign_block_decl(f, token, foreign_library, body, docs); expect_semicolon(f, decl); return decl; } -AstNode *parse_value_decl(AstFile *f, Array names, CommentGroup *docs) { +Ast *parse_value_decl(AstFile *f, Array names, CommentGroup *docs) { bool is_mutable = true; - AstNode *type = nullptr; - Array values = {}; + Ast *type = nullptr; + Array values = {}; if (f->curr_token.kind == Token_type) { type = ast_type_type(f, advance_token(f), nullptr); @@ -2446,11 +2446,11 @@ AstNode *parse_value_decl(AstFile *f, Array names, CommentGroup *docs } if (values.data == nullptr) { - values = array_make(heap_allocator()); + values = array_make(heap_allocator()); } if (f->expr_level >= 0) { - AstNode *end = nullptr; + Ast *end = nullptr; if (!is_mutable && values.count > 0) { end = values[values.count-1]; } @@ -2465,11 +2465,11 @@ AstNode *parse_value_decl(AstFile *f, Array names, CommentGroup *docs return ast_value_decl(f, names, type, values, is_mutable, docs, f->line_comment); } -AstNode *parse_simple_stmt(AstFile *f, u32 flags) { +Ast *parse_simple_stmt(AstFile *f, u32 flags) { Token token = f->curr_token; CommentGroup *docs = f->lead_comment; - Array lhs = parse_lhs_expr_list(f); + Array lhs = parse_lhs_expr_list(f); token = f->curr_token; switch (token.kind) { case Token_Eq: @@ -2493,7 +2493,7 @@ AstNode *parse_simple_stmt(AstFile *f, u32 flags) { return ast_bad_stmt(f, f->curr_token, f->curr_token); } advance_token(f); - Array rhs = parse_rhs_expr_list(f); + Array rhs = parse_rhs_expr_list(f); if (rhs.count == 0) { syntax_error(token, "No right-hand side in assignment statement."); return ast_bad_stmt(f, token, f->curr_token); @@ -2506,10 +2506,10 @@ AstNode *parse_simple_stmt(AstFile *f, u32 flags) { allow_token(f, Token_in); bool prev_allow_range = f->allow_range; f->allow_range = true; - AstNode *expr = parse_expr(f, false); + Ast *expr = parse_expr(f, false); f->allow_range = prev_allow_range; - auto rhs = array_make(heap_allocator(), 0, 1); + auto rhs = array_make(heap_allocator(), 0, 1); array_add(&rhs, expr); return ast_assign_stmt(f, token, lhs, rhs); @@ -2522,10 +2522,10 @@ AstNode *parse_simple_stmt(AstFile *f, u32 flags) { switch (f->curr_token.kind) { case Token_for: case Token_switch: { - AstNode *name = lhs[0]; - AstNode *label = ast_label_decl(f, ast_node_token(name), name); - AstNode *stmt = parse_stmt(f); - #define _SET_LABEL(Kind_, label_) case GB_JOIN2(AstNode_, Kind_): (stmt->Kind_).label = label_; break + Ast *name = lhs[0]; + Ast *label = ast_label_decl(f, ast_token(name), name); + Ast *stmt = parse_stmt(f); + #define _SET_LABEL(Kind_, label_) case GB_JOIN2(Ast_, Kind_): (stmt->Kind_).label = label_; break switch (stmt->kind) { _SET_LABEL(ForStmt, label); _SET_LABEL(RangeStmt, label); @@ -2545,10 +2545,10 @@ AstNode *parse_simple_stmt(AstFile *f, u32 flags) { case Token_ArrowLeft: if ((flags&StmtAllowFlag_Context) && lhs.count == 1) { Token arrow = expect_token(f, Token_ArrowLeft); - AstNode *body = nullptr; + Ast *body = nullptr; isize prev_level = f->expr_level; f->expr_level = -1; - AstNode *expr = parse_expr(f, false); + Ast *expr = parse_expr(f, false); f->expr_level = prev_level; if (allow_token(f, Token_do)) { @@ -2583,7 +2583,7 @@ AstNode *parse_simple_stmt(AstFile *f, u32 flags) { -AstNode *parse_block_stmt(AstFile *f, b32 is_when) { +Ast *parse_block_stmt(AstFile *f, b32 is_when) { if (!is_when && f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a block statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -2593,7 +2593,7 @@ AstNode *parse_block_stmt(AstFile *f, b32 is_when) { -AstNode *parse_results(AstFile *f) { +Ast *parse_results(AstFile *f) { if (!allow_token(f, Token_ArrowRight)) { return nullptr; } @@ -2604,14 +2604,14 @@ AstNode *parse_results(AstFile *f) { if (f->curr_token.kind != Token_OpenParen) { Token begin_token = f->curr_token; - Array empty_names = {}; - auto list = array_make(heap_allocator(), 0, 1); - AstNode *type = parse_type(f); + Array empty_names = {}; + auto list = array_make(heap_allocator(), 0, 1); + Ast *type = parse_type(f); array_add(&list, ast_field(f, empty_names, type, nullptr, 0, nullptr, nullptr)); return ast_field_list(f, begin_token, list); } - AstNode *list = nullptr; + Ast *list = nullptr; expect_token(f, Token_OpenParen); list = parse_field_list(f, nullptr, FieldFlag_Results, Token_CloseParen, true, false); expect_token_after(f, Token_CloseParen, "parameter list"); @@ -2631,9 +2631,9 @@ ProcCallingConvention string_to_calling_convention(String s) { return ProcCC_Invalid; } -AstNode *parse_proc_type(AstFile *f, Token proc_token) { - AstNode *params = nullptr; - AstNode *results = nullptr; +Ast *parse_proc_type(AstFile *f, Token proc_token) { + Ast *params = nullptr; + Ast *results = nullptr; ProcCallingConvention cc = ProcCC_Invalid; if (f->curr_token.kind == Token_String) { @@ -2665,11 +2665,11 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token) { bool is_generic = false; for_array(i, params->FieldList.list) { - AstNode *param = params->FieldList.list[i]; + Ast *param = params->FieldList.list[i]; ast_node(field, Field, param); if (field->type != nullptr) { - if (field->type->kind == AstNode_TypeType || - field->type->kind == AstNode_PolyType) { + if (field->type->kind == Ast_TypeType || + field->type->kind == Ast_PolyType) { is_generic = true; break; } @@ -2680,21 +2680,21 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token) { return ast_proc_type(f, proc_token, params, results, tags, cc, is_generic); } -AstNode *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_type_token) { +Ast *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_type_token) { if (allow_ellipsis && f->curr_token.kind == Token_Ellipsis) { Token tok = advance_token(f); - AstNode *type = parse_type_or_ident(f); + Ast *type = parse_type_or_ident(f); if (type == nullptr) { syntax_error(tok, "variadic field missing type after '...'"); type = ast_bad_expr(f, tok, f->curr_token); } return ast_ellipsis(f, tok, type); } - AstNode *type = nullptr; + Ast *type = nullptr; if (allow_type_token && f->curr_token.kind == Token_type) { Token token = expect_token(f, Token_type); - AstNode *specialization = nullptr; + Ast *specialization = nullptr; if (allow_token(f, Token_Quo)) { specialization = parse_type(f); } @@ -2803,16 +2803,16 @@ u32 check_field_prefixes(AstFile *f, isize name_count, u32 allowed_flags, u32 se return set_flags; } -struct AstNodeAndFlags { - AstNode *node; +struct AstAndFlags { + Ast *node; u32 flags; }; -Array convert_to_ident_list(AstFile *f, Array list, bool ignore_flags) { - auto idents = array_make(heap_allocator(), 0, list.count); +Array convert_to_ident_list(AstFile *f, Array list, bool ignore_flags) { + auto idents = array_make(heap_allocator(), 0, list.count); // Convert to ident list for_array(i, list) { - AstNode *ident = list[i].node; + Ast *ident = list[i].node; if (!ignore_flags) { if (i != 0) { @@ -2821,8 +2821,8 @@ Array convert_to_ident_list(AstFile *f, Array list, } switch (ident->kind) { - case AstNode_Ident: - case AstNode_BadExpr: + case Ast_Ident: + case Ast_BadExpr: break; default: syntax_error(ident, "Expected an identifier"); @@ -2835,7 +2835,7 @@ Array convert_to_ident_list(AstFile *f, Array list, } -bool parse_expect_field_separator(AstFile *f, AstNode *param) { +bool parse_expect_field_separator(AstFile *f, Ast *param) { Token token = f->curr_token; if (allow_token(f, Token_Comma)) { return true; @@ -2848,7 +2848,7 @@ bool parse_expect_field_separator(AstFile *f, AstNode *param) { return false; } -bool parse_expect_struct_separator(AstFile *f, AstNode *param) { +bool parse_expect_struct_separator(AstFile *f, Ast *param) { Token token = f->curr_token; if (allow_token(f, Token_Semicolon)) { return true; @@ -2871,27 +2871,27 @@ bool parse_expect_struct_separator(AstFile *f, AstNode *param) { } -AstNode *parse_struct_field_list(AstFile *f, isize *name_count_) { +Ast *parse_struct_field_list(AstFile *f, isize *name_count_) { CommentGroup *docs = f->lead_comment; Token start_token = f->curr_token; - auto decls = array_make(heap_allocator()); + auto decls = array_make(heap_allocator()); isize total_name_count = 0; - AstNode *params = parse_field_list(f, &total_name_count, FieldFlag_Struct, Token_CloseBrace, false, false); + Ast *params = parse_field_list(f, &total_name_count, FieldFlag_Struct, Token_CloseBrace, false, false); if (name_count_) *name_count_ = total_name_count; return params; } -AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_type_token) { +Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_type_token) { Token start_token = f->curr_token; CommentGroup *docs = f->lead_comment; - auto params = array_make(heap_allocator()); + auto params = array_make(heap_allocator()); - auto list = array_make(heap_allocator()); + auto list = array_make(heap_allocator()); defer (array_free(&list)); isize total_name_count = 0; @@ -2902,14 +2902,14 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok f->curr_token.kind != Token_Colon && f->curr_token.kind != Token_EOF) { u32 flags = parse_field_prefixes(f); - AstNode *param = parse_var_type(f, allow_ellipsis, allow_type_token); - if (param->kind == AstNode_Ellipsis) { + Ast *param = parse_var_type(f, allow_ellipsis, allow_type_token); + if (param->kind == Ast_Ellipsis) { if (seen_ellipsis) syntax_error(param, "Extra variadic parameter after ellipsis"); seen_ellipsis = true; } else if (seen_ellipsis) { syntax_error(param, "Extra parameter after ellipsis"); } - AstNodeAndFlags naf = {param, flags}; + AstAndFlags naf = {param, flags}; array_add(&list, naf); if (!allow_token(f, Token_Comma)) { break; @@ -2918,7 +2918,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok if (f->curr_token.kind == Token_Colon) { - Array names = convert_to_ident_list(f, list, true); // Copy for semantic reasons + Array names = convert_to_ident_list(f, list, true); // Copy for semantic reasons if (names.count == 0) { syntax_error(f->curr_token, "Empty field declaration"); } @@ -2929,8 +2929,8 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok set_flags = check_field_prefixes(f, names.count, allowed_flags, set_flags); total_name_count += names.count; - AstNode *type = nullptr; - AstNode *default_value = nullptr; + Ast *type = nullptr; + Ast *default_value = nullptr; expect_token_after(f, Token_Colon, "field list"); if (f->curr_token.kind != Token_Eq) { @@ -2954,7 +2954,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok default_value = nullptr; } - if (type != nullptr && type->kind == AstNode_Ellipsis) { + if (type != nullptr && type->kind == Ast_Ellipsis) { if (seen_ellipsis) syntax_error(type, "Extra variadic parameter after ellipsis"); seen_ellipsis = true; if (names.count != 1) { @@ -2965,7 +2965,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok } parse_expect_field_separator(f, type); - AstNode *param = ast_field(f, names, type, default_value, set_flags, docs, f->line_comment); + Ast *param = ast_field(f, names, type, default_value, set_flags, docs, f->line_comment); array_add(¶ms, param); @@ -2974,7 +2974,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok CommentGroup *docs = f->lead_comment; u32 set_flags = parse_field_prefixes(f); - Array names = parse_ident_list(f); + Array names = parse_ident_list(f); if (names.count == 0) { syntax_error(f->curr_token, "Empty field declaration"); break; @@ -2982,8 +2982,8 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok set_flags = check_field_prefixes(f, names.count, allowed_flags, set_flags); total_name_count += names.count; - AstNode *type = nullptr; - AstNode *default_value = nullptr; + Ast *type = nullptr; + Ast *default_value = nullptr; expect_token_after(f, Token_Colon, "field list"); if (f->curr_token.kind != Token_Eq) { type = parse_var_type(f, allow_ellipsis, allow_type_token); @@ -3001,7 +3001,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok syntax_error(f->curr_token, "Default parameters can only be applied to single values"); } - if (type != nullptr && type->kind == AstNode_Ellipsis) { + if (type != nullptr && type->kind == Ast_Ellipsis) { if (seen_ellipsis) syntax_error(type, "Extra variadic parameter after ellipsis"); seen_ellipsis = true; if (names.count != 1) { @@ -3013,7 +3013,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok bool ok = parse_expect_field_separator(f, param); - AstNode *param = ast_field(f, names, type, default_value, set_flags, docs, f->line_comment); + Ast *param = ast_field(f, names, type, default_value, set_flags, docs, f->line_comment); array_add(¶ms, param); if (!ok) { @@ -3026,19 +3026,19 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok } for_array(i, list) { - AstNode *type = list[i].node; + Ast *type = list[i].node; Token token = blank_token; if (allowed_flags&FieldFlag_Results) { // NOTE(bill): Make this nothing and not `_` token.string = str_lit(""); } - auto names = array_make(heap_allocator(), 1); - token.pos = ast_node_token(type).pos; + auto names = array_make(heap_allocator(), 1); + token.pos = ast_token(type).pos; names[0] = ast_ident(f, token); u32 flags = check_field_prefixes(f, list.count, allowed_flags, list[i].flags); - AstNode *param = ast_field(f, names, list[i].node, nullptr, flags, docs, f->line_comment); + Ast *param = ast_field(f, names, list[i].node, nullptr, flags, docs, f->line_comment); array_add(¶ms, param); } @@ -3046,7 +3046,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok return ast_field_list(f, start_token, params); } -AstNode *parse_type_or_ident(AstFile *f) { +Ast *parse_type_or_ident(AstFile *f) { bool prev_allow_type = f->allow_type; isize prev_expr_level = f->expr_level; defer ({ @@ -3058,15 +3058,15 @@ AstNode *parse_type_or_ident(AstFile *f) { f->expr_level = -1; bool lhs = true; - AstNode *operand = parse_operand(f, lhs); - AstNode *type = parse_atom_expr(f, operand, lhs); + Ast *operand = parse_operand(f, lhs); + Ast *type = parse_atom_expr(f, operand, lhs); return type; } -AstNode *parse_body(AstFile *f) { - Array stmts = {}; +Ast *parse_body(AstFile *f) { + Array stmts = {}; Token open, close; isize prev_expr_level = f->expr_level; @@ -3080,17 +3080,17 @@ AstNode *parse_body(AstFile *f) { return ast_block_stmt(f, stmts, open, close); } -AstNode *parse_if_stmt(AstFile *f) { +Ast *parse_if_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use an if statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } Token token = expect_token(f, Token_if); - AstNode *init = nullptr; - AstNode *cond = nullptr; - AstNode *body = nullptr; - AstNode *else_stmt = nullptr; + Ast *init = nullptr; + Ast *cond = nullptr; + Ast *body = nullptr; + Ast *else_stmt = nullptr; isize prev_level = f->expr_level; f->expr_level = -1; @@ -3141,11 +3141,11 @@ AstNode *parse_if_stmt(AstFile *f) { return ast_if_stmt(f, token, init, cond, body, else_stmt); } -AstNode *parse_when_stmt(AstFile *f) { +Ast *parse_when_stmt(AstFile *f) { Token token = expect_token(f, Token_when); - AstNode *cond = nullptr; - AstNode *body = nullptr; - AstNode *else_stmt = nullptr; + Ast *cond = nullptr; + Ast *body = nullptr; + Ast *else_stmt = nullptr; isize prev_level = f->expr_level; isize when_level = f->when_level; @@ -3190,7 +3190,7 @@ AstNode *parse_when_stmt(AstFile *f) { } -AstNode *parse_return_stmt(AstFile *f) { +Ast *parse_return_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a return statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -3201,13 +3201,13 @@ AstNode *parse_return_stmt(AstFile *f) { } Token token = expect_token(f, Token_return); - auto results = array_make(heap_allocator()); + auto results = array_make(heap_allocator()); while (f->curr_token.kind != Token_Semicolon) { - AstNode *arg = parse_expr(f, false); + Ast *arg = parse_expr(f, false); // if (f->curr_token.kind == Token_Eq) { // Token eq = expect_token(f, Token_Eq); - // AstNode *value = parse_value(f); + // Ast *value = parse_value(f); // arg = ast_field_value(f, arg, value, eq); // } @@ -3219,7 +3219,7 @@ AstNode *parse_return_stmt(AstFile *f) { advance_token(f); } - AstNode *end = nullptr; + Ast *end = nullptr; if (results.count > 0) { end = results[results.count-1]; } @@ -3227,7 +3227,7 @@ AstNode *parse_return_stmt(AstFile *f) { return ast_return_stmt(f, token, results); } -AstNode *parse_for_stmt(AstFile *f) { +Ast *parse_for_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a for statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -3235,10 +3235,10 @@ AstNode *parse_for_stmt(AstFile *f) { Token token = expect_token(f, Token_for); - AstNode *init = nullptr; - AstNode *cond = nullptr; - AstNode *post = nullptr; - AstNode *body = nullptr; + Ast *init = nullptr; + Ast *cond = nullptr; + Ast *post = nullptr; + Ast *body = nullptr; bool is_range = false; if (f->curr_token.kind != Token_OpenBrace && @@ -3249,7 +3249,7 @@ AstNode *parse_for_stmt(AstFile *f) { if (f->curr_token.kind == Token_in) { Token in_token = expect_token(f, Token_in); - AstNode *rhs = nullptr; + Ast *rhs = nullptr; bool prev_allow_range = f->allow_range; f->allow_range = true; rhs = parse_expr(f, false); @@ -3265,7 +3265,7 @@ AstNode *parse_for_stmt(AstFile *f) { if (f->curr_token.kind != Token_Semicolon) { cond = parse_simple_stmt(f, StmtAllowFlag_In); - if (cond->kind == AstNode_AssignStmt && cond->AssignStmt.op.kind == Token_in) { + if (cond->kind == Ast_AssignStmt && cond->AssignStmt.op.kind == Token_in) { is_range = true; } } @@ -3292,10 +3292,10 @@ AstNode *parse_for_stmt(AstFile *f) { } if (is_range) { - GB_ASSERT(cond->kind == AstNode_AssignStmt); + GB_ASSERT(cond->kind == Ast_AssignStmt); Token in_token = cond->AssignStmt.op; - AstNode *value = nullptr; - AstNode *index = nullptr; + Ast *value = nullptr; + Ast *index = nullptr; switch (cond->AssignStmt.lhs.count) { case 1: value = cond->AssignStmt.lhs[0]; @@ -3309,7 +3309,7 @@ AstNode *parse_for_stmt(AstFile *f) { return ast_bad_stmt(f, token, f->curr_token); } - AstNode *rhs = nullptr; + Ast *rhs = nullptr; if (cond->AssignStmt.rhs.count > 0) { rhs = cond->AssignStmt.rhs[0]; } @@ -3321,9 +3321,9 @@ AstNode *parse_for_stmt(AstFile *f) { } -AstNode *parse_case_clause(AstFile *f, bool is_type) { +Ast *parse_case_clause(AstFile *f, bool is_type) { Token token = f->curr_token; - Array list = {}; + Array list = {}; expect_token(f, Token_case); bool prev_allow_range = f->allow_range; f->allow_range = !is_type; @@ -3332,25 +3332,25 @@ AstNode *parse_case_clause(AstFile *f, bool is_type) { } f->allow_range = prev_allow_range; expect_token(f, Token_Colon); // TODO(bill): Is this the best syntax? - Array stmts = parse_stmt_list(f); + Array stmts = parse_stmt_list(f); return ast_case_clause(f, token, list, stmts); } -AstNode *parse_switch_stmt(AstFile *f) { +Ast *parse_switch_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a match statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } Token token = expect_token(f, Token_switch); - AstNode *init = nullptr; - AstNode *tag = nullptr; - AstNode *body = nullptr; + Ast *init = nullptr; + Ast *tag = nullptr; + Ast *body = nullptr; Token open, close; bool is_type_match = false; - auto list = array_make(heap_allocator()); + auto list = array_make(heap_allocator()); if (f->curr_token.kind != Token_OpenBrace) { isize prev_level = f->expr_level; @@ -3358,12 +3358,12 @@ AstNode *parse_switch_stmt(AstFile *f) { defer (f->expr_level = prev_level); if (allow_token(f, Token_in)) { - auto lhs = array_make(heap_allocator(), 0, 1); - auto rhs = array_make(heap_allocator(), 0, 1); + auto lhs = array_make(heap_allocator(), 0, 1); + auto rhs = array_make(heap_allocator(), 0, 1); Token blank_ident = token; blank_ident.kind = Token_Ident; blank_ident.string = str_lit("_"); - AstNode *blank = ast_ident(f, blank_ident); + Ast *blank = ast_ident(f, blank_ident); array_add(&lhs, blank); array_add(&rhs, parse_expr(f, false)); @@ -3371,7 +3371,7 @@ AstNode *parse_switch_stmt(AstFile *f) { is_type_match = true; } else { tag = parse_simple_stmt(f, StmtAllowFlag_In); - if (tag->kind == AstNode_AssignStmt && tag->AssignStmt.op.kind == Token_in) { + if (tag->kind == Ast_AssignStmt && tag->AssignStmt.op.kind == Token_in) { is_type_match = true; } else { if (allow_token(f, Token_Semicolon)) { @@ -3401,23 +3401,23 @@ AstNode *parse_switch_stmt(AstFile *f) { return ast_switch_stmt(f, token, init, tag, body); } -AstNode *parse_defer_stmt(AstFile *f) { +Ast *parse_defer_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a defer statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } Token token = expect_token(f, Token_defer); - AstNode *stmt = parse_stmt(f); + Ast *stmt = parse_stmt(f); switch (stmt->kind) { - case AstNode_EmptyStmt: + case Ast_EmptyStmt: syntax_error(token, "Empty statement after defer (e.g. ';')"); break; - case AstNode_DeferStmt: + case Ast_DeferStmt: syntax_error(token, "You cannot defer a defer statement"); stmt = stmt->DeferStmt.stmt; break; - case AstNode_ReturnStmt: + case Ast_ReturnStmt: syntax_error(token, "You cannot defer a return statement"); break; } @@ -3431,7 +3431,7 @@ enum ImportDeclKind { ImportDecl_Using, }; -AstNode *parse_import_decl(AstFile *f, ImportDeclKind kind) { +Ast *parse_import_decl(AstFile *f, ImportDeclKind kind) { CommentGroup *docs = f->lead_comment; Token token = expect_token(f, Token_import); Token import_name = {}; @@ -3452,7 +3452,7 @@ AstNode *parse_import_decl(AstFile *f, ImportDeclKind kind) { Token file_path = expect_token_after(f, Token_String, "import"); - AstNode *s = nullptr; + Ast *s = nullptr; if (f->curr_proc != nullptr) { syntax_error(import_name, "You cannot use 'import' within a procedure. This must be done at the file scope"); s = ast_bad_decl(f, import_name, file_path); @@ -3464,11 +3464,11 @@ AstNode *parse_import_decl(AstFile *f, ImportDeclKind kind) { return s; } -// AstNode *parse_export_decl(AstFile *f) { +// Ast *parse_export_decl(AstFile *f) { // CommentGroup *docs = f->lead_comment; // Token token = expect_token(f, Token_export); // Token file_path = expect_token_after(f, Token_String, "export"); -// AstNode *s = nullptr; +// Ast *s = nullptr; // if (f->curr_proc != nullptr) { // syntax_error(token, "You cannot use 'export' within a procedure. This must be done at the file scope"); // s = ast_bad_decl(f, token, file_path); @@ -3480,7 +3480,7 @@ AstNode *parse_import_decl(AstFile *f, ImportDeclKind kind) { // return s; // } -AstNode *parse_foreign_decl(AstFile *f) { +Ast *parse_foreign_decl(AstFile *f) { CommentGroup *docs = f->lead_comment; Token token = expect_token(f, Token_foreign); @@ -3505,7 +3505,7 @@ AstNode *parse_foreign_decl(AstFile *f) { syntax_error(lib_name, "Illegal foreign_library name: '_'"); } Token file_path = expect_token(f, Token_String); - AstNode *s = nullptr; + Ast *s = nullptr; if (f->curr_proc != nullptr) { syntax_error(lib_name, "You cannot use foreign_library within a procedure. This must be done at the file scope"); s = ast_bad_decl(f, lib_name, file_path); @@ -3522,8 +3522,8 @@ AstNode *parse_foreign_decl(AstFile *f) { } -AstNode *parse_stmt(AstFile *f) { - AstNode *s = nullptr; +Ast *parse_stmt(AstFile *f) { + Ast *s = nullptr; Token token = f->curr_token; switch (token.kind) { // Operands @@ -3568,7 +3568,7 @@ AstNode *parse_stmt(AstFile *f) { case Token_continue: case Token_fallthrough: { Token token = advance_token(f); - AstNode *label = nullptr; + Ast *label = nullptr; if (token.kind != Token_fallthrough && f->curr_token.kind == Token_Ident) { label = parse_ident(f); @@ -3585,8 +3585,8 @@ AstNode *parse_stmt(AstFile *f) { return parse_import_decl(f, ImportDecl_Using); } - AstNode *decl = nullptr; - Array list = parse_lhs_expr_list(f); + Ast *decl = nullptr; + Array list = parse_lhs_expr_list(f); if (list.count == 0) { syntax_error(token, "Illegal use of 'using' statement"); expect_semicolon(f, nullptr); @@ -3600,7 +3600,7 @@ AstNode *parse_stmt(AstFile *f) { expect_token_after(f, Token_Colon, "identifier list"); decl = parse_value_decl(f, list, docs); - if (decl != nullptr && decl->kind == AstNode_ValueDecl) { + if (decl != nullptr && decl->kind == Ast_ValueDecl) { if (!decl->ValueDecl.is_mutable) { syntax_error(token, "'using' may only be applied to variable declarations"); return decl; @@ -3616,18 +3616,18 @@ AstNode *parse_stmt(AstFile *f) { case Token_At: { advance_token(f); - Array elems = {}; + Array elems = {}; Token open = expect_token(f, Token_OpenParen); f->expr_level++; if (f->curr_token.kind != Token_CloseParen) { - elems = array_make(heap_allocator()); + elems = array_make(heap_allocator()); while (f->curr_token.kind != Token_CloseParen && f->curr_token.kind != Token_EOF) { - AstNode *elem = nullptr; + Ast *elem = nullptr; elem = parse_ident(f); if (f->curr_token.kind == Token_Eq) { Token eq = expect_token(f, Token_Eq); - AstNode *value = parse_value(f); + Ast *value = parse_value(f); elem = ast_field_value(f, elem, value, eq); } @@ -3641,15 +3641,15 @@ AstNode *parse_stmt(AstFile *f) { f->expr_level--; Token close = expect_closing(f, Token_CloseParen, str_lit("attribute")); - AstNode *attribute = ast_attribute(f, token, open, close, elems); + Ast *attribute = ast_attribute(f, token, open, close, elems); - AstNode *decl = parse_stmt(f); - if (decl->kind == AstNode_ValueDecl) { + Ast *decl = parse_stmt(f); + if (decl->kind == Ast_ValueDecl) { array_add(&decl->ValueDecl.attributes, attribute); - } else if (decl->kind == AstNode_ForeignBlockDecl) { + } else if (decl->kind == Ast_ForeignBlockDecl) { array_add(&decl->ForeignBlockDecl.attributes, attribute); } else { - syntax_error(decl, "Expected a value or foreign declaration after an attribute, got %.*s", LIT(ast_node_strings[decl->kind])); + syntax_error(decl, "Expected a value or foreign declaration after an attribute, got %.*s", LIT(ast_strings[decl->kind])); return ast_bad_stmt(f, token, f->curr_token); } @@ -3657,7 +3657,7 @@ AstNode *parse_stmt(AstFile *f) { } case Token_Hash: { - AstNode *s = nullptr; + Ast *s = nullptr; Token hash_token = expect_token(f, Token_Hash); Token name = expect_token(f, Token_Ident); String tag = name.string; @@ -3690,10 +3690,10 @@ AstNode *parse_stmt(AstFile *f) { } else if (tag == "complete") { s = parse_stmt(f); switch (s->kind) { - case AstNode_SwitchStmt: + case Ast_SwitchStmt: s->SwitchStmt.complete = true; break; - case AstNode_TypeSwitchStmt: + case Ast_TypeSwitchStmt: s->TypeSwitchStmt.complete = true; break; default: @@ -3702,7 +3702,7 @@ AstNode *parse_stmt(AstFile *f) { } return s; } else if (tag == "assert") { - AstNode *t = ast_basic_directive(f, hash_token, tag); + Ast *t = ast_basic_directive(f, hash_token, tag); return ast_expr_stmt(f, parse_call_expr(f, t)); } @@ -3735,18 +3735,18 @@ AstNode *parse_stmt(AstFile *f) { return ast_bad_stmt(f, token, f->curr_token); } -Array parse_stmt_list(AstFile *f) { - auto list = array_make(heap_allocator()); +Array parse_stmt_list(AstFile *f) { + auto list = array_make(heap_allocator()); while (f->curr_token.kind != Token_case && f->curr_token.kind != Token_CloseBrace && f->curr_token.kind != Token_EOF) { - AstNode *stmt = parse_stmt(f); - if (stmt && stmt->kind != AstNode_EmptyStmt) { + Ast *stmt = parse_stmt(f); + if (stmt && stmt->kind != Ast_EmptyStmt) { array_add(&list, stmt); - if (stmt->kind == AstNode_ExprStmt && + if (stmt->kind == Ast_ExprStmt && stmt->ExprStmt.expr != nullptr && - stmt->ExprStmt.expr->kind == AstNode_ProcLit) { + stmt->ExprStmt.expr->kind == Ast_ProcLit) { syntax_error(stmt, "Procedure literal evaluated but not used"); } } @@ -4024,7 +4024,7 @@ bool is_import_path_valid(String path) { return false; } -bool determine_path_from_string(Parser *p, AstNode *node, String base_dir, String original_string, String *path) { +bool determine_path_from_string(Parser *p, Ast *node, String base_dir, String original_string, String *path) { GB_ASSERT(path != nullptr); gbAllocator a = heap_allocator(); @@ -4060,13 +4060,13 @@ bool determine_path_from_string(Parser *p, AstNode *node, String base_dir, Strin defer (gb_mutex_unlock(&p->file_decl_mutex)); - if (node->kind == AstNode_ForeignImportDecl) { + if (node->kind == Ast_ForeignImportDecl) { node->ForeignImportDecl.collection_name = collection_name; } if (collection_name.len > 0) { if (collection_name == "system") { - if (node->kind != AstNode_ForeignImportDecl) { + if (node->kind != Ast_ForeignImportDecl) { syntax_error(node, "The library collection 'system' is restrict for 'foreign_library'"); return false; } else { @@ -4087,7 +4087,7 @@ bool determine_path_from_string(Parser *p, AstNode *node, String base_dir, Strin // working directory of the exe to the library search paths. // Static libraries can be linked directly with the full pathname // - if (node->kind == AstNode_ForeignImportDecl && string_ends_with(file_str, str_lit(".so"))) { + if (node->kind == Ast_ForeignImportDecl && string_ends_with(file_str, str_lit(".so"))) { *path = file_str; return true; } @@ -4102,9 +4102,9 @@ bool determine_path_from_string(Parser *p, AstNode *node, String base_dir, Strin -void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array &decls); +void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array &decls); -void parse_setup_file_when_stmt(Parser *p, AstFile *f, String base_dir, AstNodeWhenStmt *ws) { +void parse_setup_file_when_stmt(Parser *p, AstFile *f, String base_dir, AstWhenStmt *ws) { if (ws->body != nullptr) { auto stmts = ws->body->BlockStmt.stmts; parse_setup_file_decls(p, f, base_dir, stmts); @@ -4112,37 +4112,37 @@ void parse_setup_file_when_stmt(Parser *p, AstFile *f, String base_dir, AstNodeW if (ws->else_stmt != nullptr) { switch (ws->else_stmt->kind) { - case AstNode_BlockStmt: { + case Ast_BlockStmt: { auto stmts = ws->else_stmt->BlockStmt.stmts; parse_setup_file_decls(p, f, base_dir, stmts); } break; - case AstNode_WhenStmt: + case Ast_WhenStmt: parse_setup_file_when_stmt(p, f, base_dir, &ws->else_stmt->WhenStmt); break; } } } -void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array &decls) { +void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array &decls) { for_array(i, decls) { - AstNode *node = decls[i]; - if (!is_ast_node_decl(node) && - node->kind != AstNode_WhenStmt && - node->kind != AstNode_BadStmt && - node->kind != AstNode_EmptyStmt) { + Ast *node = decls[i]; + if (!is_ast_decl(node) && + node->kind != Ast_WhenStmt && + node->kind != Ast_BadStmt && + node->kind != Ast_EmptyStmt) { // NOTE(bill): Sanity check - if (node->kind == AstNode_ExprStmt) { - AstNode *expr = node->ExprStmt.expr; - if (expr->kind == AstNode_CallExpr && - expr->CallExpr.proc->kind == AstNode_BasicDirective) { + if (node->kind == Ast_ExprStmt) { + Ast *expr = node->ExprStmt.expr; + if (expr->kind == Ast_CallExpr && + expr->CallExpr.proc->kind == Ast_BasicDirective) { f->directive_count += 1; continue; } } - syntax_error(node, "Only declarations are allowed at file scope, got %.*s", LIT(ast_node_strings[node->kind])); - } else if (node->kind == AstNode_ImportDecl) { + syntax_error(node, "Only declarations are allowed at file scope, got %.*s", LIT(ast_strings[node->kind])); + } else if (node->kind == Ast_ImportDecl) { ast_node(id, ImportDecl, node); String original_string = string_trim_whitespace(id->relpath.string); @@ -4155,8 +4155,8 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Arrayfullpath = import_path; - try_add_import_path(p, import_path, original_string, ast_node_token(node).pos); - } else if (node->kind == AstNode_ForeignImportDecl) { + try_add_import_path(p, import_path, original_string, ast_token(node).pos); + } else if (node->kind == Ast_ForeignImportDecl) { ast_node(fl, ForeignImportDecl, node); String file_str = fl->filepath.string; @@ -4171,7 +4171,7 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Arrayfullpath = foreign_path; } - } else if (node->kind == AstNode_WhenStmt) { + } else if (node->kind == Ast_WhenStmt) { ast_node(ws, WhenStmt, node); parse_setup_file_when_stmt(p, f, base_dir, ws); } @@ -4305,7 +4305,7 @@ bool parse_file(Parser *p, AstFile *f) { } } - AstNode *pd = ast_package_decl(f, f->package_token, package_name, docs, f->line_comment); + Ast *pd = ast_package_decl(f, f->package_token, package_name, docs, f->line_comment); expect_semicolon(f, pd); f->pkg_decl = pd; diff --git a/src/parser.hpp b/src/parser.hpp index 4b56154ef..47c0571e0 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -1,4 +1,4 @@ -struct AstNode; +struct Ast; struct Scope; struct Type; struct Entity; @@ -52,7 +52,7 @@ struct AstFile { AstPackage * pkg; Scope * scope; - AstNode * pkg_decl; + Ast * pkg_decl; String fullpath; Tokenizer tokenizer; Array tokens; @@ -71,12 +71,12 @@ struct AstFile { bool allow_type; isize when_level; - Array decls; - Array imports; // 'import' 'using import' + Array decls; + Array imports; // 'import' 'using import' isize directive_count; - AstNode * curr_proc; + Ast * curr_proc; // DeclInfo * decl_info; // NOTE(bill): Created in checker isize error_count; @@ -173,192 +173,192 @@ enum StmtAllowFlag { StmtAllowFlag_Context = 1<<2, }; -#define AST_NODE_KINDS \ - AST_NODE_KIND(Ident, "identifier", struct { \ +#define AST_KINDS \ + AST_KIND(Ident, "identifier", struct { \ Token token; \ Entity *entity; \ }) \ - AST_NODE_KIND(Implicit, "implicit", Token) \ - AST_NODE_KIND(Undef, "undef", Token) \ - AST_NODE_KIND(BasicLit, "basic literal", struct { \ + AST_KIND(Implicit, "implicit", Token) \ + AST_KIND(Undef, "undef", Token) \ + AST_KIND(BasicLit, "basic literal", struct { \ Token token; \ }) \ - AST_NODE_KIND(BasicDirective, "basic directive", struct { \ + AST_KIND(BasicDirective, "basic directive", struct { \ Token token; \ String name; \ }) \ - AST_NODE_KIND(Ellipsis, "ellipsis", struct { \ + AST_KIND(Ellipsis, "ellipsis", struct { \ Token token; \ - AstNode *expr; \ + Ast *expr; \ }) \ - AST_NODE_KIND(ProcGroup, "procedure group", struct { \ - Token token; \ - Token open; \ - Token close; \ - Array args; \ + AST_KIND(ProcGroup, "procedure group", struct { \ + Token token; \ + Token open; \ + Token close; \ + Array args; \ }) \ - AST_NODE_KIND(ProcLit, "procedure literal", struct { \ - AstNode * type; \ - AstNode * body; \ - u64 tags; \ + AST_KIND(ProcLit, "procedure literal", struct { \ + Ast *type; \ + Ast *body; \ + u64 tags; \ ProcInlining inlining; \ }) \ - AST_NODE_KIND(CompoundLit, "compound literal", struct { \ - AstNode *type; \ - Array elems; \ + AST_KIND(CompoundLit, "compound literal", struct { \ + Ast *type; \ + Array elems; \ Token open, close; \ }) \ -AST_NODE_KIND(_ExprBegin, "", struct {}) \ - AST_NODE_KIND(BadExpr, "bad expression", struct { Token begin, end; }) \ - AST_NODE_KIND(TagExpr, "tag expression", struct { Token token, name; AstNode *expr; }) \ - AST_NODE_KIND(RunExpr, "run expression", struct { Token token, name; AstNode *expr; }) \ - AST_NODE_KIND(UnaryExpr, "unary expression", struct { Token op; AstNode *expr; }) \ - AST_NODE_KIND(BinaryExpr, "binary expression", struct { Token op; AstNode *left, *right; } ) \ - AST_NODE_KIND(ParenExpr, "parentheses expression", struct { AstNode *expr; Token open, close; }) \ - AST_NODE_KIND(SelectorExpr, "selector expression", struct { Token token; AstNode *expr, *selector; }) \ - AST_NODE_KIND(IndexExpr, "index expression", struct { AstNode *expr, *index; Token open, close; }) \ - AST_NODE_KIND(DerefExpr, "dereference expression", struct { Token op; AstNode *expr; }) \ - AST_NODE_KIND(SliceExpr, "slice expression", struct { \ - AstNode *expr; \ +AST_KIND(_ExprBegin, "", struct {}) \ + AST_KIND(BadExpr, "bad expression", struct { Token begin, end; }) \ + AST_KIND(TagExpr, "tag expression", struct { Token token, name; Ast *expr; }) \ + AST_KIND(RunExpr, "run expression", struct { Token token, name; Ast *expr; }) \ + AST_KIND(UnaryExpr, "unary expression", struct { Token op; Ast *expr; }) \ + AST_KIND(BinaryExpr, "binary expression", struct { Token op; Ast *left, *right; } ) \ + AST_KIND(ParenExpr, "parentheses expression", struct { Ast *expr; Token open, close; }) \ + AST_KIND(SelectorExpr, "selector expression", struct { Token token; Ast *expr, *selector; }) \ + AST_KIND(IndexExpr, "index expression", struct { Ast *expr, *index; Token open, close; }) \ + AST_KIND(DerefExpr, "dereference expression", struct { Token op; Ast *expr; }) \ + AST_KIND(SliceExpr, "slice expression", struct { \ + Ast *expr; \ Token open, close; \ Token interval; \ - AstNode *low, *high; \ + Ast *low, *high; \ }) \ - AST_NODE_KIND(CallExpr, "call expression", struct { \ - AstNode * proc; \ - Array args; \ + AST_KIND(CallExpr, "call expression", struct { \ + Ast * proc; \ + Array args; \ Token open; \ Token close; \ Token ellipsis; \ }) \ - AST_NODE_KIND(FieldValue, "field value", struct { Token eq; AstNode *field, *value; }) \ - AST_NODE_KIND(TernaryExpr, "ternary expression", struct { AstNode *cond, *x, *y; }) \ - AST_NODE_KIND(TypeAssertion, "type assertion", struct { AstNode *expr; Token dot; AstNode *type; }) \ - AST_NODE_KIND(TypeCast, "type cast", struct { Token token; AstNode *type, *expr; }) \ - AST_NODE_KIND(AutoCast, "auto_cast", struct { Token token; AstNode *expr; }) \ -AST_NODE_KIND(_ExprEnd, "", struct {}) \ -AST_NODE_KIND(_StmtBegin, "", struct {}) \ - AST_NODE_KIND(BadStmt, "bad statement", struct { Token begin, end; }) \ - AST_NODE_KIND(EmptyStmt, "empty statement", struct { Token token; }) \ - AST_NODE_KIND(ExprStmt, "expression statement", struct { AstNode *expr; } ) \ - AST_NODE_KIND(TagStmt, "tag statement", struct { \ + AST_KIND(FieldValue, "field value", struct { Token eq; Ast *field, *value; }) \ + AST_KIND(TernaryExpr, "ternary expression", struct { Ast *cond, *x, *y; }) \ + AST_KIND(TypeAssertion, "type assertion", struct { Ast *expr; Token dot; Ast *type; }) \ + AST_KIND(TypeCast, "type cast", struct { Token token; Ast *type, *expr; }) \ + AST_KIND(AutoCast, "auto_cast", struct { Token token; Ast *expr; }) \ +AST_KIND(_ExprEnd, "", struct {}) \ +AST_KIND(_StmtBegin, "", struct {}) \ + AST_KIND(BadStmt, "bad statement", struct { Token begin, end; }) \ + AST_KIND(EmptyStmt, "empty statement", struct { Token token; }) \ + AST_KIND(ExprStmt, "expression statement", struct { Ast *expr; } ) \ + AST_KIND(TagStmt, "tag statement", struct { \ Token token; \ Token name; \ - AstNode *stmt; \ + Ast * stmt; \ }) \ - AST_NODE_KIND(AssignStmt, "assign statement", struct { \ + AST_KIND(AssignStmt, "assign statement", struct { \ Token op; \ - Array lhs, rhs; \ + Array lhs, rhs; \ }) \ - AST_NODE_KIND(IncDecStmt, "increment decrement statement", struct { \ + AST_KIND(IncDecStmt, "increment decrement statement", struct { \ Token op; \ - AstNode *expr; \ + Ast *expr; \ }) \ -AST_NODE_KIND(_ComplexStmtBegin, "", struct {}) \ - AST_NODE_KIND(BlockStmt, "block statement", struct { \ - Array stmts; \ +AST_KIND(_ComplexStmtBegin, "", struct {}) \ + AST_KIND(BlockStmt, "block statement", struct { \ + Array stmts; \ Token open, close; \ }) \ - AST_NODE_KIND(IfStmt, "if statement", struct { \ - Token token; \ - AstNode *init; \ - AstNode *cond; \ - AstNode *body; \ - AstNode *else_stmt; \ + AST_KIND(IfStmt, "if statement", struct { \ + Token token; \ + Ast * init; \ + Ast * cond; \ + Ast * body; \ + Ast * else_stmt; \ }) \ - AST_NODE_KIND(WhenStmt, "when statement", struct { \ + AST_KIND(WhenStmt, "when statement", struct { \ Token token; \ - AstNode *cond; \ - AstNode *body; \ - AstNode *else_stmt; \ + Ast *cond; \ + Ast *body; \ + Ast *else_stmt; \ bool is_cond_determined; \ bool determined_cond; \ }) \ - AST_NODE_KIND(ReturnStmt, "return statement", struct { \ + AST_KIND(ReturnStmt, "return statement", struct { \ Token token; \ - Array results; \ + Array results; \ }) \ - AST_NODE_KIND(ForStmt, "for statement", struct { \ - Token token; \ - AstNode *label; \ - AstNode *init; \ - AstNode *cond; \ - AstNode *post; \ - AstNode *body; \ + AST_KIND(ForStmt, "for statement", struct { \ + Token token; \ + Ast *label; \ + Ast *init; \ + Ast *cond; \ + Ast *post; \ + Ast *body; \ }) \ - AST_NODE_KIND(RangeStmt, "range statement", struct { \ - Token token; \ - AstNode *label; \ - AstNode *val0; \ - AstNode *val1; \ - Token in_token; \ - AstNode *expr; \ - AstNode *body; \ + AST_KIND(RangeStmt, "range statement", struct { \ + Token token; \ + Ast *label; \ + Ast *val0; \ + Ast *val1; \ + Token in_token; \ + Ast *expr; \ + Ast *body; \ }) \ - AST_NODE_KIND(CaseClause, "case clause", struct { \ + AST_KIND(CaseClause, "case clause", struct { \ Token token; \ - Array list; \ - Array stmts; \ + Array list; \ + Array stmts; \ Entity *implicit_entity; \ }) \ - AST_NODE_KIND(SwitchStmt, "switch statement", struct { \ - Token token; \ - AstNode *label; \ - AstNode *init; \ - AstNode *tag; \ - AstNode *body; \ - bool complete; \ + AST_KIND(SwitchStmt, "switch statement", struct { \ + Token token; \ + Ast *label; \ + Ast *init; \ + Ast *tag; \ + Ast *body; \ + bool complete; \ }) \ - AST_NODE_KIND(TypeSwitchStmt, "type switch statement", struct { \ - Token token; \ - AstNode *label; \ - AstNode *tag; \ - AstNode *body; \ - bool complete; \ - }) \ - AST_NODE_KIND(DeferStmt, "defer statement", struct { Token token; AstNode *stmt; }) \ - AST_NODE_KIND(BranchStmt, "branch statement", struct { Token token; AstNode *label; }) \ - AST_NODE_KIND(UsingStmt, "using statement", struct { \ + AST_KIND(TypeSwitchStmt, "type switch statement", struct { \ Token token; \ - Array list; \ + Ast *label; \ + Ast *tag; \ + Ast *body; \ + bool complete; \ }) \ - AST_NODE_KIND(PushContext, "context <- statement", struct { \ - Token token; \ - AstNode *expr; \ - AstNode *body; \ - }) \ -AST_NODE_KIND(_ComplexStmtEnd, "", struct {}) \ -AST_NODE_KIND(_StmtEnd, "", struct {}) \ -AST_NODE_KIND(_DeclBegin, "", struct {}) \ - AST_NODE_KIND(BadDecl, "bad declaration", struct { Token begin, end; }) \ - AST_NODE_KIND(ForeignBlockDecl, "foreign block declaration", struct { \ - Token token; \ - AstNode * foreign_library; \ - AstNode * body; \ - Array attributes; \ - CommentGroup * docs; \ - }) \ - AST_NODE_KIND(Label, "label", struct { \ + AST_KIND(DeferStmt, "defer statement", struct { Token token; Ast *stmt; }) \ + AST_KIND(BranchStmt, "branch statement", struct { Token token; Ast *label; }) \ + AST_KIND(UsingStmt, "using statement", struct { \ Token token; \ - AstNode *name; \ + Array list; \ }) \ - AST_NODE_KIND(ValueDecl, "value declaration", struct { \ - Array names; \ - AstNode * type; \ - Array values; \ - Array attributes; \ - CommentGroup * docs; \ - CommentGroup * comment; \ - bool is_using; \ - bool is_mutable; \ + AST_KIND(PushContext, "context <- statement", struct { \ + Token token; \ + Ast *expr; \ + Ast *body; \ }) \ - AST_NODE_KIND(PackageDecl, "package declaration", struct { \ +AST_KIND(_ComplexStmtEnd, "", struct {}) \ +AST_KIND(_StmtEnd, "", struct {}) \ +AST_KIND(_DeclBegin, "", struct {}) \ + AST_KIND(BadDecl, "bad declaration", struct { Token begin, end; }) \ + AST_KIND(ForeignBlockDecl, "foreign block declaration", struct { \ + Token token; \ + Ast *foreign_library; \ + Ast *body; \ + Array attributes; \ + CommentGroup *docs; \ + }) \ + AST_KIND(Label, "label", struct { \ + Token token; \ + Ast *name; \ + }) \ + AST_KIND(ValueDecl, "value declaration", struct { \ + Array names; \ + Ast * type; \ + Array values; \ + Array attributes; \ + CommentGroup *docs; \ + CommentGroup *comment; \ + bool is_using; \ + bool is_mutable; \ + }) \ + AST_KIND(PackageDecl, "package declaration", struct { \ Token token; \ Token name; \ CommentGroup *docs; \ CommentGroup *comment; \ }) \ - AST_NODE_KIND(ImportDecl, "import declaration", struct { \ + AST_KIND(ImportDecl, "import declaration", struct { \ AstPackage *package; \ Token token; \ Token relpath; \ @@ -368,7 +368,7 @@ AST_NODE_KIND(_DeclBegin, "", struct {}) \ CommentGroup *comment; \ bool is_using; \ }) \ - AST_NODE_KIND(ForeignImportDecl, "foreign import declaration", struct { \ + AST_KIND(ForeignImportDecl, "foreign import declaration", struct { \ Token token; \ Token filepath; \ Token library_name; \ @@ -377,170 +377,170 @@ AST_NODE_KIND(_DeclBegin, "", struct {}) \ CommentGroup *docs; \ CommentGroup *comment; \ }) \ -AST_NODE_KIND(_DeclEnd, "", struct {}) \ - AST_NODE_KIND(Attribute, "attribute", struct { \ - Token token; \ - AstNode *type; \ - Array elems; \ - Token open, close; \ +AST_KIND(_DeclEnd, "", struct {}) \ + AST_KIND(Attribute, "attribute", struct { \ + Token token; \ + Ast *type; \ + Array elems; \ + Token open, close; \ }) \ - AST_NODE_KIND(Field, "field", struct { \ - Array names; \ - AstNode * type; \ - AstNode * default_value; \ - u32 flags; \ - CommentGroup * docs; \ - CommentGroup * comment; \ + AST_KIND(Field, "field", struct { \ + Array names; \ + Ast * type; \ + Ast * default_value; \ + u32 flags; \ + CommentGroup * docs; \ + CommentGroup * comment; \ }) \ - AST_NODE_KIND(FieldList, "field list", struct { \ + AST_KIND(FieldList, "field list", struct { \ + Token token; \ + Array list; \ + }) \ + AST_KIND(UnionField, "union field", struct { \ + Ast *name; \ + Ast *list; \ + }) \ +AST_KIND(_TypeBegin, "", struct {}) \ + AST_KIND(TypeType, "type", struct { \ Token token; \ - Array list; \ + Ast *specialization; \ }) \ - AST_NODE_KIND(UnionField, "union field", struct { \ - AstNode *name; \ - AstNode *list; \ - }) \ -AST_NODE_KIND(_TypeBegin, "", struct {}) \ - AST_NODE_KIND(TypeType, "type", struct { \ + AST_KIND(HelperType, "helper type", struct { \ Token token; \ - AstNode *specialization; \ + Ast *type; \ }) \ - AST_NODE_KIND(HelperType, "helper type", struct { \ + AST_KIND(DistinctType, "distinct type", struct { \ Token token; \ - AstNode *type; \ + Ast *type; \ }) \ - AST_NODE_KIND(DistinctType, "distinct type", struct { \ - Token token; \ - AstNode *type; \ - }) \ - AST_NODE_KIND(PolyType, "polymorphic type", struct { \ + AST_KIND(PolyType, "polymorphic type", struct { \ Token token; \ - AstNode *type; \ - AstNode *specialization; \ + Ast *type; \ + Ast *specialization; \ }) \ - AST_NODE_KIND(ProcType, "procedure type", struct { \ - Token token; \ - AstNode *params; \ - AstNode *results; \ - u64 tags; \ + AST_KIND(ProcType, "procedure type", struct { \ + Token token; \ + Ast *params; \ + Ast *results; \ + u64 tags; \ ProcCallingConvention calling_convention; \ - bool generic; \ + bool generic; \ }) \ - AST_NODE_KIND(PointerType, "pointer type", struct { \ + AST_KIND(PointerType, "pointer type", struct { \ Token token; \ - AstNode *type; \ + Ast *type; \ }) \ - AST_NODE_KIND(ArrayType, "array type", struct { \ + AST_KIND(ArrayType, "array type", struct { \ Token token; \ - AstNode *count; \ - AstNode *elem; \ + Ast *count; \ + Ast *elem; \ }) \ - AST_NODE_KIND(DynamicArrayType, "dynamic array type", struct { \ + AST_KIND(DynamicArrayType, "dynamic array type", struct { \ Token token; \ - AstNode *elem; \ + Ast *elem; \ }) \ - AST_NODE_KIND(StructType, "struct type", struct { \ - Token token; \ - Array fields; \ - isize field_count; \ - AstNode * polymorphic_params; \ - AstNode * align; \ - bool is_packed; \ - bool is_raw_union; \ + AST_KIND(StructType, "struct type", struct { \ + Token token; \ + Array fields; \ + isize field_count; \ + Ast *polymorphic_params; \ + Ast *align; \ + bool is_packed; \ + bool is_raw_union; \ }) \ - AST_NODE_KIND(UnionType, "union type", struct { \ - Token token; \ - Array variants; \ - AstNode * align; \ + AST_KIND(UnionType, "union type", struct { \ + Token token; \ + Array variants; \ + Ast * align; \ }) \ - AST_NODE_KIND(EnumType, "enum type", struct { \ - Token token; \ - AstNode * base_type; \ - Array fields; /* FieldValue */ \ - bool is_export; \ + AST_KIND(EnumType, "enum type", struct { \ + Token token; \ + Ast * base_type; \ + Array fields; /* FieldValue */ \ + bool is_export; \ }) \ - AST_NODE_KIND(BitFieldType, "bit field type", struct { \ - Token token; \ - Array fields; /* FieldValue with : */ \ - AstNode * align; \ + AST_KIND(BitFieldType, "bit field type", struct { \ + Token token; \ + Array fields; /* FieldValue with : */ \ + Ast * align; \ }) \ - AST_NODE_KIND(MapType, "map type", struct { \ - Token token; \ - AstNode *count; \ - AstNode *key; \ - AstNode *value; \ + AST_KIND(MapType, "map type", struct { \ + Token token; \ + Ast *count; \ + Ast *key; \ + Ast *value; \ }) \ -AST_NODE_KIND(_TypeEnd, "", struct {}) +AST_KIND(_TypeEnd, "", struct {}) -enum AstNodeKind { - AstNode_Invalid, -#define AST_NODE_KIND(_kind_name_, ...) GB_JOIN2(AstNode_, _kind_name_), - AST_NODE_KINDS -#undef AST_NODE_KIND - AstNode_Count, +enum AstKind { + Ast_Invalid, +#define AST_KIND(_kind_name_, ...) GB_JOIN2(Ast_, _kind_name_), + AST_KINDS +#undef AST_KIND + Ast_COUNT, }; -String const ast_node_strings[] = { +String const ast_strings[] = { {cast(u8 *)"invalid node", gb_size_of("invalid node")}, -#define AST_NODE_KIND(_kind_name_, name, ...) {cast(u8 *)name, gb_size_of(name)-1}, - AST_NODE_KINDS -#undef AST_NODE_KIND +#define AST_KIND(_kind_name_, name, ...) {cast(u8 *)name, gb_size_of(name)-1}, + AST_KINDS +#undef AST_KIND }; -#define AST_NODE_KIND(_kind_name_, name, ...) typedef __VA_ARGS__ GB_JOIN2(AstNode, _kind_name_); - AST_NODE_KINDS -#undef AST_NODE_KIND +#define AST_KIND(_kind_name_, name, ...) typedef __VA_ARGS__ GB_JOIN2(Ast, _kind_name_); + AST_KINDS +#undef AST_KIND -isize const ast_node_sizes[] = { +isize const ast_variant_sizes[] = { 0, -#define AST_NODE_KIND(_kind_name_, name, ...) gb_size_of(GB_JOIN2(AstNode, _kind_name_)), - AST_NODE_KINDS -#undef AST_NODE_KIND +#define AST_KIND(_kind_name_, name, ...) gb_size_of(GB_JOIN2(Ast, _kind_name_)), + AST_KINDS +#undef AST_KIND }; -struct AstNode { - AstNodeKind kind; - u32 stmt_state_flags; - AstFile * file; - Scope * scope; - bool been_handled; +struct Ast { + AstKind kind; + u32 stmt_state_flags; + AstFile *file; + Scope * scope; + bool been_handled; union { -#define AST_NODE_KIND(_kind_name_, name, ...) GB_JOIN2(AstNode, _kind_name_) _kind_name_; - AST_NODE_KINDS -#undef AST_NODE_KIND +#define AST_KIND(_kind_name_, name, ...) GB_JOIN2(Ast, _kind_name_) _kind_name_; + AST_KINDS +#undef AST_KIND }; }; -#define ast_node(n_, Kind_, node_) GB_JOIN2(AstNode, Kind_) *n_ = &(node_)->Kind_; GB_ASSERT_MSG((node_)->kind == GB_JOIN2(AstNode_, Kind_), \ +#define ast_node(n_, Kind_, node_) GB_JOIN2(Ast, Kind_) *n_ = &(node_)->Kind_; GB_ASSERT_MSG((node_)->kind == GB_JOIN2(Ast_, Kind_), \ "expected '%.*s' got '%.*s'", \ - LIT(ast_node_strings[GB_JOIN2(AstNode_, Kind_)]), LIT(ast_node_strings[(node_)->kind])) -#define case_ast_node(n_, Kind_, node_) case GB_JOIN2(AstNode_, Kind_): { ast_node(n_, Kind_, node_); + LIT(ast_strings[GB_JOIN2(Ast_, Kind_)]), LIT(ast_strings[(node_)->kind])) +#define case_ast_node(n_, Kind_, node_) case GB_JOIN2(Ast_, Kind_): { ast_node(n_, Kind_, node_); #ifndef case_end #define case_end } break; #endif -gb_inline bool is_ast_node_expr(AstNode *node) { - return gb_is_between(node->kind, AstNode__ExprBegin+1, AstNode__ExprEnd-1); +gb_inline bool is_ast_expr(Ast *node) { + return gb_is_between(node->kind, Ast__ExprBegin+1, Ast__ExprEnd-1); } -gb_inline bool is_ast_node_stmt(AstNode *node) { - return gb_is_between(node->kind, AstNode__StmtBegin+1, AstNode__StmtEnd-1); +gb_inline bool is_ast_stmt(Ast *node) { + return gb_is_between(node->kind, Ast__StmtBegin+1, Ast__StmtEnd-1); } -gb_inline bool is_ast_node_complex_stmt(AstNode *node) { - return gb_is_between(node->kind, AstNode__ComplexStmtBegin+1, AstNode__ComplexStmtEnd-1); +gb_inline bool is_ast_complex_stmt(Ast *node) { + return gb_is_between(node->kind, Ast__ComplexStmtBegin+1, Ast__ComplexStmtEnd-1); } -gb_inline bool is_ast_node_decl(AstNode *node) { - return gb_is_between(node->kind, AstNode__DeclBegin+1, AstNode__DeclEnd-1); +gb_inline bool is_ast_decl(Ast *node) { + return gb_is_between(node->kind, Ast__DeclBegin+1, Ast__DeclEnd-1); } -gb_inline bool is_ast_node_type(AstNode *node) { - return gb_is_between(node->kind, AstNode__TypeBegin+1, AstNode__TypeEnd-1); +gb_inline bool is_ast_type(Ast *node) { + return gb_is_between(node->kind, Ast__TypeBegin+1, Ast__TypeEnd-1); } -gb_inline bool is_ast_node_when_stmt(AstNode *node) { - return node->kind == AstNode_WhenStmt; +gb_inline bool is_ast_when_stmt(Ast *node) { + return node->kind == Ast_WhenStmt; } gb_global Arena global_ast_arena = {}; @@ -550,4 +550,4 @@ gbAllocator ast_allocator(void) { return arena_allocator(arena); } -AstNode *alloc_ast_node(AstFile *f, AstNodeKind kind); +Ast *alloc_ast_node(AstFile *f, AstKind kind); diff --git a/src/types.cpp b/src/types.cpp index 3921d5fa5..2541094e8 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1,5 +1,5 @@ struct Scope; -struct AstNode; +struct Ast; enum BasicKind { Basic_Invalid, @@ -81,7 +81,7 @@ struct BasicType { struct TypeStruct { Array fields; - AstNode *node; + Ast *node; Scope * scope; Array offsets; @@ -130,7 +130,7 @@ struct TypeStruct { TYPE_KIND(Struct, TypeStruct) \ TYPE_KIND(Enum, struct { \ Array fields; \ - AstNode *node; \ + Ast *node; \ Scope * scope; \ Entity * names; \ Type * base_type; \ @@ -141,7 +141,7 @@ struct TypeStruct { }) \ TYPE_KIND(Union, struct { \ Array variants; \ - AstNode *node; \ + Ast *node; \ Scope * scope; \ i64 variant_block_size; \ i64 custom_align; \ @@ -153,7 +153,7 @@ struct TypeStruct { bool are_offsets_set; \ }) \ TYPE_KIND(Proc, struct { \ - AstNode *node; \ + Ast *node; \ Scope * scope; \ Type * params; /* Type_Tuple */ \ Type * results; /* Type_Tuple */ \