| ... | ... | @@ -12,7 +12,7 @@ pub const Error = error{ |
| 12 | 12 | }; |
| 13 | 13 | |
| 14 | 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 | 16 | // cannot render an invalid tree |
| 17 | 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 | 64 | |
| 65 | 65 | fn renderRoot( |
| 66 | 66 | allocator: *mem.Allocator, |
| 67 | | stream: var, |
| 67 | stream: anytype, |
| 68 | 68 | tree: *ast.Tree, |
| 69 | 69 | ) (@TypeOf(stream).Error || Error)!void { |
| 70 | 70 | // render all the line comments at the beginning of the file |
| ... | ... | @@ -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 | 195 | return renderExtraNewlineToken(tree, stream, start_col, node.firstToken()); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | fn renderExtraNewlineToken( |
| 199 | 199 | tree: *ast.Tree, |
| 200 | | stream: var, |
| 200 | stream: anytype, |
| 201 | 201 | start_col: *usize, |
| 202 | 202 | first_token: ast.TokenIndex, |
| 203 | 203 | ) @TypeOf(stream).Error!void { |
| ... | ... | @@ -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 | 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 | 226 | switch (decl.id) { |
| 227 | 227 | .FnProto => { |
| 228 | 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 | 358 | |
| 359 | 359 | fn renderExpression( |
| 360 | 360 | allocator: *mem.Allocator, |
| 361 | | stream: var, |
| 361 | stream: anytype, |
| 362 | 362 | tree: *ast.Tree, |
| 363 | 363 | indent: usize, |
| 364 | 364 | start_col: *usize, |
| ... | ... | @@ -1179,9 +1179,15 @@ fn renderExpression( |
| 1179 | 1179 | const error_type = @fieldParentPtr(ast.Node.ErrorType, "base", base); |
| 1180 | 1180 | return renderToken(tree, stream, error_type.token, indent, start_col, space); |
| 1181 | 1181 | }, |
| 1182 | | .VarType => { |
| 1183 | | const var_type = @fieldParentPtr(ast.Node.VarType, "base", base); |
| 1184 | | return renderToken(tree, stream, var_type.token, indent, start_col, space); |
| 1182 | .AnyType => { |
| 1183 | const any_type = @fieldParentPtr(ast.Node.AnyType, "base", base); |
| 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 | 1192 | .ContainerDecl => { |
| 1187 | 1193 | const container_decl = @fieldParentPtr(ast.Node.ContainerDecl, "base", base); |
| ... | ... | @@ -2053,7 +2059,7 @@ fn renderExpression( |
| 2053 | 2059 | |
| 2054 | 2060 | fn renderAsmOutput( |
| 2055 | 2061 | allocator: *mem.Allocator, |
| 2056 | | stream: var, |
| 2062 | stream: anytype, |
| 2057 | 2063 | tree: *ast.Tree, |
| 2058 | 2064 | indent: usize, |
| 2059 | 2065 | start_col: *usize, |
| ... | ... | @@ -2081,7 +2087,7 @@ fn renderAsmOutput( |
| 2081 | 2087 | |
| 2082 | 2088 | fn renderAsmInput( |
| 2083 | 2089 | allocator: *mem.Allocator, |
| 2084 | | stream: var, |
| 2090 | stream: anytype, |
| 2085 | 2091 | tree: *ast.Tree, |
| 2086 | 2092 | indent: usize, |
| 2087 | 2093 | start_col: *usize, |
| ... | ... | @@ -2099,7 +2105,7 @@ fn renderAsmInput( |
| 2099 | 2105 | |
| 2100 | 2106 | fn renderVarDecl( |
| 2101 | 2107 | allocator: *mem.Allocator, |
| 2102 | | stream: var, |
| 2108 | stream: anytype, |
| 2103 | 2109 | tree: *ast.Tree, |
| 2104 | 2110 | indent: usize, |
| 2105 | 2111 | start_col: *usize, |
| ... | ... | @@ -2171,7 +2177,7 @@ fn renderVarDecl( |
| 2171 | 2177 | |
| 2172 | 2178 | fn renderParamDecl( |
| 2173 | 2179 | allocator: *mem.Allocator, |
| 2174 | | stream: var, |
| 2180 | stream: anytype, |
| 2175 | 2181 | tree: *ast.Tree, |
| 2176 | 2182 | indent: usize, |
| 2177 | 2183 | start_col: *usize, |
| ... | ... | @@ -2198,7 +2204,7 @@ fn renderParamDecl( |
| 2198 | 2204 | |
| 2199 | 2205 | fn renderStatement( |
| 2200 | 2206 | allocator: *mem.Allocator, |
| 2201 | | stream: var, |
| 2207 | stream: anytype, |
| 2202 | 2208 | tree: *ast.Tree, |
| 2203 | 2209 | indent: usize, |
| 2204 | 2210 | start_col: *usize, |
| ... | ... | @@ -2236,7 +2242,7 @@ const Space = enum { |
| 2236 | 2242 | |
| 2237 | 2243 | fn renderTokenOffset( |
| 2238 | 2244 | tree: *ast.Tree, |
| 2239 | | stream: var, |
| 2245 | stream: anytype, |
| 2240 | 2246 | token_index: ast.TokenIndex, |
| 2241 | 2247 | indent: usize, |
| 2242 | 2248 | start_col: *usize, |
| ... | ... | @@ -2434,7 +2440,7 @@ fn renderTokenOffset( |
| 2434 | 2440 | |
| 2435 | 2441 | fn renderToken( |
| 2436 | 2442 | tree: *ast.Tree, |
| 2437 | | stream: var, |
| 2443 | stream: anytype, |
| 2438 | 2444 | token_index: ast.TokenIndex, |
| 2439 | 2445 | indent: usize, |
| 2440 | 2446 | start_col: *usize, |
| ... | ... | @@ -2445,8 +2451,8 @@ fn renderToken( |
| 2445 | 2451 | |
| 2446 | 2452 | fn renderDocComments( |
| 2447 | 2453 | tree: *ast.Tree, |
| 2448 | | stream: var, |
| 2449 | | node: var, |
| 2454 | stream: anytype, |
| 2455 | node: anytype, |
| 2450 | 2456 | indent: usize, |
| 2451 | 2457 | start_col: *usize, |
| 2452 | 2458 | ) (@TypeOf(stream).Error || Error)!void { |
| ... | ... | @@ -2456,7 +2462,7 @@ fn renderDocComments( |
| 2456 | 2462 | |
| 2457 | 2463 | fn renderDocCommentsToken( |
| 2458 | 2464 | tree: *ast.Tree, |
| 2459 | | stream: var, |
| 2465 | stream: anytype, |
| 2460 | 2466 | comment: *ast.Node.DocComment, |
| 2461 | 2467 | first_token: ast.TokenIndex, |
| 2462 | 2468 | indent: usize, |
| ... | ... | @@ -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 | 2542 | for (slice) |byte| switch (byte) { |
| 2537 | 2543 | '\t' => try stream.writeAll(" "), |
| 2538 | 2544 | '\r' => {}, |