mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: minor fixes + tests
This commit is contained in:
parent
887f1a73f7
commit
fd75cce0f3
@ -78,7 +78,7 @@ const (
|
|||||||
'vlib/time/time_test.v',
|
'vlib/time/time_test.v',
|
||||||
'vlib/time/misc/misc_test.v',
|
'vlib/time/misc/misc_test.v',
|
||||||
'vlib/v/doc/doc_test.v',
|
'vlib/v/doc/doc_test.v',
|
||||||
// 'vlib/v/fmt/fmt_keep_test.v',
|
'vlib/v/fmt/fmt_keep_test.v',
|
||||||
'vlib/v/fmt/fmt_test.v',
|
'vlib/v/fmt/fmt_test.v',
|
||||||
'vlib/v/gen/cgen_test.v',
|
'vlib/v/gen/cgen_test.v',
|
||||||
// 'vlib/v/parser/parser_test.v',
|
// 'vlib/v/parser/parser_test.v',
|
||||||
|
@ -2,11 +2,8 @@
|
|||||||
// Use of this source code is governed by an MIT license
|
// Use of this source code is governed by an MIT license
|
||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
module ast
|
module ast
|
||||||
/*
|
|
||||||
These methods are used only by vfmt, vdoc, and for debugging.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
// These methods are used only by vfmt, vdoc, and for debugging.
|
||||||
import (
|
import (
|
||||||
v.table
|
v.table
|
||||||
strings
|
strings
|
||||||
@ -21,7 +18,10 @@ pub fn (node &FnDecl) str(t &table.Table) string {
|
|||||||
if node.is_method {
|
if node.is_method {
|
||||||
sym := t.get_type_symbol(node.receiver.typ)
|
sym := t.get_type_symbol(node.receiver.typ)
|
||||||
name := sym.name.after('.')
|
name := sym.name.after('.')
|
||||||
m := if node.rec_mut { 'mut ' } else { '' }
|
mut m := if node.rec_mut { 'mut ' } else { '' }
|
||||||
|
if !node.rec_mut && table.type_is_ptr(node.receiver.typ) {
|
||||||
|
m = '&'
|
||||||
|
}
|
||||||
receiver = '($node.receiver.name $m$name) '
|
receiver = '($node.receiver.name $m$name) '
|
||||||
}
|
}
|
||||||
name := node.name.after('.')
|
name := node.name.after('.')
|
||||||
@ -35,14 +35,13 @@ pub fn (node &FnDecl) str(t &table.Table) string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
is_last_arg := i == node.args.len - 1
|
is_last_arg := i == node.args.len - 1
|
||||||
should_add_type := is_last_arg || node.args[i + 1].typ != arg.typ ||
|
should_add_type := is_last_arg || node.args[i + 1].typ != arg.typ || (node.is_variadic && i ==
|
||||||
(node.is_variadic && i == node.args.len - 2)
|
node.args.len - 2)
|
||||||
f.write(arg.name)
|
f.write(arg.name)
|
||||||
if should_add_type {
|
if should_add_type {
|
||||||
if node.is_variadic && is_last_arg {
|
if node.is_variadic && is_last_arg {
|
||||||
f.write(' ...' + t.type_to_str(arg.typ))
|
f.write(' ...' + t.type_to_str(arg.typ))
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
f.write(' ' + t.type_to_str(arg.typ))
|
f.write(' ' + t.type_to_str(arg.typ))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
fn foo(a []os.File) {
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IfExpr {
|
struct IfExpr {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
vlib/v/fmt/tests/struct_keep.vv
Normal file
22
vlib/v/fmt/tests/struct_keep.vv
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
fn foo(a []os.File) {
|
||||||
|
}
|
||||||
|
|
||||||
|
struct User {
|
||||||
|
age int
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_users(users []User) {
|
||||||
|
println(users.len)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (u &User) foo(u2 &User) {
|
||||||
|
}
|
||||||
|
|
||||||
|
type Expr = IfExpr | IntegerLiteral
|
||||||
|
|
||||||
|
fn exprs(e []Expr) {
|
||||||
|
println(e.len)
|
||||||
|
}
|
@ -613,7 +613,7 @@ pub fn (table &Table) type_to_str(t Type) string {
|
|||||||
if vals.len > 2 {
|
if vals.len > 2 {
|
||||||
res = vals[vals.len - 2] + '.' + vals[vals.len - 1]
|
res = vals[vals.len - 2] + '.' + vals[vals.len - 1]
|
||||||
}
|
}
|
||||||
if sym.kind == .array {
|
if sym.kind == .array && !res.starts_with('[]') {
|
||||||
res = '[]' + res
|
res = '[]' + res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user