| ... | ... | @@ -237,6 +237,10 @@ pub const Decl = struct { |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | pub fn tokSrcLoc(decl: *Decl, token_index: ast.TokenIndex) LazySrcLoc { |
| 241 | return .{ .token_offset = token_index - decl.srcToken() }; |
| 242 | } |
| 243 | |
| 240 | 244 | pub fn srcLoc(decl: *Decl) SrcLoc { |
| 241 | 245 | return .{ |
| 242 | 246 | .container = .{ .decl = decl }, |
| ... | ... | @@ -1000,8 +1004,7 @@ pub const Scope = struct { |
| 1000 | 1004 | } |
| 1001 | 1005 | |
| 1002 | 1006 | pub fn tokSrcLoc(gz: *GenZir, token_index: ast.TokenIndex) LazySrcLoc { |
| 1003 | | const decl_token = gz.zir_code.decl.srcToken(); |
| 1004 | | return .{ .token_offset = token_index - decl_token }; |
| 1007 | return gz.zir_code.decl.tokSrcLoc(token_index); |
| 1005 | 1008 | } |
| 1006 | 1009 | |
| 1007 | 1010 | pub fn addFnTypeCc(gz: *GenZir, args: struct { |
| ... | ... | @@ -2244,8 +2247,7 @@ fn astgenAndSemaFn( |
| 2244 | 2247 | .{}, |
| 2245 | 2248 | ); |
| 2246 | 2249 | } |
| 2247 | | // TODO use a Decl-local source location instead. |
| 2248 | | const export_src: LazySrcLoc = .{ .token_abs = maybe_export_token }; |
| 2250 | const export_src = decl.tokSrcLoc(maybe_export_token); |
| 2249 | 2251 | const name = tree.tokenSlice(fn_proto.name_token.?); // TODO identifierTokenString |
| 2250 | 2252 | // The scope needs to have the decl in it. |
| 2251 | 2253 | try mod.analyzeExport(&block_scope.base, export_src, name, decl); |
| ... | ... | @@ -2337,14 +2339,11 @@ fn astgenAndSemaVarDecl( |
| 2337 | 2339 | }; |
| 2338 | 2340 | defer gen_scope.instructions.deinit(mod.gpa); |
| 2339 | 2341 | |
| 2340 | | const init_result_loc: astgen.ResultLoc = if (var_decl.ast.type_node != 0) |
| 2341 | | .{ |
| 2342 | | .ty = try astgen.expr(mod, &gen_scope.base, .{ |
| 2343 | | .ty = @enumToInt(zir.Const.type_type), |
| 2344 | | }, var_decl.ast.type_node), |
| 2345 | | } |
| 2346 | | else |
| 2347 | | .none; |
| 2342 | const init_result_loc: astgen.ResultLoc = if (var_decl.ast.type_node != 0) .{ |
| 2343 | .ty = try astgen.expr(mod, &gen_scope.base, .{ |
| 2344 | .ty = @enumToInt(zir.Const.type_type), |
| 2345 | }, var_decl.ast.type_node), |
| 2346 | } else .none; |
| 2348 | 2347 | |
| 2349 | 2348 | const init_inst = try astgen.comptimeExpr( |
| 2350 | 2349 | mod, |
| ... | ... | @@ -2499,8 +2498,7 @@ fn astgenAndSemaVarDecl( |
| 2499 | 2498 | |
| 2500 | 2499 | if (var_decl.extern_export_token) |maybe_export_token| { |
| 2501 | 2500 | if (token_tags[maybe_export_token] == .keyword_export) { |
| 2502 | | // TODO make this src relative to containing Decl |
| 2503 | | const export_src: LazySrcLoc = .{ .token_abs = maybe_export_token }; |
| 2501 | const export_src = decl.tokSrcLoc(maybe_export_token); |
| 2504 | 2502 | const name_token = var_decl.ast.mut_token + 1; |
| 2505 | 2503 | const name = tree.tokenSlice(name_token); // TODO identifierTokenString |
| 2506 | 2504 | // The scope needs to have the decl in it. |