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 › compiler/ › translate-c/ › Translator.zig › translate
translate
Translator.translate
pub fn translate (options : Options ) mem .Allocator .Error ![]u8
File
Code
pub fn translate (options : Options ) mem .Allocator .Error ![]u8 {
const gpa = options .gpa ;
var arena_allocator = std .heap .ArenaAllocator .init (gpa );
defer arena_allocator .deinit ();
const arena = arena_allocator .allocator ();
var translator : Translator = .{
.gpa = gpa ,
.arena = arena ,
.alias_list = .empty ,
.global_scope = try arena .create (Scope .Root ),
.comp = options .comp ,
.pp = options .pp ,
.tree = options .tree ,
.pub_static = options .pub_static ,
.func_bodies = options .func_bodies ,
.keep_macro_literals = options .keep_macro_literals ,
.default_init = options .default_init ,
.strict_flex_arrays = options .strict_flex_arrays ,
};
translator .global_scope .* = Scope .Root .init (&translator );
defer {
translator .type_decls .deinit (gpa );
translator .alias_list .deinit (gpa );
translator .global_names .deinit (gpa );
translator .weak_global_names .deinit (gpa );
translator .opaque_demotes .deinit (gpa );
translator .unnamed_typedefs .deinit (gpa );
translator .anonymous_record_field_names .deinit (gpa );
translator .typedefs .deinit (gpa );
translator .global_scope .deinit ();
translator .wip_var_inits .deinit (gpa );
}
try translator .prepopulateGlobalNameTable ();
try translator .transTopLevelDecls ();
try translator .global_scope .nodes .append (gpa , try ZigTag .warning .create (arena , "\n" ));
try translator .transMacros ();
for (translator .alias_list .items ) |alias | {
if (!translator .global_scope .sym_table .contains (alias .alias )) {
const node = try ZigTag .alias .create (arena , .{ .actual = alias .alias , .mangled = alias .name });
try translator .addTopLevelDecl (alias .alias , node );
}
}
try translator .global_scope .processContainerMemberFns ();
var allocating : std .Io .Writer .Allocating = .init (gpa );
defer allocating .deinit ();
allocating .writer .writeAll (
\\const __root = @This();
\\pub const __builtin = @import("std").zig.c_translation.builtins;
\\pub const __helpers = @import("std").zig.c_translation.helpers;
\\
) catch return error .OutOfMemory ;
var zig_ast = try ast .render (gpa , translator .global_scope .nodes .items );
defer {
gpa .free (zig_ast .source );
zig_ast .deinit (gpa );
}
zig_ast .render (gpa , &allocating .writer , .{}) catch return error .OutOfMemory ;
return allocating .toOwnedSlice ();
}