std: add helper functions to std.zig.Ast for extracting data out of nodes
This commit is contained in:
296
src/AstGen.zig
296
src/AstGen.zig
@@ -771,8 +771,9 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
|
||||
|
||||
.identifier => return identifier(gz, scope, ri, node),
|
||||
|
||||
.asm_simple => return asmExpr(gz, scope, ri, node, tree.asmSimple(node)),
|
||||
.@"asm" => return asmExpr(gz, scope, ri, node, tree.asmFull(node)),
|
||||
.asm_simple,
|
||||
.@"asm",
|
||||
=> return asmExpr(gz, scope, ri, node, tree.fullAsm(node).?),
|
||||
|
||||
.string_literal => return stringLiteral(gz, ri, node),
|
||||
.multiline_string_literal => return multilineStringLiteral(gz, ri, node),
|
||||
@@ -797,12 +798,17 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
|
||||
return builtinCall(gz, scope, ri, node, params);
|
||||
},
|
||||
|
||||
.call_one, .call_one_comma, .async_call_one, .async_call_one_comma => {
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
return callExpr(gz, scope, ri, node, tree.callOne(¶ms, node));
|
||||
},
|
||||
.call, .call_comma, .async_call, .async_call_comma => {
|
||||
return callExpr(gz, scope, ri, node, tree.callFull(node));
|
||||
.call_one,
|
||||
.call_one_comma,
|
||||
.async_call_one,
|
||||
.async_call_one_comma,
|
||||
.call,
|
||||
.call_comma,
|
||||
.async_call,
|
||||
.async_call_comma,
|
||||
=> {
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
return callExpr(gz, scope, ri, node, tree.fullCall(&buf, node).?);
|
||||
},
|
||||
|
||||
.unreachable_literal => {
|
||||
@@ -819,15 +825,16 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
|
||||
.@"return" => return ret(gz, scope, node),
|
||||
.field_access => return fieldAccess(gz, scope, ri, node),
|
||||
|
||||
.if_simple => return ifExpr(gz, scope, ri.br(), node, tree.ifSimple(node)),
|
||||
.@"if" => return ifExpr(gz, scope, ri.br(), node, tree.ifFull(node)),
|
||||
.if_simple,
|
||||
.@"if",
|
||||
=> return ifExpr(gz, scope, ri.br(), node, tree.fullIf(node).?),
|
||||
|
||||
.while_simple => return whileExpr(gz, scope, ri.br(), node, tree.whileSimple(node), false),
|
||||
.while_cont => return whileExpr(gz, scope, ri.br(), node, tree.whileCont(node), false),
|
||||
.@"while" => return whileExpr(gz, scope, ri.br(), node, tree.whileFull(node), false),
|
||||
.while_simple,
|
||||
.while_cont,
|
||||
.@"while",
|
||||
=> return whileExpr(gz, scope, ri.br(), node, tree.fullWhile(node).?, false),
|
||||
|
||||
.for_simple => return forExpr(gz, scope, ri.br(), node, tree.forSimple(node), false),
|
||||
.@"for" => return forExpr(gz, scope, ri.br(), node, tree.forFull(node), false),
|
||||
.for_simple, .@"for" => return forExpr(gz, scope, ri.br(), node, tree.fullWhile(node).?, false),
|
||||
|
||||
.slice_open => {
|
||||
const lhs = try expr(gz, scope, .{ .rl = .ref }, node_datas[node].lhs);
|
||||
@@ -1012,32 +1019,28 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
|
||||
),
|
||||
},
|
||||
|
||||
.ptr_type_aligned => return ptrType(gz, scope, ri, node, tree.ptrTypeAligned(node)),
|
||||
.ptr_type_sentinel => return ptrType(gz, scope, ri, node, tree.ptrTypeSentinel(node)),
|
||||
.ptr_type => return ptrType(gz, scope, ri, node, tree.ptrType(node)),
|
||||
.ptr_type_bit_range => return ptrType(gz, scope, ri, node, tree.ptrTypeBitRange(node)),
|
||||
.ptr_type_aligned,
|
||||
.ptr_type_sentinel,
|
||||
.ptr_type,
|
||||
.ptr_type_bit_range,
|
||||
=> return ptrType(gz, scope, ri, node, tree.fullPtrType(node).?),
|
||||
|
||||
.container_decl,
|
||||
.container_decl_trailing,
|
||||
=> return containerDecl(gz, scope, ri, node, tree.containerDecl(node)),
|
||||
.container_decl_two, .container_decl_two_trailing => {
|
||||
var buffer: [2]Ast.Node.Index = undefined;
|
||||
return containerDecl(gz, scope, ri, node, tree.containerDeclTwo(&buffer, node));
|
||||
},
|
||||
.container_decl_arg,
|
||||
.container_decl_arg_trailing,
|
||||
=> return containerDecl(gz, scope, ri, node, tree.containerDeclArg(node)),
|
||||
|
||||
.container_decl_two,
|
||||
.container_decl_two_trailing,
|
||||
.tagged_union,
|
||||
.tagged_union_trailing,
|
||||
=> return containerDecl(gz, scope, ri, node, tree.taggedUnion(node)),
|
||||
.tagged_union_two, .tagged_union_two_trailing => {
|
||||
var buffer: [2]Ast.Node.Index = undefined;
|
||||
return containerDecl(gz, scope, ri, node, tree.taggedUnionTwo(&buffer, node));
|
||||
},
|
||||
.tagged_union_enum_tag,
|
||||
.tagged_union_enum_tag_trailing,
|
||||
=> return containerDecl(gz, scope, ri, node, tree.taggedUnionEnumTag(node)),
|
||||
.tagged_union_two,
|
||||
.tagged_union_two_trailing,
|
||||
=> {
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
return containerDecl(gz, scope, ri, node, tree.fullContainerDecl(&buf, node).?);
|
||||
},
|
||||
|
||||
.@"break" => return breakExpr(gz, scope, node),
|
||||
.@"continue" => return continueExpr(gz, scope, node),
|
||||
@@ -1057,49 +1060,39 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
|
||||
|
||||
.@"try" => return tryExpr(gz, scope, ri, node, node_datas[node].lhs),
|
||||
|
||||
.array_init_one, .array_init_one_comma => {
|
||||
var elements: [1]Ast.Node.Index = undefined;
|
||||
return arrayInitExpr(gz, scope, ri, node, tree.arrayInitOne(&elements, node));
|
||||
},
|
||||
.array_init_dot_two, .array_init_dot_two_comma => {
|
||||
var elements: [2]Ast.Node.Index = undefined;
|
||||
return arrayInitExpr(gz, scope, ri, node, tree.arrayInitDotTwo(&elements, node));
|
||||
},
|
||||
.array_init_one,
|
||||
.array_init_one_comma,
|
||||
.array_init_dot_two,
|
||||
.array_init_dot_two_comma,
|
||||
.array_init_dot,
|
||||
.array_init_dot_comma,
|
||||
=> return arrayInitExpr(gz, scope, ri, node, tree.arrayInitDot(node)),
|
||||
.array_init,
|
||||
.array_init_comma,
|
||||
=> return arrayInitExpr(gz, scope, ri, node, tree.arrayInit(node)),
|
||||
=> {
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
return arrayInitExpr(gz, scope, ri, node, tree.fullArrayInit(&buf, node).?);
|
||||
},
|
||||
|
||||
.struct_init_one, .struct_init_one_comma => {
|
||||
var fields: [1]Ast.Node.Index = undefined;
|
||||
return structInitExpr(gz, scope, ri, node, tree.structInitOne(&fields, node));
|
||||
},
|
||||
.struct_init_dot_two, .struct_init_dot_two_comma => {
|
||||
var fields: [2]Ast.Node.Index = undefined;
|
||||
return structInitExpr(gz, scope, ri, node, tree.structInitDotTwo(&fields, node));
|
||||
},
|
||||
.struct_init_one,
|
||||
.struct_init_one_comma,
|
||||
.struct_init_dot_two,
|
||||
.struct_init_dot_two_comma,
|
||||
.struct_init_dot,
|
||||
.struct_init_dot_comma,
|
||||
=> return structInitExpr(gz, scope, ri, node, tree.structInitDot(node)),
|
||||
.struct_init,
|
||||
.struct_init_comma,
|
||||
=> return structInitExpr(gz, scope, ri, node, tree.structInit(node)),
|
||||
=> {
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
return structInitExpr(gz, scope, ri, node, tree.fullStructInit(&buf, node).?);
|
||||
},
|
||||
|
||||
.fn_proto_simple => {
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
return fnProtoExpr(gz, scope, ri, node, tree.fnProtoSimple(¶ms, node));
|
||||
},
|
||||
.fn_proto_multi => {
|
||||
return fnProtoExpr(gz, scope, ri, node, tree.fnProtoMulti(node));
|
||||
},
|
||||
.fn_proto_one => {
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
return fnProtoExpr(gz, scope, ri, node, tree.fnProtoOne(¶ms, node));
|
||||
},
|
||||
.fn_proto => {
|
||||
return fnProtoExpr(gz, scope, ri, node, tree.fnProto(node));
|
||||
.fn_proto_simple,
|
||||
.fn_proto_multi,
|
||||
.fn_proto_one,
|
||||
.fn_proto,
|
||||
=> {
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
return fnProtoExpr(gz, scope, ri, node, tree.fullFnProto(&buf, node).?);
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1374,11 +1367,7 @@ fn arrayInitExpr(
|
||||
};
|
||||
|
||||
infer: {
|
||||
const array_type: Ast.full.ArrayType = switch (node_tags[array_init.ast.type_expr]) {
|
||||
.array_type => tree.arrayType(array_init.ast.type_expr),
|
||||
.array_type_sentinel => tree.arrayTypeSentinel(array_init.ast.type_expr),
|
||||
else => break :infer,
|
||||
};
|
||||
const array_type: Ast.full.ArrayType = tree.fullArrayType(array_init.ast.type_expr) orelse break :infer;
|
||||
// This intentionally does not support `@"_"` syntax.
|
||||
if (node_tags[array_type.ast.elem_count] == .identifier and
|
||||
mem.eql(u8, tree.tokenSlice(main_tokens[array_type.ast.elem_count]), "_"))
|
||||
@@ -1606,17 +1595,13 @@ fn structInitExpr(
|
||||
} else array: {
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const main_tokens = tree.nodes.items(.main_token);
|
||||
const array_type: Ast.full.ArrayType = switch (node_tags[struct_init.ast.type_expr]) {
|
||||
.array_type => tree.arrayType(struct_init.ast.type_expr),
|
||||
.array_type_sentinel => tree.arrayTypeSentinel(struct_init.ast.type_expr),
|
||||
else => {
|
||||
if (struct_init.ast.fields.len == 0) {
|
||||
const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
|
||||
const result = try gz.addUnNode(.struct_init_empty, ty_inst, node);
|
||||
return rvalue(gz, ri, result, node);
|
||||
}
|
||||
break :array;
|
||||
},
|
||||
const array_type: Ast.full.ArrayType = tree.fullArrayType(struct_init.ast.type_expr) orelse {
|
||||
if (struct_init.ast.fields.len == 0) {
|
||||
const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
|
||||
const result = try gz.addUnNode(.struct_init_empty, ty_inst, node);
|
||||
return rvalue(gz, ri, result, node);
|
||||
}
|
||||
break :array;
|
||||
};
|
||||
const is_inferred_array_len = node_tags[array_type.ast.elem_count] == .identifier and
|
||||
// This intentionally does not support `@"_"` syntax.
|
||||
@@ -2321,10 +2306,10 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod
|
||||
while (true) {
|
||||
switch (node_tags[inner_node]) {
|
||||
// zig fmt: off
|
||||
.global_var_decl => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.globalVarDecl(statement)),
|
||||
.local_var_decl => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.localVarDecl(statement)),
|
||||
.simple_var_decl => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.simpleVarDecl(statement)),
|
||||
.aligned_var_decl => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.alignedVarDecl(statement)),
|
||||
.global_var_decl,
|
||||
.local_var_decl,
|
||||
.simple_var_decl,
|
||||
.aligned_var_decl, => scope = try varDecl(gz, scope, statement, block_arena_allocator, tree.fullVarDecl(statement).?),
|
||||
|
||||
.@"defer" => scope = try deferStmt(gz, scope, statement, block_arena_allocator, .defer_normal),
|
||||
.@"errdefer" => scope = try deferStmt(gz, scope, statement, block_arena_allocator, .defer_error),
|
||||
@@ -2351,12 +2336,12 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod
|
||||
continue;
|
||||
},
|
||||
|
||||
.while_simple => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.whileSimple(inner_node), true),
|
||||
.while_cont => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.whileCont(inner_node), true),
|
||||
.@"while" => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.whileFull(inner_node), true),
|
||||
.while_simple,
|
||||
.while_cont,
|
||||
.@"while", => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.fullWhile(inner_node).?, true),
|
||||
|
||||
.for_simple => _ = try forExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.forSimple(inner_node), true),
|
||||
.@"for" => _ = try forExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.forFull(inner_node), true),
|
||||
.for_simple,
|
||||
.@"for", => _ = try forExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.fullWhile(inner_node).?, true),
|
||||
|
||||
else => noreturn_src_node = try unusedResultExpr(gz, scope, inner_node),
|
||||
// zig fmt: on
|
||||
@@ -4491,12 +4476,8 @@ fn structDeclInner(
|
||||
var is_tuple = false;
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
for (container_decl.ast.members) |member_node| {
|
||||
switch (node_tags[member_node]) {
|
||||
.container_field_init => is_tuple = tree.containerFieldInit(member_node).ast.tuple_like,
|
||||
.container_field_align => is_tuple = tree.containerFieldAlign(member_node).ast.tuple_like,
|
||||
.container_field => is_tuple = tree.containerField(member_node).ast.tuple_like,
|
||||
else => continue,
|
||||
}
|
||||
const container_field = tree.fullContainerField(member_node) orelse continue;
|
||||
is_tuple = container_field.ast.tuple_like;
|
||||
if (is_tuple) break;
|
||||
}
|
||||
if (is_tuple) for (container_decl.ast.members) |member_node| {
|
||||
@@ -4802,7 +4783,6 @@ fn containerDecl(
|
||||
const gpa = astgen.gpa;
|
||||
const tree = astgen.tree;
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
|
||||
const prev_fn_block = astgen.fn_block;
|
||||
astgen.fn_block = null;
|
||||
@@ -4844,14 +4824,9 @@ fn containerDecl(
|
||||
var nonexhaustive_node: Ast.Node.Index = 0;
|
||||
var nonfinal_nonexhaustive = false;
|
||||
for (container_decl.ast.members) |member_node| {
|
||||
var member = switch (node_tags[member_node]) {
|
||||
.container_field_init => tree.containerFieldInit(member_node),
|
||||
.container_field_align => tree.containerFieldAlign(member_node),
|
||||
.container_field => tree.containerField(member_node),
|
||||
else => {
|
||||
decls += 1;
|
||||
continue;
|
||||
},
|
||||
var member = tree.fullContainerField(member_node) orelse {
|
||||
decls += 1;
|
||||
continue;
|
||||
};
|
||||
member.convertToNonTupleLike(astgen.tree.nodes);
|
||||
if (member.ast.tuple_like) {
|
||||
@@ -5114,90 +5089,33 @@ fn containerMember(
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
switch (node_tags[member_node]) {
|
||||
.container_field_init => return ContainerMemberResult{ .field = tree.containerFieldInit(member_node) },
|
||||
.container_field_align => return ContainerMemberResult{ .field = tree.containerFieldAlign(member_node) },
|
||||
.container_field => return ContainerMemberResult{ .field = tree.containerField(member_node) },
|
||||
.container_field_init,
|
||||
.container_field_align,
|
||||
.container_field,
|
||||
=> return ContainerMemberResult{ .field = tree.fullContainerField(member_node).? },
|
||||
|
||||
.fn_decl => {
|
||||
const fn_proto = node_datas[member_node].lhs;
|
||||
const body = node_datas[member_node].rhs;
|
||||
switch (node_tags[fn_proto]) {
|
||||
.fn_proto_simple => {
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
astgen.fnDecl(gz, scope, wip_members, member_node, body, tree.fnProtoSimple(¶ms, fn_proto)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
.fn_proto_multi => {
|
||||
astgen.fnDecl(gz, scope, wip_members, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
.fn_proto_one => {
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
astgen.fnDecl(gz, scope, wip_members, member_node, body, tree.fnProtoOne(¶ms, fn_proto)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
.fn_proto => {
|
||||
astgen.fnDecl(gz, scope, wip_members, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
},
|
||||
.fn_proto_simple => {
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
astgen.fnDecl(gz, scope, wip_members, member_node, 0, tree.fnProtoSimple(¶ms, member_node)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
.fn_proto_multi => {
|
||||
astgen.fnDecl(gz, scope, wip_members, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
.fn_proto_one => {
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
astgen.fnDecl(gz, scope, wip_members, member_node, 0, tree.fnProtoOne(¶ms, member_node)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
.fn_proto => {
|
||||
astgen.fnDecl(gz, scope, wip_members, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) {
|
||||
.fn_proto,
|
||||
.fn_proto_multi,
|
||||
.fn_proto_one,
|
||||
.fn_proto_simple,
|
||||
.fn_decl,
|
||||
=> {
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullFnProto(&buf, member_node).?;
|
||||
const body = if (node_tags[member_node] == .fn_decl) node_datas[member_node].rhs else 0;
|
||||
|
||||
astgen.fnDecl(gz, scope, wip_members, member_node, body, full) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
|
||||
.global_var_decl => {
|
||||
astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
.local_var_decl => {
|
||||
astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
.simple_var_decl => {
|
||||
astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
},
|
||||
.aligned_var_decl => {
|
||||
astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) {
|
||||
.global_var_decl,
|
||||
.local_var_decl,
|
||||
.simple_var_decl,
|
||||
.aligned_var_decl,
|
||||
=> {
|
||||
astgen.globalVarDecl(gz, scope, wip_members, member_node, tree.fullVarDecl(member_node).?) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.AnalysisFail => {},
|
||||
};
|
||||
@@ -6538,11 +6456,7 @@ fn switchExpr(
|
||||
var else_src: ?Ast.TokenIndex = null;
|
||||
var underscore_src: ?Ast.TokenIndex = null;
|
||||
for (case_nodes) |case_node| {
|
||||
const case = switch (node_tags[case_node]) {
|
||||
.switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
|
||||
.switch_case, .switch_case_inline => tree.switchCase(case_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const case = tree.fullSwitchCase(case_node).?;
|
||||
if (case.payload_token) |payload_token| {
|
||||
if (token_tags[payload_token] == .asterisk) {
|
||||
any_payload_is_ref = true;
|
||||
@@ -6689,11 +6603,7 @@ fn switchExpr(
|
||||
var multi_case_index: u32 = 0;
|
||||
var scalar_case_index: u32 = 0;
|
||||
for (case_nodes) |case_node| {
|
||||
const case = switch (node_tags[case_node]) {
|
||||
.switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
|
||||
.switch_case, .switch_case_inline => tree.switchCase(case_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const case = tree.fullSwitchCase(case_node).?;
|
||||
|
||||
const is_multi_case = case.ast.values.len > 1 or
|
||||
(case.ast.values.len == 1 and node_tags[case.ast.values[0]] == .switch_range);
|
||||
|
||||
484
src/Module.zig
484
src/Module.zig
@@ -1040,34 +1040,13 @@ pub const Struct = struct {
|
||||
return s.srcLoc(mod);
|
||||
};
|
||||
const node = owner_decl.relativeToNodeIndex(0);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
switch (node_tags[node]) {
|
||||
.container_decl,
|
||||
.container_decl_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.containerDecl(node)),
|
||||
.container_decl_two, .container_decl_two_trailing => {
|
||||
var buffer: [2]Ast.Node.Index = undefined;
|
||||
return queryFieldSrc(tree.*, query, file, tree.containerDeclTwo(&buffer, node));
|
||||
},
|
||||
.container_decl_arg,
|
||||
.container_decl_arg_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.containerDeclArg(node)),
|
||||
|
||||
.tagged_union,
|
||||
.tagged_union_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.taggedUnion(node)),
|
||||
.tagged_union_two, .tagged_union_two_trailing => {
|
||||
var buffer: [2]Ast.Node.Index = undefined;
|
||||
return queryFieldSrc(tree.*, query, file, tree.taggedUnionTwo(&buffer, node));
|
||||
},
|
||||
.tagged_union_enum_tag,
|
||||
.tagged_union_enum_tag_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.taggedUnionEnumTag(node)),
|
||||
|
||||
.root => return queryFieldSrc(tree.*, query, file, tree.containerDeclRoot()),
|
||||
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
if (tree.fullContainerDecl(&buf, node)) |container_decl| {
|
||||
return queryFieldSrc(tree.*, query, file, container_decl);
|
||||
} else {
|
||||
// This struct was generated using @Type
|
||||
else => return s.srcLoc(mod),
|
||||
return s.srcLoc(mod);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1207,34 +1186,12 @@ pub const EnumFull = struct {
|
||||
return e.srcLoc(mod);
|
||||
};
|
||||
const node = owner_decl.relativeToNodeIndex(0);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
switch (node_tags[node]) {
|
||||
.container_decl,
|
||||
.container_decl_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.containerDecl(node)),
|
||||
.container_decl_two, .container_decl_two_trailing => {
|
||||
var buffer: [2]Ast.Node.Index = undefined;
|
||||
return queryFieldSrc(tree.*, query, file, tree.containerDeclTwo(&buffer, node));
|
||||
},
|
||||
.container_decl_arg,
|
||||
.container_decl_arg_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.containerDeclArg(node)),
|
||||
|
||||
.tagged_union,
|
||||
.tagged_union_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.taggedUnion(node)),
|
||||
.tagged_union_two, .tagged_union_two_trailing => {
|
||||
var buffer: [2]Ast.Node.Index = undefined;
|
||||
return queryFieldSrc(tree.*, query, file, tree.taggedUnionTwo(&buffer, node));
|
||||
},
|
||||
.tagged_union_enum_tag,
|
||||
.tagged_union_enum_tag_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.taggedUnionEnumTag(node)),
|
||||
|
||||
.root => return queryFieldSrc(tree.*, query, file, tree.containerDeclRoot()),
|
||||
|
||||
// This struct was generated using @Type
|
||||
else => return e.srcLoc(mod),
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
if (tree.fullContainerDecl(&buf, node)) |container_decl| {
|
||||
return queryFieldSrc(tree.*, query, file, container_decl);
|
||||
} else {
|
||||
// This enum was generated using @Type
|
||||
return e.srcLoc(mod);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1315,30 +1272,13 @@ pub const Union = struct {
|
||||
return u.srcLoc(mod);
|
||||
};
|
||||
const node = owner_decl.relativeToNodeIndex(0);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
switch (node_tags[node]) {
|
||||
.container_decl,
|
||||
.container_decl_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.containerDecl(node)),
|
||||
.container_decl_two, .container_decl_two_trailing => {
|
||||
var buffer: [2]Ast.Node.Index = undefined;
|
||||
return queryFieldSrc(tree.*, query, file, tree.containerDeclTwo(&buffer, node));
|
||||
},
|
||||
.container_decl_arg,
|
||||
.container_decl_arg_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.containerDeclArg(node)),
|
||||
.tagged_union,
|
||||
.tagged_union_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.taggedUnion(node)),
|
||||
.tagged_union_two,
|
||||
.tagged_union_two_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.taggedUnionTwo(&buf, node)),
|
||||
.tagged_union_enum_tag,
|
||||
.tagged_union_enum_tag_trailing,
|
||||
=> return queryFieldSrc(tree.*, query, file, tree.taggedUnionEnumTag(node)),
|
||||
if (tree.fullContainerDecl(&buf, node)) |container_decl| {
|
||||
return queryFieldSrc(tree.*, query, file, container_decl);
|
||||
} else {
|
||||
// This union was generated using @Type
|
||||
else => return u.srcLoc(mod),
|
||||
return u.srcLoc(mod);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2304,10 +2244,11 @@ pub const SrcLoc = struct {
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const full = switch (node_tags[node]) {
|
||||
.global_var_decl => tree.globalVarDecl(node),
|
||||
.local_var_decl => tree.localVarDecl(node),
|
||||
.simple_var_decl => tree.simpleVarDecl(node),
|
||||
.aligned_var_decl => tree.alignedVarDecl(node),
|
||||
.global_var_decl,
|
||||
.local_var_decl,
|
||||
.simple_var_decl,
|
||||
.aligned_var_decl,
|
||||
=> tree.fullVarDecl(node).?,
|
||||
.@"usingnamespace" => {
|
||||
const node_data = tree.nodes.items(.data);
|
||||
return nodeToSpan(tree, node_data[node].lhs);
|
||||
@@ -2325,53 +2266,25 @@ pub const SrcLoc = struct {
|
||||
.node_offset_var_decl_align => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const full: Ast.full.VarDecl = switch (node_tags[node]) {
|
||||
.global_var_decl => tree.globalVarDecl(node),
|
||||
.local_var_decl => tree.localVarDecl(node),
|
||||
.simple_var_decl => tree.simpleVarDecl(node),
|
||||
.aligned_var_decl => tree.alignedVarDecl(node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullVarDecl(node).?;
|
||||
return nodeToSpan(tree, full.ast.align_node);
|
||||
},
|
||||
.node_offset_var_decl_section => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const full: Ast.full.VarDecl = switch (node_tags[node]) {
|
||||
.global_var_decl => tree.globalVarDecl(node),
|
||||
.local_var_decl => tree.localVarDecl(node),
|
||||
.simple_var_decl => tree.simpleVarDecl(node),
|
||||
.aligned_var_decl => tree.alignedVarDecl(node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullVarDecl(node).?;
|
||||
return nodeToSpan(tree, full.ast.section_node);
|
||||
},
|
||||
.node_offset_var_decl_addrspace => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const full: Ast.full.VarDecl = switch (node_tags[node]) {
|
||||
.global_var_decl => tree.globalVarDecl(node),
|
||||
.local_var_decl => tree.localVarDecl(node),
|
||||
.simple_var_decl => tree.simpleVarDecl(node),
|
||||
.aligned_var_decl => tree.alignedVarDecl(node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullVarDecl(node).?;
|
||||
return nodeToSpan(tree, full.ast.addrspace_node);
|
||||
},
|
||||
.node_offset_var_decl_init => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const full: Ast.full.VarDecl = switch (node_tags[node]) {
|
||||
.global_var_decl => tree.globalVarDecl(node),
|
||||
.local_var_decl => tree.localVarDecl(node),
|
||||
.simple_var_decl => tree.simpleVarDecl(node),
|
||||
.aligned_var_decl => tree.alignedVarDecl(node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullVarDecl(node).?;
|
||||
return nodeToSpan(tree, full.ast.init_node);
|
||||
},
|
||||
.node_offset_builtin_call_arg0 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 0),
|
||||
@@ -2392,14 +2305,8 @@ pub const SrcLoc = struct {
|
||||
.node_offset_slice_sentinel,
|
||||
=> |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const full = switch (node_tags[node]) {
|
||||
.slice_open => tree.sliceOpen(node),
|
||||
.slice => tree.slice(node),
|
||||
.slice_sentinel => tree.sliceSentinel(node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullSlice(node).?;
|
||||
const part_node = switch (src_loc.lazy) {
|
||||
.node_offset_slice_ptr => full.ast.sliced,
|
||||
.node_offset_slice_start => full.ast.start,
|
||||
@@ -2411,24 +2318,9 @@ pub const SrcLoc = struct {
|
||||
},
|
||||
.node_offset_call_func => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
const full = switch (node_tags[node]) {
|
||||
.call_one,
|
||||
.call_one_comma,
|
||||
.async_call_one,
|
||||
.async_call_one_comma,
|
||||
=> tree.callOne(¶ms, node),
|
||||
|
||||
.call,
|
||||
.call_comma,
|
||||
.async_call,
|
||||
.async_call_comma,
|
||||
=> tree.callFull(node),
|
||||
|
||||
else => unreachable,
|
||||
};
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullCall(&buf, node).?;
|
||||
return nodeToSpan(tree, full.ast.fn_expr);
|
||||
},
|
||||
.node_offset_field_name => |node_off| {
|
||||
@@ -2451,24 +2343,14 @@ pub const SrcLoc = struct {
|
||||
},
|
||||
.node_offset_asm_source => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const full = switch (node_tags[node]) {
|
||||
.asm_simple => tree.asmSimple(node),
|
||||
.@"asm" => tree.asmFull(node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullAsm(node).?;
|
||||
return nodeToSpan(tree, full.ast.template);
|
||||
},
|
||||
.node_offset_asm_ret_ty => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const full = switch (node_tags[node]) {
|
||||
.asm_simple => tree.asmSimple(node),
|
||||
.@"asm" => tree.asmFull(node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullAsm(node).?;
|
||||
const asm_output = full.outputs[0];
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
return nodeToSpan(tree, node_datas[asm_output].lhs);
|
||||
@@ -2479,13 +2361,17 @@ pub const SrcLoc = struct {
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const src_node = switch (node_tags[node]) {
|
||||
.if_simple => tree.ifSimple(node).ast.cond_expr,
|
||||
.@"if" => tree.ifFull(node).ast.cond_expr,
|
||||
.while_simple => tree.whileSimple(node).ast.cond_expr,
|
||||
.while_cont => tree.whileCont(node).ast.cond_expr,
|
||||
.@"while" => tree.whileFull(node).ast.cond_expr,
|
||||
.for_simple => tree.forSimple(node).ast.cond_expr,
|
||||
.@"for" => tree.forFull(node).ast.cond_expr,
|
||||
.if_simple,
|
||||
.@"if",
|
||||
=> tree.fullIf(node).?.ast.cond_expr,
|
||||
|
||||
.while_simple,
|
||||
.while_cont,
|
||||
.@"while",
|
||||
.for_simple,
|
||||
.@"for",
|
||||
=> tree.fullWhile(node).?.ast.cond_expr,
|
||||
|
||||
.@"orelse" => node,
|
||||
.@"catch" => node,
|
||||
else => unreachable,
|
||||
@@ -2521,11 +2407,7 @@ pub const SrcLoc = struct {
|
||||
const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
|
||||
const case_nodes = tree.extra_data[extra.start..extra.end];
|
||||
for (case_nodes) |case_node| {
|
||||
const case = switch (node_tags[case_node]) {
|
||||
.switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
|
||||
.switch_case, .switch_case_inline => tree.switchCase(case_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const case = tree.fullSwitchCase(case_node).?;
|
||||
const is_special = (case.ast.values.len == 0) or
|
||||
(case.ast.values.len == 1 and
|
||||
node_tags[case.ast.values[0]] == .identifier and
|
||||
@@ -2545,11 +2427,7 @@ pub const SrcLoc = struct {
|
||||
const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
|
||||
const case_nodes = tree.extra_data[extra.start..extra.end];
|
||||
for (case_nodes) |case_node| {
|
||||
const case = switch (node_tags[case_node]) {
|
||||
.switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
|
||||
.switch_case, .switch_case_inline => tree.switchCase(case_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const case = tree.fullSwitchCase(case_node).?;
|
||||
const is_special = (case.ast.values.len == 0) or
|
||||
(case.ast.values.len == 1 and
|
||||
node_tags[case.ast.values[0]] == .identifier and
|
||||
@@ -2566,12 +2444,7 @@ pub const SrcLoc = struct {
|
||||
.node_offset_switch_prong_capture => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const case_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const case = switch (node_tags[case_node]) {
|
||||
.switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
|
||||
.switch_case, .switch_case_inline => tree.switchCase(case_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const case = tree.fullSwitchCase(case_node).?;
|
||||
const start_tok = case.payload_token.?;
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
const end_tok = switch (token_tags[start_tok]) {
|
||||
@@ -2585,116 +2458,38 @@ pub const SrcLoc = struct {
|
||||
},
|
||||
.node_offset_fn_type_align => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
const full = switch (node_tags[node]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node),
|
||||
.fn_proto => tree.fnProto(node),
|
||||
.fn_decl => switch (node_tags[node_datas[node].lhs]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node_datas[node].lhs),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node_datas[node].lhs),
|
||||
.fn_proto => tree.fnProto(node_datas[node].lhs),
|
||||
else => unreachable,
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullFnProto(&buf, node).?;
|
||||
return nodeToSpan(tree, full.ast.align_expr);
|
||||
},
|
||||
.node_offset_fn_type_addrspace => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
const full = switch (node_tags[node]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node),
|
||||
.fn_proto => tree.fnProto(node),
|
||||
.fn_decl => switch (node_tags[node_datas[node].lhs]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node_datas[node].lhs),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node_datas[node].lhs),
|
||||
.fn_proto => tree.fnProto(node_datas[node].lhs),
|
||||
else => unreachable,
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullFnProto(&buf, node).?;
|
||||
return nodeToSpan(tree, full.ast.addrspace_expr);
|
||||
},
|
||||
.node_offset_fn_type_section => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
const full = switch (node_tags[node]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node),
|
||||
.fn_proto => tree.fnProto(node),
|
||||
.fn_decl => switch (node_tags[node_datas[node].lhs]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node_datas[node].lhs),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node_datas[node].lhs),
|
||||
.fn_proto => tree.fnProto(node_datas[node].lhs),
|
||||
else => unreachable,
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullFnProto(&buf, node).?;
|
||||
return nodeToSpan(tree, full.ast.section_expr);
|
||||
},
|
||||
.node_offset_fn_type_cc => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
const full = switch (node_tags[node]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node),
|
||||
.fn_proto => tree.fnProto(node),
|
||||
.fn_decl => switch (node_tags[node_datas[node].lhs]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node_datas[node].lhs),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node_datas[node].lhs),
|
||||
.fn_proto => tree.fnProto(node_datas[node].lhs),
|
||||
else => unreachable,
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullFnProto(&buf, node).?;
|
||||
return nodeToSpan(tree, full.ast.callconv_expr);
|
||||
},
|
||||
|
||||
.node_offset_fn_type_ret_ty => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
const full = switch (node_tags[node]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node),
|
||||
.fn_proto => tree.fnProto(node),
|
||||
.fn_decl => blk: {
|
||||
const fn_proto = node_datas[node].lhs;
|
||||
break :blk switch (node_tags[fn_proto]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, fn_proto),
|
||||
.fn_proto_multi => tree.fnProtoMulti(fn_proto),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, fn_proto),
|
||||
.fn_proto => tree.fnProto(fn_proto),
|
||||
else => unreachable,
|
||||
};
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullFnProto(&buf, node).?;
|
||||
return nodeToSpan(tree, full.ast.return_type);
|
||||
},
|
||||
.node_offset_param => |node_off| {
|
||||
@@ -2742,27 +2537,9 @@ pub const SrcLoc = struct {
|
||||
|
||||
.node_offset_lib_name => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
const full = switch (node_tags[parent_node]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, parent_node),
|
||||
.fn_proto_multi => tree.fnProtoMulti(parent_node),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, parent_node),
|
||||
.fn_proto => tree.fnProto(parent_node),
|
||||
.fn_decl => blk: {
|
||||
const fn_proto = node_datas[parent_node].lhs;
|
||||
break :blk switch (node_tags[fn_proto]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, fn_proto),
|
||||
.fn_proto_multi => tree.fnProtoMulti(fn_proto),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, fn_proto),
|
||||
.fn_proto => tree.fnProto(fn_proto),
|
||||
else => unreachable,
|
||||
};
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullFnProto(&buf, parent_node).?;
|
||||
const tok_index = full.lib_name.?;
|
||||
const start = tree.tokens.items(.start)[tok_index];
|
||||
const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);
|
||||
@@ -2771,38 +2548,23 @@ pub const SrcLoc = struct {
|
||||
|
||||
.node_offset_array_type_len => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
const full: Ast.full.ArrayType = switch (node_tags[parent_node]) {
|
||||
.array_type => tree.arrayType(parent_node),
|
||||
.array_type_sentinel => tree.arrayTypeSentinel(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullArrayType(parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.elem_count);
|
||||
},
|
||||
.node_offset_array_type_sentinel => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
const full: Ast.full.ArrayType = switch (node_tags[parent_node]) {
|
||||
.array_type => tree.arrayType(parent_node),
|
||||
.array_type_sentinel => tree.arrayTypeSentinel(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullArrayType(parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.sentinel);
|
||||
},
|
||||
.node_offset_array_type_elem => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
const full: Ast.full.ArrayType = switch (node_tags[parent_node]) {
|
||||
.array_type => tree.arrayType(parent_node),
|
||||
.array_type_sentinel => tree.arrayTypeSentinel(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullArrayType(parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.elem_type);
|
||||
},
|
||||
.node_offset_un_op => |node_off| {
|
||||
@@ -2814,86 +2576,44 @@ pub const SrcLoc = struct {
|
||||
},
|
||||
.node_offset_ptr_elem => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
|
||||
.ptr_type_aligned => tree.ptrTypeAligned(parent_node),
|
||||
.ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
|
||||
.ptr_type => tree.ptrType(parent_node),
|
||||
.ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullPtrType(parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.child_type);
|
||||
},
|
||||
.node_offset_ptr_sentinel => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
|
||||
.ptr_type_aligned => tree.ptrTypeAligned(parent_node),
|
||||
.ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
|
||||
.ptr_type => tree.ptrType(parent_node),
|
||||
.ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullPtrType(parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.sentinel);
|
||||
},
|
||||
.node_offset_ptr_align => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
|
||||
.ptr_type_aligned => tree.ptrTypeAligned(parent_node),
|
||||
.ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
|
||||
.ptr_type => tree.ptrType(parent_node),
|
||||
.ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullPtrType(parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.align_node);
|
||||
},
|
||||
.node_offset_ptr_addrspace => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
|
||||
.ptr_type_aligned => tree.ptrTypeAligned(parent_node),
|
||||
.ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
|
||||
.ptr_type => tree.ptrType(parent_node),
|
||||
.ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullPtrType(parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.addrspace_node);
|
||||
},
|
||||
.node_offset_ptr_bitoffset => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
|
||||
.ptr_type_aligned => tree.ptrTypeAligned(parent_node),
|
||||
.ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
|
||||
.ptr_type => tree.ptrType(parent_node),
|
||||
.ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullPtrType(parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.bit_range_start);
|
||||
},
|
||||
.node_offset_ptr_hostsize => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
const full: Ast.full.PtrType = switch (node_tags[parent_node]) {
|
||||
.ptr_type_aligned => tree.ptrTypeAligned(parent_node),
|
||||
.ptr_type_sentinel => tree.ptrTypeSentinel(parent_node),
|
||||
.ptr_type => tree.ptrType(parent_node),
|
||||
.ptr_type_bit_range => tree.ptrTypeBitRange(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullPtrType(parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.bit_range_end);
|
||||
},
|
||||
.node_offset_container_tag => |node_off| {
|
||||
@@ -2933,17 +2653,10 @@ pub const SrcLoc = struct {
|
||||
},
|
||||
.node_offset_init_ty => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const parent_node = src_loc.declRelativeToNodeIndex(node_off);
|
||||
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
const full: Ast.full.ArrayInit = switch (node_tags[parent_node]) {
|
||||
.array_init_one, .array_init_one_comma => tree.arrayInitOne(buf[0..1], parent_node),
|
||||
.array_init_dot_two, .array_init_dot_two_comma => tree.arrayInitDotTwo(&buf, parent_node),
|
||||
.array_init_dot, .array_init_dot_comma => tree.arrayInitDot(parent_node),
|
||||
.array_init, .array_init_comma => tree.arrayInit(parent_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const full = tree.fullArrayInit(&buf, parent_node).?;
|
||||
return nodeToSpan(tree, full.ast.type_expr);
|
||||
},
|
||||
.node_offset_store_ptr => |node_off| {
|
||||
@@ -6097,11 +5810,7 @@ pub const SwitchProngSrc = union(enum) {
|
||||
var multi_i: u32 = 0;
|
||||
var scalar_i: u32 = 0;
|
||||
for (case_nodes) |case_node| {
|
||||
const case = switch (node_tags[case_node]) {
|
||||
.switch_case_one, .switch_case_inline_one => tree.switchCaseOne(case_node),
|
||||
.switch_case, .switch_case_inline => tree.switchCase(case_node),
|
||||
else => unreachable,
|
||||
};
|
||||
const case = tree.fullSwitchCase(case_node).?;
|
||||
if (case.ast.values.len == 0)
|
||||
continue;
|
||||
if (case.ast.values.len == 1 and
|
||||
@@ -6223,15 +5932,9 @@ fn queryFieldSrc(
|
||||
file_scope: *File,
|
||||
container_decl: Ast.full.ContainerDecl,
|
||||
) SrcLoc {
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
var field_index: usize = 0;
|
||||
for (container_decl.ast.members) |member_node| {
|
||||
const field = switch (node_tags[member_node]) {
|
||||
.container_field_init => tree.containerFieldInit(member_node),
|
||||
.container_field_align => tree.containerFieldAlign(member_node),
|
||||
.container_field => tree.containerField(member_node),
|
||||
else => continue,
|
||||
};
|
||||
const field = tree.fullContainerField(member_node) orelse continue;
|
||||
if (field_index == query.index) {
|
||||
return switch (query.range) {
|
||||
.name => .{
|
||||
@@ -6275,24 +5978,9 @@ pub fn paramSrc(
|
||||
});
|
||||
return LazySrcLoc.nodeOffset(0);
|
||||
};
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = decl.relativeToNodeIndex(func_node_offset);
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
const full = switch (node_tags[node]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node),
|
||||
.fn_proto => tree.fnProto(node),
|
||||
.fn_decl => switch (node_tags[node_datas[node].lhs]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node_datas[node].lhs),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node_datas[node].lhs),
|
||||
.fn_proto_one => tree.fnProtoOne(¶ms, node_datas[node].lhs),
|
||||
.fn_proto => tree.fnProto(node_datas[node].lhs),
|
||||
else => unreachable,
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullFnProto(&buf, node).?;
|
||||
var it = full.iterate(tree);
|
||||
var i: usize = 0;
|
||||
while (it.next()) |param| : (i += 1) {
|
||||
@@ -6358,18 +6046,6 @@ pub fn initSrc(
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
const node = decl.relativeToNodeIndex(init_node_offset);
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
const full = switch (node_tags[node]) {
|
||||
.array_init_one, .array_init_one_comma => tree.arrayInitOne(buf[0..1], node).ast.elements,
|
||||
.array_init_dot_two, .array_init_dot_two_comma => tree.arrayInitDotTwo(&buf, node).ast.elements,
|
||||
.array_init_dot, .array_init_dot_comma => tree.arrayInitDot(node).ast.elements,
|
||||
.array_init, .array_init_comma => tree.arrayInit(node).ast.elements,
|
||||
|
||||
.struct_init_one, .struct_init_one_comma => tree.structInitOne(buf[0..1], node).ast.fields,
|
||||
.struct_init_dot_two, .struct_init_dot_two_comma => tree.structInitDotTwo(&buf, node).ast.fields,
|
||||
.struct_init_dot, .struct_init_dot_comma => tree.structInitDot(node).ast.fields,
|
||||
.struct_init, .struct_init_comma => tree.structInit(node).ast.fields,
|
||||
else => return LazySrcLoc.nodeOffset(init_node_offset),
|
||||
};
|
||||
switch (node_tags[node]) {
|
||||
.array_init_one,
|
||||
.array_init_one_comma,
|
||||
@@ -6379,7 +6055,10 @@ pub fn initSrc(
|
||||
.array_init_dot_comma,
|
||||
.array_init,
|
||||
.array_init_comma,
|
||||
=> return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full[init_index])),
|
||||
=> {
|
||||
const full = tree.fullArrayInit(&buf, node).?.ast.elements;
|
||||
return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full[init_index]));
|
||||
},
|
||||
.struct_init_one,
|
||||
.struct_init_one_comma,
|
||||
.struct_init_dot_two,
|
||||
@@ -6388,8 +6067,11 @@ pub fn initSrc(
|
||||
.struct_init_dot_comma,
|
||||
.struct_init,
|
||||
.struct_init_comma,
|
||||
=> return LazySrcLoc{ .node_offset_initializer = decl.nodeIndexToRelative(full[init_index]) },
|
||||
else => unreachable,
|
||||
=> {
|
||||
const full = tree.fullStructInit(&buf, node).?.ast.fields;
|
||||
return LazySrcLoc{ .node_offset_initializer = decl.nodeIndexToRelative(full[init_index]) };
|
||||
},
|
||||
else => return LazySrcLoc.nodeOffset(init_node_offset),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6422,13 +6104,7 @@ pub fn optionsSrc(gpa: Allocator, decl: *Decl, base_src: LazySrcLoc, wanted: []c
|
||||
else => unreachable,
|
||||
};
|
||||
var buf: [2]std.zig.Ast.Node.Index = undefined;
|
||||
const init_nodes = switch (node_tags[arg_node]) {
|
||||
.struct_init_one, .struct_init_one_comma => tree.structInitOne(buf[0..1], arg_node).ast.fields,
|
||||
.struct_init_dot_two, .struct_init_dot_two_comma => tree.structInitDotTwo(&buf, arg_node).ast.fields,
|
||||
.struct_init_dot, .struct_init_dot_comma => tree.structInitDot(arg_node).ast.fields,
|
||||
.struct_init, .struct_init_comma => tree.structInit(arg_node).ast.fields,
|
||||
else => return base_src,
|
||||
};
|
||||
const init_nodes = if (tree.fullStructInit(&buf, arg_node)) |struct_init| struct_init.ast.fields else return base_src;
|
||||
for (init_nodes) |init_node| {
|
||||
// . IDENTIFIER = init_node
|
||||
const name_token = tree.firstToken(init_node) - 2;
|
||||
|
||||
25
src/Sema.zig
25
src/Sema.zig
@@ -2150,29 +2150,8 @@ fn addFieldErrNote(
|
||||
|
||||
const container_node = decl.relativeToNodeIndex(0);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
var buffer: [2]std.zig.Ast.Node.Index = undefined;
|
||||
const container_decl = switch (node_tags[container_node]) {
|
||||
.root => tree.containerDeclRoot(),
|
||||
.container_decl,
|
||||
.container_decl_trailing,
|
||||
=> tree.containerDecl(container_node),
|
||||
.container_decl_two,
|
||||
.container_decl_two_trailing,
|
||||
=> tree.containerDeclTwo(&buffer, container_node),
|
||||
.container_decl_arg,
|
||||
.container_decl_arg_trailing,
|
||||
=> tree.containerDeclArg(container_node),
|
||||
.tagged_union,
|
||||
.tagged_union_trailing,
|
||||
=> tree.taggedUnion(container_node),
|
||||
.tagged_union_two,
|
||||
.tagged_union_two_trailing,
|
||||
=> tree.taggedUnionTwo(&buffer, container_node),
|
||||
.tagged_union_enum_tag,
|
||||
.tagged_union_enum_tag_trailing,
|
||||
=> tree.taggedUnionEnumTag(container_node),
|
||||
else => break :blk decl.srcLoc(),
|
||||
};
|
||||
var buf: [2]std.zig.Ast.Node.Index = undefined;
|
||||
const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc();
|
||||
|
||||
var it_index: usize = 0;
|
||||
for (container_decl.ast.members) |member_node| {
|
||||
|
||||
Reference in New Issue
Block a user