aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/docgen.zig48
-rw-r--r--doc/langref.html.in20
2 files changed, 50 insertions, 18 deletions
diff --git a/doc/docgen.zig b/doc/docgen.zig
index ad13275a4c..1261981af3 100644
--- a/doc/docgen.zig
+++ b/doc/docgen.zig
@@ -8,6 +8,7 @@ const Progress = std.Progress;
const print = std.debug.print;
const mem = std.mem;
const testing = std.testing;
+const Allocator = std.mem.Allocator;
const max_doc_file_size = 10 * 1024 * 1024;
@@ -326,7 +327,7 @@ const Action = enum {
Close,
};
-fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
+fn genToc(allocator: *Allocator, tokenizer: *Tokenizer) !Toc {
var urls = std.StringHashMap(Token).init(allocator);
errdefer urls.deinit();
@@ -630,7 +631,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
};
}
-fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
+fn urlize(allocator: *Allocator, input: []const u8) ![]u8 {
var buf = std.ArrayList(u8).init(allocator);
defer buf.deinit();
@@ -649,7 +650,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
return buf.toOwnedSlice();
}
-fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
+fn escapeHtml(allocator: *Allocator, input: []const u8) ![]u8 {
var buf = std.ArrayList(u8).init(allocator);
defer buf.deinit();
@@ -695,7 +696,7 @@ test "term color" {
testing.expectEqualSlices(u8, "A<span class=\"t32\">green</span>B", result);
}
-fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
+fn termColor(allocator: *Allocator, input: []const u8) ![]u8 {
var buf = std.ArrayList(u8).init(allocator);
defer buf.deinit();
@@ -789,8 +790,15 @@ fn isType(name: []const u8) bool {
return false;
}
-fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token, raw_src: []const u8) !void {
- const src = mem.trim(u8, raw_src, " \n");
+fn tokenizeAndPrintRaw(
+ allocator: *Allocator,
+ docgen_tokenizer: *Tokenizer,
+ out: anytype,
+ source_token: Token,
+ raw_src: []const u8,
+) !void {
+ const src_non_terminated = mem.trim(u8, raw_src, " \n");
+ const src = try allocator.dupeZ(u8, src_non_terminated);
try out.writeAll("<code class=\"zig\">");
var tokenizer = std.zig.Tokenizer.init(src);
var index: usize = 0;
@@ -1016,12 +1024,24 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:
try out.writeAll("</code>");
}
-fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token) !void {
+fn tokenizeAndPrint(
+ allocator: *Allocator,
+ docgen_tokenizer: *Tokenizer,
+ out: anytype,
+ source_token: Token,
+) !void {
const raw_src = docgen_tokenizer.buffer[source_token.start..source_token.end];
- return tokenizeAndPrintRaw(docgen_tokenizer, out, source_token, raw_src);
+ return tokenizeAndPrintRaw(allocator, docgen_tokenizer, out, source_token, raw_src);
}
-fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8, do_code_tests: bool) !void {
+fn genHtml(
+ allocator: *Allocator,
+ tokenizer: *Tokenizer,
+ toc: *Toc,
+ out: anytype,
+ zig_exe: []const u8,
+ do_code_tests: bool,
+) !void {
var progress = Progress{};
const root_node = try progress.start("Generating docgen examples", toc.nodes.len);
defer root_node.end();
@@ -1048,7 +1068,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
},
.Builtin => |tok| {
try out.writeAll("<pre>");
- try tokenizeAndPrintRaw(tokenizer, out, tok, builtin_code);
+ try tokenizeAndPrintRaw(allocator, tokenizer, out, tok, builtin_code);
try out.writeAll("</pre>");
},
.HeaderOpen => |info| {
@@ -1069,7 +1089,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
try out.writeAll("</ul>\n");
},
.Syntax => |content_tok| {
- try tokenizeAndPrint(tokenizer, out, content_tok);
+ try tokenizeAndPrint(allocator, tokenizer, out, content_tok);
},
.Code => |code| {
const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];
@@ -1078,7 +1098,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
try out.print("<p class=\"file\">{s}.zig</p>", .{code.name});
}
try out.writeAll("<pre>");
- try tokenizeAndPrint(tokenizer, out, code.source_token);
+ try tokenizeAndPrint(allocator, tokenizer, out, code.source_token);
try out.writeAll("</pre>");
if (!do_code_tests) {
@@ -1497,7 +1517,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
}
}
-fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult {
+fn exec(allocator: *Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult {
const result = try ChildProcess.exec(.{
.allocator = allocator,
.argv = args,
@@ -1521,7 +1541,7 @@ fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u
return result;
}
-fn getBuiltinCode(allocator: *mem.Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 {
+fn getBuiltinCode(allocator: *Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 {
const result = try exec(allocator, env_map, &[_][]const u8{ zig_exe, "build-obj", "--show-builtin" });
return result.stdout;
}
diff --git a/doc/langref.html.in b/doc/langref.html.in
index 31de76359e..cd7bc3be5c 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -3025,7 +3025,7 @@ test "@tagName" {
</p>
{#code_begin|obj_err|parameter of type 'Foo' not allowed in function with calling convention 'C'#}
const Foo = enum { a, b, c };
-export fn entry(foo: Foo) void { }
+export fn entry(foo: Foo) void { _ = foo; }
{#code_end#}
<p>
For a C-ABI-compatible enum, provide an explicit tag type to
@@ -3346,7 +3346,7 @@ test "call foo" {
<p>
Blocks are used to limit the scope of variable declarations:
</p>
- {#code_begin|test_err|undeclared identifier#}
+ {#code_begin|test_err|unused local variable#}
test "access variable after block scope" {
{
var x: i32 = 1;
@@ -3377,7 +3377,7 @@ test "labeled break from labeled block expression" {
{#header_open|Shadowing#}
<p>It is never allowed for an identifier to "hide" another one by using the same name:</p>
- {#code_begin|test_err|redefinition#}
+ {#code_begin|test_err|local shadows declaration#}
const pi = 3.14;
test "inside test block" {
@@ -5257,6 +5257,7 @@ test "float widening" {
// Compile time coercion of float to int
test "implicit cast to comptime_int" {
var f: f32 = 54.0 / 5;
+ _ = f;
}
{#code_end#}
{#header_close#}
@@ -5817,6 +5818,7 @@ fn foo(condition: bool) void {
if (condition) f32 else u64,
1234,
5678);
+ _ = result;
}
{#code_end#}
<p>
@@ -6313,7 +6315,7 @@ pub fn printValue(self: *Writer, value: anytype) !void {
<p>
And now, what happens if we give too many arguments to {#syntax#}printf{#endsyntax#}?
</p>
- {#code_begin|test_err|Unused argument in "here is a string: '{s}' here is a number: {}#}
+ {#code_begin|test_err|Unused argument in 'here is a string: '{s}' here is a number: {}#}
const print = @import("std").debug.print;
const a_number: i32 = 1234;
@@ -8853,6 +8855,7 @@ pub fn main() void {
comptime {
const array: [5]u8 = "hello".*;
const garbage = array[5];
+ _ = garbage;
}
{#code_end#}
<p>At runtime:</p>
@@ -8873,6 +8876,7 @@ fn foo(x: []const u8) u8 {
comptime {
const value: i32 = -1;
const unsigned = @intCast(u32, value);
+ _ = unsigned;
}
{#code_end#}
<p>At runtime:</p>
@@ -8895,6 +8899,7 @@ pub fn main() void {
comptime {
const spartan_count: u16 = 300;
const byte = @intCast(u8, spartan_count);
+ _ = byte;
}
{#code_end#}
<p>At runtime:</p>
@@ -9028,6 +9033,7 @@ test "wraparound addition and subtraction" {
{#code_begin|test_err|operation caused overflow#}
comptime {
const x = @shlExact(@as(u8, 0b01010101), 2);
+ _ = x;
}
{#code_end#}
<p>At runtime:</p>
@@ -9046,6 +9052,7 @@ pub fn main() void {
{#code_begin|test_err|exact shift shifted out 1 bits#}
comptime {
const x = @shrExact(@as(u8, 0b10101010), 2);
+ _ = x;
}
{#code_end#}
<p>At runtime:</p>
@@ -9066,6 +9073,7 @@ comptime {
const a: i32 = 1;
const b: i32 = 0;
const c = a / b;
+ _ = c;
}
{#code_end#}
<p>At runtime:</p>
@@ -9087,6 +9095,7 @@ comptime {
const a: i32 = 10;
const b: i32 = 0;
const c = a % b;
+ _ = c;
}
{#code_end#}
<p>At runtime:</p>
@@ -9108,6 +9117,7 @@ comptime {
const a: u32 = 10;
const b: u32 = 3;
const c = @divExact(a, b);
+ _ = c;
}
{#code_end#}
<p>At runtime:</p>
@@ -9300,6 +9310,7 @@ fn foo(set1: Set1) void {
comptime {
const ptr = @intToPtr(*align(1) i32, 0x1);
const aligned = @alignCast(4, ptr);
+ _ = aligned;
}
{#code_end#}
<p>At runtime:</p>
@@ -9414,6 +9425,7 @@ fn bar(f: *Foo) void {
comptime {
const opt_ptr: ?*i32 = null;
const ptr = @ptrCast(*i32, opt_ptr);
+ _ = ptr;
}
{#code_end#}
<p>At runtime:</p>