| ... | @@ -12,7 +12,7 @@ pub const Error = error{ | ... | @@ -12,7 +12,7 @@ pub const Error = error{ |
| 12 | }; | 12 | }; |
| 13 | | 13 | |
| 14 | /// Returns whether anything changed | 14 | /// Returns whether anything changed |
| 15 | pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf(stream).Error || Error)!bool { | 15 | pub fn render(allocator: *mem.Allocator, stream: anytype, tree: *ast.Tree) (@TypeOf(stream).Error || Error)!bool { |
| 16 | // cannot render an invalid tree | 16 | // cannot render an invalid tree |
| 17 | std.debug.assert(tree.errors.len == 0); | 17 | std.debug.assert(tree.errors.len == 0); |
| 18 | | 18 | |
| ... | @@ -64,7 +64,7 @@ pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf( | ... | @@ -64,7 +64,7 @@ pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf( |
| 64 | | 64 | |
| 65 | fn renderRoot( | 65 | fn renderRoot( |
| 66 | allocator: *mem.Allocator, | 66 | allocator: *mem.Allocator, |
| 67 | stream: var, | 67 | stream: anytype, |
| 68 | tree: *ast.Tree, | 68 | tree: *ast.Tree, |
| 69 | ) (@TypeOf(stream).Error || Error)!void { | 69 | ) (@TypeOf(stream).Error || Error)!void { |
| 70 | // render all the line comments at the beginning of the file | 70 | // render all the line comments at the beginning of the file |
| ... | @@ -191,13 +191,13 @@ fn renderRoot( | ... | @@ -191,13 +191,13 @@ fn renderRoot( |
| 191 | } | 191 | } |
| 192 | } | 192 | } |
| 193 | | 193 | |
| 194 | fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @TypeOf(stream).Error!void { | 194 | fn renderExtraNewline(tree: *ast.Tree, stream: anytype, start_col: *usize, node: *ast.Node) @TypeOf(stream).Error!void { |
| 195 | return renderExtraNewlineToken(tree, stream, start_col, node.firstToken()); | 195 | return renderExtraNewlineToken(tree, stream, start_col, node.firstToken()); |
| 196 | } | 196 | } |
| 197 | | 197 | |
| 198 | fn renderExtraNewlineToken( | 198 | fn renderExtraNewlineToken( |
| 199 | tree: *ast.Tree, | 199 | tree: *ast.Tree, |
| 200 | stream: var, | 200 | stream: anytype, |
| 201 | start_col: *usize, | 201 | start_col: *usize, |
| 202 | first_token: ast.TokenIndex, | 202 | first_token: ast.TokenIndex, |
| 203 | ) @TypeOf(stream).Error!void { | 203 | ) @TypeOf(stream).Error!void { |
| ... | @@ -218,11 +218,11 @@ fn renderExtraNewlineToken( | ... | @@ -218,11 +218,11 @@ fn renderExtraNewlineToken( |
| 218 | } | 218 | } |
| 219 | } | 219 | } |
| 220 | | 220 | |
| 221 | fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@TypeOf(stream).Error || Error)!void { | 221 | fn renderTopLevelDecl(allocator: *mem.Allocator, stream: anytype, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@TypeOf(stream).Error || Error)!void { |
| 222 | try renderContainerDecl(allocator, stream, tree, indent, start_col, decl, .Newline); | 222 | try renderContainerDecl(allocator, stream, tree, indent, start_col, decl, .Newline); |
| 223 | } | 223 | } |
| 224 | | 224 | |
| 225 | fn renderContainerDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node, space: Space) (@TypeOf(stream).Error || Error)!void { | 225 | fn renderContainerDecl(allocator: *mem.Allocator, stream: anytype, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node, space: Space) (@TypeOf(stream).Error || Error)!void { |
| 226 | switch (decl.id) { | 226 | switch (decl.id) { |
| 227 | .FnProto => { | 227 | .FnProto => { |
| 228 | const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl); | 228 | const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl); |
| ... | @@ -358,7 +358,7 @@ fn renderContainerDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, | ... | @@ -358,7 +358,7 @@ fn renderContainerDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, |
| 358 | | 358 | |
| 359 | fn renderExpression( | 359 | fn renderExpression( |
| 360 | allocator: *mem.Allocator, | 360 | allocator: *mem.Allocator, |
| 361 | stream: var, | 361 | stream: anytype, |
| 362 | tree: *ast.Tree, | 362 | tree: *ast.Tree, |
| 363 | indent: usize, | 363 | indent: usize, |
| 364 | start_col: *usize, | 364 | start_col: *usize, |
| ... | @@ -1179,9 +1179,15 @@ fn renderExpression( | ... | @@ -1179,9 +1179,15 @@ fn renderExpression( |
| 1179 | const error_type = @fieldParentPtr(ast.Node.ErrorType, "base", base); | 1179 | const error_type = @fieldParentPtr(ast.Node.ErrorType, "base", base); |
| 1180 | return renderToken(tree, stream, error_type.token, indent, start_col, space); | 1180 | return renderToken(tree, stream, error_type.token, indent, start_col, space); |
| 1181 | }, | 1181 | }, |
| 1182 | .VarType => { | 1182 | .AnyType => { |
| 1183 | const var_type = @fieldParentPtr(ast.Node.VarType, "base", base); | 1183 | const any_type = @fieldParentPtr(ast.Node.AnyType, "base", base); |
| 1184 | return renderToken(tree, stream, var_type.token, indent, start_col, space); | 1184 | if (mem.eql(u8, tree.tokenSlice(any_type.token), "var")) { |
| | 1185 | // TODO remove in next release cycle |
| | 1186 | try stream.writeAll("anytype"); |
| | 1187 | if (space == .Comma) try stream.writeAll(",\n"); |
| | 1188 | return; |
| | 1189 | } |
| | 1190 | return renderToken(tree, stream, any_type.token, indent, start_col, space); |
| 1185 | }, | 1191 | }, |
| 1186 | .ContainerDecl => { | 1192 | .ContainerDecl => { |
| 1187 | const container_decl = @fieldParentPtr(ast.Node.ContainerDecl, "base", base); | 1193 | const container_decl = @fieldParentPtr(ast.Node.ContainerDecl, "base", base); |
| ... | @@ -2053,7 +2059,7 @@ fn renderExpression( | ... | @@ -2053,7 +2059,7 @@ fn renderExpression( |
| 2053 | | 2059 | |
| 2054 | fn renderAsmOutput( | 2060 | fn renderAsmOutput( |
| 2055 | allocator: *mem.Allocator, | 2061 | allocator: *mem.Allocator, |
| 2056 | stream: var, | 2062 | stream: anytype, |
| 2057 | tree: *ast.Tree, | 2063 | tree: *ast.Tree, |
| 2058 | indent: usize, | 2064 | indent: usize, |
| 2059 | start_col: *usize, | 2065 | start_col: *usize, |
| ... | @@ -2081,7 +2087,7 @@ fn renderAsmOutput( | ... | @@ -2081,7 +2087,7 @@ fn renderAsmOutput( |
| 2081 | | 2087 | |
| 2082 | fn renderAsmInput( | 2088 | fn renderAsmInput( |
| 2083 | allocator: *mem.Allocator, | 2089 | allocator: *mem.Allocator, |
| 2084 | stream: var, | 2090 | stream: anytype, |
| 2085 | tree: *ast.Tree, | 2091 | tree: *ast.Tree, |
| 2086 | indent: usize, | 2092 | indent: usize, |
| 2087 | start_col: *usize, | 2093 | start_col: *usize, |
| ... | @@ -2099,7 +2105,7 @@ fn renderAsmInput( | ... | @@ -2099,7 +2105,7 @@ fn renderAsmInput( |
| 2099 | | 2105 | |
| 2100 | fn renderVarDecl( | 2106 | fn renderVarDecl( |
| 2101 | allocator: *mem.Allocator, | 2107 | allocator: *mem.Allocator, |
| 2102 | stream: var, | 2108 | stream: anytype, |
| 2103 | tree: *ast.Tree, | 2109 | tree: *ast.Tree, |
| 2104 | indent: usize, | 2110 | indent: usize, |
| 2105 | start_col: *usize, | 2111 | start_col: *usize, |
| ... | @@ -2171,7 +2177,7 @@ fn renderVarDecl( | ... | @@ -2171,7 +2177,7 @@ fn renderVarDecl( |
| 2171 | | 2177 | |
| 2172 | fn renderParamDecl( | 2178 | fn renderParamDecl( |
| 2173 | allocator: *mem.Allocator, | 2179 | allocator: *mem.Allocator, |
| 2174 | stream: var, | 2180 | stream: anytype, |
| 2175 | tree: *ast.Tree, | 2181 | tree: *ast.Tree, |
| 2176 | indent: usize, | 2182 | indent: usize, |
| 2177 | start_col: *usize, | 2183 | start_col: *usize, |
| ... | @@ -2198,7 +2204,7 @@ fn renderParamDecl( | ... | @@ -2198,7 +2204,7 @@ fn renderParamDecl( |
| 2198 | | 2204 | |
| 2199 | fn renderStatement( | 2205 | fn renderStatement( |
| 2200 | allocator: *mem.Allocator, | 2206 | allocator: *mem.Allocator, |
| 2201 | stream: var, | 2207 | stream: anytype, |
| 2202 | tree: *ast.Tree, | 2208 | tree: *ast.Tree, |
| 2203 | indent: usize, | 2209 | indent: usize, |
| 2204 | start_col: *usize, | 2210 | start_col: *usize, |
| ... | @@ -2236,7 +2242,7 @@ const Space = enum { | ... | @@ -2236,7 +2242,7 @@ const Space = enum { |
| 2236 | | 2242 | |
| 2237 | fn renderTokenOffset( | 2243 | fn renderTokenOffset( |
| 2238 | tree: *ast.Tree, | 2244 | tree: *ast.Tree, |
| 2239 | stream: var, | 2245 | stream: anytype, |
| 2240 | token_index: ast.TokenIndex, | 2246 | token_index: ast.TokenIndex, |
| 2241 | indent: usize, | 2247 | indent: usize, |
| 2242 | start_col: *usize, | 2248 | start_col: *usize, |
| ... | @@ -2434,7 +2440,7 @@ fn renderTokenOffset( | ... | @@ -2434,7 +2440,7 @@ fn renderTokenOffset( |
| 2434 | | 2440 | |
| 2435 | fn renderToken( | 2441 | fn renderToken( |
| 2436 | tree: *ast.Tree, | 2442 | tree: *ast.Tree, |
| 2437 | stream: var, | 2443 | stream: anytype, |
| 2438 | token_index: ast.TokenIndex, | 2444 | token_index: ast.TokenIndex, |
| 2439 | indent: usize, | 2445 | indent: usize, |
| 2440 | start_col: *usize, | 2446 | start_col: *usize, |
| ... | @@ -2445,8 +2451,8 @@ fn renderToken( | ... | @@ -2445,8 +2451,8 @@ fn renderToken( |
| 2445 | | 2451 | |
| 2446 | fn renderDocComments( | 2452 | fn renderDocComments( |
| 2447 | tree: *ast.Tree, | 2453 | tree: *ast.Tree, |
| 2448 | stream: var, | 2454 | stream: anytype, |
| 2449 | node: var, | 2455 | node: anytype, |
| 2450 | indent: usize, | 2456 | indent: usize, |
| 2451 | start_col: *usize, | 2457 | start_col: *usize, |
| 2452 | ) (@TypeOf(stream).Error || Error)!void { | 2458 | ) (@TypeOf(stream).Error || Error)!void { |
| ... | @@ -2456,7 +2462,7 @@ fn renderDocComments( | ... | @@ -2456,7 +2462,7 @@ fn renderDocComments( |
| 2456 | | 2462 | |
| 2457 | fn renderDocCommentsToken( | 2463 | fn renderDocCommentsToken( |
| 2458 | tree: *ast.Tree, | 2464 | tree: *ast.Tree, |
| 2459 | stream: var, | 2465 | stream: anytype, |
| 2460 | comment: *ast.Node.DocComment, | 2466 | comment: *ast.Node.DocComment, |
| 2461 | first_token: ast.TokenIndex, | 2467 | first_token: ast.TokenIndex, |
| 2462 | indent: usize, | 2468 | indent: usize, |
| ... | @@ -2532,7 +2538,7 @@ const FindByteOutStream = struct { | ... | @@ -2532,7 +2538,7 @@ const FindByteOutStream = struct { |
| 2532 | } | 2538 | } |
| 2533 | }; | 2539 | }; |
| 2534 | | 2540 | |
| 2535 | fn copyFixingWhitespace(stream: var, slice: []const u8) @TypeOf(stream).Error!void { | 2541 | fn copyFixingWhitespace(stream: anytype, slice: []const u8) @TypeOf(stream).Error!void { |
| 2536 | for (slice) |byte| switch (byte) { | 2542 | for (slice) |byte| switch (byte) { |
| 2537 | '\t' => try stream.writeAll(" "), | 2543 | '\t' => try stream.writeAll(" "), |
| 2538 | '\r' => {}, | 2544 | '\r' => {}, |