1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vdoc: remove duplicated code

This commit is contained in:
Alexey 2020-02-27 00:44:29 +03:00 committed by GitHub
parent ca9fa6407f
commit 394d64bfd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,8 @@ mut:
stmts []ast.Stmt // all module statements from all files stmts []ast.Stmt // all module statements from all files
} }
type FilterFn fn(node ast.FnDecl) bool
pub fn doc(mod string, table &table.Table) string { pub fn doc(mod string, table &table.Table) string {
mut d := Doc{ mut d := Doc{
out: strings.new_builder(1000) out: strings.new_builder(1000)
@ -64,39 +66,42 @@ fn (d &Doc) get_fn_node(f ast.FnDecl) string {
} }
fn (d mut Doc) print_fns() { fn (d mut Doc) print_fns() {
mut fn_names := []string fn_signatures := d.get_fn_signatures(is_pub_function)
for stmt in d.stmts { d.write_fn_signatures(fn_signatures)
match stmt { }
ast.FnDecl {
if it.is_pub && !it.is_method { fn (d mut Doc) print_methods() {
name := d.get_fn_node(it) fn_signatures := d.get_fn_signatures(is_pub_method)
fn_names << name d.write_fn_signatures(fn_signatures)
} }
}
else {} [inline]
} fn (d mut Doc) write_fn_signatures(fn_signatures []string) {
} for s in fn_signatures {
fn_names.sort()
for s in fn_names {
d.out.writeln(s) d.out.writeln(s)
} }
} }
fn (d mut Doc) print_methods() { fn (d Doc) get_fn_signatures(filter_fn FilterFn) []string {
mut fn_names := []string mut fn_signatures := []string
for stmt in d.stmts { for stmt in d.stmts {
match stmt { match stmt {
ast.FnDecl { ast.FnDecl {
if it.is_pub && it.is_method { if filter_fn(it) {
name := d.get_fn_node(it) fn_signatures << d.get_fn_node(it)
fn_names << name
} }
} }
else {} else {}
} }
} }
fn_names.sort() fn_signatures.sort()
for s in fn_names { return fn_signatures
d.out.writeln(s) }
}
fn is_pub_method(node ast.FnDecl) bool {
return node.is_pub && node.is_method
}
fn is_pub_function(node ast.FnDecl) bool {
return node.is_pub && !node.is_method
} }