| ... | ... | @@ -2330,12 +2330,14 @@ pub const Parser = struct { |
| 2330 | 2330 | }, |
| 2331 | 2331 | |
| 2332 | 2332 | State.FnProtoAlign => |fn_proto| { |
| 2333 | stack.append(State { .FnProtoReturnType = fn_proto }) catch unreachable; |
| 2334 | |
| 2333 | 2335 | if (self.eatToken(Token.Id.Keyword_align)) |align_token| { |
| 2334 | | @panic("TODO fn proto align"); |
| 2336 | try stack.append(State { .ExpectToken = Token.Id.RParen }); |
| 2337 | try stack.append(State { .Expression = DestPtr { .NullableField = &fn_proto.align_expr } }); |
| 2338 | try stack.append(State { .ExpectToken = Token.Id.LParen }); |
| 2335 | 2339 | } |
| 2336 | | stack.append(State { |
| 2337 | | .FnProtoReturnType = fn_proto, |
| 2338 | | }) catch unreachable; |
| 2340 | |
| 2339 | 2341 | continue; |
| 2340 | 2342 | }, |
| 2341 | 2343 | |
| ... | ... | @@ -2349,10 +2351,6 @@ pub const Parser = struct { |
| 2349 | 2351 | }) catch unreachable; |
| 2350 | 2352 | continue; |
| 2351 | 2353 | }, |
| 2352 | | Token.Id.Keyword_align => { |
| 2353 | | @panic("TODO fn proto align"); |
| 2354 | | continue; |
| 2355 | | }, |
| 2356 | 2354 | else => { |
| 2357 | 2355 | // TODO: this is a special case. Remove this when #760 is fixed |
| 2358 | 2356 | if (token.id == Token.Id.Keyword_error) { |
| ... | ... | @@ -3179,7 +3177,6 @@ pub const Parser = struct { |
| 3179 | 3177 | |
| 3180 | 3178 | const RenderState = union(enum) { |
| 3181 | 3179 | TopLevelDecl: &ast.Node, |
| 3182 | | FnProtoRParen: &ast.NodeFnProto, |
| 3183 | 3180 | ParamDecl: &ast.Node, |
| 3184 | 3181 | Text: []const u8, |
| 3185 | 3182 | Expression: &ast.Node, |
| ... | ... | @@ -3868,8 +3865,10 @@ pub const Parser = struct { |
| 3868 | 3865 | }, |
| 3869 | 3866 | } |
| 3870 | 3867 | |
| 3871 | | if (fn_proto.align_expr != null) { |
| 3872 | | @panic("TODO"); |
| 3868 | if (fn_proto.align_expr) |align_expr| { |
| 3869 | try stack.append(RenderState { .Text = ") " }); |
| 3870 | try stack.append(RenderState { .Expression = align_expr}); |
| 3871 | try stack.append(RenderState { .Text = "align(" }); |
| 3873 | 3872 | } |
| 3874 | 3873 | |
| 3875 | 3874 | try stack.append(RenderState { .Text = ") " }); |
| ... | ... | @@ -4271,26 +4270,6 @@ pub const Parser = struct { |
| 4271 | 4270 | ast.Node.Id.TestDecl, |
| 4272 | 4271 | ast.Node.Id.ParamDecl => unreachable, |
| 4273 | 4272 | }, |
| 4274 | | RenderState.FnProtoRParen => |fn_proto| { |
| 4275 | | try stream.print(")"); |
| 4276 | | if (fn_proto.align_expr != null) { |
| 4277 | | @panic("TODO"); |
| 4278 | | } |
| 4279 | | try stream.print(" "); |
| 4280 | | if (fn_proto.body_node) |body_node| { |
| 4281 | | try stack.append(RenderState { .Expression = body_node}); |
| 4282 | | try stack.append(RenderState { .Text = " "}); |
| 4283 | | } |
| 4284 | | switch (fn_proto.return_type) { |
| 4285 | | ast.NodeFnProto.ReturnType.Explicit => |node| { |
| 4286 | | try stack.append(RenderState { .Expression = node}); |
| 4287 | | }, |
| 4288 | | ast.NodeFnProto.ReturnType.InferErrorSet => |node| { |
| 4289 | | try stream.print("!"); |
| 4290 | | try stack.append(RenderState { .Expression = node}); |
| 4291 | | }, |
| 4292 | | } |
| 4293 | | }, |
| 4294 | 4273 | RenderState.Statement => |base| { |
| 4295 | 4274 | if (base.comment) |comment| { |
| 4296 | 4275 | for (comment.lines.toSliceConst()) |line_token| { |
| ... | ... | @@ -4644,12 +4623,20 @@ test "zig fmt: var type" { |
| 4644 | 4623 | ); |
| 4645 | 4624 | } |
| 4646 | 4625 | |
| 4647 | | test "zig fmt: extern function" { |
| 4626 | test "zig fmt: functions" { |
| 4648 | 4627 | try testCanonical( |
| 4649 | 4628 | \\extern fn puts(s: &const u8) c_int; |
| 4650 | 4629 | \\extern "c" fn puts(s: &const u8) c_int; |
| 4651 | 4630 | \\export fn puts(s: &const u8) c_int; |
| 4652 | 4631 | \\inline fn puts(s: &const u8) c_int; |
| 4632 | \\pub extern fn puts(s: &const u8) c_int; |
| 4633 | \\pub extern "c" fn puts(s: &const u8) c_int; |
| 4634 | \\pub export fn puts(s: &const u8) c_int; |
| 4635 | \\pub inline fn puts(s: &const u8) c_int; |
| 4636 | \\pub extern fn puts(s: &const u8) align(2 + 2) c_int; |
| 4637 | \\pub extern "c" fn puts(s: &const u8) align(2 + 2) c_int; |
| 4638 | \\pub export fn puts(s: &const u8) align(2 + 2) c_int; |
| 4639 | \\pub inline fn puts(s: &const u8) align(2 + 2) c_int; |
| 4653 | 4640 | \\ |
| 4654 | 4641 | ); |
| 4655 | 4642 | } |