| author | |
| committer | |
| log | d84055f9c69986f60087cf1a37f895362725f88d |
| tree | db8d825e72b6d5a7a6c8ff13c28a964308fb5972 |
| parent | ba74af2ae8c660ea3fbe0ea0483aa61bc7aaa06e |
| signature |
The main_token already has the necessary information.3 files changed, 14 insertions(+), 16 deletions(-)
lib/std/zig/Ast.zig+3-5| ... | @@ -1000,7 +1000,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1000,7 +1000,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1000 | .grouped_expression, .asm_input => return tree.nodeData(n).node_and_token[1] + end_offset, | 1000 | .grouped_expression, .asm_input => return tree.nodeData(n).node_and_token[1] + end_offset, |
| 1001 | .multiline_string_literal => return tree.nodeData(n).token_and_token[1] + end_offset, | 1001 | .multiline_string_literal => return tree.nodeData(n).token_and_token[1] + end_offset, |
| 1002 | .asm_output => return tree.nodeData(n).opt_node_and_token[1] + end_offset, | 1002 | .asm_output => return tree.nodeData(n).opt_node_and_token[1] + end_offset, |
| 1003 | .error_value => return tree.nodeData(n).opt_token_and_opt_token[1].unwrap().? + end_offset, | 1003 | .error_value => return tree.nodeMainToken(n) + 2 + end_offset, |
| 1004 | 1004 | ||
| 1005 | .anyframe_literal, | 1005 | .anyframe_literal, |
| 1006 | .char_literal, | 1006 | .char_literal, |
| ... | @@ -3713,7 +3713,7 @@ pub const Node = struct { | ... | @@ -3713,7 +3713,7 @@ pub const Node = struct { |
| 3713 | identifier, | 3713 | identifier, |
| 3714 | /// `.foo`. | 3714 | /// `.foo`. |
| 3715 | /// | 3715 | /// |
| 3716 | /// The `data` field is a `.token` to the `.`. | 3716 | /// The `data` field is unused. |
| 3717 | /// | 3717 | /// |
| 3718 | /// The `main_token` field is the identifier. | 3718 | /// The `main_token` field is the identifier. |
| 3719 | enum_literal, | 3719 | enum_literal, |
| ... | @@ -3930,9 +3930,7 @@ pub const Node = struct { | ... | @@ -3930,9 +3930,7 @@ pub const Node = struct { |
| 3930 | asm_input, | 3930 | asm_input, |
| 3931 | /// `error.a`. | 3931 | /// `error.a`. |
| 3932 | /// | 3932 | /// |
| 3933 | /// The `data` field is a `.opt_token_and_opt_token`: | 3933 | /// The `data` field is unused. |
| 3934 | /// 1. a `OptionalTokenIndex` of `.`. Can't be `.none` unless a parsing error occured. | ||
| 3935 | /// 2. a `OptionalTokenIndex` of `a`. Can't be `.none` unless a parsing error occured. | ||
| 3936 | /// | 3934 | /// |
| 3937 | /// The `main_token` field is `error` token. | 3935 | /// The `main_token` field is `error` token. |
| 3938 | error_value, | 3936 | error_value, |
lib/std/zig/AstGen.zig+2-2| ... | @@ -1012,7 +1012,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -1012,7 +1012,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 1012 | .ref_coerced_ty, .ptr, .inferred_ptr, .destructure => return rvalue(gz, ri, res, node), | 1012 | .ref_coerced_ty, .ptr, .inferred_ptr, .destructure => return rvalue(gz, ri, res, node), |
| 1013 | } | 1013 | } |
| 1014 | } else return simpleStrTok(gz, ri, tree.nodeMainToken(node), node, .enum_literal), | 1014 | } else return simpleStrTok(gz, ri, tree.nodeMainToken(node), node, .enum_literal), |
| 1015 | .error_value => return simpleStrTok(gz, ri, tree.nodeData(node).opt_token_and_opt_token[1].unwrap().?, node, .error_value), | 1015 | .error_value => return simpleStrTok(gz, ri, tree.nodeMainToken(node) + 2, node, .error_value), |
| 1016 | // TODO restore this when implementing https://github.com/ziglang/zig/issues/6025 | 1016 | // TODO restore this when implementing https://github.com/ziglang/zig/issues/6025 |
| 1017 | // .anyframe_literal => return rvalue(gz, ri, .anyframe_type, node), | 1017 | // .anyframe_literal => return rvalue(gz, ri, .anyframe_type, node), |
| 1018 | .anyframe_literal => { | 1018 | .anyframe_literal => { |
| ... | @@ -8184,7 +8184,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref | ... | @@ -8184,7 +8184,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref |
| 8184 | if (tree.nodeTag(operand_node) == .error_value) { | 8184 | if (tree.nodeTag(operand_node) == .error_value) { |
| 8185 | // Hot path for `return error.Foo`. This bypasses result location logic as well as logic | 8185 | // Hot path for `return error.Foo`. This bypasses result location logic as well as logic |
| 8186 | // for detecting whether to add something to the function's inferred error set. | 8186 | // for detecting whether to add something to the function's inferred error set. |
| 8187 | const ident_token = tree.nodeData(operand_node).opt_token_and_opt_token[1].unwrap().?; | 8187 | const ident_token = tree.nodeMainToken(operand_node) + 2; |
| 8188 | const err_name_str_index = try astgen.identAsString(ident_token); | 8188 | const err_name_str_index = try astgen.identAsString(ident_token); |
| 8189 | const defer_counts = countDefers(defer_outer, scope); | 8189 | const defer_counts = countDefers(defer_outer, scope); |
| 8190 | if (!defer_counts.need_err_code) { | 8190 | if (!defer_counts.need_err_code) { |
lib/std/zig/Parse.zig+9-9| ... | @@ -2647,11 +2647,14 @@ fn parsePrimaryTypeExpr(p: *Parse) !?Node.Index { | ... | @@ -2647,11 +2647,14 @@ fn parsePrimaryTypeExpr(p: *Parse) !?Node.Index { |
| 2647 | .keyword_for => return try p.parseFor(expectTypeExpr), | 2647 | .keyword_for => return try p.parseFor(expectTypeExpr), |
| 2648 | .keyword_while => return try p.parseWhileTypeExpr(), | 2648 | .keyword_while => return try p.parseWhileTypeExpr(), |
| 2649 | .period => switch (p.tokenTag(p.tok_i + 1)) { | 2649 | .period => switch (p.tokenTag(p.tok_i + 1)) { |
| 2650 | .identifier => return try p.addNode(.{ | 2650 | .identifier => { |
| 2651 | .tag = .enum_literal, | 2651 | p.tok_i += 1; |
| 2652 | .data = .{ .token = p.nextToken() }, // dot | 2652 | return try p.addNode(.{ |
| 2653 | .main_token = p.nextToken(), // identifier | 2653 | .tag = .enum_literal, |
| 2654 | }), | 2654 | .main_token = p.nextToken(), // identifier |
| 2655 | .data = undefined, | ||
| 2656 | }); | ||
| 2657 | }, | ||
| 2655 | .l_brace => { | 2658 | .l_brace => { |
| 2656 | const lbrace = p.tok_i + 1; | 2659 | const lbrace = p.tok_i + 1; |
| 2657 | p.tok_i = lbrace + 1; | 2660 | p.tok_i = lbrace + 1; |
| ... | @@ -2772,10 +2775,7 @@ fn parsePrimaryTypeExpr(p: *Parse) !?Node.Index { | ... | @@ -2772,10 +2775,7 @@ fn parsePrimaryTypeExpr(p: *Parse) !?Node.Index { |
| 2772 | return try p.addNode(.{ | 2775 | return try p.addNode(.{ |
| 2773 | .tag = .error_value, | 2776 | .tag = .error_value, |
| 2774 | .main_token = main_token, | 2777 | .main_token = main_token, |
| 2775 | .data = .{ .opt_token_and_opt_token = .{ | 2778 | .data = undefined, |
| 2776 | .fromOptional(period), | ||
| 2777 | .fromOptional(identifier), | ||
| 2778 | } }, | ||
| 2779 | }); | 2779 | }); |
| 2780 | }, | 2780 | }, |
| 2781 | }, | 2781 | }, |