Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ast.lasttoken() does not handle addrspace section #467

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ pub fn lastToken(tree: Ast, node: Ast.Node.Index) Ast.TokenIndex {
},
.fn_proto_one => {
const extra = tree.extraData(datas[n].lhs, Node.FnProtoOne);
// linksection, callconv, align can appear in any order, so we
// addrspace, linksection, callconv, align can appear in any order, so we
// find the last one here.
// rhs can be zero if no return type is provided
var max_node: Node.Index = 0;
Expand All @@ -763,6 +763,14 @@ pub fn lastToken(tree: Ast, node: Ast.Node.Index) Ast.TokenIndex {
max_offset = 1; // for the rparen
}
}
if (extra.addrspace_expr != 0) {
const start = token_starts[main_tokens[extra.addrspace_expr]];
if (start > max_start) {
max_node = extra.addrspace_expr;
max_start = start;
max_offset = 1; // for the rparen
}
}
if (extra.section_expr != 0) {
const start = token_starts[main_tokens[extra.section_expr]];
if (start > max_start) {
Expand Down Expand Up @@ -797,7 +805,7 @@ pub fn lastToken(tree: Ast, node: Ast.Node.Index) Ast.TokenIndex {
},
.fn_proto => {
const extra = tree.extraData(datas[n].lhs, Node.FnProto);
// linksection, callconv, align can appear in any order, so we
// addrspace, linksection, callconv, align can appear in any order, so we
// find the last one here.
// rhs can be zero if no return type is provided
var max_node: Node.Index = 0;
Expand All @@ -816,6 +824,14 @@ pub fn lastToken(tree: Ast, node: Ast.Node.Index) Ast.TokenIndex {
max_offset = 1; // for the rparen
}
}
if (extra.addrspace_expr != 0) {
const start = token_starts[main_tokens[extra.addrspace_expr]];
if (start > max_start) {
max_node = extra.addrspace_expr;
max_start = start;
max_offset = 1; // for the rparen
}
}
if (extra.section_expr != 0) {
const start = token_starts[main_tokens[extra.section_expr]];
if (start > max_start) {
Expand Down