vdoc: print structs and enums

pull/3984/head
Alexander Medvednikov 2020-03-10 19:49:04 +01:00
parent 568d859fc0
commit 1143320b8b
1 changed files with 41 additions and 4 deletions

View File

@ -48,6 +48,12 @@ pub fn doc(mod string, table &table.Table) string {
file_ast := parser.parse_file(os.join_path(path,file), table, .skip_comments) file_ast := parser.parse_file(os.join_path(path,file), table, .skip_comments)
d.stmts << file_ast.stmts d.stmts << file_ast.stmts
} }
if d.stmts.len == 0 {
println('nothing here')
exit(1)
}
d.print_structs()
d.print_enums()
d.print_fns() d.print_fns()
d.out.writeln('') d.out.writeln('')
d.print_methods() d.print_methods()
@ -91,8 +97,7 @@ fn (d Doc) get_fn_signatures(filter_fn FilterFn) []string {
fn_signatures << d.get_fn_node(it) fn_signatures << d.get_fn_node(it)
} }
} }
else { else {}
}
} }
} }
fn_signatures.sort() fn_signatures.sort()
@ -106,3 +111,35 @@ fn is_pub_method(node ast.FnDecl) bool {
fn is_pub_function(node ast.FnDecl) bool { fn is_pub_function(node ast.FnDecl) bool {
return node.is_pub && !node.is_method && !node.is_deprecated return node.is_pub && !node.is_method && !node.is_deprecated
} }
// TODO it's probably better to keep using AST, not `table`
fn (d mut Doc) print_enums() {
for typ in d.table.types {
if typ.kind != .enum_ {
continue
}
d.out.writeln('enum $typ.name {')
info := typ.info as table.Enum
for val in info.vals {
d.out.writeln('\t$val')
}
d.out.writeln('}')
}
}
fn (d mut Doc) print_structs() {
for typ in d.table.types {
if typ.kind != .struct_ || !typ.name.starts_with(d.mod + '.') {
// !typ.name[0].is_capital() || typ.name.starts_with('C.') {
continue
}
name := typ.name.after('.')
d.out.writeln('struct $name {')
info := typ.info as table.Struct
for field in info.fields {
sym := d.table.get_type_symbol(field.typ)
d.out.writeln('\t$field.name $sym.name')
}
d.out.writeln('}\n')
}
}