authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-19 14:59:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-19 14:59:46-07:00
log132df14ee17f9fa19aa29bcbd10b61cb339b1340
treeb194435b2216f0d1bcf12a317013cc439e418e97
parenta4f0ccdfe4ebbaed34b558943279797156832f4b

stage2: fix export source locations not being relative to Decl


1 files changed, 12 insertions(+), 14 deletions(-)

src/Module.zig+12-14
......@@ -237,6 +237,10 @@ pub const Decl = struct {
237237 }
238238 }
239239
240 pub fn tokSrcLoc(decl: *Decl, token_index: ast.TokenIndex) LazySrcLoc {
241 return .{ .token_offset = token_index - decl.srcToken() };
242 }
243
240244 pub fn srcLoc(decl: *Decl) SrcLoc {
241245 return .{
242246 .container = .{ .decl = decl },
......@@ -1000,8 +1004,7 @@ pub const Scope = struct {
10001004 }
10011005
10021006 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);
10051008 }
10061009
10071010 pub fn addFnTypeCc(gz: *GenZir, args: struct {
......@@ -2244,8 +2247,7 @@ fn astgenAndSemaFn(
22442247 .{},
22452248 );
22462249 }
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);
22492251 const name = tree.tokenSlice(fn_proto.name_token.?); // TODO identifierTokenString
22502252 // The scope needs to have the decl in it.
22512253 try mod.analyzeExport(&block_scope.base, export_src, name, decl);
......@@ -2337,14 +2339,11 @@ fn astgenAndSemaVarDecl(
23372339 };
23382340 defer gen_scope.instructions.deinit(mod.gpa);
23392341
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;
23482347
23492348 const init_inst = try astgen.comptimeExpr(
23502349 mod,
......@@ -2499,8 +2498,7 @@ fn astgenAndSemaVarDecl(
24992498
25002499 if (var_decl.extern_export_token) |maybe_export_token| {
25012500 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);
25042502 const name_token = var_decl.ast.mut_token + 1;
25052503 const name = tree.tokenSlice(name_token); // TODO identifierTokenString
25062504 // The scope needs to have the decl in it.