aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorJimmi Holst Christensen <jhc@liab.dk>2018-04-12 08:46:26 +0200
committerJimmi Holst Christensen <jhc@liab.dk>2018-04-12 08:46:26 +0200
commit0d8646d262ebc3db6631421db8fc79228b6622f8 (patch)
treec5f410df568cf79e10106e159173a025e3b10a1a /std
parent2b86ffe34a7a03b20544b13f541f61bbc50ae015 (diff)
downloadzig-0d8646d262ebc3db6631421db8fc79228b6622f8.tar.gz
zig-0d8646d262ebc3db6631421db8fc79228b6622f8.zip
std.zig.parser now parses alignment of functions
Related #909 This allows it to parse `std/special/compiler_rt/index.zig`
Diffstat (limited to 'std')
-rw-r--r--std/zig/parser.zig51
1 files changed, 19 insertions, 32 deletions
diff --git a/std/zig/parser.zig b/std/zig/parser.zig
index 88e6ece35b..8948990f45 100644
--- a/std/zig/parser.zig
+++ b/std/zig/parser.zig
@@ -2330,12 +2330,14 @@ pub const Parser = struct {
},
State.FnProtoAlign => |fn_proto| {
+ stack.append(State { .FnProtoReturnType = fn_proto }) catch unreachable;
+
if (self.eatToken(Token.Id.Keyword_align)) |align_token| {
- @panic("TODO fn proto align");
+ try stack.append(State { .ExpectToken = Token.Id.RParen });
+ try stack.append(State { .Expression = DestPtr { .NullableField = &fn_proto.align_expr } });
+ try stack.append(State { .ExpectToken = Token.Id.LParen });
}
- stack.append(State {
- .FnProtoReturnType = fn_proto,
- }) catch unreachable;
+
continue;
},
@@ -2349,10 +2351,6 @@ pub const Parser = struct {
}) catch unreachable;
continue;
},
- Token.Id.Keyword_align => {
- @panic("TODO fn proto align");
- continue;
- },
else => {
// TODO: this is a special case. Remove this when #760 is fixed
if (token.id == Token.Id.Keyword_error) {
@@ -3179,7 +3177,6 @@ pub const Parser = struct {
const RenderState = union(enum) {
TopLevelDecl: &ast.Node,
- FnProtoRParen: &ast.NodeFnProto,
ParamDecl: &ast.Node,
Text: []const u8,
Expression: &ast.Node,
@@ -3868,8 +3865,10 @@ pub const Parser = struct {
},
}
- if (fn_proto.align_expr != null) {
- @panic("TODO");
+ if (fn_proto.align_expr) |align_expr| {
+ try stack.append(RenderState { .Text = ") " });
+ try stack.append(RenderState { .Expression = align_expr});
+ try stack.append(RenderState { .Text = "align(" });
}
try stack.append(RenderState { .Text = ") " });
@@ -4271,26 +4270,6 @@ pub const Parser = struct {
ast.Node.Id.TestDecl,
ast.Node.Id.ParamDecl => unreachable,
},
- RenderState.FnProtoRParen => |fn_proto| {
- try stream.print(")");
- if (fn_proto.align_expr != null) {
- @panic("TODO");
- }
- try stream.print(" ");
- if (fn_proto.body_node) |body_node| {
- try stack.append(RenderState { .Expression = body_node});
- try stack.append(RenderState { .Text = " "});
- }
- switch (fn_proto.return_type) {
- ast.NodeFnProto.ReturnType.Explicit => |node| {
- try stack.append(RenderState { .Expression = node});
- },
- ast.NodeFnProto.ReturnType.InferErrorSet => |node| {
- try stream.print("!");
- try stack.append(RenderState { .Expression = node});
- },
- }
- },
RenderState.Statement => |base| {
if (base.comment) |comment| {
for (comment.lines.toSliceConst()) |line_token| {
@@ -4644,12 +4623,20 @@ test "zig fmt: var type" {
);
}
-test "zig fmt: extern function" {
+test "zig fmt: functions" {
try testCanonical(
\\extern fn puts(s: &const u8) c_int;
\\extern "c" fn puts(s: &const u8) c_int;
\\export fn puts(s: &const u8) c_int;
\\inline fn puts(s: &const u8) c_int;
+ \\pub extern fn puts(s: &const u8) c_int;
+ \\pub extern "c" fn puts(s: &const u8) c_int;
+ \\pub export fn puts(s: &const u8) c_int;
+ \\pub inline fn puts(s: &const u8) c_int;
+ \\pub extern fn puts(s: &const u8) align(2 + 2) c_int;
+ \\pub extern "c" fn puts(s: &const u8) align(2 + 2) c_int;
+ \\pub export fn puts(s: &const u8) align(2 + 2) c_int;
+ \\pub inline fn puts(s: &const u8) align(2 + 2) c_int;
\\
);
}