mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: process C function declarations correctly
This commit is contained in:
parent
1960c6f4cb
commit
6455e57e82
@ -25,6 +25,9 @@ pub fn (node &FnDecl) str(t &table.Table) string {
|
||||
receiver = '($node.receiver.name $m$name) '
|
||||
}
|
||||
name := node.name.after('.')
|
||||
if node.is_c {
|
||||
name = 'C.$name'
|
||||
}
|
||||
f.write('fn ${receiver}${name}(')
|
||||
for i, arg in node.args {
|
||||
// skip receiver
|
||||
|
@ -173,9 +173,13 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
|
||||
s := it.str(f.table)
|
||||
// f.write(it.str(f.table))
|
||||
f.write(s.replace(f.cur_mod + '.', '')) // `Expr` instead of `ast.Expr` in mod ast
|
||||
f.writeln(' {')
|
||||
f.stmts(it.stmts)
|
||||
f.writeln('}\n')
|
||||
if !it.is_c {
|
||||
f.writeln(' {')
|
||||
f.stmts(it.stmts)
|
||||
f.writeln('}\n')
|
||||
} else {
|
||||
f.writeln('\n')
|
||||
}
|
||||
}
|
||||
ast.ForInStmt {
|
||||
f.write('for ')
|
||||
|
@ -2,6 +2,7 @@ import (
|
||||
os
|
||||
term
|
||||
benchmark
|
||||
v.ast
|
||||
v.fmt
|
||||
v.parser
|
||||
v.table
|
||||
@ -44,7 +45,7 @@ fn test_fmt() {
|
||||
continue
|
||||
}
|
||||
table := table.new_table()
|
||||
file_ast := parser.parse_file(ipath, table, .parse_comments, &pref.Preferences{})
|
||||
file_ast := parser.parse_file(ipath, table, .parse_comments, &pref.Preferences{}, &ast.Scope{parent: 0})
|
||||
result_ocontent := fmt.fmt(file_ast, table)
|
||||
if expected_ocontent != result_ocontent {
|
||||
fmt_bench.fail()
|
||||
|
@ -1,3 +1,5 @@
|
||||
fn C.func(arg int) int
|
||||
|
||||
fn fn_variadic(arg int, args ...string) {
|
||||
println('Do nothing')
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
fn C.func(arg int) int
|
||||
|
||||
fn fn_variadic(arg int, args... string) {
|
||||
println('Do nothing')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user