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