From 8fbae86bb3a872ed4a7d1d84a53c6a5d0b5747fe Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 10 Apr 2020 22:32:52 +0200 Subject: [PATCH] vfmt: skip skipped modules; add module test --- vlib/v/ast/ast.v | 1 + vlib/v/checker/checker.v | 2 +- vlib/v/fmt/fmt.v | 5 ++++- vlib/v/fmt/tests/module_struct_keep.vv | 10 ++++++++++ vlib/v/parser/parser.v | 9 +++------ 5 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 vlib/v/fmt/tests/module_struct_keep.vv diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 0abf933a62..22471d3eed 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -96,6 +96,7 @@ pub: name string path string expr Expr + is_skipped bool // module main can be skipped in single file programs } pub struct StructField { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 4c13c8f904..f08353d1e0 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -61,7 +61,7 @@ pub fn (c mut Checker) check_files(ast_files []ast.File) { c.check(file) } // Make sure fn main is defined in non lib builds - if c.pref.build_mode == .build_module { + if c.pref.build_mode == .build_module || c.pref.is_test { return } for i, f in c.table.fns { diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 189f609493..da809f4f9a 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -74,8 +74,11 @@ pub fn (f mut Fmt) writeln(s string) { } fn (f mut Fmt) mod(mod ast.Module) { - f.writeln('module $mod.name\n') f.cur_mod = mod.name + if mod.is_skipped { + return + } + f.writeln('module $mod.name\n') } fn (f mut Fmt) imports(imports []ast.Import) { diff --git a/vlib/v/fmt/tests/module_struct_keep.vv b/vlib/v/fmt/tests/module_struct_keep.vv new file mode 100644 index 0000000000..39dd3daedb --- /dev/null +++ b/vlib/v/fmt/tests/module_struct_keep.vv @@ -0,0 +1,10 @@ +module module_fmt + +pub struct MyStruct { +mut: + value int +} + +pub fn (m MyStruct) foo() bool { + return true +} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 90695c3369..3ab92e9e59 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -254,10 +254,6 @@ fn (p mut Parser) check_name() string { } pub fn (p mut Parser) top_stmt() ast.Stmt { - if p.fileis('mmm.v') { - print('!!stmt()') - println(p.tok.kind.str()) - } match p.tok.kind { .key_pub { match p.peek_tok.kind { @@ -518,7 +514,6 @@ fn (p mut Parser) range_expr(low ast.Expr) ast.Expr { return node } */ - pub fn (p &Parser) error(s string) { p.error_with_pos(s, p.tok.position()) } @@ -1409,7 +1404,8 @@ fn (p mut Parser) parse_number_literal() ast.Expr { fn (p mut Parser) module_decl() ast.Module { mut name := 'main' - if p.tok.kind == .key_module { + is_skipped := p.tok.kind != .key_module + if !is_skipped { p.check(.key_module) name = p.check_name() } @@ -1418,6 +1414,7 @@ fn (p mut Parser) module_decl() ast.Module { p.builtin_mod = p.mod == 'builtin' return ast.Module{ name: full_mod + is_skipped: is_skipped } }