From 9c1e50b1aaa4ade15183f223761f237da0950a83 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 5 Mar 2020 16:13:14 +0100 Subject: [PATCH] vdoc: don't show deprecated functions --- vlib/v/ast/ast.v | 21 +++++++++++---------- vlib/v/doc/doc.v | 4 ++-- vlib/v/parser/fn.v | 5 ++++- vlib/v/parser/parser.v | 8 +++++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index be0391a445..97feb876a4 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -130,16 +130,17 @@ pub: pub struct FnDecl { pub: - name string - stmts []Stmt - typ table.Type - args []Arg - is_pub bool - is_variadic bool - receiver Field - is_method bool - rec_mut bool // is receiver mutable - is_c bool + name string + stmts []Stmt + typ table.Type + args []Arg + is_deprecated bool + is_pub bool + is_variadic bool + receiver Field + is_method bool + rec_mut bool // is receiver mutable + is_c bool } pub struct BranchStmt { diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index a270a892a1..5961765308 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -100,9 +100,9 @@ fn (d Doc) get_fn_signatures(filter_fn FilterFn) []string { } fn is_pub_method(node ast.FnDecl) bool { - return node.is_pub && node.is_method + return node.is_pub && node.is_method && !node.is_deprecated } fn is_pub_function(node ast.FnDecl) bool { - return node.is_pub && !node.is_method + return node.is_pub && !node.is_method && !node.is_deprecated } diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 39c1ddd2c9..bd8deb233d 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -24,7 +24,7 @@ pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr { args: args muts: muts // tok: tok - + pos: tok.position() is_c: is_c or_block: ast.OrExpr{ @@ -58,6 +58,7 @@ pub fn (p mut Parser) call_args() ([]ast.Expr,[]bool) { fn (p mut Parser) fn_decl() ast.FnDecl { // p.table.clear_vars() p.open_scope() + is_deprecated := p.attr == 'deprecated' is_pub := p.tok.kind == .key_pub if is_pub { p.next() @@ -158,11 +159,13 @@ fn (p mut Parser) fn_decl() ast.FnDecl { stmts = p.parse_block() } p.close_scope() + p.attr = '' return ast.FnDecl{ name: name stmts: stmts typ: typ args: ast_args + is_deprecated: is_deprecated is_pub: is_pub is_variadic: is_variadic receiver: ast.Field{ diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 6029c920c2..a91677e391 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -40,6 +40,7 @@ mut: pref &pref.Preferences // Preferences shared from V struct builtin_mod bool mod string + attr string expr_mod string scope &ast.Scope imports map[string]string @@ -221,10 +222,10 @@ pub fn (p mut Parser) top_stmt() ast.Stmt { p.error('wrong pub keyword usage') return ast.Stmt{} } - } + } } .lsbr { - return p.attr() + return p.attribute() } .key_module { return p.module_decl() @@ -373,13 +374,14 @@ pub fn (p mut Parser) assign_expr(left ast.Expr) ast.AssignExpr { return node } -fn (p mut Parser) attr() ast.Attr { +fn (p mut Parser) attribute() ast.Attr { p.check(.lsbr) if p.tok.kind == .key_if { p.next() } name := p.check_name() p.check(.rsbr) + p.attr = name return ast.Attr{ name: name }