From 1014cfdf3b60faf9af5b062d198f4f44976cb1bc Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 16 Oct 2019 01:29:16 -0400 Subject: [PATCH] generated docs: progress towards generic types being useful See #3406 --- lib/std/hash_map.zig | 3 +- lib/std/meta.zig | 10 ++ lib/std/special/docs/index.html | 15 +- lib/std/special/docs/main.js | 249 +++++++++++++++++++++++++++++--- src/dump_analysis.cpp | 170 +++++++++++++--------- tools/merge_anal_dumps.zig | 173 ++++++++++++++++++++++ 6 files changed, 531 insertions(+), 89 deletions(-) diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 677dfe4435..7c872de5ca 100644 --- a/lib/std/hash_map.zig +++ b/lib/std/hash_map.zig @@ -36,7 +36,8 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 size: usize, max_distance_from_start_index: usize, allocator: *Allocator, - // this is used to detect bugs where a hashtable is edited while an iterator is running. + + /// This is used to detect bugs where a hashtable is edited while an iterator is running. modification_count: debug_u32, const Self = @This(); diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 52d8b54ecc..46018e0b1d 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -542,3 +542,13 @@ pub fn intToEnum(comptime Tag: type, tag_int: var) IntToEnumError!Tag { } return error.InvalidEnumTag; } + +/// Given a type and a name, return the field index according to source order. +/// Returns `null` if the field is not found. +pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int { + inline for (fields(T)) |field, i| { + if (mem.eql(u8, field.name, name)) + return comptime_int(i); + } + return null; +} diff --git a/lib/std/special/docs/index.html b/lib/std/special/docs/index.html index 83032d87da..bf71d6c04c 100644 --- a/lib/std/special/docs/index.html +++ b/lib/std/special/docs/index.html @@ -104,6 +104,16 @@ background-color: #FFBB4D; color: #000; } + #listFnExamples { + list-style-type: none; + margin: 0; + padding: 0; + } + #listFnExamples li { + padding: 0.5em 0; + white-space: nowrap; + overflow-x: auto; + } #logo { width: 8em; padding: 0.5em 1em; @@ -289,7 +299,6 @@

     
     

- @@ -357,6 +366,10 @@ +