mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: interface decl fixes (#5829)
This commit is contained in:
@@ -179,6 +179,7 @@ pub struct InterfaceDecl {
|
|||||||
pub:
|
pub:
|
||||||
name string
|
name string
|
||||||
field_names []string
|
field_names []string
|
||||||
|
is_pub bool
|
||||||
methods []FnDecl
|
methods []FnDecl
|
||||||
pos token.Position
|
pos token.Position
|
||||||
}
|
}
|
||||||
|
@@ -428,12 +428,7 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
|
|||||||
// f.imports(f.file.imports)
|
// f.imports(f.file.imports)
|
||||||
}
|
}
|
||||||
ast.InterfaceDecl {
|
ast.InterfaceDecl {
|
||||||
f.writeln('interface $it.name {')
|
f.interface_decl(it)
|
||||||
for method in it.methods {
|
|
||||||
f.write('\t')
|
|
||||||
f.writeln(method.stringify(f.table, f.cur_mod).after('fn '))
|
|
||||||
}
|
|
||||||
f.writeln('}\n')
|
|
||||||
}
|
}
|
||||||
ast.Module {
|
ast.Module {
|
||||||
f.mod(it)
|
f.mod(it)
|
||||||
@@ -662,6 +657,19 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
|||||||
f.writeln('}\n')
|
f.writeln('}\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
||||||
|
if node.is_pub {
|
||||||
|
f.write('pub ')
|
||||||
|
}
|
||||||
|
name := node.name.after('.')
|
||||||
|
f.writeln('interface $name {')
|
||||||
|
for method in node.methods {
|
||||||
|
f.write('\t')
|
||||||
|
f.writeln(method.stringify(f.table, f.cur_mod).after('fn '))
|
||||||
|
}
|
||||||
|
f.writeln('}\n')
|
||||||
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) prefix_expr_cast_expr(fexpr ast.Expr) {
|
pub fn (mut f Fmt) prefix_expr_cast_expr(fexpr ast.Expr) {
|
||||||
mut is_pe_amp_ce := false
|
mut is_pe_amp_ce := false
|
||||||
mut ce := ast.CastExpr{}
|
mut ce := ast.CastExpr{}
|
||||||
@@ -1053,7 +1061,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
|
|||||||
}
|
}
|
||||||
ast.UnsafeExpr {
|
ast.UnsafeExpr {
|
||||||
f.writeln('unsafe {')
|
f.writeln('unsafe {')
|
||||||
f.stmts(it.stmts)
|
f.stmts(node.stmts)
|
||||||
f.writeln('}')
|
f.writeln('}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
vlib/v/fmt/tests/module_interface_keep.vv
Normal file
5
vlib/v/fmt/tests/module_interface_keep.vv
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module module_fmt
|
||||||
|
|
||||||
|
pub interface MyInterface {
|
||||||
|
fun()
|
||||||
|
}
|
@@ -396,6 +396,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
|||||||
return ast.InterfaceDecl{
|
return ast.InterfaceDecl{
|
||||||
name: interface_name
|
name: interface_name
|
||||||
methods: methods
|
methods: methods
|
||||||
|
is_pub: is_pub
|
||||||
pos: start_pos
|
pos: start_pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user