parser: port threadlocal, linksection, addrspace tests
Port tests: - "threadlocal" - "linksection" - "addrspace" Implement full var decl proto with aligned_var_decl, local_var_decl, and global_var_decl node types for align/addrspace/linksection. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
40
parser.c
40
parser.c
@@ -1312,24 +1312,44 @@ static AstNodeIndex parseVarDeclProto(Parser* p) {
|
||||
|
||||
if (section_node == 0 && addrspace_node == 0) {
|
||||
if (align_node == 0) {
|
||||
return addNode(
|
||||
&p->nodes,
|
||||
return addNode(&p->nodes,
|
||||
(AstNodeItem) {
|
||||
.tag = AST_NODE_SIMPLE_VAR_DECL,
|
||||
.main_token = mut_token,
|
||||
.data = { .lhs = type_node, .rhs = 0 },
|
||||
});
|
||||
}
|
||||
if (type_node == 0) {
|
||||
return addNode(&p->nodes,
|
||||
(AstNodeItem) {
|
||||
.tag = AST_NODE_ALIGNED_VAR_DECL,
|
||||
.main_token = mut_token,
|
||||
.data = { .lhs = align_node, .rhs = 0 },
|
||||
});
|
||||
}
|
||||
return addNode(&p->nodes,
|
||||
(AstNodeItem) {
|
||||
.tag = AST_NODE_LOCAL_VAR_DECL,
|
||||
.main_token = mut_token,
|
||||
.data = {
|
||||
.lhs = type_node,
|
||||
.lhs = addExtra(p,
|
||||
(AstNodeIndex[]) { type_node, align_node }, 2),
|
||||
.rhs = 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
fprintf(stderr, "parseVarDecl got something too complicated\n");
|
||||
exit(1);
|
||||
} else {
|
||||
fprintf(stderr, "parseVarDecl got something too complicated\n");
|
||||
exit(1);
|
||||
}
|
||||
return 0; // tcc
|
||||
return addNode(&p->nodes,
|
||||
(AstNodeItem) {
|
||||
.tag = AST_NODE_GLOBAL_VAR_DECL,
|
||||
.main_token = mut_token,
|
||||
.data = {
|
||||
.lhs = addExtra(p,
|
||||
(AstNodeIndex[]) { OPT(type_node), OPT(align_node),
|
||||
OPT(addrspace_node), OPT(section_node) },
|
||||
4),
|
||||
.rhs = 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
static AstTokenIndex parseBreakLabel(Parser* p) {
|
||||
|
||||
@@ -1923,6 +1923,31 @@ test "zig fmt: allowzero pointer" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: threadlocal" {
|
||||
try testCanonical(
|
||||
\\threadlocal var x: i32 = 1234;
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: linksection" {
|
||||
try testCanonical(
|
||||
\\export var aoeu: u64 linksection(".text.derp") = 1234;
|
||||
\\export fn _start() linksection(".text.boot") callconv(.naked) noreturn {}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: addrspace" {
|
||||
try testCanonical(
|
||||
\\export var python_length: u64 align(1) addrspace(.generic);
|
||||
\\export var python_color: Color addrspace(.generic) = .green;
|
||||
\\export var python_legs: u0 align(8) addrspace(.generic) linksection(".python") = 0;
|
||||
\\export fn python_hiss() align(8) addrspace(.generic) linksection(".python") void;
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: sentinel-terminated array type" {
|
||||
try testCanonical(
|
||||
\\pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 {
|
||||
|
||||
Reference in New Issue
Block a user