mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: extract type decls code into functions to cleanup (#9126)
This commit is contained in:
parent
0f042124cb
commit
9ba312066e
@ -476,17 +476,25 @@ fn stmt_is_single_line(stmt ast.Stmt) bool {
|
||||
}
|
||||
|
||||
pub fn (mut f Fmt) type_decl(node ast.TypeDecl) {
|
||||
mut comments := []ast.Comment{}
|
||||
match node {
|
||||
ast.AliasTypeDecl {
|
||||
ast.AliasTypeDecl { f.alias_type_decl(node) }
|
||||
ast.FnTypeDecl { f.fn_type_decl(node) }
|
||||
ast.SumTypeDecl { f.sum_type_decl(node) }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut f Fmt) alias_type_decl(node ast.AliasTypeDecl) {
|
||||
if node.is_pub {
|
||||
f.write('pub ')
|
||||
}
|
||||
ptype := f.table.type_to_str(node.parent_type)
|
||||
f.write('type $node.name = $ptype')
|
||||
comments << node.comments
|
||||
|
||||
f.comments(node.comments, has_nl: false)
|
||||
f.writeln('\n')
|
||||
}
|
||||
ast.FnTypeDecl {
|
||||
|
||||
pub fn (mut f Fmt) fn_type_decl(node ast.FnTypeDecl) {
|
||||
if node.is_pub {
|
||||
f.write('pub ')
|
||||
}
|
||||
@ -529,9 +537,12 @@ pub fn (mut f Fmt) type_decl(node ast.TypeDecl) {
|
||||
} else if fn_info.return_type.has_flag(.optional) {
|
||||
f.write(' ?')
|
||||
}
|
||||
comments << node.comments
|
||||
|
||||
f.comments(node.comments, has_nl: false)
|
||||
f.writeln('\n')
|
||||
}
|
||||
ast.SumTypeDecl {
|
||||
|
||||
pub fn (mut f Fmt) sum_type_decl(node ast.SumTypeDecl) {
|
||||
if node.is_pub {
|
||||
f.write('pub ')
|
||||
}
|
||||
@ -550,13 +561,8 @@ pub fn (mut f Fmt) type_decl(node ast.TypeDecl) {
|
||||
f.wrap_long_line(3, true)
|
||||
}
|
||||
}
|
||||
comments << node.comments
|
||||
}
|
||||
}
|
||||
if comments.len > 0 {
|
||||
f.write(' ')
|
||||
f.comments(comments, has_nl: false)
|
||||
}
|
||||
|
||||
f.comments(node.comments, has_nl: false)
|
||||
f.writeln('\n')
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user