authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-17 00:22:33-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-17 00:22:53-05:00
log5aefabe045ca9c6f961bb5354961fe483085f145
tree75b6100c1792c4789c757ee1ad8d0cf5c8e9b022
parent2774fe8a1b5364729ad9faa1562e280f348c68bd

docgen: validate See Also sections

See #465

3 files changed, 149 insertions(+), 353 deletions(-)

doc/docgen.zig+90-70
...@@ -35,9 +35,10 @@ pub fn main() -> %void {...@@ -35,9 +35,10 @@ pub fn main() -> %void {
35 var file_out_stream = io.FileOutStream.init(&out_file);35 var file_out_stream = io.FileOutStream.init(&out_file);
36 var buffered_out_stream = io.BufferedOutStream.init(&file_out_stream.stream);36 var buffered_out_stream = io.BufferedOutStream.init(&file_out_stream.stream);
3737
38 const toc = try genToc(allocator, in_file_name, input_file_bytes);38 var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);
39 var toc = try genToc(allocator, &tokenizer);
3940
40 try genHtml(allocator, toc, &buffered_out_stream.stream);41 try genHtml(allocator, &tokenizer, &toc, &buffered_out_stream.stream);
41 try buffered_out_stream.flush();42 try buffered_out_stream.flush();
42}43}
4344
...@@ -240,21 +241,22 @@ const HeaderOpen = struct {...@@ -240,21 +241,22 @@ const HeaderOpen = struct {
240 n: usize,241 n: usize,
241};242};
242243
243const Tag = enum {244const SeeAlsoItem = struct {
244 Nav,245 name: []const u8,
245 HeaderOpen,246 token: Token,
246 HeaderClose,
247};247};
248248
249const Node = union(enum) {249const Node = union(enum) {
250 Content: []const u8,250 Content: []const u8,
251 Nav,251 Nav,
252 HeaderOpen: HeaderOpen,252 HeaderOpen: HeaderOpen,
253 SeeAlso: []const SeeAlsoItem,
253};254};
254255
255const Toc = struct {256const Toc = struct {
256 nodes: []Node,257 nodes: []Node,
257 toc: []u8,258 toc: []u8,
259 urls: std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8),
258};260};
259261
260const Action = enum {262const Action = enum {
...@@ -262,11 +264,9 @@ const Action = enum {...@@ -262,11 +264,9 @@ const Action = enum {
262 Close,264 Close,
263};265};
264266
265fn genToc(allocator: &mem.Allocator, source_file_name: []const u8, input_file_bytes: []const u8) -> %Toc {267fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) -> %Toc {
266 var tokenizer = Tokenizer.init(source_file_name, input_file_bytes);
267
268 var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);268 var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);
269 defer urls.deinit();269 %defer urls.deinit();
270270
271 var header_stack_size: usize = 0;271 var header_stack_size: usize = 0;
272 var last_action = Action.Open;272 var last_action = Action.Open;
...@@ -287,89 +287,98 @@ fn genToc(allocator: &mem.Allocator, source_file_name: []const u8, input_file_by...@@ -287,89 +287,98 @@ fn genToc(allocator: &mem.Allocator, source_file_name: []const u8, input_file_by
287 switch (token.id) {287 switch (token.id) {
288 Token.Id.Eof => {288 Token.Id.Eof => {
289 if (header_stack_size != 0) {289 if (header_stack_size != 0) {
290 return parseError(&tokenizer, token, "unbalanced headers");290 return parseError(tokenizer, token, "unbalanced headers");
291 }291 }
292 try toc.write(" </ul>\n");292 try toc.write(" </ul>\n");
293 break;293 break;
294 },294 },
295 Token.Id.Content => {295 Token.Id.Content => {
296 try nodes.append(Node {.Content = input_file_bytes[token.start..token.end] });296 try nodes.append(Node {.Content = tokenizer.buffer[token.start..token.end] });
297 },297 },
298 Token.Id.BracketOpen => {298 Token.Id.BracketOpen => {
299 const tag_token = try eatToken(&tokenizer, Token.Id.TagContent);299 const tag_token = try eatToken(tokenizer, Token.Id.TagContent);
300 const tag_name = input_file_bytes[tag_token.start..tag_token.end];300 const tag_name = tokenizer.buffer[tag_token.start..tag_token.end];
301301
302 var tag: Tag = undefined;
303 if (mem.eql(u8, tag_name, "nav")) {302 if (mem.eql(u8, tag_name, "nav")) {
304 tag = Tag.Nav;303 _ = eatToken(tokenizer, Token.Id.BracketClose);
304
305 try nodes.append(Node.Nav);
305 } else if (mem.eql(u8, tag_name, "header_open")) {306 } else if (mem.eql(u8, tag_name, "header_open")) {
306 tag = Tag.HeaderOpen;307 _ = eatToken(tokenizer, Token.Id.Separator);
308 const content_token = try eatToken(tokenizer, Token.Id.TagContent);
309 const content = tokenizer.buffer[content_token.start..content_token.end];
310 _ = eatToken(tokenizer, Token.Id.BracketClose);
311
307 header_stack_size += 1;312 header_stack_size += 1;
313
314 const urlized = try urlize(allocator, content);
315 try nodes.append(Node{.HeaderOpen = HeaderOpen {
316 .name = content,
317 .url = urlized,
318 .n = header_stack_size,
319 }});
320 if (try urls.put(urlized, tag_token)) |other_tag_token| {
321 parseError(tokenizer, tag_token, "duplicate header url: #{}", urlized) catch {};
322 parseError(tokenizer, other_tag_token, "other tag here") catch {};
323 return error.ParseError;
324 }
325 if (last_action == Action.Open) {
326 try toc.writeByte('\n');
327 try toc.writeByteNTimes(' ', header_stack_size * 4);
328 try toc.write("<ul>\n");
329 } else {
330 last_action = Action.Open;
331 }
332 try toc.writeByteNTimes(' ', 4 + header_stack_size * 4);
333 try toc.print("<li><a href=\"#{}\">{}</a>", urlized, content);
308 } else if (mem.eql(u8, tag_name, "header_close")) {334 } else if (mem.eql(u8, tag_name, "header_close")) {
309 if (header_stack_size == 0) {335 if (header_stack_size == 0) {
310 return parseError(&tokenizer, tag_token, "unbalanced close header");336 return parseError(tokenizer, tag_token, "unbalanced close header");
311 }337 }
312 header_stack_size -= 1;338 header_stack_size -= 1;
313 tag = Tag.HeaderClose;339 _ = eatToken(tokenizer, Token.Id.BracketClose);
314 } else {340
315 return parseError(&tokenizer, tag_token, "unrecognized tag name: {}", tag_name);341 if (last_action == Action.Close) {
316 }342 try toc.writeByteNTimes(' ', 8 + header_stack_size * 4);
317343 try toc.write("</ul></li>\n");
318 var tag_content: ?[]const u8 = null;344 } else {
319 const maybe_sep = tokenizer.next();345 try toc.write("</li>\n");
320 if (maybe_sep.id == Token.Id.Separator) {346 last_action = Action.Close;
321 const content_token = try eatToken(&tokenizer, Token.Id.TagContent);347 }
322 tag_content = input_file_bytes[content_token.start..content_token.end];348 } else if (mem.eql(u8, tag_name, "see_also")) {
323 _ = eatToken(&tokenizer, Token.Id.BracketClose);349 var list = std.ArrayList(SeeAlsoItem).init(allocator);
324 } else {350 %defer list.deinit();
325 try assertToken(&tokenizer, maybe_sep, Token.Id.BracketClose);351
326 }352 while (true) {
327353 const see_also_tok = tokenizer.next();
328 switch (tag) {354 switch (see_also_tok.id) {
329 Tag.HeaderOpen => {355 Token.Id.TagContent => {
330 const content = tag_content ?? return parseError(&tokenizer, tag_token, "expected header content");356 const content = tokenizer.buffer[see_also_tok.start..see_also_tok.end];
331 const urlized = try urlize(allocator, content);357 try list.append(SeeAlsoItem {
332 try nodes.append(Node{.HeaderOpen = HeaderOpen {358 .name = content,
333 .name = content,359 .token = see_also_tok,
334 .url = urlized,360 });
335 .n = header_stack_size,361 },
336 }});362 Token.Id.Separator => {},
337 if (try urls.put(urlized, tag_token)) |other_tag_token| {363 Token.Id.BracketClose => {
338 parseError(&tokenizer, tag_token, "duplicate header url: #{}", urlized) catch {};364 try nodes.append(Node {.SeeAlso = list.toOwnedSlice() } );
339 parseError(&tokenizer, other_tag_token, "other tag here") catch {};365 break;
340 return error.ParseError;366 },
341 }367 else => return parseError(tokenizer, see_also_tok, "invalid see_also token"),
342 if (last_action == Action.Open) {
343 try toc.writeByte('\n');
344 try toc.writeByteNTimes(' ', header_stack_size * 4);
345 try toc.write("<ul>\n");
346 } else {
347 last_action = Action.Open;
348 }
349 try toc.writeByteNTimes(' ', 4 + header_stack_size * 4);
350 try toc.print("<li><a href=\"#{}\">{}</a>", urlized, content);
351 },
352 Tag.HeaderClose => {
353 if (last_action == Action.Close) {
354 try toc.writeByteNTimes(' ', 8 + header_stack_size * 4);
355 try toc.write("</ul></li>\n");
356 } else {
357 try toc.write("</li>\n");
358 last_action = Action.Close;
359 }368 }
360 },369 }
361 Tag.Nav => {370 } else {
362 try nodes.append(Node.Nav);371 return parseError(tokenizer, tag_token, "unrecognized tag name: {}", tag_name);
363 },
364 }372 }
365 },373 },
366 else => return parseError(&tokenizer, token, "invalid token"),374 else => return parseError(tokenizer, token, "invalid token"),
367 }375 }
368 }376 }
369377
370 return Toc {378 return Toc {
371 .nodes = nodes.toOwnedSlice(),379 .nodes = nodes.toOwnedSlice(),
372 .toc = toc_buf.toOwnedSlice(),380 .toc = toc_buf.toOwnedSlice(),
381 .urls = urls,
373 };382 };
374}383}
375384
...@@ -393,7 +402,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) -> %[]u8 {...@@ -393,7 +402,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) -> %[]u8 {
393 return buf.toOwnedSlice();402 return buf.toOwnedSlice();
394}403}
395404
396fn genHtml(allocator: &mem.Allocator, toc: &const Toc, out: &io.OutStream) -> %void {405fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io.OutStream) -> %void {
397 for (toc.nodes) |node| {406 for (toc.nodes) |node| {
398 switch (node) {407 switch (node) {
399 Node.Content => |data| {408 Node.Content => |data| {
...@@ -405,6 +414,17 @@ fn genHtml(allocator: &mem.Allocator, toc: &const Toc, out: &io.OutStream) -> %v...@@ -405,6 +414,17 @@ fn genHtml(allocator: &mem.Allocator, toc: &const Toc, out: &io.OutStream) -> %v
405 Node.HeaderOpen => |info| {414 Node.HeaderOpen => |info| {
406 try out.print("<h{} id=\"{}\">{}</h{}>\n", info.n, info.url, info.name, info.n);415 try out.print("<h{} id=\"{}\">{}</h{}>\n", info.n, info.url, info.name, info.n);
407 },416 },
417 Node.SeeAlso => |items| {
418 try out.write("<p>See also:</p><ul>\n");
419 for (items) |item| {
420 const url = try urlize(allocator, item.name);
421 if (!toc.urls.contains(url)) {
422 return parseError(tokenizer, item.token, "url not found: {}", url);
423 }
424 try out.print("<li><a href=\"#{}\">{}</a></li>\n", url, item.name);
425 }
426 try out.write("</ul>\n");
427 },
408 }428 }
409 }429 }
410430
doc/langref.html.in+55-283
...@@ -77,13 +77,7 @@ Hello, world!</code></pre>...@@ -77,13 +77,7 @@ Hello, world!</code></pre>
77pub fn main() -&gt; %void {77pub fn main() -&gt; %void {
78 warn("Hello, world!\n");78 warn("Hello, world!\n");
79}</code></pre>79}</code></pre>
80 <p>See also:</p>80 {#see_also|Values|@import|Errors|Root Source File#}
81 <ul>
82 <li><a href="#values">Values</a></li>
83 <li><a href="#builtin-import">@import</a></li>
84 <li><a href="#errors">Errors</a></li>
85 <li><a href="#root-source-file">Root Source File</a></li>
86 </ul>
87 {#header_close#}81 {#header_close#}
88 {#header_open|Source Encoding#}82 {#header_open|Source Encoding#}
89 <p>Zig source code is encoded in UTF-8. An invalid UTF-8 byte sequence results in a compile error.</p>83 <p>Zig source code is encoded in UTF-8. An invalid UTF-8 byte sequence results in a compile error.</p>
...@@ -391,13 +385,7 @@ value: 1234</code></pre>...@@ -391,13 +385,7 @@ value: 1234</code></pre>
391 <td>an error code</td>385 <td>an error code</td>
392 </tr>386 </tr>
393 </table>387 </table>
394 <p>See also:</p>388 {#see_also|Integers|Floats|void|Errors#}
395 <ul>
396 <li><a href="#integers">Integers</a></li>
397 <li><a href="#floats">Floats</a></li>
398 <li><a href="#void">void</a></li>
399 <li><a href="#errors">Errors</a></li>
400 </ul>
401 {#header_close#}389 {#header_close#}
402 {#header_open|Primitive Values#}390 {#header_open|Primitive Values#}
403 <table>391 <table>
...@@ -426,11 +414,7 @@ value: 1234</code></pre>...@@ -426,11 +414,7 @@ value: 1234</code></pre>
426 <td>refers to the thing in immediate scope</td>414 <td>refers to the thing in immediate scope</td>
427 </tr>415 </tr>
428 </table>416 </table>
429 <p>See also:</p>417 {#see_also|Nullables|this#}
430 <ul>
431 <li><a href="#nullables">Nullables</a></li>
432 <li><a href="#this">this</a></li>
433 </ul>
434 {#header_close#}418 {#header_close#}
435 {#header_open|String Literals#}419 {#header_open|String Literals#}
436 <pre><code class="zig">const assert = @import("std").debug.assert;420 <pre><code class="zig">const assert = @import("std").debug.assert;
...@@ -452,11 +436,7 @@ test "string literals" {...@@ -452,11 +436,7 @@ test "string literals" {
452}</code></pre>436}</code></pre>
453 <pre><code class="sh">$ zig test string_literals.zig437 <pre><code class="sh">$ zig test string_literals.zig
454Test 1/1 string literals...OK</code></pre>438Test 1/1 string literals...OK</code></pre>
455 <p>See also:</p>439 {#see_also|Arrays|Zig Test#}
456 <ul>
457 <li><a href="#arrays">Arrays</a></li>
458 <li><a href="#zig-test">Zig Test</a></li>
459 </ul>
460 {#header_open|Escape Sequences#}440 {#header_open|Escape Sequences#}
461 <table>441 <table>
462 <tr>442 <tr>
...@@ -538,10 +518,7 @@ Test 1/1 string literals...OK</code></pre>...@@ -538,10 +518,7 @@ Test 1/1 string literals...OK</code></pre>
538 In this example the variable <code>c_string_literal</code> has type <code>&amp;const char</code> and518 In this example the variable <code>c_string_literal</code> has type <code>&amp;const char</code> and
539 has a terminating null byte.519 has a terminating null byte.
540 </p>520 </p>
541 <p>See also:</p>521 {#see_also|@embedFile#}
542 <ul>
543 <li><a href="#builtin-embedFile">@embedFile</a></li>
544 </ul>
545 {#header_close#}522 {#header_close#}
546 {#header_close#}523 {#header_close#}
547 {#header_open|Assignment#}524 {#header_open|Assignment#}
...@@ -627,12 +604,7 @@ const binary_int = 0b11110000;</code></pre>...@@ -627,12 +604,7 @@ const binary_int = 0b11110000;</code></pre>
627 integer overflow. Also available are operations such as <code>+%</code> and604 integer overflow. Also available are operations such as <code>+%</code> and
628 <code>-%</code> which are defined to have wrapping arithmetic on all targets.605 <code>-%</code> which are defined to have wrapping arithmetic on all targets.
629 </p>606 </p>
630 <p>See also:</p>607 {#see_also|Integer Overflow|Division by Zero|Wrapping Operations#}
631 <ul>
632 <li><a href="#undef-integer-overflow">Integer Overflow</a></li>
633 <li><a href="#undef-division-by-zero">Division By Zero</a></li>
634 <li><a href="#undef-int-overflow-wrap">Wrapping Operations</a></li>
635 </ul>
636 {#header_close#}608 {#header_close#}
637 {#header_close#}609 {#header_close#}
638 {#header_open|Floats#}610 {#header_open|Floats#}
...@@ -680,11 +652,7 @@ $ zig build-exe test.zig --object foo.o...@@ -680,11 +652,7 @@ $ zig build-exe test.zig --object foo.o
680$ ./test652$ ./test
681optimized = 1.0e-2653optimized = 1.0e-2
682strict = 9.765625e-3</code></pre>654strict = 9.765625e-3</code></pre>
683 <p>See also:</p>655 {#see_also|@setFloatMode|Division by Zero#}
684 <ul>
685 <li><a href="#builtin-setFloatMode">@setFloatMode</a></li>
686 <li><a href="#undef-division-by-zero">Division By Zero</a></li>
687 </ul>
688 {#header_close#}656 {#header_close#}
689 {#header_open|Operators#}657 {#header_open|Operators#}
690 {#header_open|Table of Operators#}658 {#header_open|Table of Operators#}
...@@ -1402,11 +1370,7 @@ Test 1/4 iterate over an array...OK...@@ -1402,11 +1370,7 @@ Test 1/4 iterate over an array...OK
1402Test 2/4 modify an array...OK1370Test 2/4 modify an array...OK
1403Test 3/4 compile-time array initalization...OK1371Test 3/4 compile-time array initalization...OK
1404Test 4/4 array initialization with function calls...OK</code></pre>1372Test 4/4 array initialization with function calls...OK</code></pre>
1405 <p>See also:</p>1373 {#see_also|for|Slices#}
1406 <ul>
1407 <li><a href="#for">for</a></li>
1408 <li><a href="#slices">Slices</a></li>
1409 </ul>
1410 {#header_close#}1374 {#header_close#}
1411 {#header_open|Pointers#}1375 {#header_open|Pointers#}
1412 <pre><code class="zig">const assert = @import("std").debug.assert;1376 <pre><code class="zig">const assert = @import("std").debug.assert;
...@@ -1659,11 +1623,7 @@ Tests failed. Use the following command to reproduce the failure:...@@ -1659,11 +1623,7 @@ Tests failed. Use the following command to reproduce the failure:
1659 <p>Instead, use <a href="#builtin-bitCast">@bitCast</a>:1623 <p>Instead, use <a href="#builtin-bitCast">@bitCast</a>:
1660 <pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre>1624 <pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre>
1661 <p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p>1625 <p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p>
1662 <p>See also:</p>1626 {#see_also|Slices|Memory#}
1663 <ul>
1664 <li><a href="#slices">Slices</a></li>
1665 <li><a href="#memory">Memory</a></li>
1666 </ul>
1667 {#header_close#}1627 {#header_close#}
1668 {#header_close#}1628 {#header_close#}
1669 {#header_open|Slices#}1629 {#header_open|Slices#}
...@@ -1760,12 +1720,7 @@ test "slice widening" {...@@ -1760,12 +1720,7 @@ test "slice widening" {
1760Test 1/3 using slices for strings...OK1720Test 1/3 using slices for strings...OK
1761Test 2/3 slice pointer...OK1721Test 2/3 slice pointer...OK
1762Test 3/3 slice widening...OK</code></pre>1722Test 3/3 slice widening...OK</code></pre>
1763 <p>See also:</p>1723 {#see_also|Pointers|for|Arrays#}
1764 <ul>
1765 <li><a href="#pointers">Pointers</a></li>
1766 <li><a href="#for">for</a></li>
1767 <li><a href="#arrays">Arrays</a></li>
1768 </ul>
1769 {#header_close#}1724 {#header_close#}
1770 {#header_open|struct#}1725 {#header_open|struct#}
1771 <pre><code class="zig">// Declare a struct.1726 <pre><code class="zig">// Declare a struct.
...@@ -1907,11 +1862,7 @@ Test 1/4 dot product...OK...@@ -1907,11 +1862,7 @@ Test 1/4 dot product...OK
1907Test 2/4 struct namespaced variable...OK1862Test 2/4 struct namespaced variable...OK
1908Test 3/4 field parent pointer...OK1863Test 3/4 field parent pointer...OK
1909Test 4/4 linked list...OK</code></pre>1864Test 4/4 linked list...OK</code></pre>
1910 <p>See also:</p>1865 {#see_also|comptime|@fieldParentPtr#}
1911 <ul>
1912 <li><a href="#comptime">comptime</a></li>
1913 <li><a href="#builtin-fieldParentPtr">@fieldParentPtr</a></li>
1914 </ul>
1915 {#header_close#}1866 {#header_close#}
1916 {#header_open|enum#}1867 {#header_open|enum#}
1917 <pre><code class="zig">const assert = @import("std").debug.assert;1868 <pre><code class="zig">const assert = @import("std").debug.assert;
...@@ -2024,12 +1975,7 @@ Test 5/8 @TagType...OK...@@ -2024,12 +1975,7 @@ Test 5/8 @TagType...OK
2024Test 6/8 @memberCount...OK1975Test 6/8 @memberCount...OK
2025Test 7/8 @memberName...OK1976Test 7/8 @memberName...OK
2026Test 8/8 @tagName...OK</code></pre>1977Test 8/8 @tagName...OK</code></pre>
2027 <p>See also:</p>1978 {#see_also|@memberName|@memberCount|@tagName#}
2028 <ul>
2029 <li><a href="#builtin-memberName">@memberName</a></li>
2030 <li><a href="#builtin-memberCount">@memberCount</a></li>
2031 <li><a href="#builtin-tagName">@tagName</a></li>
2032 </ul>
2033 {#header_close#}1979 {#header_close#}
2034 {#header_open|union#}1980 {#header_open|union#}
2035 <pre><code class="zig">const assert = @import("std").debug.assert;1981 <pre><code class="zig">const assert = @import("std").debug.assert;
...@@ -2235,13 +2181,7 @@ test "switch inside function" {...@@ -2235,13 +2181,7 @@ test "switch inside function" {
2235Test 1/2 switch simple...OK2181Test 1/2 switch simple...OK
2236Test 2/2 switch enum...OK2182Test 2/2 switch enum...OK
2237Test 3/3 switch inside function...OK</code></pre>2183Test 3/3 switch inside function...OK</code></pre>
2238 <p>See also:</p>2184 {#see_also|comptime|enum|@compileError|Compile Variables#}
2239 <ul>
2240 <li><a href="#comptime">comptime</a></li>
2241 <li><a href="#enum">enum</a></li>
2242 <li><a href="#builtin-compileError">@compileError</a></li>
2243 <li><a href="#compile-variables">Compile Variables</a></li>
2244 </ul>
2245 {#header_close#}2185 {#header_close#}
2246 {#header_open|while#}2186 {#header_open|while#}
2247 <pre><code class="zig">const assert = @import("std").debug.assert;2187 <pre><code class="zig">const assert = @import("std").debug.assert;
...@@ -2404,14 +2344,7 @@ Test 5/8 while loop continuation expression, more complicated...OK...@@ -2404,14 +2344,7 @@ Test 5/8 while loop continuation expression, more complicated...OK
2404Test 6/8 while else...OK2344Test 6/8 while else...OK
2405Test 7/8 while null capture...OK2345Test 7/8 while null capture...OK
2406Test 8/8 inline while loop...OK</code></pre>2346Test 8/8 inline while loop...OK</code></pre>
2407 <p>See also:</p>2347 {#see_also|if|Nullables|Errors|comptime|unreachable#}
2408 <ul>
2409 <li><a href="#if">if</a></li>
2410 <li><a href="#nullables">Nullables</a></li>
2411 <li><a href="#errors">Errors</a></li>
2412 <li><a href="#comptime">comptime</a></li>
2413 <li><a href="#unreachable">unreachable</a></li>
2414 </ul>
2415 {#header_close#}2348 {#header_close#}
2416 {#header_open|for#}2349 {#header_open|for#}
2417 <pre><code class="zig">const assert = @import("std").debug.assert;2350 <pre><code class="zig">const assert = @import("std").debug.assert;
...@@ -2507,13 +2440,7 @@ Test 1/4 for basics...OK...@@ -2507,13 +2440,7 @@ Test 1/4 for basics...OK
2507Test 2/4 for reference...OK2440Test 2/4 for reference...OK
2508Test 3/4 for else...OK2441Test 3/4 for else...OK
2509Test 4/4 inline for loop...OK</code></pre>2442Test 4/4 inline for loop...OK</code></pre>
2510 <p>See also:</p>2443 {#see_also|while|comptime|Arrays|Slices#}
2511 <ul>
2512 <li><a href="#while">while</a></li>
2513 <li><a href="#comptime">comptime</a></li>
2514 <li><a href="#arrays">Arrays</a></li>
2515 <li><a href="#slices">Slices</a></li>
2516 </ul>
2517 {#header_close#}2444 {#header_close#}
2518 {#header_open|if#}2445 {#header_open|if#}
2519 <pre><code class="zig">// If expressions have three uses, corresponding to the three types:2446 <pre><code class="zig">// If expressions have three uses, corresponding to the three types:
...@@ -2628,29 +2555,9 @@ test "if error union" {...@@ -2628,29 +2555,9 @@ test "if error union" {
2628Test 1/3 if boolean...OK2555Test 1/3 if boolean...OK
2629Test 2/3 if nullable...OK2556Test 2/3 if nullable...OK
2630Test 3/3 if error union...OK</code></pre>2557Test 3/3 if error union...OK</code></pre>
2631 <p>See also:</p>2558 {#see_also|Nullables|Errors#}
2632 <ul>
2633 <li><a href="#nullables">Nullables</a></li>
2634 <li><a href="#errors">Errors</a></li>
2635 </ul>
2636 {#header_close#}2559 {#header_close#}
2637 {#header_open|goto#}2560 {#header_open|defer#}
2638 <pre><code class="zig">const assert = @import("std").debug.assert;
2639
2640test "goto" {
2641 var value = false;
2642 goto label;
2643 value = true;
2644
2645label:
2646 assert(value == false);
2647}
2648</code></pre>
2649 <pre><code class="sh">$ zig test goto.zig
2650Test 1/1 goto...OK
2651</code></pre>
2652<p>Note that there are <a href="https://github.com/zig-lang/zig/issues/346">plans to remove goto</a></p>
2653{{deheader_open:fer}}
2654 <pre><code class="zig">const assert = @import("std").debug.assert;2561 <pre><code class="zig">const assert = @import("std").debug.assert;
2655const printf = @import("std").io.stdout.printf;2562const printf = @import("std").io.stdout.printf;
26562563
...@@ -2736,10 +2643,7 @@ encountered an error!...@@ -2736,10 +2643,7 @@ encountered an error!
2736end of function2643end of function
2737OK2644OK
2738</code></pre>2645</code></pre>
2739 <p>See also:</p>2646 {#see_also|Errors#}
2740 <ul>
2741 <li><a href="#errors">Errors</a></li>
2742 </ul>
2743 {#header_close#}2647 {#header_close#}
2744 {#header_open|unreachable#}2648 {#header_open|unreachable#}
2745 <p>2649 <p>
...@@ -2811,12 +2715,7 @@ comptime {...@@ -2811,12 +2715,7 @@ comptime {
2811test.zig:9:12: error: unreachable code2715test.zig:9:12: error: unreachable code
2812 assert(@typeOf(unreachable) == noreturn);2716 assert(@typeOf(unreachable) == noreturn);
2813 ^</code></pre>2717 ^</code></pre>
2814 <p>See also:</p>2718 {#see_also|Zig Test|Build Mode|comptime#}
2815 <ul>
2816 <li><a href="#zig-test">Zig Test</a></li>
2817 <li><a href="#build-mode">Build Mode</a></li>
2818 <li><a href="#comptime">comptime</a></li>
2819 </ul>
2820 {#header_close#}2719 {#header_close#}
2821 {#header_close#}2720 {#header_close#}
2822 {#header_open|noreturn#}2721 {#header_open|noreturn#}
...@@ -3142,12 +3041,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 {...@@ -3142,12 +3041,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 {
3142 in other languages.3041 in other languages.
3143 </li>3042 </li>
3144 </ul>3043 </ul>
3145 <p>See also:</p>3044 {#see_also|defer|if|switch#}
3146 <ul>
3147 <li><a href="#defer">defer</a></li>
3148 <li><a href="#if">if</a></li>
3149 <li><a href="#switch">switch</a></li>
3150 </ul>
3151 {#header_close#}3045 {#header_close#}
3152 {#header_open|Nullables#}3046 {#header_open|Nullables#}
3153 <p>3047 <p>
...@@ -3976,11 +3870,7 @@ comptime {...@@ -3976,11 +3870,7 @@ comptime {
3976 The result is a target-specific compile time constant. It is guaranteed to be3870 The result is a target-specific compile time constant. It is guaranteed to be
3977 less than or equal to <a href="#builtin-sizeOf">@sizeOf(T)</a>.3871 less than or equal to <a href="#builtin-sizeOf">@sizeOf(T)</a>.
3978 </p>3872 </p>
3979 <p>See also:</p>3873 {#see_also|Alignment#}
3980 <ul>
3981 <li><a href="#alignment">Alignment</a></li>
3982 </ul>
3983
3984 {#header_close#}3874 {#header_close#}
3985 {#header_open|@cDefine#}3875 {#header_open|@cDefine#}
3986 <pre><code class="zig">@cDefine(comptime name: []u8, value)</code></pre>3876 <pre><code class="zig">@cDefine(comptime name: []u8, value)</code></pre>
...@@ -3999,14 +3889,7 @@ comptime {...@@ -3999,14 +3889,7 @@ comptime {
3999 Use the void value, like this:3889 Use the void value, like this:
4000 </p>3890 </p>
4001 <pre><code class="zig">@cDefine("_GNU_SOURCE", {})</code></pre>3891 <pre><code class="zig">@cDefine("_GNU_SOURCE", {})</code></pre>
4002 <p>See also:</p>3892 {#see_also|Import from C Header File|@cInclude|@cImport|@cUndef|void#}
4003 <ul>
4004 <li><a href="#c-import">Import from C Header File</a></li>
4005 <li><a href="#builtin-cInclude">@cInclude</a></li>
4006 <li><a href="#builtin-cImport">@cImport</a></li>
4007 <li><a href="#builtin-cUndef">@cUndef</a></li>
4008 <li><a href="#void">void</a></li>
4009 </ul>
4010 {#header_close#}3893 {#header_close#}
4011 {#header_open|@cImport#}3894 {#header_open|@cImport#}
4012 <pre><code class="zig">@cImport(expression) -&gt; (namespace)</code></pre>3895 <pre><code class="zig">@cImport(expression) -&gt; (namespace)</code></pre>
...@@ -4019,13 +3902,7 @@ comptime {...@@ -4019,13 +3902,7 @@ comptime {
4019 <code>@cInclude</code>, <code>@cDefine</code>, and <code>@cUndef</code> work3902 <code>@cInclude</code>, <code>@cDefine</code>, and <code>@cUndef</code> work
4020 within this expression, appending to a temporary buffer which is then parsed as C code.3903 within this expression, appending to a temporary buffer which is then parsed as C code.
4021 </p>3904 </p>
4022 <p>See also:</p>3905 {#see_also|Import from C Header File|@cInclude|@cDefine|@cUndef#}
4023 <ul>
4024 <li><a href="#c-import">Import from C Header File</a></li>
4025 <li><a href="#builtin-cInclude">@cInclude</a></li>
4026 <li><a href="#builtin-cDefine">@cDefine</a></li>
4027 <li><a href="#builtin-cUndef">@cUndef</a></li>
4028 </ul>
4029 {#header_close#}3906 {#header_close#}
4030 {#header_open|@cInclude#}3907 {#header_open|@cInclude#}
4031 <pre><code class="zig">@cInclude(comptime path: []u8)</code></pre>3908 <pre><code class="zig">@cInclude(comptime path: []u8)</code></pre>
...@@ -4036,13 +3913,7 @@ comptime {...@@ -4036,13 +3913,7 @@ comptime {
4036 This appends <code>#include <$path>\n</code> to the <code>c_import</code>3913 This appends <code>#include <$path>\n</code> to the <code>c_import</code>
4037 temporary buffer.3914 temporary buffer.
4038 </p>3915 </p>
4039 <p>See also:</p>3916 {#see_also|Import from C Header File|@cImport|@cDefine|@cUndef#}
4040 <ul>
4041 <li><a href="#c-import">Import from C Header File</a></li>
4042 <li><a href="#builtin-cImport">@cImport</a></li>
4043 <li><a href="#builtin-cDefine">@cDefine</a></li>
4044 <li><a href="#builtin-cUndef">@cUndef</a></li>
4045 </ul>
4046 {#header_close#}3917 {#header_close#}
4047 {#header_open|@cUndef#}3918 {#header_open|@cUndef#}
4048 <pre><code class="zig">@cUndef(comptime name: []u8)</code></pre>3919 <pre><code class="zig">@cUndef(comptime name: []u8)</code></pre>
...@@ -4053,13 +3924,7 @@ comptime {...@@ -4053,13 +3924,7 @@ comptime {
4053 This appends <code>#undef $name</code> to the <code>@cImport</code>3924 This appends <code>#undef $name</code> to the <code>@cImport</code>
4054 temporary buffer.3925 temporary buffer.
4055 </p>3926 </p>
4056 <p>See also:</p>3927 {#see_also|Import from C Header File|@cImport|@cDefine|@cInclude#}
4057 <ul>
4058 <li><a href="#c-import">Import from C Header File</a></li>
4059 <li><a href="#builtin-cImport">@cImport</a></li>
4060 <li><a href="#builtin-cDefine">@cDefine</a></li>
4061 <li><a href="#builtin-cInclude">@cInclude</a></li>
4062 </ul>
4063 {#header_close#}3928 {#header_close#}
4064 {#header_open|@canImplicitCast#}3929 {#header_open|@canImplicitCast#}
4065 <pre><code class="zig">@canImplicitCast(comptime T: type, value) -&gt; bool</code></pre>3930 <pre><code class="zig">@canImplicitCast(comptime T: type, value) -&gt; bool</code></pre>
...@@ -4091,11 +3956,7 @@ comptime {...@@ -4091,11 +3956,7 @@ comptime {
4091 <code>AtomicOrder</code> can be found with <code>@import("builtin").AtomicOrder</code>.3956 <code>AtomicOrder</code> can be found with <code>@import("builtin").AtomicOrder</code>.
4092 </p>3957 </p>
4093 <p><code>@typeOf(ptr).alignment</code> must be <code>&gt;= @sizeOf(T).</code></p>3958 <p><code>@typeOf(ptr).alignment</code> must be <code>&gt;= @sizeOf(T).</code></p>
4094 <p>See also:</p>3959 {#see_also|Compile Variables#}
4095 <ul>
4096 <li><a href="#compile-variables">Compile Variables</a></li>
4097 </ul>
4098
4099 {#header_close#}3960 {#header_close#}
4100 {#header_open|@compileError#}3961 {#header_open|@compileError#}
4101 <pre><code class="zig">@compileError(comptime msg: []u8)</code></pre>3962 <pre><code class="zig">@compileError(comptime msg: []u8)</code></pre>
...@@ -4183,12 +4044,8 @@ test.zig:6:2: error: found compile log statement...@@ -4183,12 +4044,8 @@ test.zig:6:2: error: found compile log statement
4183 <li><code>@divExact(6, 3) == 2</code></li>4044 <li><code>@divExact(6, 3) == 2</code></li>
4184 <li><code>@divExact(a, b) * b == a</code></li>4045 <li><code>@divExact(a, b) * b == a</code></li>
4185 </ul>4046 </ul>
4186 <p>See also:</p>4047 <p>For a function that returns a possible error code, use <code>@import("std").math.divExact</code>.</p>
4187 <ul>4048 {#see_also|@divTrunc|@divFloor#}
4188 <li><a href="#builtin-divTrunc">@divTrunc</a></li>
4189 <li><a href="#builtin-divFloor">@divFloor</a></li>
4190 <li><code>@import("std").math.divExact</code></li>
4191 </ul>
4192 {#header_close#}4049 {#header_close#}
4193 {#header_open|@divFloor#}4050 {#header_open|@divFloor#}
4194 <pre><code class="zig">@divFloor(numerator: T, denominator: T) -&gt; T</code></pre>4051 <pre><code class="zig">@divFloor(numerator: T, denominator: T) -&gt; T</code></pre>
...@@ -4201,12 +4058,8 @@ test.zig:6:2: error: found compile log statement...@@ -4201,12 +4058,8 @@ test.zig:6:2: error: found compile log statement
4201 <li><code>@divFloor(-5, 3) == -2</code></li>4058 <li><code>@divFloor(-5, 3) == -2</code></li>
4202 <li><code>@divFloor(a, b) + @mod(a, b) == a</code></li>4059 <li><code>@divFloor(a, b) + @mod(a, b) == a</code></li>
4203 </ul>4060 </ul>
4204 <p>See also:</p>4061 <p>For a function that returns a possible error code, use <code>@import("std").math.divFloor</code>.</p>
4205 <ul>4062 {#see_also|@divTrunc|@divExact#}
4206 <li><a href="#builtin-divTrunc">@divTrunc</a></li>
4207 <li><a href="#builtin-divExact">@divExact</a></li>
4208 <li><code>@import("std").math.divFloor</code></li>
4209 </ul>
4210 {#header_close#}4063 {#header_close#}
4211 {#header_open|@divTrunc#}4064 {#header_open|@divTrunc#}
4212 <pre><code class="zig">@divTrunc(numerator: T, denominator: T) -&gt; T</code></pre>4065 <pre><code class="zig">@divTrunc(numerator: T, denominator: T) -&gt; T</code></pre>
...@@ -4219,12 +4072,8 @@ test.zig:6:2: error: found compile log statement...@@ -4219,12 +4072,8 @@ test.zig:6:2: error: found compile log statement
4219 <li><code>@divTrunc(-5, 3) == -1</code></li>4072 <li><code>@divTrunc(-5, 3) == -1</code></li>
4220 <li><code>@divTrunc(a, b) + @rem(a, b) == a</code></li>4073 <li><code>@divTrunc(a, b) + @rem(a, b) == a</code></li>
4221 </ul>4074 </ul>
4222 <p>See also:</p>4075 <p>For a function that returns a possible error code, use <code>@import("std").math.divTrunc</code>.</p>
4223 <ul>4076 {#see_also|@divFloor|@divExact#}
4224 <li><a href="#builtin-divFloor">@divFloor</a></li>
4225 <li><a href="#builtin-divExact">@divExact</a></li>
4226 <li><code>@import("std").math.divTrunc</code></li>
4227 </ul>
4228 {#header_close#}4077 {#header_close#}
4229 {#header_open|@embedFile#}4078 {#header_open|@embedFile#}
4230 <pre><code class="zig">@embedFile(comptime path: []const u8) -&gt; [X]u8</code></pre>4079 <pre><code class="zig">@embedFile(comptime path: []const u8) -&gt; [X]u8</code></pre>
...@@ -4236,10 +4085,7 @@ test.zig:6:2: error: found compile log statement...@@ -4236,10 +4085,7 @@ test.zig:6:2: error: found compile log statement
4236 <p>4085 <p>
4237 <code>path</code> is absolute or relative to the current file, just like <code>@import</code>.4086 <code>path</code> is absolute or relative to the current file, just like <code>@import</code>.
4238 </p>4087 </p>
4239 <p>See also:</p>4088 {#see_also|@import#}
4240 <ul>
4241 <li><a href="#builtin-import">@import</a></li>
4242 </ul>
4243 {#header_close#}4089 {#header_close#}
4244 {#header_open|@export#}4090 {#header_open|@export#}
4245 <pre><code class="zig">@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) -&gt; []const u8</code></pre>4091 <pre><code class="zig">@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) -&gt; []const u8</code></pre>
...@@ -4294,10 +4140,7 @@ test.zig:6:2: error: found compile log statement...@@ -4294,10 +4140,7 @@ test.zig:6:2: error: found compile log statement
4294 <p>4140 <p>
4295 <code>AtomicOrder</code> can be found with <code>@import("builtin").AtomicOrder</code>.4141 <code>AtomicOrder</code> can be found with <code>@import("builtin").AtomicOrder</code>.
4296 </p>4142 </p>
4297 <p>See also:</p>4143 {#see_also|Compile Variables#}
4298 <ul>
4299 <li><a href="#compile-variables">Compile Variables</a></li>
4300 </ul>
4301 {#header_close#}4144 {#header_close#}
4302 {#header_open|@fieldParentPtr#}4145 {#header_open|@fieldParentPtr#}
4303 <pre><code class="zig">@fieldParentPtr(comptime ParentType: type, comptime field_name: []const u8,4146 <pre><code class="zig">@fieldParentPtr(comptime ParentType: type, comptime field_name: []const u8,
...@@ -4338,11 +4181,7 @@ test.zig:6:2: error: found compile log statement...@@ -4338,11 +4181,7 @@ test.zig:6:2: error: found compile log statement
4338 <li><code>@import("std")</code> - Zig Standard Library</li>4181 <li><code>@import("std")</code> - Zig Standard Library</li>
4339 <li><code>@import("builtin")</code> - Compiler-provided types and variables</li>4182 <li><code>@import("builtin")</code> - Compiler-provided types and variables</li>
4340 </ul>4183 </ul>
4341 <p>See also:</p>4184 {#see_also|Compile Variables|@embedFile#}
4342 <ul>
4343 <li><a href="#compile-variables">Compile Variables</a></li>
4344 <li><a href="#builtin-embedFile">@embedFile</a></li>
4345 </ul>
4346 {#header_close#}4185 {#header_close#}
4347 {#header_open|@inlineCall#}4186 {#header_open|@inlineCall#}
4348 <pre><code class="zig">@inlineCall(function: X, args: ...) -&gt; Y</code></pre>4187 <pre><code class="zig">@inlineCall(function: X, args: ...) -&gt; Y</code></pre>
...@@ -4359,10 +4198,7 @@ fn add(a: i32, b: i32) -&gt; i32 { a + b }</code></pre>...@@ -4359,10 +4198,7 @@ fn add(a: i32, b: i32) -&gt; i32 { a + b }</code></pre>
4359 Unlike a normal function call, however, <code>@inlineCall</code> guarantees that the call4198 Unlike a normal function call, however, <code>@inlineCall</code> guarantees that the call
4360 will be inlined. If the call cannot be inlined, a compile error is emitted.4199 will be inlined. If the call cannot be inlined, a compile error is emitted.
4361 </p>4200 </p>
4362 <p>See also:</p>4201 {#see_also|@noInlineCall#}
4363 <ul>
4364 <li><a href="#builtin-noInlineCall">@noInlineCall</a></li>
4365 </ul>
4366 {#header_close#}4202 {#header_close#}
4367 {#header_open|@intToPtr#}4203 {#header_open|@intToPtr#}
4368 <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -&gt; DestType</code></pre>4204 <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -&gt; DestType</code></pre>
...@@ -4454,11 +4290,8 @@ mem.set(u8, dest, c);</code></pre>...@@ -4454,11 +4290,8 @@ mem.set(u8, dest, c);</code></pre>
4454 <li><code>@mod(-5, 3) == 1</code></li>4290 <li><code>@mod(-5, 3) == 1</code></li>
4455 <li><code>@divFloor(a, b) + @mod(a, b) == a</code></li>4291 <li><code>@divFloor(a, b) + @mod(a, b) == a</code></li>
4456 </ul>4292 </ul>
4457 <p>See also:</p>4293 <p>For a function that returns an error code, see <code>@import("std").math.mod</code>.</p>
4458 <ul>4294 {#see_also|@rem#}
4459 <li><a href="#builtin-rem">@rem</a></li>
4460 <li><code>@import("std").math.mod</code></li>
4461 </ul>
4462 {#header_close#}4295 {#header_close#}
4463 {#header_open|@mulWithOverflow#}4296 {#header_open|@mulWithOverflow#}
4464 <pre><code class="zig">@mulWithOverflow(comptime T: type, a: T, b: T, result: &amp;T) -&gt; bool</code></pre>4297 <pre><code class="zig">@mulWithOverflow(comptime T: type, a: T, b: T, result: &amp;T) -&gt; bool</code></pre>
...@@ -4483,10 +4316,7 @@ fn add(a: i32, b: i32) -&gt; i32 { a + b }</code></pre>...@@ -4483,10 +4316,7 @@ fn add(a: i32, b: i32) -&gt; i32 { a + b }</code></pre>
4483 Unlike a normal function call, however, <code>@noInlineCall</code> guarantees that the call4316 Unlike a normal function call, however, <code>@noInlineCall</code> guarantees that the call
4484 will not be inlined. If the call must be inlined, a compile error is emitted.4317 will not be inlined. If the call must be inlined, a compile error is emitted.
4485 </p>4318 </p>
4486 <p>See also:</p>4319 {#see_also|@inlineCall#}
4487 <ul>
4488 <li><a href="#builtin-inlineCall">@inlineCall</a></li>
4489 </ul>
4490 {#header_close#}4320 {#header_close#}
4491 {#header_open|@offsetOf#}4321 {#header_open|@offsetOf#}
4492 <pre><code class="zig">@offsetOf(comptime T: type, comptime field_name: [] const u8) -&gt; (number literal)</code></pre>4322 <pre><code class="zig">@offsetOf(comptime T: type, comptime field_name: [] const u8) -&gt; (number literal)</code></pre>
...@@ -4529,11 +4359,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'...@@ -4529,11 +4359,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'
4529 <li>From library code, calling the programmer's panic function if they exposed one in the root source file.</li>4359 <li>From library code, calling the programmer's panic function if they exposed one in the root source file.</li>
4530 <li>When mixing C and Zig code, calling the canonical panic implementation across multiple .o files.</li>4360 <li>When mixing C and Zig code, calling the canonical panic implementation across multiple .o files.</li>
4531 </ul>4361 </ul>
4532 <p>See also:</p>4362 {#see_also|Root Source File#}
4533 <ul>
4534 <li><a href="#root-source-file">Root Source File</a></li>
4535 </ul>
4536
4537 {#header_close#}4363 {#header_close#}
4538 {#header_open|@ptrCast#}4364 {#header_open|@ptrCast#}
4539 <pre><code class="zig">@ptrCast(comptime DestType: type, value: var) -&gt; DestType</code></pre>4365 <pre><code class="zig">@ptrCast(comptime DestType: type, value: var) -&gt; DestType</code></pre>
...@@ -4565,11 +4391,8 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'...@@ -4565,11 +4391,8 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'
4565 <li><code>@rem(-5, 3) == -2</code></li>4391 <li><code>@rem(-5, 3) == -2</code></li>
4566 <li><code>@divTrunc(a, b) + @rem(a, b) == a</code></li>4392 <li><code>@divTrunc(a, b) + @rem(a, b) == a</code></li>
4567 </ul>4393 </ul>
4568 <p>See also:</p>4394 <p>For a function that returns an error code, see <code>@import("std").math.rem</code>.</p>
4569 <ul>4395 {#see_also|@mod#}
4570 <li><a href="#builtin-mod">@mod</a></li>
4571 <li><code>@import("std").math.rem</code></li>
4572 </ul>
4573 {#header_close#}4396 {#header_close#}
4574 {#header_open|@returnAddress#}4397 {#header_open|@returnAddress#}
4575 <pre><code class="zig">@returnAddress()</code></pre>4398 <pre><code class="zig">@returnAddress()</code></pre>
...@@ -4584,7 +4407,6 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'...@@ -4584,7 +4407,6 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'
4584 <p>4407 <p>
4585 This function is only valid within function scope.4408 This function is only valid within function scope.
4586 </p>4409 </p>
4587
4588 {#header_close#}4410 {#header_close#}
4589 {#header_open|@setDebugSafety#}4411 {#header_open|@setDebugSafety#}
4590 <pre><code class="zig">@setDebugSafety(scope, safety_on: bool)</code></pre>4412 <pre><code class="zig">@setDebugSafety(scope, safety_on: bool)</code></pre>
...@@ -4623,11 +4445,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'...@@ -4623,11 +4445,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'
4623 <pre><code class="sh">$ ./zig build-obj test.zig</code></pre>4445 <pre><code class="sh">$ ./zig build-obj test.zig</code></pre>
4624 <p>(no output because it worked fine)</p>4446 <p>(no output because it worked fine)</p>
46254447
4626 <p>See also:</p>4448 {#see_also|comptime#}
4627 <ul>
4628 <li><a href="#comptime">comptime</a></li>
4629 </ul>
4630
4631 {#header_close#}4449 {#header_close#}
4632 {#header_open|@setFloatMode#}4450 {#header_open|@setFloatMode#}
4633 <pre><code class="zig">@setFloatMode(scope, mode: @import("builtin").FloatMode)</code></pre>4451 <pre><code class="zig">@setFloatMode(scope, mode: @import("builtin").FloatMode)</code></pre>
...@@ -4655,21 +4473,14 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'...@@ -4655,21 +4473,14 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'
4655 <code>Strict</code> - Floating point operations follow strict IEEE compliance.4473 <code>Strict</code> - Floating point operations follow strict IEEE compliance.
4656 </li>4474 </li>
4657 </ul>4475 </ul>
4658 <p>See also:</p>4476 {#see_also|Floating Point Operations#}
4659 <ul>
4660 <li><a href="#float-operations">Floating Point Operations</a></li>
4661 </ul>
4662
4663 {#header_close#}4477 {#header_close#}
4664 {#header_open|@setGlobalLinkage#}4478 {#header_open|@setGlobalLinkage#}
4665 <pre><code class="zig">@setGlobalLinkage(global_variable_name, comptime linkage: GlobalLinkage)</code></pre>4479 <pre><code class="zig">@setGlobalLinkage(global_variable_name, comptime linkage: GlobalLinkage)</code></pre>
4666 <p>4480 <p>
4667 <code>GlobalLinkage</code> can be found with <code>@import("builtin").GlobalLinkage</code>.4481 <code>GlobalLinkage</code> can be found with <code>@import("builtin").GlobalLinkage</code>.
4668 </p>4482 </p>
4669 <p>See also:</p>4483 {#see_also|Compile Variables#}
4670 <ul>
4671 <li><a href="#compile-variables">Compile Variables</a></li>
4672 </ul>
4673 {#header_close#}4484 {#header_close#}
4674 {#header_open|@setGlobalSection#}4485 {#header_open|@setGlobalSection#}
4675 <pre><code class="zig">@setGlobalSection(global_variable_name, comptime section_name: []const u8) -&gt; bool</code></pre>4486 <pre><code class="zig">@setGlobalSection(global_variable_name, comptime section_name: []const u8) -&gt; bool</code></pre>
...@@ -4687,11 +4498,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'...@@ -4687,11 +4498,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'
4687 The type of <code>shift_amt</code> is an unsigned integer with <code>log2(T.bit_count)</code> bits.4498 The type of <code>shift_amt</code> is an unsigned integer with <code>log2(T.bit_count)</code> bits.
4688 This is because <code>shift_amt &gt;= T.bit_count</code> is undefined behavior.4499 This is because <code>shift_amt &gt;= T.bit_count</code> is undefined behavior.
4689 </p>4500 </p>
4690 <p>See also:</p>4501 {#see_also|@shrExact|@shlWithOverflow#}
4691 <ul>
4692 <li><a href="#builtin-shrExact">@shrExact</a></li>
4693 <li><a href="#builtin-shlWithOverflow">@shlWithOverflow</a></li>
4694 </ul>
4695 {#header_close#}4502 {#header_close#}
4696 {#header_open|@shlWithOverflow#}4503 {#header_open|@shlWithOverflow#}
4697 <pre><code class="zig">@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: &amp;T) -&gt; bool</code></pre>4504 <pre><code class="zig">@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: &amp;T) -&gt; bool</code></pre>
...@@ -4704,11 +4511,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'...@@ -4704,11 +4511,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'
4704 The type of <code>shift_amt</code> is an unsigned integer with <code>log2(T.bit_count)</code> bits.4511 The type of <code>shift_amt</code> is an unsigned integer with <code>log2(T.bit_count)</code> bits.
4705 This is because <code>shift_amt &gt;= T.bit_count</code> is undefined behavior.4512 This is because <code>shift_amt &gt;= T.bit_count</code> is undefined behavior.
4706 </p>4513 </p>
4707 <p>See also:</p>4514 {#see_also|@shlExact|@shrExact#}
4708 <ul>
4709 <li><a href="#builtin-shlExact">@shlExact</a></li>
4710 <li><a href="#builtin-shrExact">@shrExact</a></li>
4711 </ul>
4712 {#header_close#}4515 {#header_close#}
4713 {#header_open|@shrExact#}4516 {#header_open|@shrExact#}
4714 <pre><code class="zig">@shrExact(value: T, shift_amt: Log2T) -&gt; T</code></pre>4517 <pre><code class="zig">@shrExact(value: T, shift_amt: Log2T) -&gt; T</code></pre>
...@@ -4720,10 +4523,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'...@@ -4720,10 +4523,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat'
4720 The type of <code>shift_amt</code> is an unsigned integer with <code>log2(T.bit_count)</code> bits.4523 The type of <code>shift_amt</code> is an unsigned integer with <code>log2(T.bit_count)</code> bits.
4721 This is because <code>shift_amt &gt;= T.bit_count</code> is undefined behavior.4524 This is because <code>shift_amt &gt;= T.bit_count</code> is undefined behavior.
4722 </p>4525 </p>
4723 <p>See also:</p>4526 {#see_also|@shlExact|@shlWithOverflow#}
4724 <ul>
4725 <li><a href="#builtin-shlExact">@shlExact</a></li>
4726 </ul>
4727 {#header_close#}4527 {#header_close#}
4728 {#header_open|@sizeOf#}4528 {#header_open|@sizeOf#}
4729 <pre><code class="zig">@sizeOf(comptime T: type) -&gt; (number literal)</code></pre>4529 <pre><code class="zig">@sizeOf(comptime T: type) -&gt; (number literal)</code></pre>
...@@ -4863,12 +4663,7 @@ pub fn build(b: &amp;Builder) {...@@ -4863,12 +4663,7 @@ pub fn build(b: &amp;Builder) {
4863 <li>Safety checks enabled</li>4663 <li>Safety checks enabled</li>
4864 <li>Slow compilation speed</li>4664 <li>Slow compilation speed</li>
4865 </ul>4665 </ul>
4866 <p>See also:</p>4666 {#see_also|Compile Variables|Zig Build System|Undefined Behavior#}
4867 <ul>
4868 <li><a href="#compile-variables">Compile Variables</a></li>
4869 <li><a href="#zig-build-system">Zig Build System</a></li>
4870 <li><a href="#undefined-behavior">Undefined Behavior</a></li>
4871 </ul>
4872 {#header_close#}4667 {#header_close#}
4873 {#header_close#}4668 {#header_close#}
4874 {#header_open|Undefined Behavior#}4669 {#header_open|Undefined Behavior#}
...@@ -5234,10 +5029,7 @@ comptime {...@@ -5234,10 +5029,7 @@ comptime {
5234 <p>TODO: importance of checking for allocation failure</p>5029 <p>TODO: importance of checking for allocation failure</p>
5235 <p>TODO: mention overcommit and the OOM Killer</p>5030 <p>TODO: mention overcommit and the OOM Killer</p>
5236 <p>TODO: mention recursion</p>5031 <p>TODO: mention recursion</p>
5237 <p>See also:</p>5032 {#see_also|Pointers#}
5238 <ul>
5239 <li><a href="#pointers">Pointers</a></li>
5240 </ul>
52415033
5242 {#header_close#}5034 {#header_close#}
5243 {#header_open|Compile Variables#}5035 {#header_open|Compile Variables#}
...@@ -5406,10 +5198,7 @@ pub const object_format = ObjectFormat.elf;...@@ -5406,10 +5198,7 @@ pub const object_format = ObjectFormat.elf;
5406pub const mode = Mode.ReleaseFast;5198pub const mode = Mode.ReleaseFast;
5407pub const link_libs = [][]const u8 {5199pub const link_libs = [][]const u8 {
5408};</code></pre>5200};</code></pre>
5409 <p>See also:</p>5201 {#see_also|Build Mode#}
5410 <ul>
5411 <li><a href="#build-mode">Build Mode</a></li>
5412 </ul>
5413 {#header_close#}5202 {#header_close#}
5414 {#header_open|Root Source File#}5203 {#header_open|Root Source File#}
5415 <p>TODO: explain how root source file finds other files</p>5204 <p>TODO: explain how root source file finds other files</p>
...@@ -5456,10 +5245,7 @@ pub const link_libs = [][]const u8 {...@@ -5456,10 +5245,7 @@ pub const link_libs = [][]const u8 {
5456 <li><code>c_longdouble</code></li>5245 <li><code>c_longdouble</code></li>
5457 <li><code>c_void</code></li>5246 <li><code>c_void</code></li>
5458 </ul>5247 </ul>
5459 <p>See also:</p>5248 {#see_also|Primitive Types#}
5460 <ul>
5461 <li><a href="#primitive-types">Primitive Types</a></li>
5462 </ul>
5463 {#header_close#}5249 {#header_close#}
5464 {#header_open|C String Literals#}5250 {#header_open|C String Literals#}
5465 <pre><code class="zig">extern fn puts(&amp;const u8);5251 <pre><code class="zig">extern fn puts(&amp;const u8);
...@@ -5472,10 +5258,7 @@ pub fn main() -&gt; %void {...@@ -5472,10 +5258,7 @@ pub fn main() -&gt; %void {
5472 c\\multiline C string literal5258 c\\multiline C string literal
5473 );5259 );
5474}</code></pre>5260}</code></pre>
5475 <p>See also:</p>5261 {#see_also|String Literals#}
5476 <ul>
5477 <li><a href="#string-literals">String Literals</a></li>
5478 </ul>
5479 {#header_close#}5262 {#header_close#}
5480 {#header_open|Import from C Header File#}5263 {#header_open|Import from C Header File#}
5481 <p>5264 <p>
...@@ -5504,14 +5287,7 @@ const c = @cImport({...@@ -5504,14 +5287,7 @@ const c = @cImport({
5504 }5287 }
5505 @cInclude("soundio.h");5288 @cInclude("soundio.h");
5506});</code></pre>5289});</code></pre>
5507 <p>See also:</p>5290 {#see_also|@cImport|@cInclude|@cDefine|@cUndef|@import#}
5508 <ul>
5509 <li><a href="#builtin-cImport">@cImport</a></li>
5510 <li><a href="#builtin-cInclude">@cInclude</a></li>
5511 <li><a href="#builtin-cDefine">@cDefine</a></li>
5512 <li><a href="#builtin-cUndef">@cUndef</a></li>
5513 <li><a href="#builtin-import">@import</a></li>
5514 </ul>
5515 {#header_close#}5291 {#header_close#}
5516 {#header_open|Mixing Object Files#}5292 {#header_open|Mixing Object Files#}
5517 <p>5293 <p>
...@@ -5571,11 +5347,7 @@ pub fn build(b: &amp;Builder) {...@@ -5571,11 +5347,7 @@ pub fn build(b: &amp;Builder) {
5571 <pre><code class="sh">$ zig build5347 <pre><code class="sh">$ zig build
5572$ ./test5348$ ./test
5573all your base are belong to us</code></pre>5349all your base are belong to us</code></pre>
5574 <p>See also:</p>5350 {#see_also|Targets|Zig Build System#}
5575 <ul>
5576 <li><a href="#targets">Targets</a></li>
5577 <li><a href="#zig-build-system">Zig Build System</a></li>
5578 </ul>
5579 {#header_close#}5351 {#header_close#}
5580 {#header_close#}5352 {#header_close#}
5581 {#header_open|Targets#}5353 {#header_open|Targets#}
std/hash_map.zig+4
...@@ -109,6 +109,10 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -109,6 +109,10 @@ pub fn HashMap(comptime K: type, comptime V: type,
109 return hm.internalGet(key);109 return hm.internalGet(key);
110 }110 }
111111
112 pub fn contains(hm: &Self, key: K) -> bool {
113 return hm.get(key) != null;
114 }
115
112 pub fn remove(hm: &Self, key: K) -> ?&Entry {116 pub fn remove(hm: &Self, key: K) -> ?&Entry {
113 hm.incrementModificationCount();117 hm.incrementModificationCount();
114 const start_index = hm.keyToIndex(key);118 const start_index = hm.keyToIndex(key);