vfmt: skip skipped modules; add module test
parent
b95a47b5a7
commit
8fbae86bb3
|
@ -96,6 +96,7 @@ pub:
|
||||||
name string
|
name string
|
||||||
path string
|
path string
|
||||||
expr Expr
|
expr Expr
|
||||||
|
is_skipped bool // module main can be skipped in single file programs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StructField {
|
pub struct StructField {
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub fn (c mut Checker) check_files(ast_files []ast.File) {
|
||||||
c.check(file)
|
c.check(file)
|
||||||
}
|
}
|
||||||
// Make sure fn main is defined in non lib builds
|
// 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
|
return
|
||||||
}
|
}
|
||||||
for i, f in c.table.fns {
|
for i, f in c.table.fns {
|
||||||
|
|
|
@ -74,8 +74,11 @@ pub fn (f mut Fmt) writeln(s string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (f mut Fmt) mod(mod ast.Module) {
|
fn (f mut Fmt) mod(mod ast.Module) {
|
||||||
f.writeln('module $mod.name\n')
|
|
||||||
f.cur_mod = mod.name
|
f.cur_mod = mod.name
|
||||||
|
if mod.is_skipped {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
f.writeln('module $mod.name\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (f mut Fmt) imports(imports []ast.Import) {
|
fn (f mut Fmt) imports(imports []ast.Import) {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
module module_fmt
|
||||||
|
|
||||||
|
pub struct MyStruct {
|
||||||
|
mut:
|
||||||
|
value int
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (m MyStruct) foo() bool {
|
||||||
|
return true
|
||||||
|
}
|
|
@ -254,10 +254,6 @@ fn (p mut Parser) check_name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (p mut Parser) top_stmt() ast.Stmt {
|
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 {
|
match p.tok.kind {
|
||||||
.key_pub {
|
.key_pub {
|
||||||
match p.peek_tok.kind {
|
match p.peek_tok.kind {
|
||||||
|
@ -518,7 +514,6 @@ fn (p mut Parser) range_expr(low ast.Expr) ast.Expr {
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub fn (p &Parser) error(s string) {
|
pub fn (p &Parser) error(s string) {
|
||||||
p.error_with_pos(s, p.tok.position())
|
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 {
|
fn (p mut Parser) module_decl() ast.Module {
|
||||||
mut name := 'main'
|
mut name := 'main'
|
||||||
if p.tok.kind == .key_module {
|
is_skipped := p.tok.kind != .key_module
|
||||||
|
if !is_skipped {
|
||||||
p.check(.key_module)
|
p.check(.key_module)
|
||||||
name = p.check_name()
|
name = p.check_name()
|
||||||
}
|
}
|
||||||
|
@ -1418,6 +1414,7 @@ fn (p mut Parser) module_decl() ast.Module {
|
||||||
p.builtin_mod = p.mod == 'builtin'
|
p.builtin_mod = p.mod == 'builtin'
|
||||||
return ast.Module{
|
return ast.Module{
|
||||||
name: full_mod
|
name: full_mod
|
||||||
|
is_skipped: is_skipped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue