parser: implement asm_legacy, port inline asm tests
Add AST_NODE_ASM_LEGACY for legacy string clobber format.
When asm clobbers use string literals ("clobber1", "clobber2"),
produce asm_legacy node instead of asm node.
Port tests:
- "preserves clobbers in inline asm with stray comma"
- "remove trailing comma at the end of assembly clobber"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -171,6 +171,7 @@ fn zigNode(token: c_uint) Ast.Node.Tag {
|
||||
c.AST_NODE_BLOCK => .block,
|
||||
c.AST_NODE_BLOCK_SEMICOLON => .block_semicolon,
|
||||
c.AST_NODE_ASM_SIMPLE => .asm_simple,
|
||||
c.AST_NODE_ASM_LEGACY => .asm_legacy,
|
||||
c.AST_NODE_ASM => .@"asm",
|
||||
c.AST_NODE_ASM_OUTPUT => .asm_output,
|
||||
c.AST_NODE_ASM_INPUT => .asm_input,
|
||||
@@ -569,6 +570,60 @@ test "zig fmt: tuple struct" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: preserves clobbers in inline asm with stray comma" {
|
||||
try testTransform(
|
||||
\\fn foo() void {
|
||||
\\ asm volatile (""
|
||||
\\ : [_] "" (-> type),
|
||||
\\ :
|
||||
\\ : "clobber"
|
||||
\\ );
|
||||
\\ asm volatile (""
|
||||
\\ :
|
||||
\\ : [_] "" (type),
|
||||
\\ : "clobber"
|
||||
\\ );
|
||||
\\}
|
||||
\\
|
||||
,
|
||||
\\fn foo() void {
|
||||
\\ asm volatile (""
|
||||
\\ : [_] "" (-> type),
|
||||
\\ :
|
||||
\\ : .{ .clobber = true }
|
||||
\\ );
|
||||
\\ asm volatile (""
|
||||
\\ :
|
||||
\\ : [_] "" (type),
|
||||
\\ : .{ .clobber = true }
|
||||
\\ );
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: remove trailing comma at the end of assembly clobber" {
|
||||
try testTransform(
|
||||
\\fn foo() void {
|
||||
\\ asm volatile (""
|
||||
\\ : [_] "" (-> type),
|
||||
\\ :
|
||||
\\ : "clobber1", "clobber2",
|
||||
\\ );
|
||||
\\}
|
||||
\\
|
||||
,
|
||||
\\fn foo() void {
|
||||
\\ asm volatile (""
|
||||
\\ : [_] "" (-> type),
|
||||
\\ :
|
||||
\\ : .{ .clobber1 = true, .clobber2 = true }
|
||||
\\ );
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: respect line breaks in struct field value declaration" {
|
||||
try testCanonical(
|
||||
\\const Foo = struct {
|
||||
|
||||
Reference in New Issue
Block a user