Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › zig/ › AstGen.zig › Scratch
Scratch
AstGen.Scratch
const Scratch = struct
File
Code
const Scratch = struct {
astgen : *AstGen ,
scratch_top : u32 ,
fn init (astgen : *AstGen ) Scratch {
return .{
.astgen = astgen ,
.scratch_top = @intCast (astgen .scratch .items .len ),
};
}
fn reset (s : *Scratch ) void {
s .astgen .scratch .shrinkRetainingCapacity (s .scratch_top );
s .* = undefined ;
}
fn addSlice (s : *Scratch , len : u32 ) Allocator .Error !Slice {
const start : u32 = @intCast (s .astgen .scratch .items .len );
try s .astgen .scratch .resize (s .astgen .gpa , start + len );
return .{ .start = start , .len = len };
}
fn addOptionalSlice (s : *Scratch , present : bool , len : u32 ) Allocator .Error !?Slice {
if (!present ) return null ;
return try addSlice (s , len );
}
fn appendBodyWithFixups (s : *Scratch , body : []const Zir .Inst .Index ) Allocator .Error !u32 {
const len = countBodyLenAfterFixups (s .astgen , body );
try s .astgen .scratch .ensureUnusedCapacity (s .astgen .gpa , len );
appendBodyWithFixupsArrayList (s .astgen , &s .astgen .scratch , body );
return len ;
}
fn all (s : *Scratch ) Slice {
const len = s .astgen .scratch .items .len - s .scratch_top ;
return .{ .start = s .scratch_top , .len = @intCast (len ) };
}
const Slice = struct {
start : u32 ,
len : u32 ,
fn get (s : Slice , astgen : *AstGen ) []u32 {
return astgen .scratch .items [s .start ..][0 ..s .len ];
}
};
}