@@ -69,6 +69,8 @@ pub fn generateZirData(self: *Autodoc) !void {
69
69
}
70
70
}
71
71
72
+ log .debug ("Ref map size: {}" , .{Ref .typed_value_map .len });
73
+
72
74
const root_src_dir = self .module .main_pkg .root_src_directory ;
73
75
const root_src_path = self .module .main_pkg .root_src_path ;
74
76
const joined_src_path = try root_src_dir .join (self .arena , &.{root_src_path });
@@ -159,6 +161,9 @@ pub fn generateZirData(self: *Autodoc) !void {
159
161
.void_type = > .{
160
162
.Void = .{ .name = tmpbuf .toOwnedSlice () },
161
163
},
164
+ .type_info_type = > .{
165
+ .Unanalyzed = .{},
166
+ },
162
167
.type_type = > .{
163
168
.Type = .{ .name = tmpbuf .toOwnedSlice () },
164
169
},
@@ -608,6 +613,7 @@ const DocData = struct {
608
613
type : usize , // index in `types`
609
614
this : usize , // index in `types`
610
615
declRef : usize , // index in `decls`
616
+ builtinField : enum { len , ptr },
611
617
fieldRef : FieldRef ,
612
618
refPath : []Expr ,
613
619
int : struct {
@@ -697,20 +703,26 @@ const DocData = struct {
697
703
var jsw = std .json .writeStream (w , 15 );
698
704
try jsw .beginObject ();
699
705
try jsw .objectField (@tagName (active_tag ));
700
- inline for (comptime std .meta .fields (Expr )) | case | {
701
- if (@field (Expr , case .name ) == active_tag ) {
702
- switch (active_tag ) {
703
- .int = > {
704
- if (self .int .negated ) try w .writeAll ("-" );
705
- try jsw .emitNumber (self .int .value );
706
- },
707
- .int_big = > {
706
+ switch (self ) {
707
+ .int = > {
708
+ if (self .int .negated ) try w .writeAll ("-" );
709
+ try jsw .emitNumber (self .int .value );
710
+ },
711
+ .int_big = > {
708
712
709
- //@panic("TODO: json serialization of big ints!");
710
- //if (v.negated) try w.writeAll("-");
711
- //try jsw.emitNumber(v.value);
712
- },
713
- else = > {
713
+ //@panic("TODO: json serialization of big ints!");
714
+ //if (v.negated) try w.writeAll("-");
715
+ //try jsw.emitNumber(v.value);
716
+ },
717
+ .builtinField = > {
718
+ try jsw .emitString (@tagName (self .builtinField ));
719
+ },
720
+ else = > {
721
+ inline for (comptime std .meta .fields (Expr )) | case | {
722
+ // TODO: this is super ugly, fix once `inline else` is a thing
723
+ if (comptime std .mem .eql (u8 , case .name , "builtinField" ))
724
+ continue ;
725
+ if (@field (Expr , case .name ) == active_tag ) {
714
726
try std .json .stringify (@field (self , case .name ), opt , w );
715
727
jsw .state_index -= 1 ;
716
728
// TODO: we should not reach into the state of the
@@ -719,9 +731,9 @@ const DocData = struct {
719
731
// would be nice to have a proper integration
720
732
// between the json writer and the generic
721
733
// std.json.stringify implementation
722
- },
734
+ }
723
735
}
724
- }
736
+ },
725
737
}
726
738
try jsw .endObject ();
727
739
}
@@ -1907,31 +1919,38 @@ fn walkInstruction(
1907
1919
const extra = file .zir .extraData (Zir .Inst .Field , pl_node .payload_index );
1908
1920
1909
1921
var path : std .ArrayListUnmanaged (DocData .Expr ) = .{};
1910
- var lhs = @enumToInt (extra .data .lhs ) - Ref .typed_value_map .len ; // underflow = need to handle Refs
1911
-
1912
1922
try path .append (self .arena , .{
1913
1923
.string = file .zir .nullTerminatedString (extra .data .field_name_start ),
1914
1924
});
1925
+
1915
1926
// Put inside path the starting index of each decl name that
1916
- // we encounter as we navigate through all the field_vals
1917
- while (tags [lhs ] == .field_val or
1918
- tags [lhs ] == .field_call_bind or
1919
- tags [lhs ] == .field_ptr or
1920
- tags [lhs ] == .field_type )
1921
- {
1922
- const lhs_extra = file .zir .extraData (
1923
- Zir .Inst .Field ,
1924
- data [lhs ].pl_node .payload_index ,
1925
- );
1927
+ // we encounter as we navigate through all the field_*s
1928
+ const lhs_ref = blk : {
1929
+ var lhs_extra = extra ;
1930
+ while (true ) {
1931
+ if (@enumToInt (lhs_extra .data .lhs ) < Ref .typed_value_map .len ) {
1932
+ break :blk lhs_extra .data .lhs ;
1933
+ }
1926
1934
1927
- try path .append (self .arena , .{
1928
- .string = file .zir .nullTerminatedString (lhs_extra .data .field_name_start ),
1929
- });
1930
- lhs = @enumToInt (lhs_extra .data .lhs ) - Ref .typed_value_map .len ; // underflow = need to handle Refs
1931
- }
1935
+ const lhs = @enumToInt (lhs_extra .data .lhs ) - Ref .typed_value_map .len ;
1936
+ if (tags [lhs ] != .field_val and
1937
+ tags [lhs ] != .field_call_bind and
1938
+ tags [lhs ] != .field_ptr and
1939
+ tags [lhs ] != .field_type ) break :blk lhs_extra .data .lhs ;
1940
+
1941
+ lhs_extra = file .zir .extraData (
1942
+ Zir .Inst .Field ,
1943
+ data [lhs ].pl_node .payload_index ,
1944
+ );
1945
+
1946
+ try path .append (self .arena , .{
1947
+ .string = file .zir .nullTerminatedString (lhs_extra .data .field_name_start ),
1948
+ });
1949
+ }
1950
+ };
1932
1951
1933
1952
// TODO: double check that we really don't need type info here
1934
- const wr = try self .walkInstruction (file , parent_scope , lhs , false );
1953
+ const wr = try self .walkRef (file , parent_scope , lhs_ref , false );
1935
1954
try path .append (self .arena , wr .expr );
1936
1955
1937
1956
// This way the data in `path` has the same ordering that the ref
@@ -1950,7 +1969,7 @@ fn walkInstruction(
1950
1969
// - (2) Paths can sometimes never resolve fully. This means that
1951
1970
// any value that depends on that will have to become a
1952
1971
// comptimeExpr.
1953
- try self .tryResolveRefPath (file , lhs , path .items );
1972
+ try self .tryResolveRefPath (file , inst_index , path .items );
1954
1973
return DocData.WalkResult { .expr = .{ .refPath = path .items } };
1955
1974
},
1956
1975
.int_type = > {
@@ -2055,6 +2074,46 @@ fn walkInstruction(
2055
2074
);
2056
2075
return self .cteTodo (@tagName (tags [inst_index ]));
2057
2076
},
2077
+ .struct_init_anon = > {
2078
+ const pl_node = data [inst_index ].pl_node ;
2079
+ const extra = file .zir .extraData (Zir .Inst .StructInitAnon , pl_node .payload_index );
2080
+
2081
+ const field_vals = try self .arena .alloc (
2082
+ DocData .Expr .FieldVal ,
2083
+ extra .data .fields_len ,
2084
+ );
2085
+
2086
+ log .debug ("number of fields: {}" , .{extra .data .fields_len });
2087
+ var idx = extra .end ;
2088
+ for (field_vals ) | * fv | {
2089
+ const init_extra = file .zir .extraData (Zir .Inst .StructInitAnon .Item , idx );
2090
+ const field_name = file .zir .nullTerminatedString (init_extra .data .field_name );
2091
+ fv .* = .{
2092
+ .name = field_name ,
2093
+ .val = DocData.WalkResult {
2094
+ .expr = .{ .comptimeExpr = 0 },
2095
+ },
2096
+ };
2097
+ // printWithContext(
2098
+ // file,
2099
+ // inst_index,
2100
+ // "analyzing field [{}] %{} `{s}`",
2101
+ // .{ i, init_extra.data.init, field_name },
2102
+ // );
2103
+ // const value = try self.walkRef(
2104
+ // file,
2105
+ // parent_scope,
2106
+ // init_extra.data.init,
2107
+ // need_type,
2108
+ // );
2109
+ // fv.* = .{ .name = field_name, .val = value };
2110
+ // idx = init_extra.end;
2111
+ }
2112
+
2113
+ return DocData.WalkResult {
2114
+ .expr = .{ .@"struct" = field_vals },
2115
+ };
2116
+ },
2058
2117
.error_set_decl = > {
2059
2118
const pl_node = data [inst_index ].pl_node ;
2060
2119
const extra = file .zir .extraData (Zir .Inst .ErrorSetDecl , pl_node .payload_index );
@@ -3096,6 +3155,20 @@ fn tryResolveRefPath(
3096
3155
3097
3156
return ;
3098
3157
},
3158
+ .Array = > {
3159
+ if (std .mem .eql (u8 , child_string , "len" )) {
3160
+ path [i + 1 ] = .{
3161
+ .builtinField = .len ,
3162
+ };
3163
+ } else {
3164
+ panicWithContext (
3165
+ file ,
3166
+ inst_index ,
3167
+ "TODO: handle `{s}` in tryResolveDeclPath.type.Array\n Info: {}" ,
3168
+ .{ child_string , resolved_parent },
3169
+ );
3170
+ }
3171
+ },
3099
3172
.Enum = > | t_enum | {
3100
3173
for (t_enum .pubDecls ) | d | {
3101
3174
// TODO: this could be improved a lot
@@ -3822,9 +3895,12 @@ fn walkRef(
3822
3895
} else if (enum_value < Ref .typed_value_map .len ) {
3823
3896
switch (ref ) {
3824
3897
else = > {
3825
- std .debug .panic ("TODO: handle {s} in `walkRef`\n " , .{
3826
- @tagName (ref ),
3827
- });
3898
+ panicWithContext (
3899
+ file ,
3900
+ 0 ,
3901
+ "TODO: handle {s} in walkRef" ,
3902
+ .{@tagName (ref )},
3903
+ );
3828
3904
},
3829
3905
.undef = > {
3830
3906
return DocData.WalkResult { .expr = .@"undefined" };
0 commit comments