From 46ec400cb345b9b20c1573c5ae31e4e65dde6629 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 27 Feb 2020 03:46:09 +0800 Subject: [PATCH] vdoc: sort function names --- vlib/v/doc/doc.v | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index dd60946129..19242662d8 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -47,7 +47,7 @@ pub fn doc(mod string, table &table.Table) string { d.stmts << file_ast.stmts } d.print_fns() - d.writeln('') + d.out.writeln('') d.print_methods() /* for stmt in file_ast.stmts { @@ -59,36 +59,44 @@ pub fn doc(mod string, table &table.Table) string { return d.out.str() } -fn (d mut Doc) writeln(s string) { - d.out.writeln(s) -} - -fn (d mut Doc) write_fn_node(f ast.FnDecl) { - d.writeln(f.str(d.table).replace(d.mod + '.', '')) +fn (d &Doc) get_fn_node(f ast.FnDecl) string { + return f.str(d.table).replace(d.mod + '.', '') } fn (d mut Doc) print_fns() { + mut fn_names := []string for stmt in d.stmts { match stmt { ast.FnDecl { if it.is_pub && !it.is_method { - d.write_fn_node(it) + name := d.get_fn_node(it) + fn_names << name } } else {} + } } + fn_names.sort() + for s in fn_names { + d.out.writeln(s) } } fn (d mut Doc) print_methods() { + mut fn_names := []string for stmt in d.stmts { match stmt { ast.FnDecl { if it.is_pub && it.is_method { - d.write_fn_node(it) + name := d.get_fn_node(it) + fn_names << name } } else {} + } } + fn_names.sort() + for s in fn_names { + d.out.writeln(s) } }