From 2a990d69669c2a2cd16134e8ebbd2750060f8071 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 27 May 2021 16:32:35 -0700 Subject: stage1: rework tokenizer to match stage2 * Extracts AstGen logic from ir.cpp into astgen.cpp. Reduces the largest file of stage1 from 33,551 lines to 25,510. * tokenizer: rework it completely to match the stage2 tokenizer logic. They can now be maintained together; when one is changed, the other can be changed in the same way. - Each token now takes up 13 bytes instead of 64 bytes. The tokenizer does not parse char literals, string literals, integer literals, etc into meaningful data. Instead, that happens during parsing or astgen. - no longer store line offsets. Error messages scan source files to find the line/column as needed (same as stage2). - main loop: instead of checking the loop, handle a null byte explicitly in the switch statements. This is a nice improvement that we may want to backport to stage2. - delete some dead tokens, artifacts of past syntax that no longer exists. * Parser: fix a TODO by parsing builtin functions as tokens rather than `@` as a separate token. This is how stage2 does it. * Remove some debugging infrastructure. These will need to be redone, if at all, as the code migrates to match stage2. - remove the ast_render code. - remove the IR debugging stuff - remove teh token printing code --- src/stage1/parser.cpp | 1501 ++++++++++++++++++++++++++++++------------------- 1 file changed, 911 insertions(+), 590 deletions(-) (limited to 'src/stage1/parser.cpp') diff --git a/src/stage1/parser.cpp b/src/stage1/parser.cpp index 19cd977c71..51acc6a566 100644 --- a/src/stage1/parser.cpp +++ b/src/stage1/parser.cpp @@ -16,28 +16,34 @@ struct ParseContext { Buf *buf; - size_t current_token; - ZigList *tokens; + // Shortcut to `owner->data.structure.root_struct->token_ids`. + TokenId *token_ids; + // Shortcut to `owner->data.structure.root_struct->token_locs`. + TokenLoc *token_locs; ZigType *owner; + TokenIndex current_token; ErrColor err_color; + // Shortcut to `owner->data.structure.root_struct->token_count`. + uint32_t token_count; }; struct PtrPayload { - Token *asterisk; - Token *payload; + TokenIndex asterisk; + TokenIndex payload; }; struct PtrIndexPayload { - Token *asterisk; - Token *payload; - Token *index; + TokenIndex asterisk; + TokenIndex payload; + TokenIndex index; }; static AstNode *ast_parse_root(ParseContext *pc); static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc); static AstNode *ast_parse_test_decl(ParseContext *pc); static AstNode *ast_parse_top_level_comptime(ParseContext *pc); -static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, Buf *doc_comments); +static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, + TokenIndex doc_comments); static AstNode *ast_parse_fn_proto(ParseContext *pc); static AstNode *ast_parse_var_decl(ParseContext *pc); static AstNode *ast_parse_container_field(ParseContext *pc); @@ -87,8 +93,8 @@ static AsmOutput *ast_parse_asm_output_item(ParseContext *pc); static AstNode *ast_parse_asm_input(ParseContext *pc); static AsmInput *ast_parse_asm_input_item(ParseContext *pc); static AstNode *ast_parse_asm_clobbers(ParseContext *pc); -static Token *ast_parse_break_label(ParseContext *pc); -static Token *ast_parse_block_label(ParseContext *pc); +static TokenIndex ast_parse_break_label(ParseContext *pc); +static TokenIndex ast_parse_block_label(ParseContext *pc); static AstNode *ast_parse_field_init(ParseContext *pc); static AstNode *ast_parse_while_continue_expr(ParseContext *pc); static AstNode *ast_parse_link_section(ParseContext *pc); @@ -98,7 +104,7 @@ static AstNode *ast_parse_param_type(ParseContext *pc); static AstNode *ast_parse_if_prefix(ParseContext *pc); static AstNode *ast_parse_while_prefix(ParseContext *pc); static AstNode *ast_parse_for_prefix(ParseContext *pc); -static Token *ast_parse_payload(ParseContext *pc); +static TokenIndex ast_parse_payload(ParseContext *pc); static Optional ast_parse_ptr_payload(ParseContext *pc); static Optional ast_parse_ptr_index_payload(ParseContext *pc); static AstNode *ast_parse_switch_prong(ParseContext *pc); @@ -122,27 +128,25 @@ static AstNode *ast_parse_byte_align(ParseContext *pc); ATTRIBUTE_PRINTF(3, 4) ATTRIBUTE_NORETURN -static void ast_error(ParseContext *pc, Token *token, const char *format, ...) { +static void ast_error(ParseContext *pc, TokenIndex token, const char *format, ...) { va_list ap; va_start(ap, format); Buf *msg = buf_vprintf(format, ap); va_end(ap); - - ErrorMsg *err = err_msg_create_with_line(pc->owner->data.structure.root_struct->path, - token->start_line, token->start_column, - pc->owner->data.structure.root_struct->source_code, - pc->owner->data.structure.root_struct->line_offsets, msg); - err->line_start = token->start_line; - err->column_start = token->start_column; + RootStruct *root_struct = pc->owner->data.structure.root_struct; + assert(token < root_struct->token_count); + uint32_t byte_offset = root_struct->token_locs[token].offset; + ErrorMsg *err = err_msg_create_with_offset(root_struct->path, + byte_offset, buf_ptr(root_struct->source_code), msg); print_err_msg(err, pc->err_color); exit(EXIT_FAILURE); } ATTRIBUTE_NORETURN -static void ast_invalid_token_error(ParseContext *pc, Token *token) { - ast_error(pc, token, "invalid token: '%s'", token_name(token->id)); +static void ast_invalid_token_error(ParseContext *pc, TokenIndex token) { + ast_error(pc, token, "invalid token: '%s'", token_name(pc->token_ids[token])); } static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) { @@ -152,48 +156,44 @@ static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) { return node; } -static AstNode *ast_create_node(ParseContext *pc, NodeType type, Token *first_token) { +static AstNode *ast_create_node(ParseContext *pc, NodeType type, TokenIndex first_token) { assert(first_token); AstNode *node = ast_create_node_no_line_info(pc, type); - node->line = first_token->start_line; - node->column = first_token->start_column; + node->main_token = first_token; return node; } static AstNode *ast_create_node_copy_line_info(ParseContext *pc, NodeType type, AstNode *from) { assert(from); AstNode *node = ast_create_node_no_line_info(pc, type); - node->line = from->line; - node->column = from->column; + node->main_token = from->main_token; return node; } -static Token *peek_token_i(ParseContext *pc, size_t i) { - return &pc->tokens->at(pc->current_token + i); -} - -static Token *peek_token(ParseContext *pc) { - return peek_token_i(pc, 0); +static TokenIndex peek_token(ParseContext *pc) { + return pc->current_token; } -static Token *eat_token(ParseContext *pc) { - Token *res = peek_token(pc); +static TokenIndex eat_token(ParseContext *pc) { + TokenIndex res = peek_token(pc); pc->current_token += 1; return res; } -static Token *eat_token_if(ParseContext *pc, TokenId id) { - Token *res = peek_token(pc); - if (res->id == id) +static TokenIndex eat_token_if(ParseContext *pc, TokenId id) { + TokenIndex res = peek_token(pc); + if (pc->token_ids[res] == id) { return eat_token(pc); + } - return nullptr; + return 0; } -static Token *expect_token(ParseContext *pc, TokenId id) { - Token *res = eat_token(pc); - if (res->id != id) - ast_error(pc, res, "expected token '%s', found '%s'", token_name(id), token_name(res->id)); +static TokenIndex expect_token(ParseContext *pc, TokenId id) { + TokenIndex res = eat_token(pc); + TokenId actual_id = pc->token_ids[res]; + if (actual_id != id) + ast_error(pc, res, "expected token '%s', found '%s'", token_name(id), token_name(actual_id)); return res; } @@ -202,23 +202,23 @@ static void put_back_token(ParseContext *pc) { pc->current_token -= 1; } -static Buf *token_buf(Token *token) { - if (token == nullptr) +static Buf *token_buf(ParseContext *pc, TokenIndex token) { + if (token == 0) return nullptr; - assert(token->id == TokenIdStringLiteral || token->id == TokenIdMultilineStringLiteral || token->id == TokenIdSymbol); - return &token->data.str_lit.str; -} -static BigInt *token_bigint(Token *token) { - assert(token->id == TokenIdIntLiteral); - return &token->data.int_lit.bigint; + RootStruct *root_struct = pc->owner->data.structure.root_struct; + if (root_struct->token_ids[token] == TokenIdIdentifier) { + return token_identifier_buf(root_struct, token); + } else if (root_struct->token_ids[token] == TokenIdStringLiteral) { + return token_string_literal_buf(root_struct, token); + } else { + zig_unreachable(); + } } -static AstNode *token_symbol(ParseContext *pc, Token *token) { - assert(token->id == TokenIdSymbol); - AstNode *res = ast_create_node(pc, NodeTypeSymbol, token); - res->data.symbol_expr.symbol = token_buf(token); - return res; +static AstNode *token_identifier(ParseContext *pc, TokenIndex token) { + assert(pc->token_ids[token] == TokenIdIdentifier); + return ast_create_node(pc, NodeTypeIdentifier, token); } // (Rule SEP)* Rule? @@ -231,7 +231,7 @@ static ZigList ast_parse_list(ParseContext *pc, TokenId sep, T *(*parser)(P break; res.append(curr); - if (eat_token_if(pc, sep) == nullptr) + if (eat_token_if(pc, sep) == 0) break; } @@ -355,22 +355,22 @@ static AstNode *ast_parse_if_expr_helper(ParseContext *pc, AstNode *(*body_parse return nullptr; AstNode *body = ast_expect(pc, body_parser); - Token *err_payload = nullptr; + TokenIndex err_payload = 0; AstNode *else_body = nullptr; - if (eat_token_if(pc, TokenIdKeywordElse) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordElse) != 0) { err_payload = ast_parse_payload(pc); else_body = ast_expect(pc, body_parser); } assert(res->type == NodeTypeIfOptional); - if (err_payload != nullptr) { + if (err_payload != 0) { AstNodeTestExpr old = res->data.test_expr; res->type = NodeTypeIfErrorExpr; res->data.if_err_expr.target_node = old.target_node; res->data.if_err_expr.var_is_ptr = old.var_is_ptr; res->data.if_err_expr.var_symbol = old.var_symbol; res->data.if_err_expr.then_node = body; - res->data.if_err_expr.err_symbol = token_buf(err_payload); + res->data.if_err_expr.err_symbol = token_buf(pc, err_payload); res->data.if_err_expr.else_node = else_body; return res; } @@ -395,22 +395,22 @@ static AstNode *ast_parse_loop_expr_helper( AstNode *(*for_parser)(ParseContext *), AstNode *(*while_parser)(ParseContext *) ) { - Token *inline_token = eat_token_if(pc, TokenIdKeywordInline); + TokenIndex inline_token = eat_token_if(pc, TokenIdKeywordInline); AstNode *for_expr = for_parser(pc); if (for_expr != nullptr) { assert(for_expr->type == NodeTypeForExpr); - for_expr->data.for_expr.is_inline = inline_token != nullptr; + for_expr->data.for_expr.is_inline = inline_token != 0; return for_expr; } AstNode *while_expr = while_parser(pc); if (while_expr != nullptr) { assert(while_expr->type == NodeTypeWhileExpr); - while_expr->data.while_expr.is_inline = inline_token != nullptr; + while_expr->data.while_expr.is_inline = inline_token != 0; return while_expr; } - if (inline_token != nullptr) + if (inline_token != 0) ast_invalid_token_error(pc, peek_token(pc)); return nullptr; } @@ -423,7 +423,7 @@ static AstNode *ast_parse_for_expr_helper(ParseContext *pc, AstNode *(*body_pars AstNode *body = ast_expect(pc, body_parser); AstNode *else_body = nullptr; - if (eat_token_if(pc, TokenIdKeywordElse) != nullptr) + if (eat_token_if(pc, TokenIdKeywordElse) != 0) else_body = ast_expect(pc, body_parser); assert(res->type == NodeTypeForExpr); @@ -439,24 +439,24 @@ static AstNode *ast_parse_while_expr_helper(ParseContext *pc, AstNode *(*body_pa return nullptr; AstNode *body = ast_expect(pc, body_parser); - Token *err_payload = nullptr; + TokenIndex err_payload = 0; AstNode *else_body = nullptr; - if (eat_token_if(pc, TokenIdKeywordElse) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordElse) != 0) { err_payload = ast_parse_payload(pc); else_body = ast_expect(pc, body_parser); } assert(res->type == NodeTypeWhileExpr); res->data.while_expr.body = body; - res->data.while_expr.err_symbol = token_buf(err_payload); + res->data.while_expr.err_symbol = token_buf(pc, err_payload); res->data.while_expr.else_node = else_body; return res; } template AstNode *ast_parse_bin_op_simple(ParseContext *pc) { - Token *op_token = eat_token_if(pc, id); - if (op_token == nullptr) + TokenIndex op_token = eat_token_if(pc, id); + if (op_token == 0) return nullptr; AstNode *res = ast_create_node(pc, NodeTypeBinOpExpr, op_token); @@ -464,20 +464,25 @@ AstNode *ast_parse_bin_op_simple(ParseContext *pc) { return res; } -AstNode *ast_parse(Buf *buf, ZigList *tokens, ZigType *owner, ErrColor err_color) { +AstNode *ast_parse(Buf *buf, ZigType *owner, ErrColor err_color) { + RootStruct *root_struct = owner->data.structure.root_struct; + ParseContext pc = {}; pc.err_color = err_color; pc.owner = owner; pc.buf = buf; - pc.tokens = tokens; + pc.token_ids = root_struct->token_ids; + pc.token_locs = root_struct->token_locs; + pc.token_count = root_struct->token_count; + pc.current_token = 1; // Skip over the first (invalid) token. return ast_parse_root(&pc); } // Root <- skip ContainerMembers eof static AstNode *ast_parse_root(ParseContext *pc) { - Token *first = peek_token(pc); + TokenIndex first = peek_token(pc); AstNodeContainerDecl members = ast_parse_container_members(pc); - if (pc->current_token != pc->tokens->length - 1) + if (pc->current_token != pc->token_count - 1) ast_invalid_token_error(pc, peek_token(pc)); AstNode *node = ast_create_node(pc, NodeTypeContainerDecl, first); @@ -486,70 +491,26 @@ static AstNode *ast_parse_root(ParseContext *pc) { node->data.container_decl.layout = ContainerLayoutAuto; node->data.container_decl.kind = ContainerKindStruct; node->data.container_decl.is_root = true; - if (buf_len(&members.doc_comments) != 0) { - node->data.container_decl.doc_comments = members.doc_comments; - } + node->data.container_decl.doc_comments = members.doc_comments; return node; } -static Token *ast_parse_multiline_string_literal(ParseContext *pc, Buf *buf) { - Token *first_str_token = nullptr; - Token *str_token = nullptr; - while ((str_token = eat_token_if(pc, TokenIdMultilineStringLiteral))) { - if (first_str_token == nullptr) { - first_str_token = str_token; - } - if (buf->list.length == 0) { - buf_resize(buf, 0); - } - buf_append_buf(buf, token_buf(str_token)); - - // Ignore inline comments - size_t cur_token = pc->current_token; - while (eat_token_if(pc, TokenIdDocComment)); - - // Lookahead to see if there's another multilne string literal, - // if not, we have to revert back to before the doc comment - if (peek_token(pc)->id != TokenIdMultilineStringLiteral) { - pc->current_token = cur_token; - } else { - buf_append_char(buf, '\n'); // Add a newline between comments - } +static TokenIndex ast_parse_multi_tok(ParseContext *pc, TokenId token_id) { + TokenIndex first_token = eat_token_if(pc, token_id); + TokenIndex token = first_token; + while (token != 0) { + token = eat_token_if(pc, token_id); } - return first_str_token; + return first_token; } -static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) { - Token *first_doc_token = nullptr; - Token *doc_token = nullptr; - while ((doc_token = eat_token_if(pc, TokenIdDocComment))) { - if (first_doc_token == nullptr) { - first_doc_token = doc_token; - } - if (buf->list.length == 0) { - buf_resize(buf, 0); - } - // chops off '///' but leaves '\n' - buf_append_mem(buf, buf_ptr(pc->buf) + doc_token->start_pos + 3, - doc_token->end_pos - doc_token->start_pos - 3); - } - return first_doc_token; +static TokenIndex ast_parse_doc_comments(ParseContext *pc) { + return ast_parse_multi_tok(pc, TokenIdDocComment); } -static void ast_parse_container_doc_comments(ParseContext *pc, Buf *buf) { - if (buf_len(buf) != 0 && peek_token(pc)->id == TokenIdContainerDocComment) { - buf_append_char(buf, '\n'); - } - Token *doc_token = nullptr; - while ((doc_token = eat_token_if(pc, TokenIdContainerDocComment))) { - if (buf->list.length == 0) { - buf_resize(buf, 0); - } - // chops off '//!' but leaves '\n' - buf_append_mem(buf, buf_ptr(pc->buf) + doc_token->start_pos + 3, - doc_token->end_pos - doc_token->start_pos - 3); - } +static TokenIndex ast_parse_container_doc_comments(ParseContext *pc) { + return ast_parse_multi_tok(pc, TokenIdContainerDocComment); } enum ContainerFieldState { @@ -570,14 +531,11 @@ enum ContainerFieldState { // / static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) { AstNodeContainerDecl res = {}; - Buf tld_doc_comment_buf = BUF_INIT; - buf_resize(&tld_doc_comment_buf, 0); ContainerFieldState field_state = ContainerFieldStateNone; - Token *first_token = nullptr; + TokenIndex first_token = 0; + res.doc_comments = ast_parse_container_doc_comments(pc); for (;;) { - ast_parse_container_doc_comments(pc, &tld_doc_comment_buf); - - Token *peeked_token = peek_token(pc); + TokenIndex peeked_token = peek_token(pc); AstNode *test_decl = ast_parse_test_decl(pc); if (test_decl != nullptr) { @@ -599,15 +557,14 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) { continue; } - Buf doc_comment_buf = BUF_INIT; - ast_parse_doc_comments(pc, &doc_comment_buf); + TokenIndex first_doc_token = ast_parse_doc_comments(pc); peeked_token = peek_token(pc); - Token *visib_token = eat_token_if(pc, TokenIdKeywordPub); - VisibMod visib_mod = visib_token != nullptr ? VisibModPub : VisibModPrivate; + TokenIndex visib_token = eat_token_if(pc, TokenIdKeywordPub); + VisibMod visib_mod = (visib_token != 0) ? VisibModPub : VisibModPrivate; - AstNode *top_level_decl = ast_parse_top_level_decl(pc, visib_mod, &doc_comment_buf); + AstNode *top_level_decl = ast_parse_top_level_decl(pc, visib_mod, first_doc_token); if (top_level_decl != nullptr) { if (field_state == ContainerFieldStateSeen) { field_state = ContainerFieldStateEnd; @@ -617,11 +574,11 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) { continue; } - if (visib_token != nullptr) { + if (visib_token != 0) { ast_error(pc, peek_token(pc), "expected function or variable declaration after pub"); } - Token *comptime_token = eat_token_if(pc, TokenIdKeywordCompTime); + TokenIndex comptime_token = eat_token_if(pc, TokenIdKeywordCompTime); AstNode *container_field = ast_parse_container_field(pc); if (container_field != nullptr) { @@ -636,10 +593,10 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) { } assert(container_field->type == NodeTypeStructField); - container_field->data.struct_field.doc_comments = doc_comment_buf; + container_field->data.struct_field.doc_comments = first_doc_token; container_field->data.struct_field.comptime_token = comptime_token; res.fields.append(container_field); - if (eat_token_if(pc, TokenIdComma) != nullptr) { + if (eat_token_if(pc, TokenIdComma) != 0) { continue; } else { break; @@ -648,33 +605,32 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) { break; } - res.doc_comments = tld_doc_comment_buf; return res; } // TestDecl <- KEYWORD_test STRINGLITERALSINGLE Block static AstNode *ast_parse_test_decl(ParseContext *pc) { - Token *test = eat_token_if(pc, TokenIdKeywordTest); - if (test == nullptr) + TokenIndex test = eat_token_if(pc, TokenIdKeywordTest); + if (test == 0) return nullptr; - Token *name = eat_token_if(pc, TokenIdStringLiteral); + TokenIndex name = eat_token_if(pc, TokenIdStringLiteral); AstNode *block = ast_expect(pc, ast_parse_block); AstNode *res = ast_create_node(pc, NodeTypeTestDecl, test); - res->data.test_decl.name = name ? token_buf(name) : nullptr; + res->data.test_decl.name = name ? token_buf(pc, name) : nullptr; res->data.test_decl.body = block; return res; } // TopLevelComptime <- KEYWORD_comptime BlockExpr static AstNode *ast_parse_top_level_comptime(ParseContext *pc) { - Token *comptime = eat_token_if(pc, TokenIdKeywordCompTime); - if (comptime == nullptr) + TokenIndex comptime = eat_token_if(pc, TokenIdKeywordCompTime); + if (comptime == 0) return nullptr; // 1 token lookahead because it could be a comptime struct field - Token *lbrace = peek_token(pc); - if (lbrace->id != TokenIdLBrace) { + TokenIndex lbrace = peek_token(pc); + if (pc->token_ids[lbrace] != TokenIdLBrace) { put_back_token(pc); return nullptr; } @@ -689,39 +645,40 @@ static AstNode *ast_parse_top_level_comptime(ParseContext *pc) { // <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / (KEYWORD_inline / KEYWORD_noinline))? FnProto (SEMICOLON / Block) // / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl // / KEYWORD_use Expr SEMICOLON -static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, Buf *doc_comments) { - Token *first = eat_token_if(pc, TokenIdKeywordExport); - if (first == nullptr) +static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, + TokenIndex doc_comments) +{ + TokenIndex first = eat_token_if(pc, TokenIdKeywordExport); + if (first == 0) first = eat_token_if(pc, TokenIdKeywordExtern); - if (first == nullptr) + if (first == 0) first = eat_token_if(pc, TokenIdKeywordInline); - if (first == nullptr) + if (first == 0) first = eat_token_if(pc, TokenIdKeywordNoInline); - if (first != nullptr) { - Token *lib_name = nullptr; - if (first->id == TokenIdKeywordExtern) + if (first != 0) { + TokenIndex lib_name = 0; + if (pc->token_ids[first] == TokenIdKeywordExtern) lib_name = eat_token_if(pc, TokenIdStringLiteral); - if (first->id != TokenIdKeywordNoInline && first->id != TokenIdKeywordInline) { - Token *thread_local_kw = eat_token_if(pc, TokenIdKeywordThreadLocal); + if (pc->token_ids[first] != TokenIdKeywordNoInline && pc->token_ids[first] != TokenIdKeywordInline) { + TokenIndex thread_local_kw = eat_token_if(pc, TokenIdKeywordThreadLocal); AstNode *var_decl = ast_parse_var_decl(pc); if (var_decl != nullptr) { assert(var_decl->type == NodeTypeVariableDeclaration); - if (first->id == TokenIdKeywordExtern && var_decl->data.variable_declaration.expr != nullptr) { + if (pc->token_ids[first] == TokenIdKeywordExtern && var_decl->data.variable_declaration.expr != nullptr) { ast_error(pc, first, "extern variables have no initializers"); } - var_decl->line = first->start_line; - var_decl->column = first->start_column; + var_decl->main_token = first; var_decl->data.variable_declaration.threadlocal_tok = thread_local_kw; var_decl->data.variable_declaration.visib_mod = visib_mod; - var_decl->data.variable_declaration.doc_comments = *doc_comments; - var_decl->data.variable_declaration.is_extern = first->id == TokenIdKeywordExtern; - var_decl->data.variable_declaration.is_export = first->id == TokenIdKeywordExport; - var_decl->data.variable_declaration.lib_name = token_buf(lib_name); + var_decl->data.variable_declaration.doc_comments = doc_comments; + var_decl->data.variable_declaration.is_extern = pc->token_ids[first] == TokenIdKeywordExtern; + var_decl->data.variable_declaration.is_export = pc->token_ids[first] == TokenIdKeywordExport; + var_decl->data.variable_declaration.lib_name = token_buf(pc, lib_name); return var_decl; } - if (thread_local_kw != nullptr) + if (thread_local_kw != 0) put_back_token(pc); } @@ -732,14 +689,13 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B expect_token(pc, TokenIdSemicolon); assert(fn_proto->type == NodeTypeFnProto); - fn_proto->line = first->start_line; - fn_proto->column = first->start_column; + fn_proto->main_token = first; fn_proto->data.fn_proto.visib_mod = visib_mod; - fn_proto->data.fn_proto.doc_comments = *doc_comments; + fn_proto->data.fn_proto.doc_comments = doc_comments; if (!fn_proto->data.fn_proto.is_extern) - fn_proto->data.fn_proto.is_extern = first->id == TokenIdKeywordExtern; - fn_proto->data.fn_proto.is_export = first->id == TokenIdKeywordExport; - switch (first->id) { + fn_proto->data.fn_proto.is_extern = pc->token_ids[first] == TokenIdKeywordExtern; + fn_proto->data.fn_proto.is_export = pc->token_ids[first] == TokenIdKeywordExport; + switch (pc->token_ids[first]) { case TokenIdKeywordInline: fn_proto->data.fn_proto.fn_inline = FnInlineAlways; break; @@ -750,7 +706,7 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B fn_proto->data.fn_proto.fn_inline = FnInlineAuto; break; } - fn_proto->data.fn_proto.lib_name = token_buf(lib_name); + fn_proto->data.fn_proto.lib_name = token_buf(pc, lib_name); AstNode *res = fn_proto; if (body != nullptr) { @@ -769,17 +725,17 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B ast_invalid_token_error(pc, peek_token(pc)); } - Token *thread_local_kw = eat_token_if(pc, TokenIdKeywordThreadLocal); + TokenIndex thread_local_kw = eat_token_if(pc, TokenIdKeywordThreadLocal); AstNode *var_decl = ast_parse_var_decl(pc); if (var_decl != nullptr) { assert(var_decl->type == NodeTypeVariableDeclaration); var_decl->data.variable_declaration.visib_mod = visib_mod; - var_decl->data.variable_declaration.doc_comments = *doc_comments; + var_decl->data.variable_declaration.doc_comments = doc_comments; var_decl->data.variable_declaration.threadlocal_tok = thread_local_kw; return var_decl; } - if (thread_local_kw != nullptr) + if (thread_local_kw != 0) put_back_token(pc); AstNode *fn_proto = ast_parse_fn_proto(pc); @@ -790,7 +746,7 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B assert(fn_proto->type == NodeTypeFnProto); fn_proto->data.fn_proto.visib_mod = visib_mod; - fn_proto->data.fn_proto.doc_comments = *doc_comments; + fn_proto->data.fn_proto.doc_comments = doc_comments; AstNode *res = fn_proto; if (body != nullptr) { res = ast_create_node_copy_line_info(pc, NodeTypeFnDef, fn_proto); @@ -802,8 +758,8 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B return res; } - Token *usingnamespace = eat_token_if(pc, TokenIdKeywordUsingNamespace); - if (usingnamespace != nullptr) { + TokenIndex usingnamespace = eat_token_if(pc, TokenIdKeywordUsingNamespace); + if (usingnamespace != 0) { AstNode *expr = ast_expect(pc, ast_parse_expr); expect_token(pc, TokenIdSemicolon); @@ -818,12 +774,12 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B // FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_anytype / TypeExpr) static AstNode *ast_parse_fn_proto(ParseContext *pc) { - Token *first = eat_token_if(pc, TokenIdKeywordFn); - if (first == nullptr) { + TokenIndex first = eat_token_if(pc, TokenIdKeywordFn); + if (first == 0) { return nullptr; } - Token *identifier = eat_token_if(pc, TokenIdSymbol); + TokenIndex identifier = eat_token_if(pc, TokenIdIdentifier); expect_token(pc, TokenIdLParen); ZigList params = ast_parse_list(pc, TokenIdComma, ast_parse_param_decl); expect_token(pc, TokenIdRParen); @@ -831,29 +787,29 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) { AstNode *align_expr = ast_parse_byte_align(pc); AstNode *section_expr = ast_parse_link_section(pc); AstNode *callconv_expr = ast_parse_callconv(pc); - Token *exmark = nullptr; + TokenIndex exmark = 0; AstNode *return_type = nullptr; exmark = eat_token_if(pc, TokenIdBang); return_type = ast_parse_type_expr(pc); if (return_type == nullptr) { - Token *next = peek_token(pc); + TokenIndex next = peek_token(pc); ast_error( pc, next, "expected return type (use 'void' to return nothing), found: '%s'", - token_name(next->id) + token_name(pc->token_ids[next]) ); } AstNode *res = ast_create_node(pc, NodeTypeFnProto, first); res->data.fn_proto = {}; - res->data.fn_proto.name = token_buf(identifier); + res->data.fn_proto.name = token_buf(pc, identifier); res->data.fn_proto.params = params; res->data.fn_proto.align_expr = align_expr; res->data.fn_proto.section_expr = section_expr; res->data.fn_proto.callconv_expr = callconv_expr; - res->data.fn_proto.auto_err_set = exmark != nullptr; + res->data.fn_proto.auto_err_set = exmark != 0; res->data.fn_proto.return_type = return_type; for (size_t i = 0; i < params.length; i++) { @@ -869,28 +825,28 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) { // VarDecl <- (KEYWORD_const / KEYWORD_var) IDENTIFIER (COLON TypeExpr)? ByteAlign? LinkSection? (EQUAL Expr)? SEMICOLON static AstNode *ast_parse_var_decl(ParseContext *pc) { - Token *mut_kw = eat_token_if(pc, TokenIdKeywordConst); - if (mut_kw == nullptr) + TokenIndex mut_kw = eat_token_if(pc, TokenIdKeywordConst); + if (mut_kw == 0) mut_kw = eat_token_if(pc, TokenIdKeywordVar); - if (mut_kw == nullptr) + if (mut_kw == 0) return nullptr; - Token *identifier = expect_token(pc, TokenIdSymbol); + TokenIndex identifier = expect_token(pc, TokenIdIdentifier); AstNode *type_expr = nullptr; - if (eat_token_if(pc, TokenIdColon) != nullptr) + if (eat_token_if(pc, TokenIdColon) != 0) type_expr = ast_expect(pc, ast_parse_type_expr); AstNode *align_expr = ast_parse_byte_align(pc); AstNode *section_expr = ast_parse_link_section(pc); AstNode *expr = nullptr; - if (eat_token_if(pc, TokenIdEq) != nullptr) + if (eat_token_if(pc, TokenIdEq) != 0) expr = ast_expect(pc, ast_parse_expr); expect_token(pc, TokenIdSemicolon); AstNode *res = ast_create_node(pc, NodeTypeVariableDeclaration, mut_kw); - res->data.variable_declaration.is_const = mut_kw->id == TokenIdKeywordConst; - res->data.variable_declaration.symbol = token_buf(identifier); + res->data.variable_declaration.is_const = pc->token_ids[mut_kw] == TokenIdKeywordConst; + res->data.variable_declaration.symbol = token_buf(pc, identifier); res->data.variable_declaration.type = type_expr; res->data.variable_declaration.align_expr = align_expr; res->data.variable_declaration.section_expr = section_expr; @@ -900,14 +856,14 @@ static AstNode *ast_parse_var_decl(ParseContext *pc) { // ContainerField <- KEYWORD_comptime? IDENTIFIER (COLON TypeExpr ByteAlign?)? (EQUAL Expr)? static AstNode *ast_parse_container_field(ParseContext *pc) { - Token *identifier = eat_token_if(pc, TokenIdSymbol); - if (identifier == nullptr) + TokenIndex identifier = eat_token_if(pc, TokenIdIdentifier); + if (identifier == 0) return nullptr; AstNode *type_expr = nullptr; - if (eat_token_if(pc, TokenIdColon) != nullptr) { - Token *anytype_tok = eat_token_if(pc, TokenIdKeywordAnyType); - if (anytype_tok != nullptr) { + if (eat_token_if(pc, TokenIdColon) != 0) { + TokenIndex anytype_tok = eat_token_if(pc, TokenIdKeywordAnyType); + if (anytype_tok != 0) { type_expr = ast_create_node(pc, NodeTypeAnyTypeField, anytype_tok); } else { type_expr = ast_expect(pc, ast_parse_type_expr); @@ -915,11 +871,11 @@ static AstNode *ast_parse_container_field(ParseContext *pc) { } AstNode *align_expr = ast_parse_byte_align(pc); AstNode *expr = nullptr; - if (eat_token_if(pc, TokenIdEq) != nullptr) + if (eat_token_if(pc, TokenIdEq) != 0) expr = ast_expect(pc, ast_parse_expr); AstNode *res = ast_create_node(pc, NodeTypeStructField, identifier); - res->data.struct_field.name = token_buf(identifier); + res->data.struct_field.name = token_buf(pc, identifier); res->data.struct_field.type = type_expr; res->data.struct_field.value = expr; res->data.struct_field.align_expr = align_expr; @@ -938,52 +894,52 @@ static AstNode *ast_parse_container_field(ParseContext *pc) { // / SwitchExpr // / AssignExpr SEMICOLON static AstNode *ast_parse_statement(ParseContext *pc) { - Token *comptime = eat_token_if(pc, TokenIdKeywordCompTime); + TokenIndex comptime = eat_token_if(pc, TokenIdKeywordCompTime); AstNode *var_decl = ast_parse_var_decl(pc); if (var_decl != nullptr) { assert(var_decl->type == NodeTypeVariableDeclaration); - var_decl->data.variable_declaration.is_comptime = comptime != nullptr; + var_decl->data.variable_declaration.is_comptime = comptime != 0; return var_decl; } - if (comptime != nullptr) { + if (comptime != 0) { AstNode *statement = ast_expect(pc, ast_parse_block_expr_statement); AstNode *res = ast_create_node(pc, NodeTypeCompTime, comptime); res->data.comptime_expr.expr = statement; return res; } - Token *nosuspend = eat_token_if(pc, TokenIdKeywordNoSuspend); - if (nosuspend != nullptr) { + TokenIndex nosuspend = eat_token_if(pc, TokenIdKeywordNoSuspend); + if (nosuspend != 0) { AstNode *statement = ast_expect(pc, ast_parse_block_expr_statement); AstNode *res = ast_create_node(pc, NodeTypeNoSuspend, nosuspend); res->data.nosuspend_expr.expr = statement; return res; } - Token *suspend = eat_token_if(pc, TokenIdKeywordSuspend); - if (suspend != nullptr) { + TokenIndex suspend = eat_token_if(pc, TokenIdKeywordSuspend); + if (suspend != 0) { AstNode *statement = ast_expect(pc, ast_parse_block_expr_statement); AstNode *res = ast_create_node(pc, NodeTypeSuspend, suspend); res->data.suspend.block = statement; return res; } - Token *defer = eat_token_if(pc, TokenIdKeywordDefer); - if (defer == nullptr) + TokenIndex defer = eat_token_if(pc, TokenIdKeywordDefer); + if (defer == 0) defer = eat_token_if(pc, TokenIdKeywordErrdefer); - if (defer != nullptr) { - Token *payload = (defer->id == TokenIdKeywordErrdefer) ? - ast_parse_payload(pc) : nullptr; + if (defer != 0) { + TokenIndex payload = (pc->token_ids[defer] == TokenIdKeywordErrdefer) ? + ast_parse_payload(pc) : 0; AstNode *statement = ast_expect(pc, ast_parse_block_expr_statement); AstNode *res = ast_create_node(pc, NodeTypeDefer, defer); res->data.defer.kind = ReturnKindUnconditional; res->data.defer.expr = statement; - if (defer->id == TokenIdKeywordErrdefer) { + if (pc->token_ids[defer] == TokenIdKeywordErrdefer) { res->data.defer.kind = ReturnKindError; - if (payload != nullptr) - res->data.defer.err_payload = token_symbol(pc, payload); + if (payload != 0) + res->data.defer.err_payload = token_identifier(pc, payload); } return res; } @@ -1025,13 +981,13 @@ static AstNode *ast_parse_if_statement(ParseContext *pc) { } if (body == nullptr) { - Token *tok = eat_token(pc); - ast_error(pc, tok, "expected if body, found '%s'", token_name(tok->id)); + TokenIndex tok = eat_token(pc); + ast_error(pc, tok, "expected if body, found '%s'", token_name(pc->token_ids[tok])); } - Token *err_payload = nullptr; + TokenIndex err_payload = 0; AstNode *else_body = nullptr; - if (eat_token_if(pc, TokenIdKeywordElse) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordElse) != 0) { err_payload = ast_parse_payload(pc); else_body = ast_expect(pc, ast_parse_statement); } @@ -1040,14 +996,14 @@ static AstNode *ast_parse_if_statement(ParseContext *pc) { expect_token(pc, TokenIdSemicolon); assert(res->type == NodeTypeIfOptional); - if (err_payload != nullptr) { + if (err_payload != 0) { AstNodeTestExpr old = res->data.test_expr; res->type = NodeTypeIfErrorExpr; res->data.if_err_expr.target_node = old.target_node; res->data.if_err_expr.var_is_ptr = old.var_is_ptr; res->data.if_err_expr.var_symbol = old.var_symbol; res->data.if_err_expr.then_node = body; - res->data.if_err_expr.err_symbol = token_buf(err_payload); + res->data.if_err_expr.err_symbol = token_buf(pc, err_payload); res->data.if_err_expr.else_node = else_body; return res; } @@ -1068,11 +1024,11 @@ static AstNode *ast_parse_if_statement(ParseContext *pc) { // LabeledStatement <- BlockLabel? (Block / LoopStatement) static AstNode *ast_parse_labeled_statement(ParseContext *pc) { - Token *label = ast_parse_block_label(pc); + TokenIndex label = ast_parse_block_label(pc); AstNode *block = ast_parse_block(pc); if (block != nullptr) { assert(block->type == NodeTypeBlock); - block->data.block.name = token_buf(label); + block->data.block.name = token_buf(pc, label); return block; } @@ -1080,10 +1036,10 @@ static AstNode *ast_parse_labeled_statement(ParseContext *pc) { if (loop != nullptr) { switch (loop->type) { case NodeTypeForExpr: - loop->data.for_expr.name = token_buf(label); + loop->data.for_expr.name = token_buf(pc, label); break; case NodeTypeWhileExpr: - loop->data.while_expr.name = token_buf(label); + loop->data.while_expr.name = token_buf(pc, label); break; default: zig_unreachable(); @@ -1091,29 +1047,29 @@ static AstNode *ast_parse_labeled_statement(ParseContext *pc) { return loop; } - if (label != nullptr) + if (label != 0) ast_invalid_token_error(pc, peek_token(pc)); return nullptr; } // LoopStatement <- KEYWORD_inline? (ForStatement / WhileStatement) static AstNode *ast_parse_loop_statement(ParseContext *pc) { - Token *inline_token = eat_token_if(pc, TokenIdKeywordInline); + TokenIndex inline_token = eat_token_if(pc, TokenIdKeywordInline); AstNode *for_statement = ast_parse_for_statement(pc); if (for_statement != nullptr) { assert(for_statement->type == NodeTypeForExpr); - for_statement->data.for_expr.is_inline = inline_token != nullptr; + for_statement->data.for_expr.is_inline = inline_token != 0; return for_statement; } AstNode *while_statement = ast_parse_while_statement(pc); if (while_statement != nullptr) { assert(while_statement->type == NodeTypeWhileExpr); - while_statement->data.while_expr.is_inline = inline_token != nullptr; + while_statement->data.while_expr.is_inline = inline_token != 0; return while_statement; } - if (inline_token != nullptr) + if (inline_token != 0) ast_invalid_token_error(pc, peek_token(pc)); return nullptr; } @@ -1134,12 +1090,12 @@ static AstNode *ast_parse_for_statement(ParseContext *pc) { } if (body == nullptr) { - Token *tok = eat_token(pc); - ast_error(pc, tok, "expected loop body, found '%s'", token_name(tok->id)); + TokenIndex tok = eat_token(pc); + ast_error(pc, tok, "expected loop body, found '%s'", token_name(pc->token_ids[tok])); } AstNode *else_body = nullptr; - if (eat_token_if(pc, TokenIdKeywordElse) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordElse) != 0) { else_body = ast_expect(pc, ast_parse_statement); } @@ -1168,13 +1124,13 @@ static AstNode *ast_parse_while_statement(ParseContext *pc) { } if (body == nullptr) { - Token *tok = eat_token(pc); - ast_error(pc, tok, "expected loop body, found '%s'", token_name(tok->id)); + TokenIndex tok = eat_token(pc); + ast_error(pc, tok, "expected loop body, found '%s'", token_name(pc->token_ids[tok])); } - Token *err_payload = nullptr; + TokenIndex err_payload = 0; AstNode *else_body = nullptr; - if (eat_token_if(pc, TokenIdKeywordElse) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordElse) != 0) { err_payload = ast_parse_payload(pc); else_body = ast_expect(pc, ast_parse_statement); } @@ -1184,7 +1140,7 @@ static AstNode *ast_parse_while_statement(ParseContext *pc) { assert(res->type == NodeTypeWhileExpr); res->data.while_expr.body = body; - res->data.while_expr.err_symbol = token_buf(err_payload); + res->data.while_expr.err_symbol = token_buf(pc, err_payload); res->data.while_expr.else_node = else_body; return res; } @@ -1209,11 +1165,11 @@ static AstNode *ast_parse_block_expr_statement(ParseContext *pc) { // BlockExpr <- BlockLabel? Block static AstNode *ast_parse_block_expr(ParseContext *pc) { - Token *label = ast_parse_block_label(pc); - if (label != nullptr) { + TokenIndex label = ast_parse_block_label(pc); + if (label != 0) { AstNode *res = ast_expect(pc, ast_parse_block); assert(res->type == NodeTypeBlock); - res->data.block.name = token_buf(label); + res->data.block.name = token_buf(pc, label); return res; } @@ -1230,8 +1186,8 @@ static AstNode *ast_parse_expr(ParseContext *pc) { return ast_parse_prefix_op_expr( pc, [](ParseContext *context) { - Token *try_token = eat_token_if(context, TokenIdKeywordTry); - if (try_token != nullptr) { + TokenIndex try_token = eat_token_if(context, TokenIdKeywordTry); + if (try_token != 0) { AstNode *res = ast_create_node(context, NodeTypeReturnExpr, try_token); res->data.return_expr.kind = ReturnKindError; return res; @@ -1318,72 +1274,72 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc) { if (if_expr != nullptr) return if_expr; - Token *break_token = eat_token_if(pc, TokenIdKeywordBreak); - if (break_token != nullptr) { - Token *label = ast_parse_break_label(pc); + TokenIndex break_token = eat_token_if(pc, TokenIdKeywordBreak); + if (break_token != 0) { + TokenIndex label = ast_parse_break_label(pc); AstNode *expr = ast_parse_expr(pc); AstNode *res = ast_create_node(pc, NodeTypeBreak, break_token); - res->data.break_expr.name = token_buf(label); + res->data.break_expr.name = token_buf(pc, label); res->data.break_expr.expr = expr; return res; } - Token *comptime = eat_token_if(pc, TokenIdKeywordCompTime); - if (comptime != nullptr) { + TokenIndex comptime = eat_token_if(pc, TokenIdKeywordCompTime); + if (comptime != 0) { AstNode *expr = ast_expect(pc, ast_parse_expr); AstNode *res = ast_create_node(pc, NodeTypeCompTime, comptime); res->data.comptime_expr.expr = expr; return res; } - Token *nosuspend = eat_token_if(pc, TokenIdKeywordNoSuspend); - if (nosuspend != nullptr) { + TokenIndex nosuspend = eat_token_if(pc, TokenIdKeywordNoSuspend); + if (nosuspend != 0) { AstNode *expr = ast_expect(pc, ast_parse_expr); AstNode *res = ast_create_node(pc, NodeTypeNoSuspend, nosuspend); res->data.nosuspend_expr.expr = expr; return res; } - Token *continue_token = eat_token_if(pc, TokenIdKeywordContinue); - if (continue_token != nullptr) { - Token *label = ast_parse_break_label(pc); + TokenIndex continue_token = eat_token_if(pc, TokenIdKeywordContinue); + if (continue_token != 0) { + TokenIndex label = ast_parse_break_label(pc); AstNode *res = ast_create_node(pc, NodeTypeContinue, continue_token); - res->data.continue_expr.name = token_buf(label); + res->data.continue_expr.name = token_buf(pc, label); return res; } - Token *resume = eat_token_if(pc, TokenIdKeywordResume); - if (resume != nullptr) { + TokenIndex resume = eat_token_if(pc, TokenIdKeywordResume); + if (resume != 0) { AstNode *expr = ast_expect(pc, ast_parse_expr); AstNode *res = ast_create_node(pc, NodeTypeResume, resume); res->data.resume_expr.expr = expr; return res; } - Token *return_token = eat_token_if(pc, TokenIdKeywordReturn); - if (return_token != nullptr) { + TokenIndex return_token = eat_token_if(pc, TokenIdKeywordReturn); + if (return_token != 0) { AstNode *expr = ast_parse_expr(pc); AstNode *res = ast_create_node(pc, NodeTypeReturnExpr, return_token); res->data.return_expr.expr = expr; return res; } - Token *label = ast_parse_block_label(pc); + TokenIndex label = ast_parse_block_label(pc); AstNode *loop = ast_parse_loop_expr(pc); if (loop != nullptr) { switch (loop->type) { case NodeTypeForExpr: - loop->data.for_expr.name = token_buf(label); + loop->data.for_expr.name = token_buf(pc, label); break; case NodeTypeWhileExpr: - loop->data.while_expr.name = token_buf(label); + loop->data.while_expr.name = token_buf(pc, label); break; default: zig_unreachable(); } return loop; - } else if (label != nullptr) { + } else if (label != 0) { // Restore the tokens that we eaten by ast_parse_block_label. put_back_token(pc); put_back_token(pc); @@ -1407,8 +1363,8 @@ static AstNode *ast_parse_if_expr(ParseContext *pc) { // Block <- LBRACE Statement* RBRACE static AstNode *ast_parse_block(ParseContext *pc) { - Token *lbrace = eat_token_if(pc, TokenIdLBrace); - if (lbrace == nullptr) + TokenIndex lbrace = eat_token_if(pc, TokenIdLBrace); + if (lbrace == 0) return nullptr; ZigList statements = {}; @@ -1462,8 +1418,8 @@ static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc) { // / LBRACE Expr (COMMA Expr)* COMMA? RBRACE // / LBRACE RBRACE static AstNode *ast_parse_init_list(ParseContext *pc) { - Token *lbrace = eat_token_if(pc, TokenIdLBrace); - if (lbrace == nullptr) + TokenIndex lbrace = eat_token_if(pc, TokenIdLBrace); + if (lbrace == 0) return nullptr; AstNode *first = ast_parse_field_init(pc); @@ -1472,7 +1428,7 @@ static AstNode *ast_parse_init_list(ParseContext *pc) { res->data.container_init_expr.kind = ContainerInitKindStruct; res->data.container_init_expr.entries.append(first); - while (eat_token_if(pc, TokenIdComma) != nullptr) { + while (eat_token_if(pc, TokenIdComma) != 0) { AstNode *field_init = ast_parse_field_init(pc); if (field_init == nullptr) break; @@ -1490,7 +1446,7 @@ static AstNode *ast_parse_init_list(ParseContext *pc) { if (first != nullptr) { res->data.container_init_expr.entries.append(first); - while (eat_token_if(pc, TokenIdComma) != nullptr) { + while (eat_token_if(pc, TokenIdComma) != 0) { AstNode *expr = ast_parse_expr(pc); if (expr == nullptr) break; @@ -1535,7 +1491,7 @@ static AstNode *ast_parse_error_union_expr(ParseContext *pc) { // <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments // / PrimaryTypeExpr (SuffixOp / FnCallArguments)* static AstNode *ast_parse_suffix_expr(ParseContext *pc) { - Token *async_token = eat_token_if(pc, TokenIdKeywordAsync); + TokenIndex async_token = eat_token_if(pc, TokenIdKeywordAsync); if (async_token) { AstNode *child = ast_expect(pc, ast_parse_primary_type_expr); while (true) { @@ -1652,43 +1608,21 @@ static AstNode *ast_parse_suffix_expr(ParseContext *pc) { // / STRINGLITERAL // / SwitchExpr static AstNode *ast_parse_primary_type_expr(ParseContext *pc) { - // TODO: This is not in line with the grammar. - // Because the prev stage 1 tokenizer does not parse - // @[a-zA-Z_][a-zA-Z0-9_] as one token, it has to do a - // hack, where it accepts '@' (IDENTIFIER / KEYWORD_export / - // KEYWORD_extern). - // I'd say that it's better if '@' is part of the builtin - // identifier token. - Token *at_sign = eat_token_if(pc, TokenIdAtSign); - if (at_sign != nullptr) { - Buf *name; - Token *token; - if ((token = eat_token_if(pc, TokenIdKeywordExport)) != nullptr) { - name = buf_create_from_str("export"); - } else if ((token = eat_token_if(pc, TokenIdKeywordExtern)) != nullptr) { - name = buf_create_from_str("extern"); - } else { - token = expect_token(pc, TokenIdSymbol); - name = token_buf(token); - } - + TokenIndex builtin_tok = eat_token_if(pc, TokenIdBuiltin); + if (builtin_tok != 0) { AstNode *res = ast_expect(pc, ast_parse_fn_call_arguments); - AstNode *name_sym = ast_create_node(pc, NodeTypeSymbol, token); - name_sym->data.symbol_expr.symbol = name; + AstNode *name_sym = ast_create_node(pc, NodeTypeIdentifier, builtin_tok); assert(res->type == NodeTypeFnCallExpr); - res->line = at_sign->start_line; - res->column = at_sign->start_column; + res->main_token = builtin_tok; res->data.fn_call_expr.fn_ref_expr = name_sym; res->data.fn_call_expr.modifier = CallModifierBuiltin; return res; } - Token *char_lit = eat_token_if(pc, TokenIdCharLiteral); - if (char_lit != nullptr) { - AstNode *res = ast_create_node(pc, NodeTypeCharLiteral, char_lit); - res->data.char_literal.value = char_lit->data.char_lit.c; - return res; + TokenIndex char_lit = eat_token_if(pc, TokenIdCharLiteral); + if (char_lit != 0) { + return ast_create_node(pc, NodeTypeCharLiteral, char_lit); } AstNode *container_decl = ast_parse_container_decl(pc); @@ -1703,12 +1637,9 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) { if (error_set_decl != nullptr) return error_set_decl; - Token *float_lit = eat_token_if(pc, TokenIdFloatLiteral); - if (float_lit != nullptr) { - AstNode *res = ast_create_node(pc, NodeTypeFloatLiteral, float_lit); - res->data.float_literal.bigfloat = &float_lit->data.float_lit.bigfloat; - res->data.float_literal.overflow = float_lit->data.float_lit.overflow; - return res; + TokenIndex float_lit = eat_token_if(pc, TokenIdFloatLiteral); + if (float_lit != 0) { + return ast_create_node(pc, NodeTypeFloatLiteral, float_lit); } AstNode *fn_proto = ast_parse_fn_proto(pc); @@ -1723,86 +1654,77 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) { if (labeled_type_expr != nullptr) return labeled_type_expr; - Token *identifier = eat_token_if(pc, TokenIdSymbol); - if (identifier != nullptr) - return token_symbol(pc, identifier); + TokenIndex identifier = eat_token_if(pc, TokenIdIdentifier); + if (identifier != 0) + return token_identifier(pc, identifier); AstNode *if_type_expr = ast_parse_if_type_expr(pc); if (if_type_expr != nullptr) return if_type_expr; - Token *int_lit = eat_token_if(pc, TokenIdIntLiteral); - if (int_lit != nullptr) { - AstNode *res = ast_create_node(pc, NodeTypeIntLiteral, int_lit); - res->data.int_literal.bigint = &int_lit->data.int_lit.bigint; - return res; + TokenIndex int_lit = eat_token_if(pc, TokenIdIntLiteral); + if (int_lit != 0) { + return ast_create_node(pc, NodeTypeIntLiteral, int_lit); } - Token *comptime = eat_token_if(pc, TokenIdKeywordCompTime); - if (comptime != nullptr) { + TokenIndex comptime = eat_token_if(pc, TokenIdKeywordCompTime); + if (comptime != 0) { AstNode *expr = ast_expect(pc, ast_parse_type_expr); AstNode *res = ast_create_node(pc, NodeTypeCompTime, comptime); res->data.comptime_expr.expr = expr; return res; } - Token *error = eat_token_if(pc, TokenIdKeywordError); - if (error != nullptr) { - Token *dot = expect_token(pc, TokenIdDot); - Token *name = expect_token(pc, TokenIdSymbol); + TokenIndex error = eat_token_if(pc, TokenIdKeywordError); + if (error != 0) { + TokenIndex dot = expect_token(pc, TokenIdDot); + TokenIndex name = expect_token(pc, TokenIdIdentifier); AstNode *left = ast_create_node(pc, NodeTypeErrorType, error); AstNode *res = ast_create_node(pc, NodeTypeFieldAccessExpr, dot); res->data.field_access_expr.struct_expr = left; - res->data.field_access_expr.field_name = token_buf(name); + res->data.field_access_expr.field_name = token_buf(pc, name); return res; } - Token *false_token = eat_token_if(pc, TokenIdKeywordFalse); - if (false_token != nullptr) { + TokenIndex false_token = eat_token_if(pc, TokenIdKeywordFalse); + if (false_token != 0) { AstNode *res = ast_create_node(pc, NodeTypeBoolLiteral, false_token); res->data.bool_literal.value = false; return res; } - Token *null = eat_token_if(pc, TokenIdKeywordNull); - if (null != nullptr) + TokenIndex null = eat_token_if(pc, TokenIdKeywordNull); + if (null != 0) return ast_create_node(pc, NodeTypeNullLiteral, null); - Token *anyframe = eat_token_if(pc, TokenIdKeywordAnyFrame); - if (anyframe != nullptr) + TokenIndex anyframe = eat_token_if(pc, TokenIdKeywordAnyFrame); + if (anyframe != 0) return ast_create_node(pc, NodeTypeAnyFrameType, anyframe); - Token *true_token = eat_token_if(pc, TokenIdKeywordTrue); - if (true_token != nullptr) { + TokenIndex true_token = eat_token_if(pc, TokenIdKeywordTrue); + if (true_token != 0) { AstNode *res = ast_create_node(pc, NodeTypeBoolLiteral, true_token); res->data.bool_literal.value = true; return res; } - Token *undefined = eat_token_if(pc, TokenIdKeywordUndefined); - if (undefined != nullptr) + TokenIndex undefined = eat_token_if(pc, TokenIdKeywordUndefined); + if (undefined != 0) return ast_create_node(pc, NodeTypeUndefinedLiteral, undefined); - Token *unreachable = eat_token_if(pc, TokenIdKeywordUnreachable); - if (unreachable != nullptr) + TokenIndex unreachable = eat_token_if(pc, TokenIdKeywordUnreachable); + if (unreachable != 0) return ast_create_node(pc, NodeTypeUnreachable, unreachable); - Buf *string_buf; - Token *string_lit = eat_token_if(pc, TokenIdStringLiteral); - if (string_lit != nullptr) { - string_buf = token_buf(string_lit); - } else { - Buf multiline_string_buf = BUF_INIT; - string_lit = ast_parse_multiline_string_literal(pc, &multiline_string_buf); - if (string_lit != nullptr) { - string_buf = buf_create_from_buf(&multiline_string_buf); - } + TokenIndex string_lit = eat_token_if(pc, TokenIdStringLiteral); + if (string_lit != 0) { + return ast_create_node(pc, NodeTypeStringLiteral, string_lit); } - if (string_lit != nullptr) { - AstNode *res = ast_create_node(pc, NodeTypeStringLiteral, string_lit); - res->data.string_literal.buf = string_buf; - return res; + + TokenIndex multiline_str_lit = ast_parse_multi_tok(pc, TokenIdMultilineStringLiteralLine); + if (multiline_str_lit != 0) { + return ast_create_node(pc, NodeTypeStringLiteral, multiline_str_lit); } AstNode *switch_expr = ast_parse_switch_expr(pc); @@ -1814,22 +1736,21 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) { // ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto static AstNode *ast_parse_container_decl(ParseContext *pc) { - Token *layout_token = eat_token_if(pc, TokenIdKeywordExtern); - if (layout_token == nullptr) + TokenIndex layout_token = eat_token_if(pc, TokenIdKeywordExtern); + if (layout_token == 0) layout_token = eat_token_if(pc, TokenIdKeywordPacked); AstNode *res = ast_parse_container_decl_auto(pc); if (res == nullptr) { - if (layout_token != nullptr) + if (layout_token != 0) put_back_token(pc); return nullptr; } assert(res->type == NodeTypeContainerDecl); - if (layout_token != nullptr) { - res->line = layout_token->start_line; - res->column = layout_token->start_column; - res->data.container_decl.layout = layout_token->id == TokenIdKeywordExtern + if (layout_token != 0) { + res->main_token = layout_token; + res->data.container_decl.layout = pc->token_ids[layout_token] == TokenIdKeywordExtern ? ContainerLayoutExtern : ContainerLayoutPacked; } @@ -1838,28 +1759,27 @@ static AstNode *ast_parse_container_decl(ParseContext *pc) { // ErrorSetDecl <- KEYWORD_error LBRACE IdentifierList RBRACE static AstNode *ast_parse_error_set_decl(ParseContext *pc) { - Token *first = eat_token_if(pc, TokenIdKeywordError); - if (first == nullptr) + TokenIndex first = eat_token_if(pc, TokenIdKeywordError); + if (first == 0) return nullptr; - if (eat_token_if(pc, TokenIdLBrace) == nullptr) { + if (eat_token_if(pc, TokenIdLBrace) == 0) { put_back_token(pc); return nullptr; } ZigList decls = ast_parse_list(pc, TokenIdComma, [](ParseContext *context) { - Buf doc_comment_buf = BUF_INIT; - Token *doc_token = ast_parse_doc_comments(context, &doc_comment_buf); - Token *ident = eat_token_if(context, TokenIdSymbol); - if (ident == nullptr) + TokenIndex doc_token = ast_parse_doc_comments(context); + TokenIndex ident = eat_token_if(context, TokenIdIdentifier); + if (ident == 0) return (AstNode*)nullptr; - AstNode *symbol_node = token_symbol(context, ident); - if (doc_token == nullptr) + AstNode *symbol_node = token_identifier(context, ident); + if (doc_token == 0) return symbol_node; AstNode *field_node = ast_create_node(context, NodeTypeErrorSetField, doc_token); field_node->data.err_set_field.field_name = symbol_node; - field_node->data.err_set_field.doc_comments = doc_comment_buf; + field_node->data.err_set_field.doc_comments = doc_token; return field_node; }); expect_token(pc, TokenIdRBrace); @@ -1871,8 +1791,8 @@ static AstNode *ast_parse_error_set_decl(ParseContext *pc) { // GroupedExpr <- LPAREN Expr RPAREN static AstNode *ast_parse_grouped_expr(ParseContext *pc) { - Token *lparen = eat_token_if(pc, TokenIdLParen); - if (lparen == nullptr) + TokenIndex lparen = eat_token_if(pc, TokenIdLParen); + if (lparen == 0) return nullptr; AstNode *expr = ast_expect(pc, ast_parse_expr); @@ -1892,12 +1812,12 @@ static AstNode *ast_parse_if_type_expr(ParseContext *pc) { // <- BlockLabel Block // / BlockLabel? LoopTypeExpr static AstNode *ast_parse_labeled_type_expr(ParseContext *pc) { - Token *label = ast_parse_block_label(pc); - if (label != nullptr) { + TokenIndex label = ast_parse_block_label(pc); + if (label != 0) { AstNode *block = ast_parse_block(pc); if (block != nullptr) { assert(block->type == NodeTypeBlock); - block->data.block.name = token_buf(label); + block->data.block.name = token_buf(pc, label); return block; } } @@ -1906,10 +1826,10 @@ static AstNode *ast_parse_labeled_type_expr(ParseContext *pc) { if (loop != nullptr) { switch (loop->type) { case NodeTypeForExpr: - loop->data.for_expr.name = token_buf(label); + loop->data.for_expr.name = token_buf(pc, label); break; case NodeTypeWhileExpr: - loop->data.while_expr.name = token_buf(label); + loop->data.while_expr.name = token_buf(pc, label); break; default: zig_unreachable(); @@ -1917,7 +1837,7 @@ static AstNode *ast_parse_labeled_type_expr(ParseContext *pc) { return loop; } - if (label != nullptr) { + if (label != 0) { put_back_token(pc); put_back_token(pc); } @@ -1945,8 +1865,8 @@ static AstNode *ast_parse_while_type_expr(ParseContext *pc) { // SwitchExpr <- KEYWORD_switch LPAREN Expr RPAREN LBRACE SwitchProngList RBRACE static AstNode *ast_parse_switch_expr(ParseContext *pc) { - Token *switch_token = eat_token_if(pc, TokenIdKeywordSwitch); - if (switch_token == nullptr) + TokenIndex switch_token = eat_token_if(pc, TokenIdKeywordSwitch); + if (switch_token == 0) return nullptr; expect_token(pc, TokenIdLParen); @@ -1964,11 +1884,11 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc) { // AsmExpr <- KEYWORD_asm KEYWORD_volatile? LPAREN STRINGLITERAL AsmOutput? RPAREN static AstNode *ast_parse_asm_expr(ParseContext *pc) { - Token *asm_token = eat_token_if(pc, TokenIdKeywordAsm); - if (asm_token == nullptr) + TokenIndex asm_token = eat_token_if(pc, TokenIdKeywordAsm); + if (asm_token == 0) return nullptr; - Token *volatile_token = eat_token_if(pc, TokenIdKeywordVolatile); + TokenIndex volatile_token = eat_token_if(pc, TokenIdKeywordVolatile); expect_token(pc, TokenIdLParen); AstNode *asm_template = ast_expect(pc, ast_parse_expr); AstNode *res = ast_parse_asm_output(pc); @@ -1976,25 +1896,21 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc) { res = ast_create_node_no_line_info(pc, NodeTypeAsmExpr); expect_token(pc, TokenIdRParen); - res->line = asm_token->start_line; - res->column = asm_token->start_column; + res->main_token = asm_token; res->data.asm_expr.volatile_token = volatile_token; res->data.asm_expr.asm_template = asm_template; return res; } static AstNode *ast_parse_anon_lit(ParseContext *pc) { - Token *period = eat_token_if(pc, TokenIdDot); - if (period == nullptr) + TokenIndex period = eat_token_if(pc, TokenIdDot); + if (period == 0) return nullptr; // anon enum literal - Token *identifier = eat_token_if(pc, TokenIdSymbol); - if (identifier != nullptr) { - AstNode *res = ast_create_node(pc, NodeTypeEnumLiteral, period); - res->data.enum_literal.period = period; - res->data.enum_literal.identifier = identifier; - return res; + TokenIndex identifier = eat_token_if(pc, TokenIdIdentifier); + if (identifier != 0) { + return ast_create_node(pc, NodeTypeEnumLiteral, period); } // anon container literal @@ -2007,7 +1923,7 @@ static AstNode *ast_parse_anon_lit(ParseContext *pc) { // AsmOutput <- COLON AsmOutputList AsmInput? static AstNode *ast_parse_asm_output(ParseContext *pc) { - if (eat_token_if(pc, TokenIdColon) == nullptr) + if (eat_token_if(pc, TokenIdColon) == 0) return nullptr; ZigList output_list = ast_parse_list(pc, TokenIdComma, ast_parse_asm_output_item); @@ -2021,20 +1937,20 @@ static AstNode *ast_parse_asm_output(ParseContext *pc) { // AsmOutputItem <- LBRACKET IDENTIFIER RBRACKET STRINGLITERAL LPAREN (MINUSRARROW TypeExpr / IDENTIFIER) RPAREN static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) { - if (eat_token_if(pc, TokenIdLBracket) == nullptr) + if (eat_token_if(pc, TokenIdLBracket) == 0) return nullptr; - Token *sym_name = expect_token(pc, TokenIdSymbol); + TokenIndex sym_name = expect_token(pc, TokenIdIdentifier); expect_token(pc, TokenIdRBracket); - Token *str = eat_token_if(pc, TokenIdMultilineStringLiteral); - if (str == nullptr) + TokenIndex str = ast_parse_multi_tok(pc, TokenIdMultilineStringLiteralLine); + if (str == 0) str = expect_token(pc, TokenIdStringLiteral); expect_token(pc, TokenIdLParen); - Token *var_name = eat_token_if(pc, TokenIdSymbol); + TokenIndex var_name = eat_token_if(pc, TokenIdIdentifier); AstNode *return_type = nullptr; - if (var_name == nullptr) { + if (var_name == 0) { expect_token(pc, TokenIdArrow); return_type = ast_expect(pc, ast_parse_type_expr); } @@ -2042,16 +1958,16 @@ static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) { expect_token(pc, TokenIdRParen); AsmOutput *res = heap::c_allocator.create(); - res->asm_symbolic_name = token_buf(sym_name); - res->constraint = token_buf(str); - res->variable_name = token_buf(var_name); + res->asm_symbolic_name = token_buf(pc, sym_name); + res->constraint = token_buf(pc, str); + res->variable_name = token_buf(pc, var_name); res->return_type = return_type; return res; } // AsmInput <- COLON AsmInputList AsmClobbers? static AstNode *ast_parse_asm_input(ParseContext *pc) { - if (eat_token_if(pc, TokenIdColon) == nullptr) + if (eat_token_if(pc, TokenIdColon) == 0) return nullptr; ZigList input_list = ast_parse_list(pc, TokenIdComma, ast_parse_asm_input_item); @@ -2065,37 +1981,35 @@ static AstNode *ast_parse_asm_input(ParseContext *pc) { // AsmInputItem <- LBRACKET IDENTIFIER RBRACKET STRINGLITERAL LPAREN Expr RPAREN static AsmInput *ast_parse_asm_input_item(ParseContext *pc) { - if (eat_token_if(pc, TokenIdLBracket) == nullptr) + if (eat_token_if(pc, TokenIdLBracket) == 0) return nullptr; - Token *sym_name = expect_token(pc, TokenIdSymbol); + TokenIndex sym_name = expect_token(pc, TokenIdIdentifier); expect_token(pc, TokenIdRBracket); - Token *constraint = eat_token_if(pc, TokenIdMultilineStringLiteral); - if (constraint == nullptr) - constraint = expect_token(pc, TokenIdStringLiteral); + TokenIndex constraint = expect_token(pc, TokenIdStringLiteral); expect_token(pc, TokenIdLParen); AstNode *expr = ast_expect(pc, ast_parse_expr); expect_token(pc, TokenIdRParen); AsmInput *res = heap::c_allocator.create(); - res->asm_symbolic_name = token_buf(sym_name); - res->constraint = token_buf(constraint); + res->asm_symbolic_name = token_buf(pc, sym_name); + res->constraint = token_buf(pc, constraint); res->expr = expr; return res; } // AsmClobbers <- COLON StringList static AstNode *ast_parse_asm_clobbers(ParseContext *pc) { - if (eat_token_if(pc, TokenIdColon) == nullptr) + if (eat_token_if(pc, TokenIdColon) == 0) return nullptr; ZigList clobber_list = ast_parse_list(pc, TokenIdComma, [](ParseContext *context) { - Token *str = eat_token_if(context, TokenIdStringLiteral); - if (str == nullptr) - str = eat_token_if(context, TokenIdMultilineStringLiteral); - if (str != nullptr) - return token_buf(str); + TokenIndex str = eat_token_if(context, TokenIdStringLiteral); + if (str == 0) + str = ast_parse_multi_tok(context, TokenIdMultilineStringLiteralLine); + if (str != 0) + return token_buf(context, str); return (Buf*)nullptr; }); @@ -2105,24 +2019,24 @@ static AstNode *ast_parse_asm_clobbers(ParseContext *pc) { } // BreakLabel <- COLON IDENTIFIER -static Token *ast_parse_break_label(ParseContext *pc) { - if (eat_token_if(pc, TokenIdColon) == nullptr) - return nullptr; +static TokenIndex ast_parse_break_label(ParseContext *pc) { + if (eat_token_if(pc, TokenIdColon) == 0) + return 0; - return expect_token(pc, TokenIdSymbol); + return expect_token(pc, TokenIdIdentifier); } // BlockLabel <- IDENTIFIER COLON -static Token *ast_parse_block_label(ParseContext *pc) { - Token *ident = eat_token_if(pc, TokenIdSymbol); - if (ident == nullptr) - return nullptr; +static TokenIndex ast_parse_block_label(ParseContext *pc) { + TokenIndex ident = eat_token_if(pc, TokenIdIdentifier); + if (ident == 0) + return 0; // We do 2 token lookahead here, as we don't want to error when // parsing identifiers. - if (eat_token_if(pc, TokenIdColon) == nullptr) { + if (eat_token_if(pc, TokenIdColon) == 0) { put_back_token(pc); - return nullptr; + return 0; } return ident; @@ -2130,17 +2044,17 @@ static Token *ast_parse_block_label(ParseContext *pc) { // FieldInit <- DOT IDENTIFIER EQUAL Expr static AstNode *ast_parse_field_init(ParseContext *pc) { - Token *first = eat_token_if(pc, TokenIdDot); - if (first == nullptr) + TokenIndex first = eat_token_if(pc, TokenIdDot); + if (first == 0) return nullptr; - Token *name = eat_token_if(pc, TokenIdSymbol); - if (name == nullptr) { + TokenIndex name = eat_token_if(pc, TokenIdIdentifier); + if (name == 0) { // Because of anon literals ".{" is also valid. put_back_token(pc); return nullptr; } - if (eat_token_if(pc, TokenIdEq) == nullptr) { + if (eat_token_if(pc, TokenIdEq) == 0) { // Because ".Name" can also be intepreted as an enum literal, we should put back // those two tokens again so that the parser can try to parse them as the enum // literal later. @@ -2151,15 +2065,15 @@ static AstNode *ast_parse_field_init(ParseContext *pc) { AstNode *expr = ast_expect(pc, ast_parse_expr); AstNode *res = ast_create_node(pc, NodeTypeStructValueField, first); - res->data.struct_val_field.name = token_buf(name); + res->data.struct_val_field.name = token_buf(pc, name); res->data.struct_val_field.expr = expr; return res; } // WhileContinueExpr <- COLON LPAREN AssignExpr RPAREN static AstNode *ast_parse_while_continue_expr(ParseContext *pc) { - Token *first = eat_token_if(pc, TokenIdColon); - if (first == nullptr) + TokenIndex first = eat_token_if(pc, TokenIdColon); + if (first == 0) return nullptr; expect_token(pc, TokenIdLParen); @@ -2170,8 +2084,8 @@ static AstNode *ast_parse_while_continue_expr(ParseContext *pc) { // LinkSection <- KEYWORD_linksection LPAREN Expr RPAREN static AstNode *ast_parse_link_section(ParseContext *pc) { - Token *first = eat_token_if(pc, TokenIdKeywordLinkSection); - if (first == nullptr) + TokenIndex first = eat_token_if(pc, TokenIdKeywordLinkSection); + if (first == 0) return nullptr; expect_token(pc, TokenIdLParen); @@ -2182,8 +2096,8 @@ static AstNode *ast_parse_link_section(ParseContext *pc) { // CallConv <- KEYWORD_callconv LPAREN Expr RPAREN static AstNode *ast_parse_callconv(ParseContext *pc) { - Token *first = eat_token_if(pc, TokenIdKeywordCallconv); - if (first == nullptr) + TokenIndex first = eat_token_if(pc, TokenIdKeywordCallconv); + if (first == 0) return nullptr; expect_token(pc, TokenIdLParen); @@ -2194,28 +2108,27 @@ static AstNode *ast_parse_callconv(ParseContext *pc) { // ParamDecl <- (KEYWORD_noalias / KEYWORD_comptime)? (IDENTIFIER COLON)? ParamType static AstNode *ast_parse_param_decl(ParseContext *pc) { - Buf doc_comments = BUF_INIT; - ast_parse_doc_comments(pc, &doc_comments); + TokenIndex first_doc_comment = ast_parse_doc_comments(pc); - Token *first = eat_token_if(pc, TokenIdKeywordNoAlias); - if (first == nullptr) + TokenIndex first = eat_token_if(pc, TokenIdKeywordNoAlias); + if (first == 0) first = eat_token_if(pc, TokenIdKeywordCompTime); - Token *name = eat_token_if(pc, TokenIdSymbol); - if (name != nullptr) { - if (eat_token_if(pc, TokenIdColon) != nullptr) { - if (first == nullptr) + TokenIndex name = eat_token_if(pc, TokenIdIdentifier); + if (name != 0) { + if (eat_token_if(pc, TokenIdColon) != 0) { + if (first == 0) first = name; } else { // We put back the ident, so it can be parsed as a ParamType // later. put_back_token(pc); - name = nullptr; + name = 0; } } AstNode *res; - if (first == nullptr) { + if (first == 0) { first = peek_token(pc); res = ast_parse_param_type(pc); } else { @@ -2226,12 +2139,11 @@ static AstNode *ast_parse_param_decl(ParseContext *pc) { return nullptr; assert(res->type == NodeTypeParamDecl); - res->line = first->start_line; - res->column = first->start_column; - res->data.param_decl.name = token_buf(name); - res->data.param_decl.doc_comments = doc_comments; - res->data.param_decl.is_noalias = first->id == TokenIdKeywordNoAlias; - res->data.param_decl.is_comptime = first->id == TokenIdKeywordCompTime; + res->main_token = first; + res->data.param_decl.name = token_buf(pc, name); + res->data.param_decl.doc_comments = first_doc_comment; + res->data.param_decl.is_noalias = pc->token_ids[first] == TokenIdKeywordNoAlias; + res->data.param_decl.is_comptime = pc->token_ids[first] == TokenIdKeywordCompTime; return res; } @@ -2240,15 +2152,15 @@ static AstNode *ast_parse_param_decl(ParseContext *pc) { // / DOT3 // / TypeExpr static AstNode *ast_parse_param_type(ParseContext *pc) { - Token *anytype_token = eat_token_if(pc, TokenIdKeywordAnyType); - if (anytype_token != nullptr) { + TokenIndex anytype_token = eat_token_if(pc, TokenIdKeywordAnyType); + if (anytype_token != 0) { AstNode *res = ast_create_node(pc, NodeTypeParamDecl, anytype_token); res->data.param_decl.anytype_token = anytype_token; return res; } - Token *dots = eat_token_if(pc, TokenIdEllipsis3); - if (dots != nullptr) { + TokenIndex dots = eat_token_if(pc, TokenIdEllipsis3); + if (dots != 0) { AstNode *res = ast_create_node(pc, NodeTypeParamDecl, dots); res->data.param_decl.is_var_args = true; return res; @@ -2266,8 +2178,8 @@ static AstNode *ast_parse_param_type(ParseContext *pc) { // IfPrefix <- KEYWORD_if LPAREN Expr RPAREN PtrPayload? static AstNode *ast_parse_if_prefix(ParseContext *pc) { - Token *first = eat_token_if(pc, TokenIdKeywordIf); - if (first == nullptr) + TokenIndex first = eat_token_if(pc, TokenIdKeywordIf); + if (first == 0) return nullptr; expect_token(pc, TokenIdLParen); @@ -2279,16 +2191,16 @@ static AstNode *ast_parse_if_prefix(ParseContext *pc) { AstNode *res = ast_create_node(pc, NodeTypeIfOptional, first); res->data.test_expr.target_node = condition; if (opt_payload.unwrap(&payload)) { - res->data.test_expr.var_symbol = token_buf(payload.payload); - res->data.test_expr.var_is_ptr = payload.asterisk != nullptr; + res->data.test_expr.var_symbol = token_buf(pc, payload.payload); + res->data.test_expr.var_is_ptr = payload.asterisk != 0; } return res; } // WhilePrefix <- KEYWORD_while LPAREN Expr RPAREN PtrPayload? WhileContinueExpr? static AstNode *ast_parse_while_prefix(ParseContext *pc) { - Token *while_token = eat_token_if(pc, TokenIdKeywordWhile); - if (while_token == nullptr) + TokenIndex while_token = eat_token_if(pc, TokenIdKeywordWhile); + if (while_token == 0) return nullptr; expect_token(pc, TokenIdLParen); @@ -2302,8 +2214,8 @@ static AstNode *ast_parse_while_prefix(ParseContext *pc) { res->data.while_expr.condition = condition; res->data.while_expr.continue_expr = continue_expr; if (opt_payload.unwrap(&payload)) { - res->data.while_expr.var_symbol = token_buf(payload.payload); - res->data.while_expr.var_is_ptr = payload.asterisk != nullptr; + res->data.while_expr.var_symbol = token_buf(pc, payload.payload); + res->data.while_expr.var_is_ptr = payload.asterisk != 0; } return res; @@ -2311,8 +2223,8 @@ static AstNode *ast_parse_while_prefix(ParseContext *pc) { // ForPrefix <- KEYWORD_for LPAREN Expr RPAREN PtrIndexPayload static AstNode *ast_parse_for_prefix(ParseContext *pc) { - Token *for_token = eat_token_if(pc, TokenIdKeywordFor); - if (for_token == nullptr) + TokenIndex for_token = eat_token_if(pc, TokenIdKeywordFor); + if (for_token == 0) return nullptr; expect_token(pc, TokenIdLParen); @@ -2324,31 +2236,31 @@ static AstNode *ast_parse_for_prefix(ParseContext *pc) { AstNode *res = ast_create_node(pc, NodeTypeForExpr, for_token); res->data.for_expr.array_expr = array_expr; - res->data.for_expr.elem_node = token_symbol(pc, payload.payload); - res->data.for_expr.elem_is_ptr = payload.asterisk != nullptr; - if (payload.index != nullptr) - res->data.for_expr.index_node = token_symbol(pc, payload.index); + res->data.for_expr.elem_node = token_identifier(pc, payload.payload); + res->data.for_expr.elem_is_ptr = payload.asterisk != 0; + if (payload.index != 0) + res->data.for_expr.index_node = token_identifier(pc, payload.index); return res; } // Payload <- PIPE IDENTIFIER PIPE -static Token *ast_parse_payload(ParseContext *pc) { - if (eat_token_if(pc, TokenIdBinOr) == nullptr) - return nullptr; +static TokenIndex ast_parse_payload(ParseContext *pc) { + if (eat_token_if(pc, TokenIdBinOr) == 0) + return 0; - Token *res = expect_token(pc, TokenIdSymbol); + TokenIndex res = expect_token(pc, TokenIdIdentifier); expect_token(pc, TokenIdBinOr); return res; } // PtrPayload <- PIPE ASTERISK? IDENTIFIER PIPE static Optional ast_parse_ptr_payload(ParseContext *pc) { - if (eat_token_if(pc, TokenIdBinOr) == nullptr) + if (eat_token_if(pc, TokenIdBinOr) == 0) return Optional::none(); - Token *asterisk = eat_token_if(pc, TokenIdStar); - Token *payload = expect_token(pc, TokenIdSymbol); + TokenIndex asterisk = eat_token_if(pc, TokenIdStar); + TokenIndex payload = expect_token(pc, TokenIdIdentifier); expect_token(pc, TokenIdBinOr); PtrPayload res; @@ -2359,14 +2271,14 @@ static Optional ast_parse_ptr_payload(ParseContext *pc) { // PtrIndexPayload <- PIPE ASTERISK? IDENTIFIER (COMMA IDENTIFIER)? PIPE static Optional ast_parse_ptr_index_payload(ParseContext *pc) { - if (eat_token_if(pc, TokenIdBinOr) == nullptr) + if (eat_token_if(pc, TokenIdBinOr) == 0) return Optional::none(); - Token *asterisk = eat_token_if(pc, TokenIdStar); - Token *payload = expect_token(pc, TokenIdSymbol); - Token *index = nullptr; - if (eat_token_if(pc, TokenIdComma) != nullptr) - index = expect_token(pc, TokenIdSymbol); + TokenIndex asterisk = eat_token_if(pc, TokenIdStar); + TokenIndex payload = expect_token(pc, TokenIdIdentifier); + TokenIndex index = 0; + if (eat_token_if(pc, TokenIdComma) != 0) + index = expect_token(pc, TokenIdIdentifier); expect_token(pc, TokenIdBinOr); PtrIndexPayload res; @@ -2390,8 +2302,8 @@ static AstNode *ast_parse_switch_prong(ParseContext *pc) { assert(res->type == NodeTypeSwitchProng); res->data.switch_prong.expr = expr; if (opt_payload.unwrap(&payload)) { - res->data.switch_prong.var_symbol = token_symbol(pc, payload.payload); - res->data.switch_prong.var_is_ptr = payload.asterisk != nullptr; + res->data.switch_prong.var_symbol = token_identifier(pc, payload.payload); + res->data.switch_prong.var_is_ptr = payload.asterisk != 0; } return res; @@ -2407,7 +2319,7 @@ static AstNode *ast_parse_switch_case(ParseContext *pc) { res->data.switch_prong.items.append(first); res->data.switch_prong.any_items_are_range = first->type == NodeTypeSwitchRange; - while (eat_token_if(pc, TokenIdComma) != nullptr) { + while (eat_token_if(pc, TokenIdComma) != 0) { AstNode *item = ast_parse_switch_item(pc); if (item == nullptr) break; @@ -2419,8 +2331,8 @@ static AstNode *ast_parse_switch_case(ParseContext *pc) { return res; } - Token *else_token = eat_token_if(pc, TokenIdKeywordElse); - if (else_token != nullptr) + TokenIndex else_token = eat_token_if(pc, TokenIdKeywordElse); + if (else_token != 0) return ast_create_node(pc, NodeTypeSwitchProng, else_token); return nullptr; @@ -2432,8 +2344,8 @@ static AstNode *ast_parse_switch_item(ParseContext *pc) { if (expr == nullptr) return nullptr; - Token *dots = eat_token_if(pc, TokenIdEllipsis3); - if (dots != nullptr) { + TokenIndex dots = eat_token_if(pc, TokenIdEllipsis3); + if (dots != 0) { AstNode *expr2 = ast_expect(pc, ast_parse_expr); AstNode *res = ast_create_node(pc, NodeTypeSwitchRange, dots); res->data.switch_range.start = expr; @@ -2478,9 +2390,9 @@ static AstNode *ast_parse_assign_op(ParseContext *pc) { table[TokenIdTimesEq] = BinOpTypeAssignTimes; table[TokenIdTimesPercentEq] = BinOpTypeAssignTimesWrap; - BinOpType op = table[peek_token(pc)->id]; + BinOpType op = table[pc->token_ids[pc->current_token]]; if (op != BinOpTypeInvalid) { - Token *op_token = eat_token(pc); + TokenIndex op_token = eat_token(pc); AstNode *res = ast_create_node(pc, NodeTypeBinOpExpr, op_token); res->data.bin_op_expr.bin_op = op; return res; @@ -2506,9 +2418,9 @@ static AstNode *ast_parse_compare_op(ParseContext *pc) { table[TokenIdCmpLessOrEq] = BinOpTypeCmpLessOrEq; table[TokenIdCmpGreaterOrEq] = BinOpTypeCmpGreaterOrEq; - BinOpType op = table[peek_token(pc)->id]; + BinOpType op = table[pc->token_ids[pc->current_token]]; if (op != BinOpTypeInvalid) { - Token *op_token = eat_token(pc); + TokenIndex op_token = eat_token(pc); AstNode *res = ast_create_node(pc, NodeTypeBinOpExpr, op_token); res->data.bin_op_expr.bin_op = op; return res; @@ -2530,20 +2442,20 @@ static AstNode *ast_parse_bitwise_op(ParseContext *pc) { table[TokenIdBinOr] = BinOpTypeBinOr; table[TokenIdKeywordOrElse] = BinOpTypeUnwrapOptional; - BinOpType op = table[peek_token(pc)->id]; + BinOpType op = table[pc->token_ids[pc->current_token]]; if (op != BinOpTypeInvalid) { - Token *op_token = eat_token(pc); + TokenIndex op_token = eat_token(pc); AstNode *res = ast_create_node(pc, NodeTypeBinOpExpr, op_token); res->data.bin_op_expr.bin_op = op; return res; } - Token *catch_token = eat_token_if(pc, TokenIdKeywordCatch); - if (catch_token != nullptr) { - Token *payload = ast_parse_payload(pc); + TokenIndex catch_token = eat_token_if(pc, TokenIdKeywordCatch); + if (catch_token != 0) { + TokenIndex payload = ast_parse_payload(pc); AstNode *res = ast_create_node(pc, NodeTypeCatchExpr, catch_token); - if (payload != nullptr) - res->data.unwrap_err_expr.symbol = token_symbol(pc, payload); + if (payload != 0) + res->data.unwrap_err_expr.symbol = token_identifier(pc, payload); return res; } @@ -2559,9 +2471,9 @@ static AstNode *ast_parse_bit_shift_op(ParseContext *pc) { table[TokenIdBitShiftLeft] = BinOpTypeBitShiftLeft; table[TokenIdBitShiftRight] = BinOpTypeBitShiftRight; - BinOpType op = table[peek_token(pc)->id]; + BinOpType op = table[pc->token_ids[pc->current_token]]; if (op != BinOpTypeInvalid) { - Token *op_token = eat_token(pc); + TokenIndex op_token = eat_token(pc); AstNode *res = ast_create_node(pc, NodeTypeBinOpExpr, op_token); res->data.bin_op_expr.bin_op = op; return res; @@ -2584,9 +2496,9 @@ static AstNode *ast_parse_addition_op(ParseContext *pc) { table[TokenIdPlusPercent] = BinOpTypeAddWrap; table[TokenIdMinusPercent] = BinOpTypeSubWrap; - BinOpType op = table[peek_token(pc)->id]; + BinOpType op = table[pc->token_ids[pc->current_token]]; if (op != BinOpTypeInvalid) { - Token *op_token = eat_token(pc); + TokenIndex op_token = eat_token(pc); AstNode *res = ast_create_node(pc, NodeTypeBinOpExpr, op_token); res->data.bin_op_expr.bin_op = op; return res; @@ -2611,9 +2523,9 @@ static AstNode *ast_parse_multiply_op(ParseContext *pc) { table[TokenIdStarStar] = BinOpTypeArrayMult; table[TokenIdTimesPercent] = BinOpTypeMultWrap; - BinOpType op = table[peek_token(pc)->id]; + BinOpType op = table[pc->token_ids[pc->current_token]]; if (op != BinOpTypeInvalid) { - Token *op_token = eat_token(pc); + TokenIndex op_token = eat_token(pc); AstNode *res = ast_create_node(pc, NodeTypeBinOpExpr, op_token); res->data.bin_op_expr.bin_op = op; return res; @@ -2638,23 +2550,23 @@ static AstNode *ast_parse_prefix_op(ParseContext *pc) { table[TokenIdMinusPercent] = PrefixOpNegationWrap; table[TokenIdAmpersand] = PrefixOpAddrOf; - PrefixOp op = table[peek_token(pc)->id]; + PrefixOp op = table[pc->token_ids[pc->current_token]]; if (op != PrefixOpInvalid) { - Token *op_token = eat_token(pc); + TokenIndex op_token = eat_token(pc); AstNode *res = ast_create_node(pc, NodeTypePrefixOpExpr, op_token); res->data.prefix_op_expr.prefix_op = op; return res; } - Token *try_token = eat_token_if(pc, TokenIdKeywordTry); - if (try_token != nullptr) { + TokenIndex try_token = eat_token_if(pc, TokenIdKeywordTry); + if (try_token != 0) { AstNode *res = ast_create_node(pc, NodeTypeReturnExpr, try_token); res->data.return_expr.kind = ReturnKindError; return res; } - Token *await = eat_token_if(pc, TokenIdKeywordAwait); - if (await != nullptr) { + TokenIndex await = eat_token_if(pc, TokenIdKeywordAwait); + if (await != 0) { AstNode *res = ast_create_node(pc, NodeTypeAwaitExpr, await); return res; } @@ -2668,16 +2580,16 @@ static AstNode *ast_parse_prefix_op(ParseContext *pc) { // / ArrayTypeStart (ByteAlign / KEYWORD_const / KEYWORD_volatile)* // / PtrTypeStart (KEYWORD_align LPAREN Expr (COLON INTEGER COLON INTEGER)? RPAREN / KEYWORD_const / KEYWORD_volatile)* static AstNode *ast_parse_prefix_type_op(ParseContext *pc) { - Token *questionmark = eat_token_if(pc, TokenIdQuestion); - if (questionmark != nullptr) { + TokenIndex questionmark = eat_token_if(pc, TokenIdQuestion); + if (questionmark != 0) { AstNode *res = ast_create_node(pc, NodeTypePrefixOpExpr, questionmark); res->data.prefix_op_expr.prefix_op = PrefixOpOptional; return res; } - Token *anyframe = eat_token_if(pc, TokenIdKeywordAnyFrame); - if (anyframe != nullptr) { - if (eat_token_if(pc, TokenIdArrow) != nullptr) { + TokenIndex anyframe = eat_token_if(pc, TokenIdKeywordAnyFrame); + if (anyframe != 0) { + if (eat_token_if(pc, TokenIdArrow) != 0) { AstNode *res = ast_create_node(pc, NodeTypeAnyFrameType, anyframe); return res; } @@ -2685,18 +2597,18 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) { put_back_token(pc); } - Token *arr_init_lbracket = eat_token_if(pc, TokenIdLBracket); - if (arr_init_lbracket != nullptr) { - Token *underscore = eat_token_if(pc, TokenIdSymbol); - if (underscore == nullptr) { + TokenIndex arr_init_lbracket = eat_token_if(pc, TokenIdLBracket); + if (arr_init_lbracket != 0) { + TokenIndex underscore = eat_token_if(pc, TokenIdIdentifier); + if (underscore == 0) { put_back_token(pc); - } else if (!buf_eql_str(token_buf(underscore), "_")) { + } else if (!buf_eql_str(token_buf(pc, underscore), "_")) { put_back_token(pc); put_back_token(pc); } else { AstNode *sentinel = nullptr; - Token *colon = eat_token_if(pc, TokenIdColon); - if (colon != nullptr) { + TokenIndex colon = eat_token_if(pc, TokenIdColon); + if (colon != 0) { sentinel = ast_expect(pc, ast_parse_expr); } expect_token(pc, TokenIdRBracket); @@ -2715,33 +2627,33 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) { if (child == nullptr) child = ptr; while (true) { - Token *allowzero_token = eat_token_if(pc, TokenIdKeywordAllowZero); - if (allowzero_token != nullptr) { + TokenIndex allowzero_token = eat_token_if(pc, TokenIdKeywordAllowZero); + if (allowzero_token != 0) { child->data.pointer_type.allow_zero_token = allowzero_token; continue; } - if (eat_token_if(pc, TokenIdKeywordAlign) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordAlign) != 0) { expect_token(pc, TokenIdLParen); AstNode *align_expr = ast_expect(pc, ast_parse_expr); child->data.pointer_type.align_expr = align_expr; - if (eat_token_if(pc, TokenIdColon) != nullptr) { - Token *bit_offset_start = expect_token(pc, TokenIdIntLiteral); + if (eat_token_if(pc, TokenIdColon) != 0) { + TokenIndex bit_offset_start = expect_token(pc, TokenIdIntLiteral); expect_token(pc, TokenIdColon); - Token *host_int_bytes = expect_token(pc, TokenIdIntLiteral); - child->data.pointer_type.bit_offset_start = token_bigint(bit_offset_start); - child->data.pointer_type.host_int_bytes = token_bigint(host_int_bytes); + TokenIndex host_int_bytes = expect_token(pc, TokenIdIntLiteral); + child->data.pointer_type.bit_offset_start = bit_offset_start; + child->data.pointer_type.host_int_bytes = host_int_bytes; } expect_token(pc, TokenIdRParen); continue; } - if (eat_token_if(pc, TokenIdKeywordConst) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordConst) != 0) { child->data.pointer_type.is_const = true; continue; } - if (eat_token_if(pc, TokenIdKeywordVolatile) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordVolatile) != 0) { child->data.pointer_type.is_volatile = true; continue; } @@ -2756,8 +2668,8 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) { if (array != nullptr) { assert(array->type == NodeTypeArrayType); while (true) { - Token *allowzero_token = eat_token_if(pc, TokenIdKeywordAllowZero); - if (allowzero_token != nullptr) { + TokenIndex allowzero_token = eat_token_if(pc, TokenIdKeywordAllowZero); + if (allowzero_token != 0) { array->data.array_type.allow_zero_token = allowzero_token; continue; } @@ -2768,12 +2680,12 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) { continue; } - if (eat_token_if(pc, TokenIdKeywordConst) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordConst) != 0) { array->data.array_type.is_const = true; continue; } - if (eat_token_if(pc, TokenIdKeywordVolatile) != nullptr) { + if (eat_token_if(pc, TokenIdKeywordVolatile) != 0) { array->data.array_type.is_volatile = true; continue; } @@ -2793,14 +2705,14 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) { // / DOTASTERISK // / DOTQUESTIONMARK static AstNode *ast_parse_suffix_op(ParseContext *pc) { - Token *lbracket = eat_token_if(pc, TokenIdLBracket); - if (lbracket != nullptr) { + TokenIndex lbracket = eat_token_if(pc, TokenIdLBracket); + if (lbracket != 0) { AstNode *start = ast_expect(pc, ast_parse_expr); AstNode *end = nullptr; - if (eat_token_if(pc, TokenIdEllipsis2) != nullptr) { + if (eat_token_if(pc, TokenIdEllipsis2) != 0) { AstNode *sentinel = nullptr; end = ast_parse_expr(pc); - if (eat_token_if(pc, TokenIdColon) != nullptr) { + if (eat_token_if(pc, TokenIdColon) != 0) { sentinel = ast_parse_expr(pc); } expect_token(pc, TokenIdRBracket); @@ -2819,18 +2731,18 @@ static AstNode *ast_parse_suffix_op(ParseContext *pc) { return res; } - Token *dot_asterisk = eat_token_if(pc, TokenIdDotStar); - if (dot_asterisk != nullptr) + TokenIndex dot_asterisk = eat_token_if(pc, TokenIdDotStar); + if (dot_asterisk != 0) return ast_create_node(pc, NodeTypePtrDeref, dot_asterisk); - Token *dot = eat_token_if(pc, TokenIdDot); - if (dot != nullptr) { - if (eat_token_if(pc, TokenIdQuestion) != nullptr) + TokenIndex dot = eat_token_if(pc, TokenIdDot); + if (dot != 0) { + if (eat_token_if(pc, TokenIdQuestion) != 0) return ast_create_node(pc, NodeTypeUnwrapOptional, dot); - Token *ident = expect_token(pc, TokenIdSymbol); + TokenIndex ident = expect_token(pc, TokenIdIdentifier); AstNode *res = ast_create_node(pc, NodeTypeFieldAccessExpr, dot); - res->data.field_access_expr.field_name = token_buf(ident); + res->data.field_access_expr.field_name = token_buf(pc, ident); return res; } @@ -2839,8 +2751,8 @@ static AstNode *ast_parse_suffix_op(ParseContext *pc) { // FnCallArguments <- LPAREN ExprList RPAREN static AstNode *ast_parse_fn_call_arguments(ParseContext *pc) { - Token *paren = eat_token_if(pc, TokenIdLParen); - if (paren == nullptr) + TokenIndex paren = eat_token_if(pc, TokenIdLParen); + if (paren == 0) return nullptr; ZigList params = ast_parse_list(pc, TokenIdComma, ast_parse_expr); @@ -2854,14 +2766,14 @@ static AstNode *ast_parse_fn_call_arguments(ParseContext *pc) { // ArrayTypeStart <- LBRACKET Expr? RBRACKET static AstNode *ast_parse_array_type_start(ParseContext *pc) { - Token *lbracket = eat_token_if(pc, TokenIdLBracket); - if (lbracket == nullptr) + TokenIndex lbracket = eat_token_if(pc, TokenIdLBracket); + if (lbracket == 0) return nullptr; AstNode *size = ast_parse_expr(pc); AstNode *sentinel = nullptr; - Token *colon = eat_token_if(pc, TokenIdColon); - if (colon != nullptr) { + TokenIndex colon = eat_token_if(pc, TokenIdColon); + if (colon != 0) { sentinel = ast_expect(pc, ast_parse_expr); } expect_token(pc, TokenIdRBracket); @@ -2879,10 +2791,10 @@ static AstNode *ast_parse_array_type_start(ParseContext *pc) { static AstNode *ast_parse_ptr_type_start(ParseContext *pc) { AstNode *sentinel = nullptr; - Token *asterisk = eat_token_if(pc, TokenIdStar); - if (asterisk != nullptr) { - Token *colon = eat_token_if(pc, TokenIdColon); - if (colon != nullptr) { + TokenIndex asterisk = eat_token_if(pc, TokenIdStar); + if (asterisk != 0) { + TokenIndex colon = eat_token_if(pc, TokenIdColon); + if (colon != 0) { sentinel = ast_expect(pc, ast_parse_expr); } AstNode *res = ast_create_node(pc, NodeTypePointerType, asterisk); @@ -2891,10 +2803,10 @@ static AstNode *ast_parse_ptr_type_start(ParseContext *pc) { return res; } - Token *asterisk2 = eat_token_if(pc, TokenIdStarStar); - if (asterisk2 != nullptr) { - Token *colon = eat_token_if(pc, TokenIdColon); - if (colon != nullptr) { + TokenIndex asterisk2 = eat_token_if(pc, TokenIdStarStar); + if (asterisk2 != 0) { + TokenIndex colon = eat_token_if(pc, TokenIdColon); + if (colon != 0) { sentinel = ast_expect(pc, ast_parse_expr); } AstNode *res = ast_create_node(pc, NodeTypePointerType, asterisk2); @@ -2906,15 +2818,15 @@ static AstNode *ast_parse_ptr_type_start(ParseContext *pc) { return res; } - Token *lbracket = eat_token_if(pc, TokenIdLBracket); - if (lbracket != nullptr) { - Token *star = eat_token_if(pc, TokenIdStar); - if (star == nullptr) { + TokenIndex lbracket = eat_token_if(pc, TokenIdLBracket); + if (lbracket != 0) { + TokenIndex star = eat_token_if(pc, TokenIdStar); + if (star == 0) { put_back_token(pc); } else { - Token *c_tok = eat_token_if(pc, TokenIdSymbol); - if (c_tok != nullptr) { - if (!buf_eql_str(token_buf(c_tok), "c")) { + TokenIndex c_tok = eat_token_if(pc, TokenIdIdentifier); + if (c_tok != 0) { + if (!buf_eql_str(token_buf(pc, c_tok), "c")) { put_back_token(pc); // c symbol } else { expect_token(pc, TokenIdRBracket); @@ -2924,8 +2836,8 @@ static AstNode *ast_parse_ptr_type_start(ParseContext *pc) { } } - Token *colon = eat_token_if(pc, TokenIdColon); - if (colon != nullptr) { + TokenIndex colon = eat_token_if(pc, TokenIdColon); + if (colon != 0) { sentinel = ast_expect(pc, ast_parse_expr); } expect_token(pc, TokenIdRBracket); @@ -2951,9 +2863,7 @@ static AstNode *ast_parse_container_decl_auto(ParseContext *pc) { res->data.container_decl.fields = members.fields; res->data.container_decl.decls = members.decls; - if (buf_len(&members.doc_comments) != 0) { - res->data.container_decl.doc_comments = members.doc_comments; - } + res->data.container_decl.doc_comments = members.doc_comments; return res; } @@ -2963,8 +2873,8 @@ static AstNode *ast_parse_container_decl_auto(ParseContext *pc) { // / KEYWORD_union (LPAREN (KEYWORD_enum (LPAREN Expr RPAREN)? / Expr) RPAREN)? // / KEYWORD_opaque static AstNode *ast_parse_container_decl_type(ParseContext *pc) { - Token *first = eat_token_if(pc, TokenIdKeywordStruct); - if (first != nullptr) { + TokenIndex first = eat_token_if(pc, TokenIdKeywordStruct); + if (first != 0) { AstNode *res = ast_create_node(pc, NodeTypeContainerDecl, first); res->data.container_decl.init_arg_expr = nullptr; res->data.container_decl.kind = ContainerKindStruct; @@ -2972,7 +2882,7 @@ static AstNode *ast_parse_container_decl_type(ParseContext *pc) { } first = eat_token_if(pc, TokenIdKeywordOpaque); - if (first != nullptr) { + if (first != 0) { AstNode *res = ast_create_node(pc, NodeTypeContainerDecl, first); res->data.container_decl.init_arg_expr = nullptr; res->data.container_decl.kind = ContainerKindOpaque; @@ -2980,9 +2890,9 @@ static AstNode *ast_parse_container_decl_type(ParseContext *pc) { } first = eat_token_if(pc, TokenIdKeywordEnum); - if (first != nullptr) { + if (first != 0) { AstNode *init_arg_expr = nullptr; - if (eat_token_if(pc, TokenIdLParen) != nullptr) { + if (eat_token_if(pc, TokenIdLParen) != 0) { init_arg_expr = ast_expect(pc, ast_parse_expr); expect_token(pc, TokenIdRParen); } @@ -2993,13 +2903,13 @@ static AstNode *ast_parse_container_decl_type(ParseContext *pc) { } first = eat_token_if(pc, TokenIdKeywordUnion); - if (first != nullptr) { + if (first != 0) { AstNode *init_arg_expr = nullptr; bool auto_enum = false; - if (eat_token_if(pc, TokenIdLParen) != nullptr) { - if (eat_token_if(pc, TokenIdKeywordEnum) != nullptr) { + if (eat_token_if(pc, TokenIdLParen) != 0) { + if (eat_token_if(pc, TokenIdKeywordEnum) != 0) { auto_enum = true; - if (eat_token_if(pc, TokenIdLParen) != nullptr) { + if (eat_token_if(pc, TokenIdLParen) != 0) { init_arg_expr = ast_expect(pc, ast_parse_expr); expect_token(pc, TokenIdRParen); } @@ -3022,7 +2932,7 @@ static AstNode *ast_parse_container_decl_type(ParseContext *pc) { // ByteAlign <- KEYWORD_align LPAREN Expr RPAREN static AstNode *ast_parse_byte_align(ParseContext *pc) { - if (eat_token_if(pc, TokenIdKeywordAlign) == nullptr) + if (eat_token_if(pc, TokenIdKeywordAlign) == 0) return nullptr; expect_token(pc, TokenIdLParen); @@ -3103,7 +3013,7 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont case NodeTypeCharLiteral: // none break; - case NodeTypeSymbol: + case NodeTypeIdentifier: // none break; case NodeTypePrefixOpExpr: @@ -3264,3 +3174,414 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont break; } } + +Error source_string_literal_buf(const char *source, Buf *out, size_t *bad_index) { + size_t byte_offset = 0; + + assert(source[byte_offset] == '"'); + byte_offset += 1; + + buf_resize(out, 0); + + uint32_t codepoint; + + enum { + StateStart, + StateBackslash, + StateUnicodeLBrace, + StateUnicodeDigit, + } state = StateStart; + for (;;byte_offset += 1) { + switch (state) { + case StateStart: switch (source[byte_offset]) { + case '\\': + state = StateBackslash; + continue; + case '\n': + *bad_index = byte_offset; + return ErrorInvalidCharacter; + case '"': + return ErrorNone; + default: + buf_append_char(out, source[byte_offset]); + continue; + } + case StateBackslash: switch (source[byte_offset]) { + case 'n': + buf_append_char(out, '\n'); + state = StateStart; + continue; + case 'r': + buf_append_char(out, '\r'); + state = StateStart; + continue; + case '\\': + buf_append_char(out, '\\'); + state = StateStart; + continue; + case 't': + buf_append_char(out, '\t'); + state = StateStart; + continue; + case '\'': + buf_append_char(out, '\''); + state = StateStart; + continue; + case '"': + buf_append_char(out, '"'); + state = StateStart; + continue; + case 'x': { + byte_offset += 1; + uint8_t digit1; + if (source[byte_offset] >= '0' && source[byte_offset] <= '9') { + digit1 = source[byte_offset] - '0'; + } else if (source[byte_offset] >= 'a' && source[byte_offset] <= 'z') { + digit1 = source[byte_offset] - 'a' + 10; + } else if (source[byte_offset] >= 'A' && source[byte_offset] <= 'Z') { + digit1 = source[byte_offset] - 'A' + 10; + } else { + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + + byte_offset += 1; + uint8_t digit0; + if (source[byte_offset] >= '0' && source[byte_offset] <= '9') { + digit0 = source[byte_offset] - '0'; + } else if (source[byte_offset] >= 'a' && source[byte_offset] <= 'z') { + digit0 = source[byte_offset] - 'a' + 10; + } else if (source[byte_offset] >= 'A' && source[byte_offset] <= 'Z') { + digit0 = source[byte_offset] - 'A' + 10; + } else { + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + + buf_append_char(out, digit1 * 16 + digit0); + state = StateStart; + continue; + } + case 'u': + state = StateUnicodeLBrace; + continue; + default: + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + case StateUnicodeLBrace: switch (source[byte_offset]) { + case '{': + state = StateUnicodeDigit; + codepoint = 0; + continue; + default: + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + case StateUnicodeDigit: { + uint8_t digit; + if (source[byte_offset] >= '0' && source[byte_offset] <= '9') { + digit = source[byte_offset] - '0'; + } else if (source[byte_offset] >= 'a' && source[byte_offset] <= 'z') { + digit = source[byte_offset] - 'a' + 10; + } else if (source[byte_offset] >= 'A' && source[byte_offset] <= 'Z') { + digit = source[byte_offset] - 'A' + 10; + } else if (source[byte_offset] == '}') { + if (codepoint < 0x80) { + buf_append_char(out, codepoint); + } else if (codepoint < 0x800) { + buf_append_char(out, 0xc0 | (codepoint >> 6)); + buf_append_char(out, 0x80 | (codepoint & 0x3f)); + } else if (codepoint < 0x10000) { + buf_append_char(out, 0xe0 | (codepoint >> 12)); + buf_append_char(out, 0x80 | ((codepoint >> 6) & 0x3f)); + buf_append_char(out, 0x80 | (codepoint & 0x3f)); + } else if (codepoint < 0x110000) { + buf_append_char(out, 0xf0 | (codepoint >> 18)); + buf_append_char(out, 0x80 | ((codepoint >> 12) & 0x3f)); + buf_append_char(out, 0x80 | ((codepoint >> 6) & 0x3f)); + buf_append_char(out, 0x80 | (codepoint & 0x3f)); + } else { + *bad_index = byte_offset; + return ErrorUnicodePointTooLarge; + } + state = StateStart; + continue; + } else { + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + codepoint = codepoint * 16 + digit; + continue; + } + } + } + zig_unreachable(); +} + +static uint32_t utf8_code_point(const uint8_t *bytes) { + if (bytes[0] <= 0x7f) { + return bytes[0]; + } else if (bytes[0] >= 0xc0 && bytes[0] <= 0xdf) { + uint32_t result = bytes[0] & 0x1f; + result <<= 6; + result |= bytes[1] & 0x3f; + return result; + } else if (bytes[0] >= 0xe0 && bytes[0] <= 0xef) { + uint32_t result = bytes[0] & 0xf; + + result <<= 6; + result |= bytes[1] & 0x3f; + + result <<= 6; + result |= bytes[2] & 0x3f; + + return result; + } else if (bytes[0] >= 0xf0 && bytes[0] <= 0xf7) { + uint32_t result = bytes[0] & 0x7; + + result <<= 6; + result |= bytes[1] & 0x3f; + + result <<= 6; + result |= bytes[2] & 0x3f; + + result <<= 6; + result |= bytes[3] & 0x3f; + + return result; + } else { + zig_unreachable(); + } +} + +Error source_char_literal(const char *source, uint32_t *result, size_t *bad_index) { + if (source[0] != '\\') { + *result = utf8_code_point((const uint8_t *)source); + return ErrorNone; + } + + uint32_t byte_offset = 1; + uint32_t codepoint; + + enum State { + StateBackslash, + StateUnicodeLBrace, + StateUnicodeDigit, + } state = StateBackslash; + + for (;;byte_offset += 1) { + switch (state) { + case StateBackslash: switch (source[byte_offset]) { + case 'n': + *result = '\n'; + return ErrorNone; + case 'r': + *result = '\r'; + return ErrorNone; + case '\\': + *result = '\\'; + return ErrorNone; + case 't': + *result = '\t'; + return ErrorNone; + case '\'': + *result = '\''; + return ErrorNone; + case '"': + *result = '"'; + return ErrorNone; + case 'x': { + byte_offset += 1; + uint8_t digit1; + if (source[byte_offset] >= '0' && source[byte_offset] <= '9') { + digit1 = source[byte_offset] - '0'; + } else if (source[byte_offset] >= 'a' && source[byte_offset] <= 'z') { + digit1 = source[byte_offset] - 'a' + 10; + } else if (source[byte_offset] >= 'A' && source[byte_offset] <= 'Z') { + digit1 = source[byte_offset] - 'A' + 10; + } else { + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + + byte_offset += 1; + uint8_t digit0; + if (source[byte_offset] >= '0' && source[byte_offset] <= '9') { + digit0 = source[byte_offset] - '0'; + } else if (source[byte_offset] >= 'a' && source[byte_offset] <= 'z') { + digit0 = source[byte_offset] - 'a' + 10; + } else if (source[byte_offset] >= 'A' && source[byte_offset] <= 'Z') { + digit0 = source[byte_offset] - 'A' + 10; + } else { + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + + *result = digit1 * 16 + digit0; + return ErrorNone; + } + case 'u': + state = StateUnicodeLBrace; + continue; + default: + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + case StateUnicodeLBrace: switch (source[byte_offset]) { + case '{': + state = StateUnicodeDigit; + codepoint = 0; + continue; + default: + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + case StateUnicodeDigit: { + uint8_t digit; + if (source[byte_offset] >= '0' && source[byte_offset] <= '9') { + digit = source[byte_offset] - '0'; + } else if (source[byte_offset] >= 'a' && source[byte_offset] <= 'z') { + digit = source[byte_offset] - 'a' + 10; + } else if (source[byte_offset] >= 'A' && source[byte_offset] <= 'Z') { + digit = source[byte_offset] - 'A' + 10; + } else if (source[byte_offset] == '}') { + if (codepoint < 0x110000) { + *result = codepoint; + return ErrorNone; + } else { + *bad_index = byte_offset; + return ErrorUnicodePointTooLarge; + } + } else { + *bad_index = byte_offset; + return ErrorInvalidCharacter; + } + codepoint = codepoint * 16 + digit; + continue; + } + } + } +} + + +Buf *token_string_literal_buf(RootStruct *root_struct, TokenIndex token) { + Error err; + assert(root_struct->token_ids[token] == TokenIdStringLiteral); + const char *source = buf_ptr(root_struct->source_code); + size_t byte_offset = root_struct->token_locs[token].offset; + size_t bad_index; + Buf *str = buf_alloc(); + if ((err = source_string_literal_buf(source + byte_offset, str, &bad_index))) { + zig_panic("TODO handle string literal parse error"); + } + return str; +} + +Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) { + Error err; + const char *source = buf_ptr(root_struct->source_code); + size_t byte_offset = root_struct->token_locs[token].offset; + if (root_struct->token_ids[token] == TokenIdBuiltin) { + byte_offset += 1; + } else { + assert(root_struct->token_ids[token] == TokenIdIdentifier); + } + assert(source[byte_offset] != '.'); // wrong token index + + if (source[byte_offset] == '@') { + size_t bad_index; + Buf *str = buf_alloc(); + if ((err = source_string_literal_buf(source + byte_offset + 1, str, &bad_index))) { + zig_panic("TODO handle string literal parse error"); + } + return str; + } else { + size_t start = byte_offset; + for (;; byte_offset += 1) { + if (source[byte_offset] == 0) break; + if ((source[byte_offset] >= 'a' && source[byte_offset] <= 'z') || + (source[byte_offset] >= 'A' && source[byte_offset] <= 'Z') || + (source[byte_offset] >= '0' && source[byte_offset] <= '9') || + source[byte_offset] == '_') + { + continue; + } + break; + } + return buf_create_from_mem(source + start, byte_offset - start); + } +} + +Buf *node_identifier_buf(AstNode *node) { + assert(node->type == NodeTypeIdentifier); + RootStruct *root_struct = node->owner->data.structure.root_struct; + return token_identifier_buf(root_struct, node->main_token); +} + +Buf *node_string_literal_buf(AstNode *node) { + assert(node->type == NodeTypeStringLiteral); + RootStruct *root_struct = node->owner->data.structure.root_struct; + return token_string_literal_buf(root_struct, node->main_token); +} + +void token_number_literal_bigint(RootStruct *root_struct, BigInt *result, TokenIndex token) { + const char *source = buf_ptr(root_struct->source_code); + uint32_t byte_offset = root_struct->token_locs[token].offset; + + bigint_init_unsigned(result, 0); + BigInt radix_bi; + + if (source[byte_offset] == '0') { + byte_offset += 1; + switch (source[byte_offset]) { + case 'b': + byte_offset += 1; + bigint_init_unsigned(&radix_bi, 2); + break; + case 'o': + byte_offset += 1; + bigint_init_unsigned(&radix_bi, 8); + break; + case 'x': + byte_offset += 1; + bigint_init_unsigned(&radix_bi, 16); + break; + default: + bigint_init_unsigned(&radix_bi, 10); + break; + } + } else { + bigint_init_unsigned(&radix_bi, 10); + } + + BigInt digit_value_bi = {}; + BigInt multiplied = {}; + + for (;source[byte_offset] != 0; byte_offset += 1) { + uint8_t digit; + if (source[byte_offset] >= '0' && source[byte_offset] <= '9') { + digit = source[byte_offset] - '0'; + } else if (source[byte_offset] >= 'a' && source[byte_offset] <= 'z') { + digit = source[byte_offset] - 'a' + 10; + } else if (source[byte_offset] >= 'A' && source[byte_offset] <= 'Z') { + digit = source[byte_offset] - 'A' + 10; + } else if (source[byte_offset] == '_') { + continue; + } else { + break; + } + bigint_deinit(&digit_value_bi); + bigint_init_unsigned(&digit_value_bi, digit); + + bigint_deinit(&multiplied); + bigint_mul(&multiplied, result, &radix_bi); + + bigint_add(result, &multiplied, &digit_value_bi); + } + + bigint_deinit(&digit_value_bi); + bigint_deinit(&multiplied); + bigint_deinit(&radix_bi); +} + -- cgit v1.2.3 From f5d4fe3e17533f83404c16fbceff0dc7bb12cb18 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 28 May 2021 15:22:03 -0700 Subject: stage1: memoize strings in the AST Currently, stage1 runs astgen for every comptime function call, resulting in identifier strings being allocated multiple times, wasting memory. As a workaround until the code is adjusted to make astgen run only once per source node, we memoize the result into the AST. * Rename `ir_gen_*` to `astgen_*` - Oops, meant to do this in a separate commit. My bad. * tokenizer: avoid using designated initializer syntax. MSVC does not support it. --- src/stage1/all_types.hpp | 14 + src/stage1/astgen.cpp | 887 ++++++++++++++++++++++++----------------------- src/stage1/parser.cpp | 43 +-- src/stage1/parser.hpp | 2 - src/stage1/tokenizer.cpp | 10 +- 5 files changed, 489 insertions(+), 467 deletions(-) (limited to 'src/stage1/parser.cpp') diff --git a/src/stage1/all_types.hpp b/src/stage1/all_types.hpp index 3af41c5788..27a609a1e4 100644 --- a/src/stage1/all_types.hpp +++ b/src/stage1/all_types.hpp @@ -1123,6 +1123,14 @@ struct AstNodeContainerInitExpr { ContainerInitKind kind; }; +struct AstNodeIdentifier { + Buf *name; +}; + +struct AstNodeEnumLiteral { + Buf *name; +}; + struct AstNodeBoolLiteral { bool value; }; @@ -1204,6 +1212,12 @@ struct AstNode { AstNodeAwaitExpr await_expr; AstNodeSuspend suspend; AstNodeAnyFrameType anyframe_type; + + // These are part of an astgen workaround to use less memory by + // memoizing into the AST. Once astgen is modified to only run once + // per corresponding source, this workaround can be removed. + AstNodeIdentifier identifier; + AstNodeEnumLiteral enum_literal; } data; // This is a function for use in the debugger to print diff --git a/src/stage1/astgen.cpp b/src/stage1/astgen.cpp index d7ec91f466..6f38eca936 100644 --- a/src/stage1/astgen.cpp +++ b/src/stage1/astgen.cpp @@ -21,15 +21,15 @@ struct Stage1AstGen { bool in_c_import_scope; }; -static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope); -static IrInstSrc *ir_gen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval, +static IrInstSrc *astgen_node(Stage1AstGen *ag, AstNode *node, Scope *scope); +static IrInstSrc *astgen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval, ResultLoc *result_loc); static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc); static IrInstSrc *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc); -static IrInstSrc *ir_gen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, +static IrInstSrc *astgen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, LVal lval, ResultLoc *parent_result_loc); static ResultLocCast *ir_build_cast_result_loc(Stage1AstGen *ag, IrInstSrc *dest_type, @@ -2890,7 +2890,7 @@ static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) { return instruction; } -static bool ir_gen_defers_for_block(Stage1AstGen *ag, Scope *inner_scope, Scope *outer_scope, bool *is_noreturn, IrInstSrc *err_value) { +static bool astgen_defers_for_block(Stage1AstGen *ag, Scope *inner_scope, Scope *outer_scope, bool *is_noreturn, IrInstSrc *err_value) { Scope *scope = inner_scope; if (is_noreturn != nullptr) *is_noreturn = false; while (scope != outer_scope) { @@ -2941,7 +2941,7 @@ static bool ir_gen_defers_for_block(Stage1AstGen *ag, Scope *inner_scope, Scope defer_expr_scope = err_var->child_scope; } - IrInstSrc *defer_expr_value = ir_gen_node(ag, defer_expr_node, defer_expr_scope); + IrInstSrc *defer_expr_value = astgen_node(ag, defer_expr_node, defer_expr_scope); if (defer_expr_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -3011,7 +3011,7 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { return nullptr; } -static IrInstSrc *ir_gen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { +static IrInstSrc *astgen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeReturnExpr); ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope); @@ -3038,7 +3038,7 @@ static IrInstSrc *ir_gen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, L // Temporarily set this so that if we return a type it gets the name of the function ZigFn *prev_name_fn = ag->exec->name_fn; ag->exec->name_fn = ag->fn; - return_value = ir_gen_node_extra(ag, expr_node, scope, LValNone, &result_loc_ret->base); + return_value = astgen_node_extra(ag, expr_node, scope, LValNone, &result_loc_ret->base); ag->exec->name_fn = prev_name_fn; if (return_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -3054,7 +3054,7 @@ static IrInstSrc *ir_gen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, L bool have_err_defers = defer_counts[ReturnKindError] > 0; if (!have_err_defers && !ag->codegen->have_err_ret_tracing) { // only generate unconditional defers - if (!ir_gen_defers_for_block(ag, scope, outer_scope, nullptr, nullptr)) + if (!astgen_defers_for_block(ag, scope, outer_scope, nullptr, nullptr)) return ag->codegen->invalid_inst_src; IrInstSrc *result = ir_build_return_src(ag, scope, node, nullptr); result_loc_ret->base.source_instruction = result; @@ -3078,7 +3078,7 @@ static IrInstSrc *ir_gen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, L Stage1ZirBasicBlock *ret_stmt_block = ir_create_basic_block(ag, scope, "RetStmt"); ir_set_cursor_at_end_and_append_block(ag, err_block); - if (!ir_gen_defers_for_block(ag, scope, outer_scope, nullptr, return_value)) + if (!astgen_defers_for_block(ag, scope, outer_scope, nullptr, return_value)) return ag->codegen->invalid_inst_src; if (ag->codegen->have_err_ret_tracing && !should_inline) { ir_build_save_err_ret_addr_src(ag, scope, node); @@ -3086,7 +3086,7 @@ static IrInstSrc *ir_gen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, L ir_build_br(ag, scope, node, ret_stmt_block, is_comptime); ir_set_cursor_at_end_and_append_block(ag, ok_block); - if (!ir_gen_defers_for_block(ag, scope, outer_scope, nullptr, nullptr)) + if (!astgen_defers_for_block(ag, scope, outer_scope, nullptr, nullptr)) return ag->codegen->invalid_inst_src; ir_build_br(ag, scope, node, ret_stmt_block, is_comptime); @@ -3098,7 +3098,7 @@ static IrInstSrc *ir_gen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, L case ReturnKindError: { assert(expr_node); - IrInstSrc *err_union_ptr = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr); + IrInstSrc *err_union_ptr = astgen_node_extra(ag, expr_node, scope, LValPtr, nullptr); if (err_union_ptr == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; IrInstSrc *is_err_val = ir_build_test_err_src(ag, scope, node, err_union_ptr, true, false); @@ -3126,7 +3126,7 @@ static IrInstSrc *ir_gen_return(Stage1AstGen *ag, Scope *scope, AstNode *node, L ir_build_end_expr(ag, scope, node, err_val, &result_loc_ret->base); bool is_noreturn = false; - if (!ir_gen_defers_for_block(ag, scope, outer_scope, &is_noreturn, err_val)) { + if (!astgen_defers_for_block(ag, scope, outer_scope, &is_noreturn, err_val)) { return ag->codegen->invalid_inst_src; } if (!is_noreturn) { @@ -3260,7 +3260,7 @@ static bool is_duplicate_label(CodeGen *g, Scope *scope, AstNode *node, Buf *nam return false; } -static IrInstSrc *ir_gen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *block_node, LVal lval, +static IrInstSrc *astgen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *block_node, LVal lval, ResultLoc *result_loc) { assert(block_node->type == NodeTypeBlock); @@ -3313,7 +3313,7 @@ static IrInstSrc *ir_gen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *b for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) { AstNode *statement_node = block_node->data.block.statements.at(i); - IrInstSrc *statement_value = ir_gen_node(ag, statement_node, child_scope); + IrInstSrc *statement_value = astgen_node(ag, statement_node, child_scope); if (statement_value == ag->codegen->invalid_inst_src) { // keep generating all the elements of the block in case of error, // we want to collect other compile errors @@ -3381,7 +3381,7 @@ static IrInstSrc *ir_gen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *b bool is_return_from_fn = block_node == ag->main_block_node; if (!is_return_from_fn) { - if (!ir_gen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr)) + if (!astgen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr)) return ag->codegen->invalid_inst_src; } @@ -3407,19 +3407,19 @@ static IrInstSrc *ir_gen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *b result_loc_ret->base.id = ResultLocIdReturn; ir_build_reset_result(ag, parent_scope, block_node, &result_loc_ret->base); ir_mark_gen(ir_build_end_expr(ag, parent_scope, block_node, result, &result_loc_ret->base)); - if (!ir_gen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr)) + if (!astgen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr)) return ag->codegen->invalid_inst_src; return ir_mark_gen(ir_build_return_src(ag, child_scope, result->base.source_node, result)); } -static IrInstSrc *ir_gen_bin_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) { +static IrInstSrc *astgen_bin_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) { Scope *inner_scope = scope; if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) { inner_scope = create_comptime_scope(ag->codegen, node, scope); } - IrInstSrc *op1 = ir_gen_node(ag, node->data.bin_op_expr.op1, inner_scope); - IrInstSrc *op2 = ir_gen_node(ag, node->data.bin_op_expr.op2, inner_scope); + IrInstSrc *op1 = astgen_node(ag, node->data.bin_op_expr.op1, inner_scope); + IrInstSrc *op2 = astgen_node(ag, node->data.bin_op_expr.op2, inner_scope); if (op1 == ag->codegen->invalid_inst_src || op2 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -3427,9 +3427,9 @@ static IrInstSrc *ir_gen_bin_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node return ir_build_bin_op(ag, scope, node, op_id, op1, op2, true); } -static IrInstSrc *ir_gen_merge_err_sets(Stage1AstGen *ag, Scope *scope, AstNode *node) { - IrInstSrc *op1 = ir_gen_node(ag, node->data.bin_op_expr.op1, scope); - IrInstSrc *op2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope); +static IrInstSrc *astgen_merge_err_sets(Stage1AstGen *ag, Scope *scope, AstNode *node) { + IrInstSrc *op1 = astgen_node(ag, node->data.bin_op_expr.op1, scope); + IrInstSrc *op2 = astgen_node(ag, node->data.bin_op_expr.op2, scope); if (op1 == ag->codegen->invalid_inst_src || op2 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -3441,8 +3441,8 @@ static IrInstSrc *ir_gen_merge_err_sets(Stage1AstGen *ag, Scope *scope, AstNode return ir_build_merge_err_sets(ag, scope, node, op1, op2, type_name); } -static IrInstSrc *ir_gen_assign(Stage1AstGen *ag, Scope *scope, AstNode *node) { - IrInstSrc *lvalue = ir_gen_node_extra(ag, node->data.bin_op_expr.op1, scope, LValAssign, nullptr); +static IrInstSrc *astgen_assign(Stage1AstGen *ag, Scope *scope, AstNode *node) { + IrInstSrc *lvalue = astgen_node_extra(ag, node->data.bin_op_expr.op1, scope, LValAssign, nullptr); if (lvalue == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -3452,7 +3452,7 @@ static IrInstSrc *ir_gen_assign(Stage1AstGen *ag, Scope *scope, AstNode *node) { ir_ref_instruction(lvalue, ag->current_basic_block); ir_build_reset_result(ag, scope, node, &result_loc_inst->base); - IrInstSrc *rvalue = ir_gen_node_extra(ag, node->data.bin_op_expr.op2, scope, LValNone, + IrInstSrc *rvalue = astgen_node_extra(ag, node->data.bin_op_expr.op2, scope, LValNone, &result_loc_inst->base); if (rvalue == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -3460,12 +3460,12 @@ static IrInstSrc *ir_gen_assign(Stage1AstGen *ag, Scope *scope, AstNode *node) { return ir_build_const_void(ag, scope, node); } -static IrInstSrc *ir_gen_assign_op(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) { - IrInstSrc *lvalue = ir_gen_node_extra(ag, node->data.bin_op_expr.op1, scope, LValAssign, nullptr); +static IrInstSrc *astgen_assign_op(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) { + IrInstSrc *lvalue = astgen_node_extra(ag, node->data.bin_op_expr.op1, scope, LValAssign, nullptr); if (lvalue == ag->codegen->invalid_inst_src) return lvalue; IrInstSrc *op1 = ir_build_load_ptr(ag, scope, node->data.bin_op_expr.op1, lvalue); - IrInstSrc *op2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope); + IrInstSrc *op2 = astgen_node(ag, node->data.bin_op_expr.op2, scope); if (op2 == ag->codegen->invalid_inst_src) return op2; IrInstSrc *result = ir_build_bin_op(ag, scope, node, op_id, op1, op2, true); @@ -3473,10 +3473,10 @@ static IrInstSrc *ir_gen_assign_op(Stage1AstGen *ag, Scope *scope, AstNode *node return ir_build_const_void(ag, scope, node); } -static IrInstSrc *ir_gen_bool_or(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_bool_or(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeBinOpExpr); - IrInstSrc *val1 = ir_gen_node(ag, node->data.bin_op_expr.op1, scope); + IrInstSrc *val1 = astgen_node(ag, node->data.bin_op_expr.op1, scope); if (val1 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; Stage1ZirBasicBlock *post_val1_block = ag->current_basic_block; @@ -3496,7 +3496,7 @@ static IrInstSrc *ir_gen_bool_or(Stage1AstGen *ag, Scope *scope, AstNode *node) ir_build_cond_br(ag, scope, node, val1, true_block, false_block, is_comptime); ir_set_cursor_at_end_and_append_block(ag, false_block); - IrInstSrc *val2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope); + IrInstSrc *val2 = astgen_node(ag, node->data.bin_op_expr.op2, scope); if (val2 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; Stage1ZirBasicBlock *post_val2_block = ag->current_basic_block; @@ -3515,10 +3515,10 @@ static IrInstSrc *ir_gen_bool_or(Stage1AstGen *ag, Scope *scope, AstNode *node) return ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, nullptr); } -static IrInstSrc *ir_gen_bool_and(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_bool_and(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeBinOpExpr); - IrInstSrc *val1 = ir_gen_node(ag, node->data.bin_op_expr.op1, scope); + IrInstSrc *val1 = astgen_node(ag, node->data.bin_op_expr.op1, scope); if (val1 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; Stage1ZirBasicBlock *post_val1_block = ag->current_basic_block; @@ -3538,7 +3538,7 @@ static IrInstSrc *ir_gen_bool_and(Stage1AstGen *ag, Scope *scope, AstNode *node) ir_build_cond_br(ag, scope, node, val1, true_block, false_block, is_comptime); ir_set_cursor_at_end_and_append_block(ag, true_block); - IrInstSrc *val2 = ir_gen_node(ag, node->data.bin_op_expr.op2, scope); + IrInstSrc *val2 = astgen_node(ag, node->data.bin_op_expr.op2, scope); if (val2 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; Stage1ZirBasicBlock *post_val2_block = ag->current_basic_block; @@ -3591,7 +3591,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(Stage1AstGen *ag, IrIns return peer_parent; } -static IrInstSrc *ir_gen_orelse(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_orelse(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeBinOpExpr); @@ -3599,7 +3599,7 @@ static IrInstSrc *ir_gen_orelse(Stage1AstGen *ag, Scope *parent_scope, AstNode * AstNode *op1_node = node->data.bin_op_expr.op1; AstNode *op2_node = node->data.bin_op_expr.op2; - IrInstSrc *maybe_ptr = ir_gen_node_extra(ag, op1_node, parent_scope, LValPtr, nullptr); + IrInstSrc *maybe_ptr = astgen_node_extra(ag, op1_node, parent_scope, LValPtr, nullptr); if (maybe_ptr == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -3622,7 +3622,7 @@ static IrInstSrc *ir_gen_orelse(Stage1AstGen *ag, Scope *parent_scope, AstNode * result_loc, is_comptime); ir_set_cursor_at_end_and_append_block(ag, null_block); - IrInstSrc *null_result = ir_gen_node_extra(ag, op2_node, parent_scope, LValNone, + IrInstSrc *null_result = astgen_node_extra(ag, op2_node, parent_scope, LValNone, &peer_parent->peers.at(0)->base); if (null_result == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -3648,24 +3648,24 @@ static IrInstSrc *ir_gen_orelse(Stage1AstGen *ag, Scope *parent_scope, AstNode * return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc); } -static IrInstSrc *ir_gen_error_union(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { +static IrInstSrc *astgen_error_union(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { assert(node->type == NodeTypeBinOpExpr); AstNode *op1_node = node->data.bin_op_expr.op1; AstNode *op2_node = node->data.bin_op_expr.op2; - IrInstSrc *err_set = ir_gen_node(ag, op1_node, parent_scope); + IrInstSrc *err_set = astgen_node(ag, op1_node, parent_scope); if (err_set == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; - IrInstSrc *payload = ir_gen_node(ag, op2_node, parent_scope); + IrInstSrc *payload = astgen_node(ag, op2_node, parent_scope); if (payload == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; return ir_build_error_union(ag, parent_scope, node, err_set, payload); } -static IrInstSrc *ir_gen_bin_op(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { +static IrInstSrc *astgen_bin_op(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeBinOpExpr); BinOpType bin_op_type = node->data.bin_op_expr.bin_op; @@ -3673,90 +3673,90 @@ static IrInstSrc *ir_gen_bin_op(Stage1AstGen *ag, Scope *scope, AstNode *node, L case BinOpTypeInvalid: zig_unreachable(); case BinOpTypeAssign: - return ir_lval_wrap(ag, scope, ir_gen_assign(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign(ag, scope, node), lval, result_loc); case BinOpTypeAssignTimes: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpMult), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpMult), lval, result_loc); case BinOpTypeAssignTimesWrap: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpMultWrap), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpMultWrap), lval, result_loc); case BinOpTypeAssignDiv: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpDivUnspecified), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpDivUnspecified), lval, result_loc); case BinOpTypeAssignMod: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpRemUnspecified), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpRemUnspecified), lval, result_loc); case BinOpTypeAssignPlus: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpAdd), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpAdd), lval, result_loc); case BinOpTypeAssignPlusWrap: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpAddWrap), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpAddWrap), lval, result_loc); case BinOpTypeAssignMinus: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpSub), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpSub), lval, result_loc); case BinOpTypeAssignMinusWrap: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpSubWrap), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpSubWrap), lval, result_loc); case BinOpTypeAssignBitShiftLeft: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBitShiftLeftLossy), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpBitShiftLeftLossy), lval, result_loc); case BinOpTypeAssignBitShiftRight: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBitShiftRightLossy), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpBitShiftRightLossy), lval, result_loc); case BinOpTypeAssignBitAnd: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBinAnd), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpBinAnd), lval, result_loc); case BinOpTypeAssignBitXor: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBinXor), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpBinXor), lval, result_loc); case BinOpTypeAssignBitOr: - return ir_lval_wrap(ag, scope, ir_gen_assign_op(ag, scope, node, IrBinOpBinOr), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_assign_op(ag, scope, node, IrBinOpBinOr), lval, result_loc); case BinOpTypeBoolOr: - return ir_lval_wrap(ag, scope, ir_gen_bool_or(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bool_or(ag, scope, node), lval, result_loc); case BinOpTypeBoolAnd: - return ir_lval_wrap(ag, scope, ir_gen_bool_and(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bool_and(ag, scope, node), lval, result_loc); case BinOpTypeCmpEq: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpEq), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpCmpEq), lval, result_loc); case BinOpTypeCmpNotEq: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpNotEq), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpCmpNotEq), lval, result_loc); case BinOpTypeCmpLessThan: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpLessThan), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpCmpLessThan), lval, result_loc); case BinOpTypeCmpGreaterThan: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpGreaterThan), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpCmpGreaterThan), lval, result_loc); case BinOpTypeCmpLessOrEq: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpLessOrEq), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpCmpLessOrEq), lval, result_loc); case BinOpTypeCmpGreaterOrEq: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpCmpGreaterOrEq), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpCmpGreaterOrEq), lval, result_loc); case BinOpTypeBinOr: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBinOr), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpBinOr), lval, result_loc); case BinOpTypeBinXor: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBinXor), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpBinXor), lval, result_loc); case BinOpTypeBinAnd: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBinAnd), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpBinAnd), lval, result_loc); case BinOpTypeBitShiftLeft: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBitShiftLeftLossy), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpBitShiftLeftLossy), lval, result_loc); case BinOpTypeBitShiftRight: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpBitShiftRightLossy), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpBitShiftRightLossy), lval, result_loc); case BinOpTypeAdd: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpAdd), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpAdd), lval, result_loc); case BinOpTypeAddWrap: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpAddWrap), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpAddWrap), lval, result_loc); case BinOpTypeSub: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpSub), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpSub), lval, result_loc); case BinOpTypeSubWrap: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpSubWrap), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpSubWrap), lval, result_loc); case BinOpTypeMult: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpMult), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpMult), lval, result_loc); case BinOpTypeMultWrap: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpMultWrap), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpMultWrap), lval, result_loc); case BinOpTypeDiv: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpDivUnspecified), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpDivUnspecified), lval, result_loc); case BinOpTypeMod: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpRemUnspecified), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpRemUnspecified), lval, result_loc); case BinOpTypeArrayCat: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpArrayCat), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpArrayCat), lval, result_loc); case BinOpTypeArrayMult: - return ir_lval_wrap(ag, scope, ir_gen_bin_op_id(ag, scope, node, IrBinOpArrayMult), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bin_op_id(ag, scope, node, IrBinOpArrayMult), lval, result_loc); case BinOpTypeMergeErrorSets: - return ir_lval_wrap(ag, scope, ir_gen_merge_err_sets(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_merge_err_sets(ag, scope, node), lval, result_loc); case BinOpTypeUnwrapOptional: - return ir_gen_orelse(ag, scope, node, lval, result_loc); + return astgen_orelse(ag, scope, node, lval, result_loc); case BinOpTypeErrorUnion: - return ir_lval_wrap(ag, scope, ir_gen_error_union(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_error_union(ag, scope, node), lval, result_loc); } zig_unreachable(); } -static IrInstSrc *ir_gen_int_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_int_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeIntLiteral); RootStruct *root_struct = node->owner->data.structure.root_struct; @@ -3765,7 +3765,7 @@ static IrInstSrc *ir_gen_int_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) return ir_build_const_bigint(ag, scope, node, bigint); } -static IrInstSrc *ir_gen_float_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_float_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) { Error err; assert(node->type == NodeTypeFloatLiteral); @@ -3782,7 +3782,7 @@ static IrInstSrc *ir_gen_float_lit(Stage1AstGen *ag, Scope *scope, AstNode *node return ir_build_const_bigfloat(ag, scope, node, bigfloat); } -static IrInstSrc *ir_gen_char_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_char_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) { Error err; assert(node->type == NodeTypeCharLiteral); @@ -3802,13 +3802,15 @@ static IrInstSrc *ir_gen_char_lit(Stage1AstGen *ag, Scope *scope, AstNode *node) return ir_build_const_uint(ag, scope, node, codepoint); } -static IrInstSrc *ir_gen_null_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_null_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeNullLiteral); return ir_build_const_null(ag, scope, node); } -static IrInstSrc *ir_gen_symbol(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { +static IrInstSrc *astgen_identifier(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, + ResultLoc *result_loc) +{ Error err; assert(node->type == NodeTypeIdentifier); @@ -3877,13 +3879,13 @@ static IrInstSrc *ir_gen_symbol(Stage1AstGen *ag, Scope *scope, AstNode *node, L return ir_build_undeclared_identifier(ag, scope, node, variable_name); } -static IrInstSrc *ir_gen_array_access(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_array_access(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeArrayAccessExpr); AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr; - IrInstSrc *array_ref_instruction = ir_gen_node_extra(ag, array_ref_node, scope, LValPtr, nullptr); + IrInstSrc *array_ref_instruction = astgen_node_extra(ag, array_ref_node, scope, LValPtr, nullptr); if (array_ref_instruction == ag->codegen->invalid_inst_src) return array_ref_instruction; @@ -3894,7 +3896,7 @@ static IrInstSrc *ir_gen_array_access(Stage1AstGen *ag, Scope *scope, AstNode *n ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, usize_type_inst, no_result_loc()); AstNode *subscript_node = node->data.array_access_expr.subscript; - IrInstSrc *subscript_value = ir_gen_node_extra(ag, subscript_node, scope, LValNone, &result_loc_cast->base); + IrInstSrc *subscript_value = astgen_node_extra(ag, subscript_node, scope, LValNone, &result_loc_cast->base); if (subscript_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -3909,20 +3911,20 @@ static IrInstSrc *ir_gen_array_access(Stage1AstGen *ag, Scope *scope, AstNode *n return ir_expr_wrap(ag, scope, load_ptr, result_loc); } -static IrInstSrc *ir_gen_field_access(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_field_access(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeFieldAccessExpr); AstNode *container_ref_node = node->data.field_access_expr.struct_expr; Buf *field_name = node->data.field_access_expr.field_name; - IrInstSrc *container_ref_instruction = ir_gen_node_extra(ag, container_ref_node, scope, LValPtr, nullptr); + IrInstSrc *container_ref_instruction = astgen_node_extra(ag, container_ref_node, scope, LValPtr, nullptr); if (container_ref_instruction == ag->codegen->invalid_inst_src) return container_ref_instruction; return ir_build_field_ptr(ag, scope, node, container_ref_instruction, field_name, false); } -static IrInstSrc *ir_gen_overflow_op(Stage1AstGen *ag, Scope *scope, AstNode *node, IrOverflowOp op) { +static IrInstSrc *astgen_overflow_op(Stage1AstGen *ag, Scope *scope, AstNode *node, IrOverflowOp op) { assert(node->type == NodeTypeFnCallExpr); AstNode *type_node = node->data.fn_call_expr.params.at(0); @@ -3931,26 +3933,26 @@ static IrInstSrc *ir_gen_overflow_op(Stage1AstGen *ag, Scope *scope, AstNode *no AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3); - IrInstSrc *type_value = ir_gen_node(ag, type_node, scope); + IrInstSrc *type_value = astgen_node(ag, type_node, scope); if (type_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; - IrInstSrc *op1 = ir_gen_node(ag, op1_node, scope); + IrInstSrc *op1 = astgen_node(ag, op1_node, scope); if (op1 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; - IrInstSrc *op2 = ir_gen_node(ag, op2_node, scope); + IrInstSrc *op2 = astgen_node(ag, op2_node, scope); if (op2 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; - IrInstSrc *result_ptr = ir_gen_node(ag, result_ptr_node, scope); + IrInstSrc *result_ptr = astgen_node(ag, result_ptr_node, scope); if (result_ptr == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; return ir_build_overflow_op_src(ag, scope, node, op, type_value, op1, op2, result_ptr); } -static IrInstSrc *ir_gen_mul_add(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_mul_add(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeFnCallExpr); AstNode *type_node = node->data.fn_call_expr.params.at(0); @@ -3958,26 +3960,26 @@ static IrInstSrc *ir_gen_mul_add(Stage1AstGen *ag, Scope *scope, AstNode *node) AstNode *op2_node = node->data.fn_call_expr.params.at(2); AstNode *op3_node = node->data.fn_call_expr.params.at(3); - IrInstSrc *type_value = ir_gen_node(ag, type_node, scope); + IrInstSrc *type_value = astgen_node(ag, type_node, scope); if (type_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; - IrInstSrc *op1 = ir_gen_node(ag, op1_node, scope); + IrInstSrc *op1 = astgen_node(ag, op1_node, scope); if (op1 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; - IrInstSrc *op2 = ir_gen_node(ag, op2_node, scope); + IrInstSrc *op2 = astgen_node(ag, op2_node, scope); if (op2 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; - IrInstSrc *op3 = ir_gen_node(ag, op3_node, scope); + IrInstSrc *op3 = astgen_node(ag, op3_node, scope); if (op3 == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; return ir_build_mul_add_src(ag, scope, node, type_value, op1, op2, op3); } -static IrInstSrc *ir_gen_this(Stage1AstGen *ag, Scope *orig_scope, AstNode *node) { +static IrInstSrc *astgen_this(Stage1AstGen *ag, Scope *orig_scope, AstNode *node) { for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) { if (it_scope->id == ScopeIdDecls) { ScopeDecls *decls_scope = (ScopeDecls *)it_scope; @@ -3992,7 +3994,7 @@ static IrInstSrc *ir_gen_this(Stage1AstGen *ag, Scope *orig_scope, AstNode *node zig_unreachable(); } -static IrInstSrc *ir_gen_async_call(Stage1AstGen *ag, Scope *scope, AstNode *await_node, AstNode *call_node, +static IrInstSrc *astgen_async_call(Stage1AstGen *ag, Scope *scope, AstNode *await_node, AstNode *call_node, LVal lval, ResultLoc *result_loc) { if (call_node->data.fn_call_expr.params.length != 4) { @@ -4003,17 +4005,17 @@ static IrInstSrc *ir_gen_async_call(Stage1AstGen *ag, Scope *scope, AstNode *awa } AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0); - IrInstSrc *bytes = ir_gen_node(ag, bytes_node, scope); + IrInstSrc *bytes = astgen_node(ag, bytes_node, scope); if (bytes == ag->codegen->invalid_inst_src) return bytes; AstNode *ret_ptr_node = call_node->data.fn_call_expr.params.at(1); - IrInstSrc *ret_ptr = ir_gen_node(ag, ret_ptr_node, scope); + IrInstSrc *ret_ptr = astgen_node(ag, ret_ptr_node, scope); if (ret_ptr == ag->codegen->invalid_inst_src) return ret_ptr; AstNode *fn_ref_node = call_node->data.fn_call_expr.params.at(2); - IrInstSrc *fn_ref = ir_gen_node(ag, fn_ref_node, scope); + IrInstSrc *fn_ref = astgen_node(ag, fn_ref_node, scope); if (fn_ref == ag->codegen->invalid_inst_src) return fn_ref; @@ -4028,7 +4030,7 @@ static IrInstSrc *ir_gen_async_call(Stage1AstGen *ag, Scope *scope, AstNode *awa IrInstSrc **args = heap::c_allocator.allocate(arg_count); for (size_t i = 0; i < arg_count; i += 1) { AstNode *arg_node = args_node->data.container_init_expr.entries.at(i); - IrInstSrc *arg = ir_gen_node(ag, arg_node, scope); + IrInstSrc *arg = astgen_node(ag, arg_node, scope); if (arg == ag->codegen->invalid_inst_src) return arg; args[i] = arg; @@ -4043,7 +4045,7 @@ static IrInstSrc *ir_gen_async_call(Stage1AstGen *ag, Scope *scope, AstNode *awa return ag->codegen->invalid_inst_src; } } - IrInstSrc *args = ir_gen_node(ag, args_node, scope); + IrInstSrc *args = astgen_node(ag, args_node, scope); if (args == ag->codegen->invalid_inst_src) return args; @@ -4051,11 +4053,11 @@ static IrInstSrc *ir_gen_async_call(Stage1AstGen *ag, Scope *scope, AstNode *awa return ir_lval_wrap(ag, scope, call, lval, result_loc); } -static IrInstSrc *ir_gen_fn_call_with_args(Stage1AstGen *ag, Scope *scope, AstNode *source_node, +static IrInstSrc *astgen_fn_call_with_args(Stage1AstGen *ag, Scope *scope, AstNode *source_node, AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options, AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc) { - IrInstSrc *fn_ref = ir_gen_node(ag, fn_ref_node, scope); + IrInstSrc *fn_ref = astgen_node(ag, fn_ref_node, scope); if (fn_ref == ag->codegen->invalid_inst_src) return fn_ref; @@ -4071,7 +4073,7 @@ static IrInstSrc *ir_gen_fn_call_with_args(Stage1AstGen *ag, Scope *scope, AstNo ir_build_reset_result(ag, scope, source_node, no_result); ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, arg_type, no_result); - IrInstSrc *arg = ir_gen_node_extra(ag, arg_node, scope, LValNone, &result_loc_cast->base); + IrInstSrc *arg = astgen_node_extra(ag, arg_node, scope, LValNone, &result_loc_cast->base); if (arg == ag->codegen->invalid_inst_src) return arg; @@ -4088,7 +4090,7 @@ static IrInstSrc *ir_gen_fn_call_with_args(Stage1AstGen *ag, Scope *scope, AstNo return ir_lval_wrap(ag, scope, fn_call, lval, result_loc); } -static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeFnCallExpr); @@ -4130,7 +4132,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode return ag->codegen->invalid_inst_src; } else if (arg_count == 1) { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, sub_scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, sub_scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4139,7 +4141,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode IrInstSrc **args = heap::c_allocator.allocate(arg_count); for (size_t i = 0; i < arg_count; i += 1) { AstNode *arg_node = node->data.fn_call_expr.params.at(i); - IrInstSrc *arg = ir_gen_node(ag, arg_node, sub_scope); + IrInstSrc *arg = astgen_node(ag, arg_node, sub_scope); if (arg == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; args[i] = arg; @@ -4152,7 +4154,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdSetCold: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4162,7 +4164,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdSetRuntimeSafety: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4172,7 +4174,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdSetFloatMode: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4183,7 +4185,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdBitSizeof: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4193,7 +4195,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdImport: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4208,7 +4210,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdCInclude: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4223,12 +4225,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdCDefine: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4243,7 +4245,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdCUndef: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4258,7 +4260,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdCompileErr: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4271,7 +4273,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode for (size_t i = 0; i < actual_param_count; i += 1) { AstNode *arg_node = node->data.fn_call_expr.params.at(i); - args[i] = ir_gen_node(ag, arg_node, scope); + args[i] = astgen_node(ag, arg_node, scope); if (args[i] == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; } @@ -4282,7 +4284,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdErrName: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4292,7 +4294,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdEmbedFile: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4303,32 +4305,32 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdCmpxchgStrong: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; AstNode *arg2_node = node->data.fn_call_expr.params.at(2); - IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); + IrInstSrc *arg2_value = astgen_node(ag, arg2_node, scope); if (arg2_value == ag->codegen->invalid_inst_src) return arg2_value; AstNode *arg3_node = node->data.fn_call_expr.params.at(3); - IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope); + IrInstSrc *arg3_value = astgen_node(ag, arg3_node, scope); if (arg3_value == ag->codegen->invalid_inst_src) return arg3_value; AstNode *arg4_node = node->data.fn_call_expr.params.at(4); - IrInstSrc *arg4_value = ir_gen_node(ag, arg4_node, scope); + IrInstSrc *arg4_value = astgen_node(ag, arg4_node, scope); if (arg4_value == ag->codegen->invalid_inst_src) return arg4_value; AstNode *arg5_node = node->data.fn_call_expr.params.at(5); - IrInstSrc *arg5_value = ir_gen_node(ag, arg5_node, scope); + IrInstSrc *arg5_value = astgen_node(ag, arg5_node, scope); if (arg5_value == ag->codegen->invalid_inst_src) return arg5_value; @@ -4340,7 +4342,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdFence: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4350,12 +4352,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdReduce: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4365,12 +4367,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdDivExact: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4380,12 +4382,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdDivTrunc: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4395,12 +4397,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdDivFloor: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4410,12 +4412,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdRem: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4425,12 +4427,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdMod: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4453,7 +4455,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdRound: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4463,12 +4465,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdTruncate: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4478,12 +4480,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdIntCast: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4493,12 +4495,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdFloatCast: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4508,12 +4510,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdErrSetCast: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4523,12 +4525,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdIntToFloat: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4538,12 +4540,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdFloatToInt: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4553,7 +4555,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdErrToInt: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4563,7 +4565,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdIntToErr: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4573,7 +4575,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdBoolToInt: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4583,12 +4585,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdVectorType: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4598,22 +4600,22 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdShuffle: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; AstNode *arg2_node = node->data.fn_call_expr.params.at(2); - IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); + IrInstSrc *arg2_value = astgen_node(ag, arg2_node, scope); if (arg2_value == ag->codegen->invalid_inst_src) return arg2_value; AstNode *arg3_node = node->data.fn_call_expr.params.at(3); - IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope); + IrInstSrc *arg3_value = astgen_node(ag, arg3_node, scope); if (arg3_value == ag->codegen->invalid_inst_src) return arg3_value; @@ -4624,12 +4626,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdSplat: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4640,17 +4642,17 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdMemcpy: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; AstNode *arg2_node = node->data.fn_call_expr.params.at(2); - IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); + IrInstSrc *arg2_value = astgen_node(ag, arg2_node, scope); if (arg2_value == ag->codegen->invalid_inst_src) return arg2_value; @@ -4660,17 +4662,17 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdMemset: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; AstNode *arg2_node = node->data.fn_call_expr.params.at(2); - IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); + IrInstSrc *arg2_value = astgen_node(ag, arg2_node, scope); if (arg2_value == ag->codegen->invalid_inst_src) return arg2_value; @@ -4680,7 +4682,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdWasmMemorySize: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4690,12 +4692,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdWasmMemoryGrow: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4705,12 +4707,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdField: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node_extra(ag, arg0_node, scope, LValPtr, nullptr); + IrInstSrc *arg0_value = astgen_node_extra(ag, arg0_node, scope, LValPtr, nullptr); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4726,12 +4728,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdHasField: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4741,7 +4743,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdTypeInfo: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4751,7 +4753,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdType: { AstNode *arg_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg = ir_gen_node(ag, arg_node, scope); + IrInstSrc *arg = astgen_node(ag, arg_node, scope); if (arg == ag->codegen->invalid_inst_src) return arg; @@ -4773,7 +4775,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode return ir_lval_wrap(ag, scope, ir_build_handle_src(ag, scope, node), lval, result_loc); case BuiltinFnIdFrameType: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4782,7 +4784,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode } case BuiltinFnIdFrameSize: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4792,7 +4794,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdAlignOf: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4800,19 +4802,19 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode return ir_lval_wrap(ag, scope, align_of, lval, result_loc); } case BuiltinFnIdAddWithOverflow: - return ir_lval_wrap(ag, scope, ir_gen_overflow_op(ag, scope, node, IrOverflowOpAdd), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_overflow_op(ag, scope, node, IrOverflowOpAdd), lval, result_loc); case BuiltinFnIdSubWithOverflow: - return ir_lval_wrap(ag, scope, ir_gen_overflow_op(ag, scope, node, IrOverflowOpSub), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_overflow_op(ag, scope, node, IrOverflowOpSub), lval, result_loc); case BuiltinFnIdMulWithOverflow: - return ir_lval_wrap(ag, scope, ir_gen_overflow_op(ag, scope, node, IrOverflowOpMul), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_overflow_op(ag, scope, node, IrOverflowOpMul), lval, result_loc); case BuiltinFnIdShlWithOverflow: - return ir_lval_wrap(ag, scope, ir_gen_overflow_op(ag, scope, node, IrOverflowOpShl), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_overflow_op(ag, scope, node, IrOverflowOpShl), lval, result_loc); case BuiltinFnIdMulAdd: - return ir_lval_wrap(ag, scope, ir_gen_mul_add(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_mul_add(ag, scope, node), lval, result_loc); case BuiltinFnIdTypeName: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4822,7 +4824,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdPanic: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4832,12 +4834,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdPtrCast: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4847,7 +4849,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdBitCast: { AstNode *dest_type_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *dest_type = ir_gen_node(ag, dest_type_node, scope); + IrInstSrc *dest_type = astgen_node(ag, dest_type_node, scope); if (dest_type == ag->codegen->invalid_inst_src) return dest_type; @@ -4861,7 +4863,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode ir_build_reset_result(ag, scope, node, &result_loc_bit_cast->base); AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node_extra(ag, arg1_node, scope, LValNone, + IrInstSrc *arg1_value = astgen_node_extra(ag, arg1_node, scope, LValNone, &result_loc_bit_cast->base); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4872,14 +4874,14 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdAs: { AstNode *dest_type_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *dest_type = ir_gen_node(ag, dest_type_node, scope); + IrInstSrc *dest_type = astgen_node(ag, dest_type_node, scope); if (dest_type == ag->codegen->invalid_inst_src) return dest_type; ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, dest_type, result_loc); AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node_extra(ag, arg1_node, scope, LValNone, + IrInstSrc *arg1_value = astgen_node_extra(ag, arg1_node, scope, LValNone, &result_loc_cast->base); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4890,12 +4892,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdIntToPtr: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4905,7 +4907,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdPtrToInt: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4915,7 +4917,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdTagName: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -4925,17 +4927,17 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdFieldParentPtr: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; AstNode *arg2_node = node->data.fn_call_expr.params.at(2); - IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); + IrInstSrc *arg2_value = astgen_node(ag, arg2_node, scope); if (arg2_value == ag->codegen->invalid_inst_src) return arg2_value; @@ -4946,12 +4948,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdByteOffsetOf: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4961,12 +4963,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdBitOffsetOf: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -4980,7 +4982,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, options_type_inst, no_result_loc()); AstNode *options_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *options_inner = ir_gen_node_extra(ag, options_node, scope, + IrInstSrc *options_inner = astgen_node_extra(ag, options_node, scope, LValNone, &result_loc_cast->base); if (options_inner == ag->codegen->invalid_inst_src) return options_inner; @@ -4992,7 +4994,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode if (args_node->data.container_init_expr.kind == ContainerInitKindArray || args_node->data.container_init_expr.entries.length == 0) { - return ir_gen_fn_call_with_args(ag, scope, node, + return astgen_fn_call_with_args(ag, scope, node, fn_ref_node, CallModifierNone, options, args_node->data.container_init_expr.entries.items, args_node->data.container_init_expr.entries.length, @@ -5003,11 +5005,11 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode return ag->codegen->invalid_inst_src; } } else { - IrInstSrc *fn_ref = ir_gen_node(ag, fn_ref_node, scope); + IrInstSrc *fn_ref = astgen_node(ag, fn_ref_node, scope); if (fn_ref == ag->codegen->invalid_inst_src) return fn_ref; - IrInstSrc *args = ir_gen_node(ag, args_node, scope); + IrInstSrc *args = astgen_node(ag, args_node, scope); if (args == ag->codegen->invalid_inst_src) return args; @@ -5016,16 +5018,16 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode } } case BuiltinFnIdAsyncCall: - return ir_gen_async_call(ag, scope, nullptr, node, lval, result_loc); + return astgen_async_call(ag, scope, nullptr, node, lval, result_loc); case BuiltinFnIdShlExact: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -5035,12 +5037,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdShrExact: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -5050,7 +5052,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdSetEvalBranchQuota: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -5060,12 +5062,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdAlignCast: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -5074,13 +5076,13 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode } case BuiltinFnIdThis: { - IrInstSrc *this_inst = ir_gen_this(ag, scope, node); + IrInstSrc *this_inst = astgen_this(ag, scope, node); return ir_lval_wrap(ag, scope, this_inst, lval, result_loc); } case BuiltinFnIdSetAlignStack: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -5095,12 +5097,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, options_type_inst, no_result_loc()); AstNode *target_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *target_value = ir_gen_node(ag, target_node, scope); + IrInstSrc *target_value = astgen_node(ag, target_node, scope); if (target_value == ag->codegen->invalid_inst_src) return target_value; AstNode *options_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *options_value = ir_gen_node_extra(ag, options_node, + IrInstSrc *options_value = astgen_node_extra(ag, options_node, scope, LValNone, &result_loc_cast->base); if (options_value == ag->codegen->invalid_inst_src) return options_value; @@ -5119,12 +5121,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode ResultLocCast *result_loc_cast = ir_build_cast_result_loc(ag, options_type_inst, no_result_loc()); AstNode *type_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *type_value = ir_gen_node(ag, type_node, scope); + IrInstSrc *type_value = astgen_node(ag, type_node, scope); if (type_value == ag->codegen->invalid_inst_src) return type_value; AstNode *options_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *options_value = ir_gen_node_extra(ag, options_node, + IrInstSrc *options_value = astgen_node_extra(ag, options_node, scope, LValNone, &result_loc_cast->base); if (options_value == ag->codegen->invalid_inst_src) return options_value; @@ -5144,27 +5146,27 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdAtomicRmw: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; AstNode *arg2_node = node->data.fn_call_expr.params.at(2); - IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); + IrInstSrc *arg2_value = astgen_node(ag, arg2_node, scope); if (arg2_value == ag->codegen->invalid_inst_src) return arg2_value; AstNode *arg3_node = node->data.fn_call_expr.params.at(3); - IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope); + IrInstSrc *arg3_value = astgen_node(ag, arg3_node, scope); if (arg3_value == ag->codegen->invalid_inst_src) return arg3_value; AstNode *arg4_node = node->data.fn_call_expr.params.at(4); - IrInstSrc *arg4_value = ir_gen_node(ag, arg4_node, scope); + IrInstSrc *arg4_value = astgen_node(ag, arg4_node, scope); if (arg4_value == ag->codegen->invalid_inst_src) return arg4_value; @@ -5175,17 +5177,17 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdAtomicLoad: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; AstNode *arg2_node = node->data.fn_call_expr.params.at(2); - IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); + IrInstSrc *arg2_value = astgen_node(ag, arg2_node, scope); if (arg2_value == ag->codegen->invalid_inst_src) return arg2_value; @@ -5195,22 +5197,22 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdAtomicStore: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; AstNode *arg2_node = node->data.fn_call_expr.params.at(2); - IrInstSrc *arg2_value = ir_gen_node(ag, arg2_node, scope); + IrInstSrc *arg2_value = astgen_node(ag, arg2_node, scope); if (arg2_value == ag->codegen->invalid_inst_src) return arg2_value; AstNode *arg3_node = node->data.fn_call_expr.params.at(3); - IrInstSrc *arg3_value = ir_gen_node(ag, arg3_node, scope); + IrInstSrc *arg3_value = astgen_node(ag, arg3_node, scope); if (arg3_value == ag->codegen->invalid_inst_src) return arg3_value; @@ -5221,12 +5223,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdIntToEnum: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -5236,7 +5238,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdEnumToInt: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; @@ -5250,12 +5252,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdBitReverse: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -5284,12 +5286,12 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdHasDecl: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *arg0_value = ir_gen_node(ag, arg0_node, scope); + IrInstSrc *arg0_value = astgen_node(ag, arg0_node, scope); if (arg0_value == ag->codegen->invalid_inst_src) return arg0_value; AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *arg1_value = ir_gen_node(ag, arg1_node, scope); + IrInstSrc *arg1_value = astgen_node(ag, arg1_node, scope); if (arg1_value == ag->codegen->invalid_inst_src) return arg1_value; @@ -5299,18 +5301,18 @@ static IrInstSrc *ir_gen_builtin_fn_call(Stage1AstGen *ag, Scope *scope, AstNode case BuiltinFnIdUnionInit: { AstNode *union_type_node = node->data.fn_call_expr.params.at(0); - IrInstSrc *union_type_inst = ir_gen_node(ag, union_type_node, scope); + IrInstSrc *union_type_inst = astgen_node(ag, union_type_node, scope); if (union_type_inst == ag->codegen->invalid_inst_src) return union_type_inst; AstNode *name_node = node->data.fn_call_expr.params.at(1); - IrInstSrc *name_inst = ir_gen_node(ag, name_node, scope); + IrInstSrc *name_inst = astgen_node(ag, name_node, scope); if (name_inst == ag->codegen->invalid_inst_src) return name_inst; AstNode *init_node = node->data.fn_call_expr.params.at(2); - return ir_gen_union_init_expr(ag, scope, node, union_type_inst, name_inst, init_node, + return astgen_union_init_expr(ag, scope, node, union_type_inst, name_inst, init_node, lval, result_loc); } case BuiltinFnIdSrc: @@ -5334,13 +5336,13 @@ static ScopeNoSuspend *get_scope_nosuspend(Scope *scope) { return nullptr; } -static IrInstSrc *ir_gen_fn_call(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_fn_call(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeFnCallExpr); if (node->data.fn_call_expr.modifier == CallModifierBuiltin) - return ir_gen_builtin_fn_call(ag, scope, node, lval, result_loc); + return astgen_builtin_fn_call(ag, scope, node, lval, result_loc); bool is_nosuspend = get_scope_nosuspend(scope) != nullptr; CallModifier modifier = node->data.fn_call_expr.modifier; @@ -5349,16 +5351,16 @@ static IrInstSrc *ir_gen_fn_call(Stage1AstGen *ag, Scope *scope, AstNode *node, } AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr; - return ir_gen_fn_call_with_args(ag, scope, node, fn_ref_node, modifier, + return astgen_fn_call_with_args(ag, scope, node, fn_ref_node, modifier, nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc); } -static IrInstSrc *ir_gen_if_bool_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_if_bool_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeIfBoolExpr); - IrInstSrc *condition = ir_gen_node(ag, node->data.if_bool_expr.condition, scope); + IrInstSrc *condition = astgen_node(ag, node->data.if_bool_expr.condition, scope); if (condition == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -5384,7 +5386,7 @@ static IrInstSrc *ir_gen_if_bool_expr(Stage1AstGen *ag, Scope *scope, AstNode *n ir_set_cursor_at_end_and_append_block(ag, then_block); Scope *subexpr_scope = create_runtime_scope(ag->codegen, node, scope, is_comptime); - IrInstSrc *then_expr_result = ir_gen_node_extra(ag, then_node, subexpr_scope, lval, + IrInstSrc *then_expr_result = astgen_node_extra(ag, then_node, subexpr_scope, lval, &peer_parent->peers.at(0)->base); if (then_expr_result == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -5395,7 +5397,7 @@ static IrInstSrc *ir_gen_if_bool_expr(Stage1AstGen *ag, Scope *scope, AstNode *n ir_set_cursor_at_end_and_append_block(ag, else_block); IrInstSrc *else_expr_result; if (else_node) { - else_expr_result = ir_gen_node_extra(ag, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); + else_expr_result = astgen_node_extra(ag, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); if (else_expr_result == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; } else { @@ -5418,19 +5420,19 @@ static IrInstSrc *ir_gen_if_bool_expr(Stage1AstGen *ag, Scope *scope, AstNode *n return ir_expr_wrap(ag, scope, phi, result_loc); } -static IrInstSrc *ir_gen_prefix_op_id_lval(Stage1AstGen *ag, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { +static IrInstSrc *astgen_prefix_op_id_lval(Stage1AstGen *ag, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { assert(node->type == NodeTypePrefixOpExpr); AstNode *expr_node = node->data.prefix_op_expr.primary_expr; - IrInstSrc *value = ir_gen_node_extra(ag, expr_node, scope, lval, nullptr); + IrInstSrc *value = astgen_node_extra(ag, expr_node, scope, lval, nullptr); if (value == ag->codegen->invalid_inst_src) return value; return ir_build_un_op(ag, scope, node, op_id, value); } -static IrInstSrc *ir_gen_prefix_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrUnOp op_id) { - return ir_gen_prefix_op_id_lval(ag, scope, node, op_id, LValNone); +static IrInstSrc *astgen_prefix_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrUnOp op_id) { + return astgen_prefix_op_id_lval(ag, scope, node, op_id, LValNone); } static IrInstSrc *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) { @@ -5499,7 +5501,7 @@ static Error token_number_literal_u32(Stage1AstGen *ag, AstNode *source_node, } -static IrInstSrc *ir_gen_pointer_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_pointer_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { Error err; assert(node->type == NodeTypePointerType); @@ -5516,7 +5518,7 @@ static IrInstSrc *ir_gen_pointer_type(Stage1AstGen *ag, Scope *scope, AstNode *n IrInstSrc *sentinel; if (sentinel_expr != nullptr) { - sentinel = ir_gen_node(ag, sentinel_expr, scope); + sentinel = astgen_node(ag, sentinel_expr, scope); if (sentinel == ag->codegen->invalid_inst_src) return sentinel; } else { @@ -5525,14 +5527,14 @@ static IrInstSrc *ir_gen_pointer_type(Stage1AstGen *ag, Scope *scope, AstNode *n IrInstSrc *align_value; if (align_expr != nullptr) { - align_value = ir_gen_node(ag, align_expr, scope); + align_value = astgen_node(ag, align_expr, scope); if (align_value == ag->codegen->invalid_inst_src) return align_value; } else { align_value = nullptr; } - IrInstSrc *child_type = ir_gen_node(ag, expr_node, scope); + IrInstSrc *child_type = astgen_node(ag, expr_node, scope); if (child_type == ag->codegen->invalid_inst_src) return child_type; @@ -5564,10 +5566,10 @@ static IrInstSrc *ir_gen_pointer_type(Stage1AstGen *ag, Scope *scope, AstNode *n ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero); } -static IrInstSrc *ir_gen_catch_unreachable(Stage1AstGen *ag, Scope *scope, AstNode *source_node, +static IrInstSrc *astgen_catch_unreachable(Stage1AstGen *ag, Scope *scope, AstNode *source_node, AstNode *expr_node, LVal lval, ResultLoc *result_loc) { - IrInstSrc *err_union_ptr = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr); + IrInstSrc *err_union_ptr = astgen_node_extra(ag, expr_node, scope, LValPtr, nullptr); if (err_union_ptr == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -5582,18 +5584,18 @@ static IrInstSrc *ir_gen_catch_unreachable(Stage1AstGen *ag, Scope *scope, AstNo return ir_expr_wrap(ag, scope, load_ptr, result_loc); } -static IrInstSrc *ir_gen_bool_not(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_bool_not(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypePrefixOpExpr); AstNode *expr_node = node->data.prefix_op_expr.primary_expr; - IrInstSrc *value = ir_gen_node(ag, expr_node, scope); + IrInstSrc *value = astgen_node(ag, expr_node, scope); if (value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; return ir_build_bool_not(ag, scope, node, value); } -static IrInstSrc *ir_gen_prefix_op_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_prefix_op_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypePrefixOpExpr); @@ -5604,24 +5606,24 @@ static IrInstSrc *ir_gen_prefix_op_expr(Stage1AstGen *ag, Scope *scope, AstNode case PrefixOpInvalid: zig_unreachable(); case PrefixOpBoolNot: - return ir_lval_wrap(ag, scope, ir_gen_bool_not(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bool_not(ag, scope, node), lval, result_loc); case PrefixOpBinNot: - return ir_lval_wrap(ag, scope, ir_gen_prefix_op_id(ag, scope, node, IrUnOpBinNot), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_prefix_op_id(ag, scope, node, IrUnOpBinNot), lval, result_loc); case PrefixOpNegation: - return ir_lval_wrap(ag, scope, ir_gen_prefix_op_id(ag, scope, node, IrUnOpNegation), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_prefix_op_id(ag, scope, node, IrUnOpNegation), lval, result_loc); case PrefixOpNegationWrap: - return ir_lval_wrap(ag, scope, ir_gen_prefix_op_id(ag, scope, node, IrUnOpNegationWrap), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_prefix_op_id(ag, scope, node, IrUnOpNegationWrap), lval, result_loc); case PrefixOpOptional: - return ir_lval_wrap(ag, scope, ir_gen_prefix_op_id(ag, scope, node, IrUnOpOptional), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_prefix_op_id(ag, scope, node, IrUnOpOptional), lval, result_loc); case PrefixOpAddrOf: { AstNode *expr_node = node->data.prefix_op_expr.primary_expr; - return ir_lval_wrap(ag, scope, ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_node_extra(ag, expr_node, scope, LValPtr, nullptr), lval, result_loc); } } zig_unreachable(); } -static IrInstSrc *ir_gen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, +static IrInstSrc *astgen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node, IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, LVal lval, ResultLoc *parent_result_loc) { @@ -5635,7 +5637,7 @@ static IrInstSrc *ir_gen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode ir_ref_instruction(field_ptr, ag->current_basic_block); ir_build_reset_result(ag, scope, expr_node, &result_loc_inst->base); - IrInstSrc *expr_value = ir_gen_node_extra(ag, expr_node, scope, LValNone, + IrInstSrc *expr_value = astgen_node_extra(ag, expr_node, scope, LValNone, &result_loc_inst->base); if (expr_value == ag->codegen->invalid_inst_src) return expr_value; @@ -5646,7 +5648,7 @@ static IrInstSrc *ir_gen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode return ir_lval_wrap(ag, scope, init_union, lval, parent_result_loc); } -static IrInstSrc *ir_gen_container_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_container_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *parent_result_loc) { assert(node->type == NodeTypeContainerInitExpr); @@ -5667,14 +5669,14 @@ static IrInstSrc *ir_gen_container_init_expr(Stage1AstGen *ag, Scope *scope, Ast } IrInstSrc *sentinel; if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) { - sentinel = ir_gen_node(ag, container_init_expr->type->data.inferred_array_type.sentinel, scope); + sentinel = astgen_node(ag, container_init_expr->type->data.inferred_array_type.sentinel, scope); if (sentinel == ag->codegen->invalid_inst_src) return sentinel; } else { sentinel = nullptr; } - IrInstSrc *elem_type = ir_gen_node(ag, + IrInstSrc *elem_type = astgen_node(ag, container_init_expr->type->data.inferred_array_type.child_type, scope); if (elem_type == ag->codegen->invalid_inst_src) return elem_type; @@ -5682,7 +5684,7 @@ static IrInstSrc *ir_gen_container_init_expr(Stage1AstGen *ag, Scope *scope, Ast IrInstSrc *item_count_inst = ir_build_const_usize(ag, scope, node, item_count); container_type = ir_build_array_type(ag, scope, node, item_count_inst, sentinel, elem_type); } else { - container_type = ir_gen_node(ag, container_init_expr->type, scope); + container_type = astgen_node(ag, container_init_expr->type, scope); if (container_type == ag->codegen->invalid_inst_src) return container_type; } @@ -5721,7 +5723,7 @@ static IrInstSrc *ir_gen_container_init_expr(Stage1AstGen *ag, Scope *scope, Ast ir_ref_instruction(field_ptr, ag->current_basic_block); ir_build_reset_result(ag, scope, expr_node, &result_loc_inst->base); - IrInstSrc *expr_value = ir_gen_node_extra(ag, expr_node, scope, LValNone, + IrInstSrc *expr_value = astgen_node_extra(ag, expr_node, scope, LValNone, &result_loc_inst->base); if (expr_value == ag->codegen->invalid_inst_src) return expr_value; @@ -5758,7 +5760,7 @@ static IrInstSrc *ir_gen_container_init_expr(Stage1AstGen *ag, Scope *scope, Ast ir_ref_instruction(elem_ptr, ag->current_basic_block); ir_build_reset_result(ag, scope, expr_node, &result_loc_inst->base); - IrInstSrc *expr_value = ir_gen_node_extra(ag, expr_node, scope, LValNone, + IrInstSrc *expr_value = astgen_node_extra(ag, expr_node, scope, LValNone, &result_loc_inst->base); if (expr_value == ag->codegen->invalid_inst_src) return expr_value; @@ -5812,7 +5814,7 @@ static void build_decl_var_and_init(Stage1AstGen *ag, Scope *scope, AstNode *sou ir_build_var_decl_src(ag, scope, source_node, var, nullptr, alloca); } -static IrInstSrc *ir_gen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeVariableDeclaration); AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration; @@ -5827,7 +5829,7 @@ static IrInstSrc *ir_gen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node) IrInstSrc *type_instruction; if (variable_declaration->type != nullptr) { - type_instruction = ir_gen_node(ag, variable_declaration->type, comptime_scope); + type_instruction = astgen_node(ag, variable_declaration->type, comptime_scope); if (type_instruction == ag->codegen->invalid_inst_src) return type_instruction; } else { @@ -5853,7 +5855,7 @@ static IrInstSrc *ir_gen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node) IrInstSrc *align_value = nullptr; if (variable_declaration->align_expr != nullptr) { - align_value = ir_gen_node(ag, variable_declaration->align_expr, comptime_scope); + align_value = astgen_node(ag, variable_declaration->align_expr, comptime_scope); if (align_value == ag->codegen->invalid_inst_src) return align_value; } @@ -5888,7 +5890,7 @@ static IrInstSrc *ir_gen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node) // so that the struct or enum from the init expression inherits the name. Buf *old_exec_name = ag->exec->name; ag->exec->name = variable_declaration->symbol; - IrInstSrc *init_value = ir_gen_node_extra(ag, variable_declaration->expr, init_scope, + IrInstSrc *init_value = astgen_node_extra(ag, variable_declaration->expr, init_scope, LValNone, init_result_loc); ag->exec->name = old_exec_name; @@ -5904,7 +5906,7 @@ static IrInstSrc *ir_gen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node) return ir_build_var_decl_src(ag, scope, node, var, align_value, alloca); } -static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeWhileExpr); @@ -5942,7 +5944,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod payload_scope = subexpr_scope; } ScopeExpr *spill_scope = create_expr_scope(ag->codegen, node, payload_scope); - IrInstSrc *err_val_ptr = ir_gen_node_extra(ag, node->data.while_expr.condition, subexpr_scope, + IrInstSrc *err_val_ptr = astgen_node_extra(ag, node->data.while_expr.condition, subexpr_scope, LValPtr, nullptr); if (err_val_ptr == ag->codegen->invalid_inst_src) return err_val_ptr; @@ -5990,8 +5992,8 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod // Note the body block of the loop is not the place that lval and result_loc are used - // it's actually in break statements, handled similarly to return statements. - // That is why we set those values in loop_scope above and not in this ir_gen_node call. - IrInstSrc *body_result = ir_gen_node(ag, node->data.while_expr.body, &loop_scope->base); + // That is why we set those values in loop_scope above and not in this astgen_node call. + IrInstSrc *body_result = astgen_node(ag, node->data.while_expr.body, &loop_scope->base); if (body_result == ag->codegen->invalid_inst_src) return body_result; @@ -6006,7 +6008,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod if (continue_expr_node) { ir_set_cursor_at_end_and_append_block(ag, continue_block); - IrInstSrc *expr_result = ir_gen_node(ag, continue_expr_node, payload_scope); + IrInstSrc *expr_result = astgen_node(ag, continue_expr_node, payload_scope); if (expr_result == ag->codegen->invalid_inst_src) return expr_result; if (!instr_is_unreachable(expr_result)) { @@ -6032,7 +6034,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod } ResultLocPeer *peer_result = create_peer_result(peer_parent); peer_parent->peers.append(peer_result); - IrInstSrc *else_result = ir_gen_node_extra(ag, else_node, err_scope, lval, &peer_result->base); + IrInstSrc *else_result = astgen_node_extra(ag, else_node, err_scope, lval, &peer_result->base); if (else_result == ag->codegen->invalid_inst_src) return else_result; if (!instr_is_unreachable(else_result)) @@ -6063,7 +6065,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod true, false, false, is_comptime); Scope *child_scope = payload_var->child_scope; ScopeExpr *spill_scope = create_expr_scope(ag->codegen, node, child_scope); - IrInstSrc *maybe_val_ptr = ir_gen_node_extra(ag, node->data.while_expr.condition, subexpr_scope, + IrInstSrc *maybe_val_ptr = astgen_node_extra(ag, node->data.while_expr.condition, subexpr_scope, LValPtr, nullptr); if (maybe_val_ptr == ag->codegen->invalid_inst_src) return maybe_val_ptr; @@ -6108,8 +6110,8 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod // Note the body block of the loop is not the place that lval and result_loc are used - // it's actually in break statements, handled similarly to return statements. - // That is why we set those values in loop_scope above and not in this ir_gen_node call. - IrInstSrc *body_result = ir_gen_node(ag, node->data.while_expr.body, &loop_scope->base); + // That is why we set those values in loop_scope above and not in this astgen_node call. + IrInstSrc *body_result = astgen_node(ag, node->data.while_expr.body, &loop_scope->base); if (body_result == ag->codegen->invalid_inst_src) return body_result; @@ -6124,7 +6126,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod if (continue_expr_node) { ir_set_cursor_at_end_and_append_block(ag, continue_block); - IrInstSrc *expr_result = ir_gen_node(ag, continue_expr_node, child_scope); + IrInstSrc *expr_result = astgen_node(ag, continue_expr_node, child_scope); if (expr_result == ag->codegen->invalid_inst_src) return expr_result; if (!instr_is_unreachable(expr_result)) { @@ -6142,7 +6144,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod } ResultLocPeer *peer_result = create_peer_result(peer_parent); peer_parent->peers.append(peer_result); - else_result = ir_gen_node_extra(ag, else_node, scope, lval, &peer_result->base); + else_result = astgen_node_extra(ag, else_node, scope, lval, &peer_result->base); if (else_result == ag->codegen->invalid_inst_src) return else_result; if (!instr_is_unreachable(else_result)) @@ -6166,7 +6168,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod return ir_expr_wrap(ag, scope, phi, result_loc); } else { ir_set_cursor_at_end_and_append_block(ag, cond_block); - IrInstSrc *cond_val = ir_gen_node(ag, node->data.while_expr.condition, scope); + IrInstSrc *cond_val = astgen_node(ag, node->data.while_expr.condition, scope); if (cond_val == ag->codegen->invalid_inst_src) return cond_val; Stage1ZirBasicBlock *after_cond_block = ag->current_basic_block; @@ -6204,8 +6206,8 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod // Note the body block of the loop is not the place that lval and result_loc are used - // it's actually in break statements, handled similarly to return statements. - // That is why we set those values in loop_scope above and not in this ir_gen_node call. - IrInstSrc *body_result = ir_gen_node(ag, node->data.while_expr.body, &loop_scope->base); + // That is why we set those values in loop_scope above and not in this astgen_node call. + IrInstSrc *body_result = astgen_node(ag, node->data.while_expr.body, &loop_scope->base); if (body_result == ag->codegen->invalid_inst_src) return body_result; @@ -6220,7 +6222,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod if (continue_expr_node) { ir_set_cursor_at_end_and_append_block(ag, continue_block); - IrInstSrc *expr_result = ir_gen_node(ag, continue_expr_node, subexpr_scope); + IrInstSrc *expr_result = astgen_node(ag, continue_expr_node, subexpr_scope); if (expr_result == ag->codegen->invalid_inst_src) return expr_result; if (!instr_is_unreachable(expr_result)) { @@ -6239,7 +6241,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod ResultLocPeer *peer_result = create_peer_result(peer_parent); peer_parent->peers.append(peer_result); - else_result = ir_gen_node_extra(ag, else_node, subexpr_scope, lval, &peer_result->base); + else_result = astgen_node_extra(ag, else_node, subexpr_scope, lval, &peer_result->base); if (else_result == ag->codegen->invalid_inst_src) return else_result; if (!instr_is_unreachable(else_result)) @@ -6264,7 +6266,7 @@ static IrInstSrc *ir_gen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod } } -static IrInstSrc *ir_gen_for_expr(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_for_expr(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeForExpr); @@ -6283,7 +6285,7 @@ static IrInstSrc *ir_gen_for_expr(Stage1AstGen *ag, Scope *parent_scope, AstNode ScopeExpr *spill_scope = create_expr_scope(ag->codegen, node, parent_scope); - IrInstSrc *array_val_ptr = ir_gen_node_extra(ag, array_node, &spill_scope->base, LValPtr, nullptr); + IrInstSrc *array_val_ptr = astgen_node_extra(ag, array_node, &spill_scope->base, LValPtr, nullptr); if (array_val_ptr == ag->codegen->invalid_inst_src) return array_val_ptr; @@ -6362,8 +6364,8 @@ static IrInstSrc *ir_gen_for_expr(Stage1AstGen *ag, Scope *parent_scope, AstNode // Note the body block of the loop is not the place that lval and result_loc are used - // it's actually in break statements, handled similarly to return statements. - // That is why we set those values in loop_scope above and not in this ir_gen_node call. - IrInstSrc *body_result = ir_gen_node(ag, body_node, &loop_scope->base); + // That is why we set those values in loop_scope above and not in this astgen_node call. + IrInstSrc *body_result = astgen_node(ag, body_node, &loop_scope->base); if (body_result == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -6390,7 +6392,7 @@ static IrInstSrc *ir_gen_for_expr(Stage1AstGen *ag, Scope *parent_scope, AstNode } ResultLocPeer *peer_result = create_peer_result(peer_parent); peer_parent->peers.append(peer_result); - else_result = ir_gen_node_extra(ag, else_node, parent_scope, LValNone, &peer_result->base); + else_result = astgen_node_extra(ag, else_node, parent_scope, LValNone, &peer_result->base); if (else_result == ag->codegen->invalid_inst_src) return else_result; if (!instr_is_unreachable(else_result)) @@ -6415,19 +6417,25 @@ static IrInstSrc *ir_gen_for_expr(Stage1AstGen *ag, Scope *parent_scope, AstNode return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc); } -static IrInstSrc *ir_gen_bool_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_bool_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeBoolLiteral); return ir_build_const_bool(ag, scope, node, node->data.bool_literal.value); } -static IrInstSrc *ir_gen_enum_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_enum_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeEnumLiteral); - RootStruct *root_struct = node->owner->data.structure.root_struct; - Buf *name = token_identifier_buf(root_struct, node->main_token + 1); - return ir_build_const_enum_literal(ag, scope, node, name); + // Currently, stage1 runs astgen for every comptime function call, + // resulting the allocation here wasting memory. As a workaround until + // the code is adjusted to make astgen run only once per source node, + // we memoize the result into the AST here. + if (node->data.enum_literal.name == nullptr) { + RootStruct *root_struct = node->owner->data.structure.root_struct; + node->data.enum_literal.name = token_identifier_buf(root_struct, node->main_token + 1); + } + return ir_build_const_enum_literal(ag, scope, node, node->data.enum_literal.name); } -static IrInstSrc *ir_gen_string_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_string_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { Error err; assert(node->type == NodeTypeStringLiteral); @@ -6465,10 +6473,11 @@ static IrInstSrc *ir_gen_string_literal(Stage1AstGen *ag, Scope *scope, AstNode } else { zig_unreachable(); } + return ir_build_const_str_lit(ag, scope, node, str); } -static IrInstSrc *ir_gen_array_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_array_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeArrayType); AstNode *size_node = node->data.array_type.size; @@ -6483,7 +6492,7 @@ static IrInstSrc *ir_gen_array_type(Stage1AstGen *ag, Scope *scope, AstNode *nod IrInstSrc *sentinel; if (sentinel_expr != nullptr) { - sentinel = ir_gen_node(ag, sentinel_expr, comptime_scope); + sentinel = astgen_node(ag, sentinel_expr, comptime_scope); if (sentinel == ag->codegen->invalid_inst_src) return sentinel; } else { @@ -6508,11 +6517,11 @@ static IrInstSrc *ir_gen_array_type(Stage1AstGen *ag, Scope *scope, AstNode *nod return ag->codegen->invalid_inst_src; } - IrInstSrc *size_value = ir_gen_node(ag, size_node, comptime_scope); + IrInstSrc *size_value = astgen_node(ag, size_node, comptime_scope); if (size_value == ag->codegen->invalid_inst_src) return size_value; - IrInstSrc *child_type = ir_gen_node(ag, child_type_node, comptime_scope); + IrInstSrc *child_type = astgen_node(ag, child_type_node, comptime_scope); if (child_type == ag->codegen->invalid_inst_src) return child_type; @@ -6520,14 +6529,14 @@ static IrInstSrc *ir_gen_array_type(Stage1AstGen *ag, Scope *scope, AstNode *nod } else { IrInstSrc *align_value; if (align_expr != nullptr) { - align_value = ir_gen_node(ag, align_expr, comptime_scope); + align_value = astgen_node(ag, align_expr, comptime_scope); if (align_value == ag->codegen->invalid_inst_src) return align_value; } else { align_value = nullptr; } - IrInstSrc *child_type = ir_gen_node(ag, child_type_node, comptime_scope); + IrInstSrc *child_type = astgen_node(ag, child_type_node, comptime_scope); if (child_type == ag->codegen->invalid_inst_src) return child_type; @@ -6536,14 +6545,14 @@ static IrInstSrc *ir_gen_array_type(Stage1AstGen *ag, Scope *scope, AstNode *nod } } -static IrInstSrc *ir_gen_anyframe_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_anyframe_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeAnyFrameType); AstNode *payload_type_node = node->data.anyframe_type.payload_type; IrInstSrc *payload_type_value = nullptr; if (payload_type_node != nullptr) { - payload_type_value = ir_gen_node(ag, payload_type_node, scope); + payload_type_value = astgen_node(ag, payload_type_node, scope); if (payload_type_value == ag->codegen->invalid_inst_src) return payload_type_value; @@ -6552,16 +6561,16 @@ static IrInstSrc *ir_gen_anyframe_type(Stage1AstGen *ag, Scope *scope, AstNode * return ir_build_anyframe_type(ag, scope, node, payload_type_value); } -static IrInstSrc *ir_gen_undefined_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_undefined_literal(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeUndefinedLiteral); return ir_build_const_undefined(ag, scope, node); } -static IrInstSrc *ir_gen_asm_expr(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_asm_expr(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeAsmExpr); AstNodeAsmExpr *asm_expr = &node->data.asm_expr; - IrInstSrc *asm_template = ir_gen_node(ag, asm_expr->asm_template, scope); + IrInstSrc *asm_template = astgen_node(ag, asm_expr->asm_template, scope); if (asm_template == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -6601,7 +6610,7 @@ static IrInstSrc *ir_gen_asm_expr(Stage1AstGen *ag, Scope *scope, AstNode *node) if (asm_output->return_type) { return_count += 1; - IrInstSrc *return_type = ir_gen_node(ag, asm_output->return_type, scope); + IrInstSrc *return_type = astgen_node(ag, asm_output->return_type, scope); if (return_type == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; if (return_count > 1) { @@ -6612,7 +6621,7 @@ static IrInstSrc *ir_gen_asm_expr(Stage1AstGen *ag, Scope *scope, AstNode *node) output_types[i] = return_type; } else { Buf *variable_name = asm_output->variable_name; - // TODO there is some duplication here with ir_gen_symbol. I need to do a full audit of how + // TODO there is some duplication here with astgen_identifier. I need to do a full audit of how // inline assembly works. https://github.com/ziglang/zig/issues/215 ZigVar *var = find_variable(ag->codegen, scope, variable_name, nullptr); if (var) { @@ -6635,7 +6644,7 @@ static IrInstSrc *ir_gen_asm_expr(Stage1AstGen *ag, Scope *scope, AstNode *node) } for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { AsmInput *asm_input = asm_expr->input_list.at(i); - IrInstSrc *input_value = ir_gen_node(ag, asm_input->expr, scope); + IrInstSrc *input_value = astgen_node(ag, asm_input->expr, scope); if (input_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -6646,7 +6655,7 @@ static IrInstSrc *ir_gen_asm_expr(Stage1AstGen *ag, Scope *scope, AstNode *node) output_vars, return_count, is_volatile, false); } -static IrInstSrc *ir_gen_if_optional_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_if_optional_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeIfOptional); @@ -6660,7 +6669,7 @@ static IrInstSrc *ir_gen_if_optional_expr(Stage1AstGen *ag, Scope *scope, AstNod ScopeExpr *spill_scope = create_expr_scope(ag->codegen, expr_node, scope); spill_scope->spill_harder = true; - IrInstSrc *maybe_val_ptr = ir_gen_node_extra(ag, expr_node, &spill_scope->base, LValPtr, nullptr); + IrInstSrc *maybe_val_ptr = astgen_node_extra(ag, expr_node, &spill_scope->base, LValPtr, nullptr); if (maybe_val_ptr == ag->codegen->invalid_inst_src) return maybe_val_ptr; @@ -6701,7 +6710,7 @@ static IrInstSrc *ir_gen_if_optional_expr(Stage1AstGen *ag, Scope *scope, AstNod } else { var_scope = subexpr_scope; } - IrInstSrc *then_expr_result = ir_gen_node_extra(ag, then_node, var_scope, lval, + IrInstSrc *then_expr_result = astgen_node_extra(ag, then_node, var_scope, lval, &peer_parent->peers.at(0)->base); if (then_expr_result == ag->codegen->invalid_inst_src) return then_expr_result; @@ -6712,7 +6721,7 @@ static IrInstSrc *ir_gen_if_optional_expr(Stage1AstGen *ag, Scope *scope, AstNod ir_set_cursor_at_end_and_append_block(ag, else_block); IrInstSrc *else_expr_result; if (else_node) { - else_expr_result = ir_gen_node_extra(ag, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); + else_expr_result = astgen_node_extra(ag, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); if (else_expr_result == ag->codegen->invalid_inst_src) return else_expr_result; } else { @@ -6735,7 +6744,7 @@ static IrInstSrc *ir_gen_if_optional_expr(Stage1AstGen *ag, Scope *scope, AstNod return ir_expr_wrap(ag, scope, phi, result_loc); } -static IrInstSrc *ir_gen_if_err_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_if_err_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeIfErrorExpr); @@ -6748,7 +6757,7 @@ static IrInstSrc *ir_gen_if_err_expr(Stage1AstGen *ag, Scope *scope, AstNode *no Buf *var_symbol = node->data.if_err_expr.var_symbol; Buf *err_symbol = node->data.if_err_expr.err_symbol; - IrInstSrc *err_val_ptr = ir_gen_node_extra(ag, target_node, scope, LValPtr, nullptr); + IrInstSrc *err_val_ptr = astgen_node_extra(ag, target_node, scope, LValPtr, nullptr); if (err_val_ptr == ag->codegen->invalid_inst_src) return err_val_ptr; @@ -6784,7 +6793,7 @@ static IrInstSrc *ir_gen_if_err_expr(Stage1AstGen *ag, Scope *scope, AstNode *no } else { var_scope = subexpr_scope; } - IrInstSrc *then_expr_result = ir_gen_node_extra(ag, then_node, var_scope, lval, + IrInstSrc *then_expr_result = astgen_node_extra(ag, then_node, var_scope, lval, &peer_parent->peers.at(0)->base); if (then_expr_result == ag->codegen->invalid_inst_src) return then_expr_result; @@ -6810,7 +6819,7 @@ static IrInstSrc *ir_gen_if_err_expr(Stage1AstGen *ag, Scope *scope, AstNode *no } else { err_var_scope = subexpr_scope; } - else_expr_result = ir_gen_node_extra(ag, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base); + else_expr_result = astgen_node_extra(ag, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base); if (else_expr_result == ag->codegen->invalid_inst_src) return else_expr_result; } else { @@ -6833,7 +6842,7 @@ static IrInstSrc *ir_gen_if_err_expr(Stage1AstGen *ag, Scope *scope, AstNode *no return ir_expr_wrap(ag, scope, phi, result_loc); } -static bool ir_gen_switch_prong_expr(Stage1AstGen *ag, Scope *scope, AstNode *switch_node, AstNode *prong_node, +static bool astgen_switch_prong_expr(Stage1AstGen *ag, Scope *scope, AstNode *switch_node, AstNode *prong_node, Stage1ZirBasicBlock *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime, IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len, ZigList *incoming_blocks, ZigList *incoming_values, @@ -6877,7 +6886,7 @@ static bool ir_gen_switch_prong_expr(Stage1AstGen *ag, Scope *scope, AstNode *sw child_scope = scope; } - IrInstSrc *expr_result = ir_gen_node_extra(ag, expr_node, child_scope, lval, result_loc); + IrInstSrc *expr_result = astgen_node_extra(ag, expr_node, child_scope, lval, result_loc); if (expr_result == ag->codegen->invalid_inst_src) return false; if (!instr_is_unreachable(expr_result)) @@ -6887,13 +6896,13 @@ static bool ir_gen_switch_prong_expr(Stage1AstGen *ag, Scope *scope, AstNode *sw return true; } -static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeSwitchExpr); AstNode *target_node = node->data.switch_expr.expr; - IrInstSrc *target_value_ptr = ir_gen_node_extra(ag, target_node, scope, LValPtr, nullptr); + IrInstSrc *target_value_ptr = astgen_node_extra(ag, target_node, scope, LValPtr, nullptr); if (target_value_ptr == ag->codegen->invalid_inst_src) return target_value_ptr; IrInstSrc *target_value = ir_build_switch_target(ag, scope, node, target_value_ptr); @@ -6949,11 +6958,11 @@ static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no AstNode *start_node = item_node->data.switch_range.start; AstNode *end_node = item_node->data.switch_range.end; - IrInstSrc *start_value = ir_gen_node(ag, start_node, comptime_scope); + IrInstSrc *start_value = astgen_node(ag, start_node, comptime_scope); if (start_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; - IrInstSrc *end_value = ir_gen_node(ag, end_node, comptime_scope); + IrInstSrc *end_value = astgen_node(ag, end_node, comptime_scope); if (end_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -6973,7 +6982,7 @@ static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no ok_bit = both_ok; } } else { - IrInstSrc *item_value = ir_gen_node(ag, item_node, comptime_scope); + IrInstSrc *item_value = astgen_node(ag, item_node, comptime_scope); if (item_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -7007,7 +7016,7 @@ static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no } peer_parent->peers.append(this_peer_result_loc); ir_set_cursor_at_end_and_append_block(ag, range_block_yes); - if (!ir_gen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block, + if (!astgen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block, is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) { @@ -7058,7 +7067,7 @@ static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no } peer_parent->peers.append(this_peer_result_loc); ir_set_cursor_at_end_and_append_block(ag, else_block); - if (!ir_gen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block, + if (!astgen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block, is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values, &switch_else_var, LValNone, &this_peer_result_loc->base)) { @@ -7088,7 +7097,7 @@ static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); assert(item_node->type != NodeTypeSwitchRange); - IrInstSrc *item_value = ir_gen_node(ag, item_node, comptime_scope); + IrInstSrc *item_value = astgen_node(ag, item_node, comptime_scope); if (item_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -7109,7 +7118,7 @@ static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no } peer_parent->peers.append(this_peer_result_loc); ir_set_cursor_at_end_and_append_block(ag, prong_block); - if (!ir_gen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block, + if (!astgen_switch_prong_expr(ag, subexpr_scope, node, prong_node, end_block, is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count, &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) { @@ -7165,23 +7174,23 @@ static IrInstSrc *ir_gen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode *no return ir_lval_wrap(ag, scope, result_instruction, lval, result_loc); } -static IrInstSrc *ir_gen_comptime(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval) { +static IrInstSrc *astgen_comptime(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval) { assert(node->type == NodeTypeCompTime); Scope *child_scope = create_comptime_scope(ag->codegen, node, parent_scope); // purposefully pass null for result_loc and let EndExpr handle it - return ir_gen_node_extra(ag, node->data.comptime_expr.expr, child_scope, lval, nullptr); + return astgen_node_extra(ag, node->data.comptime_expr.expr, child_scope, lval, nullptr); } -static IrInstSrc *ir_gen_nosuspend(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval) { +static IrInstSrc *astgen_nosuspend(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval) { assert(node->type == NodeTypeNoSuspend); Scope *child_scope = create_nosuspend_scope(ag->codegen, node, parent_scope); // purposefully pass null for result_loc and let EndExpr handle it - return ir_gen_node_extra(ag, node->data.nosuspend_expr.expr, child_scope, lval, nullptr); + return astgen_node_extra(ag, node->data.nosuspend_expr.expr, child_scope, lval, nullptr); } -static IrInstSrc *ir_gen_return_from_block(Stage1AstGen *ag, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) { +static IrInstSrc *astgen_return_from_block(Stage1AstGen *ag, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) { IrInstSrc *is_comptime; if (ir_should_inline(ag->exec, break_scope)) { is_comptime = ir_build_const_bool(ag, break_scope, node, true); @@ -7194,7 +7203,7 @@ static IrInstSrc *ir_gen_return_from_block(Stage1AstGen *ag, Scope *break_scope, ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent); block_scope->peer_parent->peers.append(peer_result); - result_value = ir_gen_node_extra(ag, node->data.break_expr.expr, break_scope, block_scope->lval, + result_value = astgen_node_extra(ag, node->data.break_expr.expr, break_scope, block_scope->lval, &peer_result->base); if (result_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -7203,7 +7212,7 @@ static IrInstSrc *ir_gen_return_from_block(Stage1AstGen *ag, Scope *break_scope, } Stage1ZirBasicBlock *dest_block = block_scope->end_block; - if (!ir_gen_defers_for_block(ag, break_scope, dest_block->scope, nullptr, nullptr)) + if (!astgen_defers_for_block(ag, break_scope, dest_block->scope, nullptr, nullptr)) return ag->codegen->invalid_inst_src; block_scope->incoming_blocks->append(ag->current_basic_block); @@ -7211,7 +7220,7 @@ static IrInstSrc *ir_gen_return_from_block(Stage1AstGen *ag, Scope *break_scope, return ir_build_br(ag, break_scope, node, dest_block, is_comptime); } -static IrInstSrc *ir_gen_break(Stage1AstGen *ag, Scope *break_scope, AstNode *node) { +static IrInstSrc *astgen_break(Stage1AstGen *ag, Scope *break_scope, AstNode *node) { assert(node->type == NodeTypeBreak); // Search up the scope. We'll find one of these things first: @@ -7250,7 +7259,7 @@ static IrInstSrc *ir_gen_break(Stage1AstGen *ag, Scope *break_scope, AstNode *no { assert(this_block_scope->end_block != nullptr); this_block_scope->name_used = true; - return ir_gen_return_from_block(ag, break_scope, node, this_block_scope); + return astgen_return_from_block(ag, break_scope, node, this_block_scope); } } else if (search_scope->id == ScopeIdSuspend) { add_node_error(ag->codegen, node, buf_sprintf("cannot break out of suspend block")); @@ -7271,7 +7280,7 @@ static IrInstSrc *ir_gen_break(Stage1AstGen *ag, Scope *break_scope, AstNode *no ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent); loop_scope->peer_parent->peers.append(peer_result); - result_value = ir_gen_node_extra(ag, node->data.break_expr.expr, break_scope, + result_value = astgen_node_extra(ag, node->data.break_expr.expr, break_scope, loop_scope->lval, &peer_result->base); if (result_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -7280,7 +7289,7 @@ static IrInstSrc *ir_gen_break(Stage1AstGen *ag, Scope *break_scope, AstNode *no } Stage1ZirBasicBlock *dest_block = loop_scope->break_block; - if (!ir_gen_defers_for_block(ag, break_scope, dest_block->scope, nullptr, nullptr)) + if (!astgen_defers_for_block(ag, break_scope, dest_block->scope, nullptr, nullptr)) return ag->codegen->invalid_inst_src; loop_scope->incoming_blocks->append(ag->current_basic_block); @@ -7288,7 +7297,7 @@ static IrInstSrc *ir_gen_break(Stage1AstGen *ag, Scope *break_scope, AstNode *no return ir_build_br(ag, break_scope, node, dest_block, is_comptime); } -static IrInstSrc *ir_gen_continue(Stage1AstGen *ag, Scope *continue_scope, AstNode *node) { +static IrInstSrc *astgen_continue(Stage1AstGen *ag, Scope *continue_scope, AstNode *node) { assert(node->type == NodeTypeContinue); // Search up the scope. We'll find one of these things first: @@ -7342,17 +7351,17 @@ static IrInstSrc *ir_gen_continue(Stage1AstGen *ag, Scope *continue_scope, AstNo runtime_scopes.deinit(); Stage1ZirBasicBlock *dest_block = loop_scope->continue_block; - if (!ir_gen_defers_for_block(ag, continue_scope, dest_block->scope, nullptr, nullptr)) + if (!astgen_defers_for_block(ag, continue_scope, dest_block->scope, nullptr, nullptr)) return ag->codegen->invalid_inst_src; return ir_mark_gen(ir_build_br(ag, continue_scope, node, dest_block, is_comptime)); } -static IrInstSrc *ir_gen_error_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_error_type(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeErrorType); return ir_build_const_type(ag, scope, node, ag->codegen->builtin_types.entry_global_error_set); } -static IrInstSrc *ir_gen_defer(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { +static IrInstSrc *astgen_defer(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { assert(node->type == NodeTypeDefer); ScopeDefer *defer_child_scope = create_defer_scope(ag->codegen, node, parent_scope); @@ -7364,7 +7373,7 @@ static IrInstSrc *ir_gen_defer(Stage1AstGen *ag, Scope *parent_scope, AstNode *n return ir_build_const_void(ag, parent_scope, node); } -static IrInstSrc *ir_gen_slice(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { +static IrInstSrc *astgen_slice(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeSliceExpr); AstNodeSliceExpr *slice_expr = &node->data.slice_expr; @@ -7373,17 +7382,17 @@ static IrInstSrc *ir_gen_slice(Stage1AstGen *ag, Scope *scope, AstNode *node, LV AstNode *end_node = slice_expr->end; AstNode *sentinel_node = slice_expr->sentinel; - IrInstSrc *ptr_value = ir_gen_node_extra(ag, array_node, scope, LValPtr, nullptr); + IrInstSrc *ptr_value = astgen_node_extra(ag, array_node, scope, LValPtr, nullptr); if (ptr_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; - IrInstSrc *start_value = ir_gen_node(ag, start_node, scope); + IrInstSrc *start_value = astgen_node(ag, start_node, scope); if (start_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; IrInstSrc *end_value; if (end_node) { - end_value = ir_gen_node(ag, end_node, scope); + end_value = astgen_node(ag, end_node, scope); if (end_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; } else { @@ -7392,7 +7401,7 @@ static IrInstSrc *ir_gen_slice(Stage1AstGen *ag, Scope *scope, AstNode *node, LV IrInstSrc *sentinel_value; if (sentinel_node) { - sentinel_value = ir_gen_node(ag, sentinel_node, scope); + sentinel_value = astgen_node(ag, sentinel_node, scope); if (sentinel_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; } else { @@ -7404,7 +7413,7 @@ static IrInstSrc *ir_gen_slice(Stage1AstGen *ag, Scope *scope, AstNode *node, LV return ir_lval_wrap(ag, scope, slice, lval, result_loc); } -static IrInstSrc *ir_gen_catch(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_catch(Stage1AstGen *ag, Scope *parent_scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeCatchExpr); @@ -7420,14 +7429,14 @@ static IrInstSrc *ir_gen_catch(Stage1AstGen *ag, Scope *parent_scope, AstNode *n add_node_error(ag->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); return ag->codegen->invalid_inst_src; } - return ir_gen_catch_unreachable(ag, parent_scope, node, op1_node, lval, result_loc); + return astgen_catch_unreachable(ag, parent_scope, node, op1_node, lval, result_loc); } ScopeExpr *spill_scope = create_expr_scope(ag->codegen, op1_node, parent_scope); spill_scope->spill_harder = true; - IrInstSrc *err_union_ptr = ir_gen_node_extra(ag, op1_node, &spill_scope->base, LValPtr, nullptr); + IrInstSrc *err_union_ptr = astgen_node_extra(ag, op1_node, &spill_scope->base, LValPtr, nullptr); if (err_union_ptr == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -7465,7 +7474,7 @@ static IrInstSrc *ir_gen_catch(Stage1AstGen *ag, Scope *parent_scope, AstNode *n } else { err_scope = subexpr_scope; } - IrInstSrc *err_result = ir_gen_node_extra(ag, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base); + IrInstSrc *err_result = astgen_node_extra(ag, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base); if (err_result == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; Stage1ZirBasicBlock *after_err_block = ag->current_basic_block; @@ -7535,7 +7544,7 @@ Buf *get_anon_type_name(CodeGen *codegen, Stage1Zir *exec, const char *kind_name } } -static IrInstSrc *ir_gen_container_decl(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { +static IrInstSrc *astgen_container_decl(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { assert(node->type == NodeTypeContainerDecl); ContainerKind kind = node->data.container_decl.kind; @@ -7564,7 +7573,7 @@ static IrInstSrc *ir_gen_container_decl(Stage1AstGen *ag, Scope *parent_scope, A return ir_build_const_type(ag, parent_scope, node, container_type); } -static IrInstSrc *ir_gen_err_set_decl(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { +static IrInstSrc *astgen_err_set_decl(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { assert(node->type == NodeTypeErrorSetDecl); uint32_t err_count = node->data.err_set_decl.decls.length; @@ -7615,7 +7624,7 @@ static IrInstSrc *ir_gen_err_set_decl(Stage1AstGen *ag, Scope *parent_scope, Ast return ir_build_const_type(ag, parent_scope, node, err_set_type); } -static IrInstSrc *ir_gen_fn_proto(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { +static IrInstSrc *astgen_fn_proto(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { assert(node->type == NodeTypeFnProto); size_t param_count = node->data.fn_proto.params.length; @@ -7630,7 +7639,7 @@ static IrInstSrc *ir_gen_fn_proto(Stage1AstGen *ag, Scope *parent_scope, AstNode } if (param_node->data.param_decl.anytype_token == 0) { AstNode *type_node = param_node->data.param_decl.type; - IrInstSrc *type_value = ir_gen_node(ag, type_node, parent_scope); + IrInstSrc *type_value = astgen_node(ag, type_node, parent_scope); if (type_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; param_types[i] = type_value; @@ -7641,14 +7650,14 @@ static IrInstSrc *ir_gen_fn_proto(Stage1AstGen *ag, Scope *parent_scope, AstNode IrInstSrc *align_value = nullptr; if (node->data.fn_proto.align_expr != nullptr) { - align_value = ir_gen_node(ag, node->data.fn_proto.align_expr, parent_scope); + align_value = astgen_node(ag, node->data.fn_proto.align_expr, parent_scope); if (align_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; } IrInstSrc *callconv_value = nullptr; if (node->data.fn_proto.callconv_expr != nullptr) { - callconv_value = ir_gen_node(ag, node->data.fn_proto.callconv_expr, parent_scope); + callconv_value = astgen_node(ag, node->data.fn_proto.callconv_expr, parent_scope); if (callconv_value == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; } @@ -7657,7 +7666,7 @@ static IrInstSrc *ir_gen_fn_proto(Stage1AstGen *ag, Scope *parent_scope, AstNode if (node->data.fn_proto.return_type == nullptr) { return_type = ir_build_const_type(ag, parent_scope, node, ag->codegen->builtin_types.entry_void); } else { - return_type = ir_gen_node(ag, node->data.fn_proto.return_type, parent_scope); + return_type = astgen_node(ag, node->data.fn_proto.return_type, parent_scope); if (return_type == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; } @@ -7665,17 +7674,17 @@ static IrInstSrc *ir_gen_fn_proto(Stage1AstGen *ag, Scope *parent_scope, AstNode return ir_build_fn_proto(ag, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args); } -static IrInstSrc *ir_gen_resume(Stage1AstGen *ag, Scope *scope, AstNode *node) { +static IrInstSrc *astgen_resume(Stage1AstGen *ag, Scope *scope, AstNode *node) { assert(node->type == NodeTypeResume); - IrInstSrc *target_inst = ir_gen_node_extra(ag, node->data.resume_expr.expr, scope, LValPtr, nullptr); + IrInstSrc *target_inst = astgen_node_extra(ag, node->data.resume_expr.expr, scope, LValPtr, nullptr); if (target_inst == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; return ir_build_resume_src(ag, scope, node, target_inst); } -static IrInstSrc *ir_gen_await_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, +static IrInstSrc *astgen_await_expr(Stage1AstGen *ag, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeAwaitExpr); @@ -7690,7 +7699,7 @@ static IrInstSrc *ir_gen_await_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod if (entry != nullptr) { BuiltinFnEntry *builtin_fn = entry->value; if (builtin_fn->id == BuiltinFnIdAsyncCall) { - return ir_gen_async_call(ag, scope, node, expr_node, lval, result_loc); + return astgen_async_call(ag, scope, node, expr_node, lval, result_loc); } } } @@ -7709,7 +7718,7 @@ static IrInstSrc *ir_gen_await_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod return ag->codegen->invalid_inst_src; } - IrInstSrc *target_inst = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr); + IrInstSrc *target_inst = astgen_node_extra(ag, expr_node, scope, LValPtr, nullptr); if (target_inst == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -7717,7 +7726,7 @@ static IrInstSrc *ir_gen_await_expr(Stage1AstGen *ag, Scope *scope, AstNode *nod return ir_lval_wrap(ag, scope, await_inst, lval, result_loc); } -static IrInstSrc *ir_gen_suspend(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { +static IrInstSrc *astgen_suspend(Stage1AstGen *ag, Scope *parent_scope, AstNode *node) { assert(node->type == NodeTypeSuspend); if (!ag->fn) { @@ -7742,7 +7751,7 @@ static IrInstSrc *ir_gen_suspend(Stage1AstGen *ag, Scope *parent_scope, AstNode IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(ag, parent_scope, node); ScopeSuspend *suspend_scope = create_suspend_scope(ag->codegen, node, parent_scope); Scope *child_scope = &suspend_scope->base; - IrInstSrc *susp_res = ir_gen_node(ag, node->data.suspend.block, child_scope); + IrInstSrc *susp_res = astgen_node(ag, node->data.suspend.block, child_scope); if (susp_res == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; ir_mark_gen(ir_build_check_statement_is_void(ag, child_scope, node->data.suspend.block, susp_res)); @@ -7750,7 +7759,7 @@ static IrInstSrc *ir_gen_suspend(Stage1AstGen *ag, Scope *parent_scope, AstNode return ir_mark_gen(ir_build_suspend_finish_src(ag, parent_scope, node, begin)); } -static IrInstSrc *ir_gen_node_raw(Stage1AstGen *ag, AstNode *node, Scope *scope, +static IrInstSrc *astgen_node_raw(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval, ResultLoc *result_loc) { assert(scope); @@ -7766,40 +7775,40 @@ static IrInstSrc *ir_gen_node_raw(Stage1AstGen *ag, AstNode *node, Scope *scope, case NodeTypeTestDecl: zig_unreachable(); case NodeTypeBlock: - return ir_gen_block(ag, scope, node, lval, result_loc); + return astgen_block(ag, scope, node, lval, result_loc); case NodeTypeGroupedExpr: - return ir_gen_node_raw(ag, node->data.grouped_expr, scope, lval, result_loc); + return astgen_node_raw(ag, node->data.grouped_expr, scope, lval, result_loc); case NodeTypeBinOpExpr: - return ir_gen_bin_op(ag, scope, node, lval, result_loc); + return astgen_bin_op(ag, scope, node, lval, result_loc); case NodeTypeIntLiteral: - return ir_lval_wrap(ag, scope, ir_gen_int_lit(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_int_lit(ag, scope, node), lval, result_loc); case NodeTypeFloatLiteral: - return ir_lval_wrap(ag, scope, ir_gen_float_lit(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_float_lit(ag, scope, node), lval, result_loc); case NodeTypeCharLiteral: - return ir_lval_wrap(ag, scope, ir_gen_char_lit(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_char_lit(ag, scope, node), lval, result_loc); case NodeTypeIdentifier: - return ir_gen_symbol(ag, scope, node, lval, result_loc); + return astgen_identifier(ag, scope, node, lval, result_loc); case NodeTypeFnCallExpr: - return ir_gen_fn_call(ag, scope, node, lval, result_loc); + return astgen_fn_call(ag, scope, node, lval, result_loc); case NodeTypeIfBoolExpr: - return ir_gen_if_bool_expr(ag, scope, node, lval, result_loc); + return astgen_if_bool_expr(ag, scope, node, lval, result_loc); case NodeTypePrefixOpExpr: - return ir_gen_prefix_op_expr(ag, scope, node, lval, result_loc); + return astgen_prefix_op_expr(ag, scope, node, lval, result_loc); case NodeTypeContainerInitExpr: - return ir_gen_container_init_expr(ag, scope, node, lval, result_loc); + return astgen_container_init_expr(ag, scope, node, lval, result_loc); case NodeTypeVariableDeclaration: - return ir_gen_var_decl(ag, scope, node); + return astgen_var_decl(ag, scope, node); case NodeTypeWhileExpr: - return ir_gen_while_expr(ag, scope, node, lval, result_loc); + return astgen_while_expr(ag, scope, node, lval, result_loc); case NodeTypeForExpr: - return ir_gen_for_expr(ag, scope, node, lval, result_loc); + return astgen_for_expr(ag, scope, node, lval, result_loc); case NodeTypeArrayAccessExpr: - return ir_gen_array_access(ag, scope, node, lval, result_loc); + return astgen_array_access(ag, scope, node, lval, result_loc); case NodeTypeReturnExpr: - return ir_gen_return(ag, scope, node, lval, result_loc); + return astgen_return(ag, scope, node, lval, result_loc); case NodeTypeFieldAccessExpr: { - IrInstSrc *ptr_instruction = ir_gen_field_access(ag, scope, node); + IrInstSrc *ptr_instruction = astgen_field_access(ag, scope, node); if (ptr_instruction == ag->codegen->invalid_inst_src) return ptr_instruction; if (lval == LValPtr || lval == LValAssign) @@ -7815,7 +7824,7 @@ static IrInstSrc *ir_gen_node_raw(Stage1AstGen *ag, AstNode *node, Scope *scope, if (child_lval == LValAssign) child_lval = LValPtr; - IrInstSrc *value = ir_gen_node_extra(ag, expr_node, scope, child_lval, nullptr); + IrInstSrc *value = astgen_node_extra(ag, expr_node, scope, child_lval, nullptr); if (value == ag->codegen->invalid_inst_src) return value; @@ -7828,7 +7837,7 @@ static IrInstSrc *ir_gen_node_raw(Stage1AstGen *ag, AstNode *node, Scope *scope, case NodeTypeUnwrapOptional: { AstNode *expr_node = node->data.unwrap_optional.expr; - IrInstSrc *maybe_ptr = ir_gen_node_extra(ag, expr_node, scope, LValPtr, nullptr); + IrInstSrc *maybe_ptr = astgen_node_extra(ag, expr_node, scope, LValPtr, nullptr); if (maybe_ptr == ag->codegen->invalid_inst_src) return ag->codegen->invalid_inst_src; @@ -7840,59 +7849,59 @@ static IrInstSrc *ir_gen_node_raw(Stage1AstGen *ag, AstNode *node, Scope *scope, return ir_expr_wrap(ag, scope, load_ptr, result_loc); } case NodeTypeBoolLiteral: - return ir_lval_wrap(ag, scope, ir_gen_bool_literal(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_bool_literal(ag, scope, node), lval, result_loc); case NodeTypeArrayType: - return ir_lval_wrap(ag, scope, ir_gen_array_type(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_array_type(ag, scope, node), lval, result_loc); case NodeTypePointerType: - return ir_lval_wrap(ag, scope, ir_gen_pointer_type(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_pointer_type(ag, scope, node), lval, result_loc); case NodeTypeAnyFrameType: - return ir_lval_wrap(ag, scope, ir_gen_anyframe_type(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_anyframe_type(ag, scope, node), lval, result_loc); case NodeTypeStringLiteral: - return ir_lval_wrap(ag, scope, ir_gen_string_literal(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_string_literal(ag, scope, node), lval, result_loc); case NodeTypeUndefinedLiteral: - return ir_lval_wrap(ag, scope, ir_gen_undefined_literal(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_undefined_literal(ag, scope, node), lval, result_loc); case NodeTypeAsmExpr: - return ir_lval_wrap(ag, scope, ir_gen_asm_expr(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_asm_expr(ag, scope, node), lval, result_loc); case NodeTypeNullLiteral: - return ir_lval_wrap(ag, scope, ir_gen_null_literal(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_null_literal(ag, scope, node), lval, result_loc); case NodeTypeIfErrorExpr: - return ir_gen_if_err_expr(ag, scope, node, lval, result_loc); + return astgen_if_err_expr(ag, scope, node, lval, result_loc); case NodeTypeIfOptional: - return ir_gen_if_optional_expr(ag, scope, node, lval, result_loc); + return astgen_if_optional_expr(ag, scope, node, lval, result_loc); case NodeTypeSwitchExpr: - return ir_gen_switch_expr(ag, scope, node, lval, result_loc); + return astgen_switch_expr(ag, scope, node, lval, result_loc); case NodeTypeCompTime: - return ir_expr_wrap(ag, scope, ir_gen_comptime(ag, scope, node, lval), result_loc); + return ir_expr_wrap(ag, scope, astgen_comptime(ag, scope, node, lval), result_loc); case NodeTypeNoSuspend: - return ir_expr_wrap(ag, scope, ir_gen_nosuspend(ag, scope, node, lval), result_loc); + return ir_expr_wrap(ag, scope, astgen_nosuspend(ag, scope, node, lval), result_loc); case NodeTypeErrorType: - return ir_lval_wrap(ag, scope, ir_gen_error_type(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_error_type(ag, scope, node), lval, result_loc); case NodeTypeBreak: - return ir_lval_wrap(ag, scope, ir_gen_break(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_break(ag, scope, node), lval, result_loc); case NodeTypeContinue: - return ir_lval_wrap(ag, scope, ir_gen_continue(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_continue(ag, scope, node), lval, result_loc); case NodeTypeUnreachable: return ir_build_unreachable(ag, scope, node); case NodeTypeDefer: - return ir_lval_wrap(ag, scope, ir_gen_defer(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_defer(ag, scope, node), lval, result_loc); case NodeTypeSliceExpr: - return ir_gen_slice(ag, scope, node, lval, result_loc); + return astgen_slice(ag, scope, node, lval, result_loc); case NodeTypeCatchExpr: - return ir_gen_catch(ag, scope, node, lval, result_loc); + return astgen_catch(ag, scope, node, lval, result_loc); case NodeTypeContainerDecl: - return ir_lval_wrap(ag, scope, ir_gen_container_decl(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_container_decl(ag, scope, node), lval, result_loc); case NodeTypeFnProto: - return ir_lval_wrap(ag, scope, ir_gen_fn_proto(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_fn_proto(ag, scope, node), lval, result_loc); case NodeTypeErrorSetDecl: - return ir_lval_wrap(ag, scope, ir_gen_err_set_decl(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_err_set_decl(ag, scope, node), lval, result_loc); case NodeTypeResume: - return ir_lval_wrap(ag, scope, ir_gen_resume(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_resume(ag, scope, node), lval, result_loc); case NodeTypeAwaitExpr: - return ir_gen_await_expr(ag, scope, node, lval, result_loc); + return astgen_await_expr(ag, scope, node, lval, result_loc); case NodeTypeSuspend: - return ir_lval_wrap(ag, scope, ir_gen_suspend(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_suspend(ag, scope, node), lval, result_loc); case NodeTypeEnumLiteral: - return ir_lval_wrap(ag, scope, ir_gen_enum_literal(ag, scope, node), lval, result_loc); + return ir_lval_wrap(ag, scope, astgen_enum_literal(ag, scope, node), lval, result_loc); case NodeTypeInferredArrayType: add_node_error(ag->codegen, node, buf_sprintf("inferred array size invalid here")); @@ -7910,7 +7919,7 @@ ResultLoc *no_result_loc(void) { return &result_loc_none->base; } -static IrInstSrc *ir_gen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval, +static IrInstSrc *astgen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval, ResultLoc *result_loc) { if (lval == LValAssign) { @@ -8018,7 +8027,7 @@ static IrInstSrc *ir_gen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scop } else { child_scope = &create_expr_scope(ag->codegen, node, scope)->base; } - IrInstSrc *result = ir_gen_node_raw(ag, node, child_scope, lval, result_loc); + IrInstSrc *result = astgen_node_raw(ag, node, child_scope, lval, result_loc); if (result == ag->codegen->invalid_inst_src) { if (ag->exec->first_err_trace_msg == nullptr) { ag->exec->first_err_trace_msg = ag->codegen->trace_err; @@ -8027,8 +8036,8 @@ static IrInstSrc *ir_gen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scop return result; } -static IrInstSrc *ir_gen_node(Stage1AstGen *ag, AstNode *node, Scope *scope) { - return ir_gen_node_extra(ag, node, scope, LValNone, nullptr); +static IrInstSrc *astgen_node(Stage1AstGen *ag, AstNode *node, Scope *scope) { + return astgen_node_extra(ag, node, scope, LValNone, nullptr); } bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *stage1_zir, @@ -8050,7 +8059,7 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *sta // Entry block gets a reference because we enter it to begin. ir_ref_bb(ag->current_basic_block); - IrInstSrc *result = ir_gen_node_extra(ag, node, scope, LValNone, nullptr); + IrInstSrc *result = astgen_node_extra(ag, node, scope, LValNone, nullptr); if (result == ag->codegen->invalid_inst_src) return false; diff --git a/src/stage1/parser.cpp b/src/stage1/parser.cpp index 51acc6a566..8cd624daad 100644 --- a/src/stage1/parser.cpp +++ b/src/stage1/parser.cpp @@ -202,6 +202,19 @@ static void put_back_token(ParseContext *pc) { pc->current_token -= 1; } +static Buf *token_string_literal_buf(RootStruct *root_struct, TokenIndex token) { + Error err; + assert(root_struct->token_ids[token] == TokenIdStringLiteral); + const char *source = buf_ptr(root_struct->source_code); + size_t byte_offset = root_struct->token_locs[token].offset; + size_t bad_index; + Buf *str = buf_alloc(); + if ((err = source_string_literal_buf(source + byte_offset, str, &bad_index))) { + zig_panic("TODO handle string literal parse error"); + } + return str; +} + static Buf *token_buf(ParseContext *pc, TokenIndex token) { if (token == 0) return nullptr; @@ -3465,19 +3478,6 @@ Error source_char_literal(const char *source, uint32_t *result, size_t *bad_inde } -Buf *token_string_literal_buf(RootStruct *root_struct, TokenIndex token) { - Error err; - assert(root_struct->token_ids[token] == TokenIdStringLiteral); - const char *source = buf_ptr(root_struct->source_code); - size_t byte_offset = root_struct->token_locs[token].offset; - size_t bad_index; - Buf *str = buf_alloc(); - if ((err = source_string_literal_buf(source + byte_offset, str, &bad_index))) { - zig_panic("TODO handle string literal parse error"); - } - return str; -} - Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) { Error err; const char *source = buf_ptr(root_struct->source_code); @@ -3515,14 +3515,15 @@ Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) { Buf *node_identifier_buf(AstNode *node) { assert(node->type == NodeTypeIdentifier); - RootStruct *root_struct = node->owner->data.structure.root_struct; - return token_identifier_buf(root_struct, node->main_token); -} - -Buf *node_string_literal_buf(AstNode *node) { - assert(node->type == NodeTypeStringLiteral); - RootStruct *root_struct = node->owner->data.structure.root_struct; - return token_string_literal_buf(root_struct, node->main_token); + // Currently, stage1 runs astgen for every comptime function call, + // resulting the allocation here wasting memory. As a workaround until + // the code is adjusted to make astgen run only once per source node, + // we memoize the result into the AST here. + if (node->data.identifier.name == nullptr) { + RootStruct *root_struct = node->owner->data.structure.root_struct; + node->data.identifier.name = token_identifier_buf(root_struct, node->main_token); + } + return node->data.identifier.name; } void token_number_literal_bigint(RootStruct *root_struct, BigInt *result, TokenIndex token) { diff --git a/src/stage1/parser.hpp b/src/stage1/parser.hpp index 2d9a5f0b4a..9f73444cb8 100644 --- a/src/stage1/parser.hpp +++ b/src/stage1/parser.hpp @@ -19,10 +19,8 @@ void ast_print(AstNode *node, int indent); void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *context), void *context); Buf *node_identifier_buf(AstNode *node); -Buf *node_string_literal_buf(AstNode *node); Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token); -Buf *token_string_literal_buf(RootStruct *root_struct, TokenIndex token); void token_number_literal_bigint(RootStruct *root_struct, BigInt *result, TokenIndex token); diff --git a/src/stage1/tokenizer.cpp b/src/stage1/tokenizer.cpp index 873a48b327..4550f32e8c 100644 --- a/src/stage1/tokenizer.cpp +++ b/src/stage1/tokenizer.cpp @@ -291,11 +291,11 @@ static void tokenize_error(Tokenize *t, const char *format, ...) { static void begin_token(Tokenize *t, TokenId id) { t->out->ids.append(id); - t->out->locs.append({ - .offset = (uint32_t) t->pos, - .line = t->line, - .column = t->column, - }); + TokenLoc tok_loc; + tok_loc.offset = (uint32_t) t->pos; + tok_loc.line = t->line; + tok_loc.column = t->column; + t->out->locs.append(tok_loc); } static void cancel_token(Tokenize *t) { -- cgit v1.2.3 From d888fa12a88ae7e5332de669b3c3a1dac57f5c19 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 28 May 2021 16:11:27 -0700 Subject: stage1 parser: fix the TODOs --- src/stage1/parser.cpp | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'src/stage1/parser.cpp') diff --git a/src/stage1/parser.cpp b/src/stage1/parser.cpp index 8cd624daad..b28c68e063 100644 --- a/src/stage1/parser.cpp +++ b/src/stage1/parser.cpp @@ -126,6 +126,19 @@ static AstNode *ast_parse_container_decl_auto(ParseContext *pc); static AstNode *ast_parse_container_decl_type(ParseContext *pc); static AstNode *ast_parse_byte_align(ParseContext *pc); +ATTRIBUTE_NORETURN +static void ast_error_offset(RootStruct *root_struct, ErrColor err_color, + TokenIndex token, size_t bad_index, Buf *msg) +{ + assert(token < root_struct->token_count); + uint32_t byte_offset = root_struct->token_locs[token].offset; + ErrorMsg *err = err_msg_create_with_offset(root_struct->path, + byte_offset + bad_index, buf_ptr(root_struct->source_code), msg); + + print_err_msg(err, err_color); + exit(EXIT_FAILURE); +} + ATTRIBUTE_PRINTF(3, 4) ATTRIBUTE_NORETURN static void ast_error(ParseContext *pc, TokenIndex token, const char *format, ...) { @@ -135,13 +148,7 @@ static void ast_error(ParseContext *pc, TokenIndex token, const char *format, .. va_end(ap); RootStruct *root_struct = pc->owner->data.structure.root_struct; - assert(token < root_struct->token_count); - uint32_t byte_offset = root_struct->token_locs[token].offset; - ErrorMsg *err = err_msg_create_with_offset(root_struct->path, - byte_offset, buf_ptr(root_struct->source_code), msg); - - print_err_msg(err, pc->err_color); - exit(EXIT_FAILURE); + ast_error_offset(root_struct, pc->err_color, token, 0, msg); } ATTRIBUTE_NORETURN @@ -202,20 +209,9 @@ static void put_back_token(ParseContext *pc) { pc->current_token -= 1; } -static Buf *token_string_literal_buf(RootStruct *root_struct, TokenIndex token) { +static Buf *token_buf(ParseContext *pc, TokenIndex token) { Error err; - assert(root_struct->token_ids[token] == TokenIdStringLiteral); - const char *source = buf_ptr(root_struct->source_code); - size_t byte_offset = root_struct->token_locs[token].offset; - size_t bad_index; - Buf *str = buf_alloc(); - if ((err = source_string_literal_buf(source + byte_offset, str, &bad_index))) { - zig_panic("TODO handle string literal parse error"); - } - return str; -} -static Buf *token_buf(ParseContext *pc, TokenIndex token) { if (token == 0) return nullptr; @@ -223,7 +219,16 @@ static Buf *token_buf(ParseContext *pc, TokenIndex token) { if (root_struct->token_ids[token] == TokenIdIdentifier) { return token_identifier_buf(root_struct, token); } else if (root_struct->token_ids[token] == TokenIdStringLiteral) { - return token_string_literal_buf(root_struct, token); + assert(root_struct->token_ids[token] == TokenIdStringLiteral); + const char *source = buf_ptr(root_struct->source_code); + size_t byte_offset = root_struct->token_locs[token].offset; + size_t bad_index; + Buf *str = buf_alloc(); + if ((err = source_string_literal_buf(source + byte_offset, str, &bad_index))) { + ast_error_offset(root_struct, pc->err_color, token, bad_index, + buf_create_from_str("invalid string literal character")); + } + return str; } else { zig_unreachable(); } @@ -3493,7 +3498,8 @@ Buf *token_identifier_buf(RootStruct *root_struct, TokenIndex token) { size_t bad_index; Buf *str = buf_alloc(); if ((err = source_string_literal_buf(source + byte_offset + 1, str, &bad_index))) { - zig_panic("TODO handle string literal parse error"); + ast_error_offset(root_struct, ErrColorAuto, token, bad_index + 1, + buf_create_from_str("invalid string literal character")); } return str; } else { -- cgit v1.2.3