| ... | ... | @@ -2082,60 +2082,65 @@ pub const SrcLoc = struct { |
| 2082 | 2082 | return @bitCast(Ast.Node.Index, offset + @bitCast(i32, src_loc.parent_decl_node)); |
| 2083 | 2083 | } |
| 2084 | 2084 | |
| 2085 | | pub fn byteOffset(src_loc: SrcLoc, gpa: Allocator) !u32 { |
| 2085 | pub const Span = struct { |
| 2086 | start: u32, |
| 2087 | end: u32, |
| 2088 | main: u32, |
| 2089 | }; |
| 2090 | |
| 2091 | pub fn span(src_loc: SrcLoc, gpa: Allocator) !Span { |
| 2086 | 2092 | switch (src_loc.lazy) { |
| 2087 | 2093 | .unneeded => unreachable, |
| 2088 | | .entire_file => return 0, |
| 2094 | .entire_file => return Span{ .start = 0, .end = 1, .main = 0 }, |
| 2089 | 2095 | |
| 2090 | | .byte_abs => |byte_index| return byte_index, |
| 2096 | .byte_abs => |byte_index| return Span{ .start = byte_index, .end = byte_index + 1, .main = byte_index }, |
| 2091 | 2097 | |
| 2092 | 2098 | .token_abs => |tok_index| { |
| 2093 | 2099 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2094 | | const token_starts = tree.tokens.items(.start); |
| 2095 | | return token_starts[tok_index]; |
| 2100 | const start = tree.tokens.items(.start)[tok_index]; |
| 2101 | const end = start + @intCast(u32, tree.tokenSlice(tok_index).len); |
| 2102 | return Span{ .start = start, .end = end, .main = start }; |
| 2096 | 2103 | }, |
| 2097 | 2104 | .node_abs => |node| { |
| 2098 | 2105 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2099 | | const token_starts = tree.tokens.items(.start); |
| 2100 | | const tok_index = tree.firstToken(node); |
| 2101 | | return token_starts[tok_index]; |
| 2106 | return nodeToSpan(tree, node); |
| 2102 | 2107 | }, |
| 2103 | 2108 | .byte_offset => |byte_off| { |
| 2104 | 2109 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2105 | | const token_starts = tree.tokens.items(.start); |
| 2106 | | return token_starts[src_loc.declSrcToken()] + byte_off; |
| 2110 | const tok_index = src_loc.declSrcToken(); |
| 2111 | const start = tree.tokens.items(.start)[tok_index] + byte_off; |
| 2112 | const end = start + @intCast(u32, tree.tokenSlice(tok_index).len); |
| 2113 | return Span{ .start = start, .end = end, .main = start }; |
| 2107 | 2114 | }, |
| 2108 | 2115 | .token_offset => |tok_off| { |
| 2109 | 2116 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2110 | 2117 | const tok_index = src_loc.declSrcToken() + tok_off; |
| 2111 | | const token_starts = tree.tokens.items(.start); |
| 2112 | | return token_starts[tok_index]; |
| 2118 | const start = tree.tokens.items(.start)[tok_index]; |
| 2119 | const end = start + @intCast(u32, tree.tokenSlice(tok_index).len); |
| 2120 | return Span{ .start = start, .end = end, .main = start }; |
| 2113 | 2121 | }, |
| 2114 | 2122 | .node_offset => |traced_off| { |
| 2115 | 2123 | const node_off = traced_off.x; |
| 2116 | 2124 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2117 | 2125 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| 2118 | 2126 | assert(src_loc.file_scope.tree_loaded); |
| 2119 | | const main_tokens = tree.nodes.items(.main_token); |
| 2120 | | const tok_index = main_tokens[node]; |
| 2121 | | const token_starts = tree.tokens.items(.start); |
| 2122 | | return token_starts[tok_index]; |
| 2127 | return nodeToSpan(tree, node); |
| 2123 | 2128 | }, |
| 2124 | 2129 | .node_offset_bin_op => |node_off| { |
| 2125 | 2130 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2126 | 2131 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| 2127 | 2132 | assert(src_loc.file_scope.tree_loaded); |
| 2128 | | const main_tokens = tree.nodes.items(.main_token); |
| 2129 | | const tok_index = main_tokens[node]; |
| 2130 | | const token_starts = tree.tokens.items(.start); |
| 2131 | | return token_starts[tok_index]; |
| 2133 | return nodeToSpan(tree, node); |
| 2132 | 2134 | }, |
| 2133 | | .node_offset_back2tok => |node_off| { |
| 2135 | .node_offset_initializer => |node_off| { |
| 2134 | 2136 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2135 | 2137 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| 2136 | | const tok_index = tree.firstToken(node) - 2; |
| 2137 | | const token_starts = tree.tokens.items(.start); |
| 2138 | | return token_starts[tok_index]; |
| 2138 | return tokensToSpan( |
| 2139 | tree, |
| 2140 | tree.firstToken(node) - 3, |
| 2141 | tree.lastToken(node), |
| 2142 | tree.nodes.items(.main_token)[node] - 2, |
| 2143 | ); |
| 2139 | 2144 | }, |
| 2140 | 2145 | .node_offset_var_decl_ty => |node_off| { |
| 2141 | 2146 | const tree = try src_loc.file_scope.getTree(gpa); |
| ... | ... | @@ -2148,14 +2153,13 @@ pub const SrcLoc = struct { |
| 2148 | 2153 | .aligned_var_decl => tree.alignedVarDecl(node), |
| 2149 | 2154 | else => unreachable, |
| 2150 | 2155 | }; |
| 2151 | | const tok_index = if (full.ast.type_node != 0) blk: { |
| 2152 | | const main_tokens = tree.nodes.items(.main_token); |
| 2153 | | break :blk main_tokens[full.ast.type_node]; |
| 2154 | | } else blk: { |
| 2155 | | break :blk full.ast.mut_token + 1; // the name token |
| 2156 | | }; |
| 2157 | | const token_starts = tree.tokens.items(.start); |
| 2158 | | return token_starts[tok_index]; |
| 2156 | if (full.ast.type_node != 0) { |
| 2157 | return nodeToSpan(tree, full.ast.type_node); |
| 2158 | } |
| 2159 | const tok_index = full.ast.mut_token + 1; // the name token |
| 2160 | const start = tree.tokens.items(.start)[tok_index]; |
| 2161 | const end = start + @intCast(u32, tree.tokenSlice(tok_index).len); |
| 2162 | return Span{ .start = start, .end = end, .main = start }; |
| 2159 | 2163 | }, |
| 2160 | 2164 | .node_offset_builtin_call_arg0 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 0), |
| 2161 | 2165 | .node_offset_builtin_call_arg1 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 1), |
| ... | ... | @@ -2167,10 +2171,7 @@ pub const SrcLoc = struct { |
| 2167 | 2171 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2168 | 2172 | const node_datas = tree.nodes.items(.data); |
| 2169 | 2173 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| 2170 | | const main_tokens = tree.nodes.items(.main_token); |
| 2171 | | const tok_index = main_tokens[node_datas[node].rhs]; |
| 2172 | | const token_starts = tree.tokens.items(.start); |
| 2173 | | return token_starts[tok_index]; |
| 2174 | return nodeToSpan(tree, node_datas[node].rhs); |
| 2174 | 2175 | }, |
| 2175 | 2176 | .node_offset_slice_ptr, |
| 2176 | 2177 | .node_offset_slice_start, |
| ... | ... | @@ -2186,18 +2187,14 @@ pub const SrcLoc = struct { |
| 2186 | 2187 | .slice_sentinel => tree.sliceSentinel(node), |
| 2187 | 2188 | else => unreachable, |
| 2188 | 2189 | }; |
| 2189 | | const main_tokens = tree.nodes.items(.main_token); |
| 2190 | | const tok_index = main_tokens[ |
| 2191 | | switch (src_loc.lazy) { |
| 2192 | | .node_offset_slice_ptr => full.ast.sliced, |
| 2193 | | .node_offset_slice_start => full.ast.start, |
| 2194 | | .node_offset_slice_end => full.ast.end, |
| 2195 | | .node_offset_slice_sentinel => full.ast.sentinel, |
| 2196 | | else => unreachable, |
| 2197 | | } |
| 2198 | | ]; |
| 2199 | | const token_starts = tree.tokens.items(.start); |
| 2200 | | return token_starts[tok_index]; |
| 2190 | const part_node = switch (src_loc.lazy) { |
| 2191 | .node_offset_slice_ptr => full.ast.sliced, |
| 2192 | .node_offset_slice_start => full.ast.start, |
| 2193 | .node_offset_slice_end => full.ast.end, |
| 2194 | .node_offset_slice_sentinel => full.ast.sentinel, |
| 2195 | else => unreachable, |
| 2196 | }; |
| 2197 | return nodeToSpan(tree, part_node); |
| 2201 | 2198 | }, |
| 2202 | 2199 | .node_offset_call_func => |node_off| { |
| 2203 | 2200 | const tree = try src_loc.file_scope.getTree(gpa); |
| ... | ... | @@ -2219,10 +2216,7 @@ pub const SrcLoc = struct { |
| 2219 | 2216 | |
| 2220 | 2217 | else => unreachable, |
| 2221 | 2218 | }; |
| 2222 | | const main_tokens = tree.nodes.items(.main_token); |
| 2223 | | const tok_index = main_tokens[full.ast.fn_expr]; |
| 2224 | | const token_starts = tree.tokens.items(.start); |
| 2225 | | return token_starts[tok_index]; |
| 2219 | return nodeToSpan(tree, full.ast.fn_expr); |
| 2226 | 2220 | }, |
| 2227 | 2221 | .node_offset_field_name => |node_off| { |
| 2228 | 2222 | const tree = try src_loc.file_scope.getTree(gpa); |
| ... | ... | @@ -2233,16 +2227,14 @@ pub const SrcLoc = struct { |
| 2233 | 2227 | .field_access => node_datas[node].rhs, |
| 2234 | 2228 | else => tree.firstToken(node) - 2, |
| 2235 | 2229 | }; |
| 2236 | | const token_starts = tree.tokens.items(.start); |
| 2237 | | return token_starts[tok_index]; |
| 2230 | const start = tree.tokens.items(.start)[tok_index]; |
| 2231 | const end = start + @intCast(u32, tree.tokenSlice(tok_index).len); |
| 2232 | return Span{ .start = start, .end = end, .main = start }; |
| 2238 | 2233 | }, |
| 2239 | 2234 | .node_offset_deref_ptr => |node_off| { |
| 2240 | 2235 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2241 | | const node_datas = tree.nodes.items(.data); |
| 2242 | 2236 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| 2243 | | const tok_index = node_datas[node].lhs; |
| 2244 | | const token_starts = tree.tokens.items(.start); |
| 2245 | | return token_starts[tok_index]; |
| 2237 | return nodeToSpan(tree, node); |
| 2246 | 2238 | }, |
| 2247 | 2239 | .node_offset_asm_source => |node_off| { |
| 2248 | 2240 | const tree = try src_loc.file_scope.getTree(gpa); |
| ... | ... | @@ -2253,10 +2245,7 @@ pub const SrcLoc = struct { |
| 2253 | 2245 | .@"asm" => tree.asmFull(node), |
| 2254 | 2246 | else => unreachable, |
| 2255 | 2247 | }; |
| 2256 | | const main_tokens = tree.nodes.items(.main_token); |
| 2257 | | const tok_index = main_tokens[full.ast.template]; |
| 2258 | | const token_starts = tree.tokens.items(.start); |
| 2259 | | return token_starts[tok_index]; |
| 2248 | return nodeToSpan(tree, full.ast.template); |
| 2260 | 2249 | }, |
| 2261 | 2250 | .node_offset_asm_ret_ty => |node_off| { |
| 2262 | 2251 | const tree = try src_loc.file_scope.getTree(gpa); |
| ... | ... | @@ -2269,11 +2258,7 @@ pub const SrcLoc = struct { |
| 2269 | 2258 | }; |
| 2270 | 2259 | const asm_output = full.outputs[0]; |
| 2271 | 2260 | const node_datas = tree.nodes.items(.data); |
| 2272 | | const ret_ty_node = node_datas[asm_output].lhs; |
| 2273 | | const main_tokens = tree.nodes.items(.main_token); |
| 2274 | | const tok_index = main_tokens[ret_ty_node]; |
| 2275 | | const token_starts = tree.tokens.items(.start); |
| 2276 | | return token_starts[tok_index]; |
| 2261 | return nodeToSpan(tree, node_datas[asm_output].lhs); |
| 2277 | 2262 | }, |
| 2278 | 2263 | |
| 2279 | 2264 | .node_offset_for_cond, .node_offset_if_cond => |node_off| { |
| ... | ... | @@ -2290,41 +2275,26 @@ pub const SrcLoc = struct { |
| 2290 | 2275 | .@"for" => tree.forFull(node).ast.cond_expr, |
| 2291 | 2276 | else => unreachable, |
| 2292 | 2277 | }; |
| 2293 | | const main_tokens = tree.nodes.items(.main_token); |
| 2294 | | const tok_index = main_tokens[src_node]; |
| 2295 | | const token_starts = tree.tokens.items(.start); |
| 2296 | | return token_starts[tok_index]; |
| 2278 | return nodeToSpan(tree, src_node); |
| 2297 | 2279 | }, |
| 2298 | 2280 | .node_offset_bin_lhs => |node_off| { |
| 2299 | 2281 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2300 | 2282 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| 2301 | 2283 | const node_datas = tree.nodes.items(.data); |
| 2302 | | const src_node = node_datas[node].lhs; |
| 2303 | | const main_tokens = tree.nodes.items(.main_token); |
| 2304 | | const tok_index = main_tokens[src_node]; |
| 2305 | | const token_starts = tree.tokens.items(.start); |
| 2306 | | return token_starts[tok_index]; |
| 2284 | return nodeToSpan(tree, node_datas[node].lhs); |
| 2307 | 2285 | }, |
| 2308 | 2286 | .node_offset_bin_rhs => |node_off| { |
| 2309 | 2287 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2310 | 2288 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| 2311 | 2289 | const node_datas = tree.nodes.items(.data); |
| 2312 | | const src_node = node_datas[node].rhs; |
| 2313 | | const main_tokens = tree.nodes.items(.main_token); |
| 2314 | | const tok_index = main_tokens[src_node]; |
| 2315 | | const token_starts = tree.tokens.items(.start); |
| 2316 | | return token_starts[tok_index]; |
| 2290 | return nodeToSpan(tree, node_datas[node].rhs); |
| 2317 | 2291 | }, |
| 2318 | 2292 | |
| 2319 | 2293 | .node_offset_switch_operand => |node_off| { |
| 2320 | 2294 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2321 | 2295 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| 2322 | 2296 | const node_datas = tree.nodes.items(.data); |
| 2323 | | const src_node = node_datas[node].lhs; |
| 2324 | | const main_tokens = tree.nodes.items(.main_token); |
| 2325 | | const tok_index = main_tokens[src_node]; |
| 2326 | | const token_starts = tree.tokens.items(.start); |
| 2327 | | return token_starts[tok_index]; |
| 2297 | return nodeToSpan(tree, node_datas[node].lhs); |
| 2328 | 2298 | }, |
| 2329 | 2299 | |
| 2330 | 2300 | .node_offset_switch_special_prong => |node_off| { |
| ... | ... | @@ -2347,9 +2317,7 @@ pub const SrcLoc = struct { |
| 2347 | 2317 | mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_")); |
| 2348 | 2318 | if (!is_special) continue; |
| 2349 | 2319 | |
| 2350 | | const tok_index = main_tokens[case_node]; |
| 2351 | | const token_starts = tree.tokens.items(.start); |
| 2352 | | return token_starts[tok_index]; |
| 2320 | return nodeToSpan(tree, case_node); |
| 2353 | 2321 | } else unreachable; |
| 2354 | 2322 | }, |
| 2355 | 2323 | |
| ... | ... | @@ -2375,9 +2343,7 @@ pub const SrcLoc = struct { |
| 2375 | 2343 | |
| 2376 | 2344 | for (case.ast.values) |item_node| { |
| 2377 | 2345 | if (node_tags[item_node] == .switch_range) { |
| 2378 | | const tok_index = main_tokens[item_node]; |
| 2379 | | const token_starts = tree.tokens.items(.start); |
| 2380 | | return token_starts[tok_index]; |
| 2346 | return nodeToSpan(tree, item_node); |
| 2381 | 2347 | } |
| 2382 | 2348 | } |
| 2383 | 2349 | } else unreachable; |
| ... | ... | @@ -2403,10 +2369,7 @@ pub const SrcLoc = struct { |
| 2403 | 2369 | }, |
| 2404 | 2370 | else => unreachable, |
| 2405 | 2371 | }; |
| 2406 | | const main_tokens = tree.nodes.items(.main_token); |
| 2407 | | const tok_index = main_tokens[full.ast.callconv_expr]; |
| 2408 | | const token_starts = tree.tokens.items(.start); |
| 2409 | | return token_starts[tok_index]; |
| 2372 | return nodeToSpan(tree, full.ast.callconv_expr); |
| 2410 | 2373 | }, |
| 2411 | 2374 | |
| 2412 | 2375 | .node_offset_fn_type_ret_ty => |node_off| { |
| ... | ... | @@ -2421,21 +2384,14 @@ pub const SrcLoc = struct { |
| 2421 | 2384 | .fn_proto => tree.fnProto(node), |
| 2422 | 2385 | else => unreachable, |
| 2423 | 2386 | }; |
| 2424 | | const main_tokens = tree.nodes.items(.main_token); |
| 2425 | | const tok_index = main_tokens[full.ast.return_type]; |
| 2426 | | const token_starts = tree.tokens.items(.start); |
| 2427 | | return token_starts[tok_index]; |
| 2387 | return nodeToSpan(tree, full.ast.return_type); |
| 2428 | 2388 | }, |
| 2429 | 2389 | |
| 2430 | 2390 | .node_offset_anyframe_type => |node_off| { |
| 2431 | 2391 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2432 | 2392 | const node_datas = tree.nodes.items(.data); |
| 2433 | 2393 | const parent_node = src_loc.declRelativeToNodeIndex(node_off); |
| 2434 | | const node = node_datas[parent_node].rhs; |
| 2435 | | const main_tokens = tree.nodes.items(.main_token); |
| 2436 | | const tok_index = main_tokens[node]; |
| 2437 | | const token_starts = tree.tokens.items(.start); |
| 2438 | | return token_starts[tok_index]; |
| 2394 | return nodeToSpan(tree, node_datas[parent_node].rhs); |
| 2439 | 2395 | }, |
| 2440 | 2396 | |
| 2441 | 2397 | .node_offset_lib_name => |node_off| { |
| ... | ... | @@ -2462,8 +2418,9 @@ pub const SrcLoc = struct { |
| 2462 | 2418 | else => unreachable, |
| 2463 | 2419 | }; |
| 2464 | 2420 | const tok_index = full.lib_name.?; |
| 2465 | | const token_starts = tree.tokens.items(.start); |
| 2466 | | return token_starts[tok_index]; |
| 2421 | const start = tree.tokens.items(.start)[tok_index]; |
| 2422 | const end = start + @intCast(u32, tree.tokenSlice(tok_index).len); |
| 2423 | return Span{ .start = start, .end = end, .main = start }; |
| 2467 | 2424 | }, |
| 2468 | 2425 | |
| 2469 | 2426 | .node_offset_array_type_len => |node_off| { |
| ... | ... | @@ -2476,11 +2433,7 @@ pub const SrcLoc = struct { |
| 2476 | 2433 | .array_type_sentinel => tree.arrayTypeSentinel(parent_node), |
| 2477 | 2434 | else => unreachable, |
| 2478 | 2435 | }; |
| 2479 | | const node = full.ast.elem_count; |
| 2480 | | const main_tokens = tree.nodes.items(.main_token); |
| 2481 | | const tok_index = main_tokens[node]; |
| 2482 | | const token_starts = tree.tokens.items(.start); |
| 2483 | | return token_starts[tok_index]; |
| 2436 | return nodeToSpan(tree, full.ast.elem_count); |
| 2484 | 2437 | }, |
| 2485 | 2438 | .node_offset_array_type_sentinel => |node_off| { |
| 2486 | 2439 | const tree = try src_loc.file_scope.getTree(gpa); |
| ... | ... | @@ -2492,11 +2445,7 @@ pub const SrcLoc = struct { |
| 2492 | 2445 | .array_type_sentinel => tree.arrayTypeSentinel(parent_node), |
| 2493 | 2446 | else => unreachable, |
| 2494 | 2447 | }; |
| 2495 | | const node = full.ast.sentinel; |
| 2496 | | const main_tokens = tree.nodes.items(.main_token); |
| 2497 | | const tok_index = main_tokens[node]; |
| 2498 | | const token_starts = tree.tokens.items(.start); |
| 2499 | | return token_starts[tok_index]; |
| 2448 | return nodeToSpan(tree, full.ast.sentinel); |
| 2500 | 2449 | }, |
| 2501 | 2450 | .node_offset_array_type_elem => |node_off| { |
| 2502 | 2451 | const tree = try src_loc.file_scope.getTree(gpa); |
| ... | ... | @@ -2508,21 +2457,14 @@ pub const SrcLoc = struct { |
| 2508 | 2457 | .array_type_sentinel => tree.arrayTypeSentinel(parent_node), |
| 2509 | 2458 | else => unreachable, |
| 2510 | 2459 | }; |
| 2511 | | const node = full.ast.elem_type; |
| 2512 | | const main_tokens = tree.nodes.items(.main_token); |
| 2513 | | const tok_index = main_tokens[node]; |
| 2514 | | const token_starts = tree.tokens.items(.start); |
| 2515 | | return token_starts[tok_index]; |
| 2460 | return nodeToSpan(tree, full.ast.elem_type); |
| 2516 | 2461 | }, |
| 2517 | 2462 | .node_offset_un_op => |node_off| { |
| 2518 | 2463 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2519 | 2464 | const node_datas = tree.nodes.items(.data); |
| 2520 | 2465 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| 2521 | 2466 | |
| 2522 | | const main_tokens = tree.nodes.items(.main_token); |
| 2523 | | const tok_index = main_tokens[node_datas[node].lhs]; |
| 2524 | | const token_starts = tree.tokens.items(.start); |
| 2525 | | return token_starts[tok_index]; |
| 2467 | return nodeToSpan(tree, node_datas[node].lhs); |
| 2526 | 2468 | }, |
| 2527 | 2469 | } |
| 2528 | 2470 | } |
| ... | ... | @@ -2532,7 +2474,7 @@ pub const SrcLoc = struct { |
| 2532 | 2474 | gpa: Allocator, |
| 2533 | 2475 | node_off: i32, |
| 2534 | 2476 | arg_index: u32, |
| 2535 | | ) !u32 { |
| 2477 | ) !Span { |
| 2536 | 2478 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2537 | 2479 | const node_datas = tree.nodes.items(.data); |
| 2538 | 2480 | const node_tags = tree.nodes.items(.tag); |
| ... | ... | @@ -2546,10 +2488,36 @@ pub const SrcLoc = struct { |
| 2546 | 2488 | .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + arg_index], |
| 2547 | 2489 | else => unreachable, |
| 2548 | 2490 | }; |
| 2549 | | const main_tokens = tree.nodes.items(.main_token); |
| 2550 | | const tok_index = main_tokens[param]; |
| 2491 | return nodeToSpan(tree, param); |
| 2492 | } |
| 2493 | |
| 2494 | pub fn nodeToSpan(tree: *const Ast, node: u32) Span { |
| 2495 | return tokensToSpan( |
| 2496 | tree, |
| 2497 | tree.firstToken(node), |
| 2498 | tree.lastToken(node), |
| 2499 | tree.nodes.items(.main_token)[node], |
| 2500 | ); |
| 2501 | } |
| 2502 | |
| 2503 | fn tokensToSpan(tree: *const Ast, start: Ast.TokenIndex, end: Ast.TokenIndex, main: Ast.TokenIndex) Span { |
| 2551 | 2504 | const token_starts = tree.tokens.items(.start); |
| 2552 | | return token_starts[tok_index]; |
| 2505 | var start_tok = start; |
| 2506 | var end_tok = end; |
| 2507 | |
| 2508 | if (tree.tokensOnSameLine(start, end)) { |
| 2509 | // do nothing |
| 2510 | } else if (tree.tokensOnSameLine(start, main)) { |
| 2511 | end_tok = main; |
| 2512 | } else if (tree.tokensOnSameLine(main, end)) { |
| 2513 | start_tok = main; |
| 2514 | } else { |
| 2515 | start_tok = main; |
| 2516 | end_tok = main; |
| 2517 | } |
| 2518 | const start_off = token_starts[start_tok]; |
| 2519 | const end_off = token_starts[end_tok] + @intCast(u32, tree.tokenSlice(end_tok).len); |
| 2520 | return Span{ .start = start_off, .end = end_off, .main = token_starts[main] }; |
| 2553 | 2521 | } |
| 2554 | 2522 | }; |
| 2555 | 2523 | |
| ... | ... | @@ -2603,10 +2571,9 @@ pub const LazySrcLoc = union(enum) { |
| 2603 | 2571 | /// from its containing Decl node AST index. |
| 2604 | 2572 | /// The Decl is determined contextually. |
| 2605 | 2573 | node_offset: TracedOffset, |
| 2606 | | /// The source location points to two tokens left of the first token of an AST node, |
| 2607 | | /// which is this value offset from its containing Decl node AST index. |
| 2574 | /// The source location points to the beginning of a struct initializer. |
| 2608 | 2575 | /// The Decl is determined contextually. |
| 2609 | | node_offset_back2tok: i32, |
| 2576 | node_offset_initializer: i32, |
| 2610 | 2577 | /// The source location points to a variable declaration type expression, |
| 2611 | 2578 | /// found by taking this AST node index offset from the containing |
| 2612 | 2579 | /// Decl AST node, which points to a variable declaration AST node. Next, navigate |
| ... | ... | @@ -2802,7 +2769,7 @@ pub const LazySrcLoc = union(enum) { |
| 2802 | 2769 | .byte_offset, |
| 2803 | 2770 | .token_offset, |
| 2804 | 2771 | .node_offset, |
| 2805 | | .node_offset_back2tok, |
| 2772 | .node_offset_initializer, |
| 2806 | 2773 | .node_offset_var_decl_ty, |
| 2807 | 2774 | .node_offset_for_cond, |
| 2808 | 2775 | .node_offset_builtin_call_arg0, |
| ... | ... | @@ -3313,7 +3280,11 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 3313 | 3280 | .src_loc = .{ |
| 3314 | 3281 | .file_scope = file, |
| 3315 | 3282 | .parent_decl_node = 0, |
| 3316 | | .lazy = .{ .byte_abs = token_starts[parse_err.token] + extra_offset }, |
| 3283 | .lazy = if (extra_offset == 0) .{ |
| 3284 | .token_abs = parse_err.token, |
| 3285 | } else .{ |
| 3286 | .byte_abs = token_starts[parse_err.token] + extra_offset, |
| 3287 | }, |
| 3317 | 3288 | }, |
| 3318 | 3289 | .msg = msg.toOwnedSlice(), |
| 3319 | 3290 | }; |
| ... | ... | @@ -3336,7 +3307,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 3336 | 3307 | .src_loc = .{ |
| 3337 | 3308 | .file_scope = file, |
| 3338 | 3309 | .parent_decl_node = 0, |
| 3339 | | .lazy = .{ .byte_abs = token_starts[note.token] }, |
| 3310 | .lazy = .{ .token_abs = note.token }, |
| 3340 | 3311 | }, |
| 3341 | 3312 | .msg = msg.toOwnedSlice(), |
| 3342 | 3313 | }; |