fmt: process C function declarations correctly
parent
1960c6f4cb
commit
6455e57e82
|
@ -25,6 +25,9 @@ pub fn (node &FnDecl) str(t &table.Table) string {
|
||||||
receiver = '($node.receiver.name $m$name) '
|
receiver = '($node.receiver.name $m$name) '
|
||||||
}
|
}
|
||||||
name := node.name.after('.')
|
name := node.name.after('.')
|
||||||
|
if node.is_c {
|
||||||
|
name = 'C.$name'
|
||||||
|
}
|
||||||
f.write('fn ${receiver}${name}(')
|
f.write('fn ${receiver}${name}(')
|
||||||
for i, arg in node.args {
|
for i, arg in node.args {
|
||||||
// skip receiver
|
// skip receiver
|
||||||
|
|
|
@ -173,9 +173,13 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
|
||||||
s := it.str(f.table)
|
s := it.str(f.table)
|
||||||
// f.write(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.write(s.replace(f.cur_mod + '.', '')) // `Expr` instead of `ast.Expr` in mod ast
|
||||||
f.writeln(' {')
|
if !it.is_c {
|
||||||
f.stmts(it.stmts)
|
f.writeln(' {')
|
||||||
f.writeln('}\n')
|
f.stmts(it.stmts)
|
||||||
|
f.writeln('}\n')
|
||||||
|
} else {
|
||||||
|
f.writeln('\n')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ast.ForInStmt {
|
ast.ForInStmt {
|
||||||
f.write('for ')
|
f.write('for ')
|
||||||
|
|
|
@ -2,6 +2,7 @@ import (
|
||||||
os
|
os
|
||||||
term
|
term
|
||||||
benchmark
|
benchmark
|
||||||
|
v.ast
|
||||||
v.fmt
|
v.fmt
|
||||||
v.parser
|
v.parser
|
||||||
v.table
|
v.table
|
||||||
|
@ -44,7 +45,7 @@ fn test_fmt() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
table := table.new_table()
|
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)
|
result_ocontent := fmt.fmt(file_ast, table)
|
||||||
if expected_ocontent != result_ocontent {
|
if expected_ocontent != result_ocontent {
|
||||||
fmt_bench.fail()
|
fmt_bench.fail()
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
fn C.func(arg int) int
|
||||||
|
|
||||||
fn fn_variadic(arg int, args ...string) {
|
fn fn_variadic(arg int, args ...string) {
|
||||||
println('Do nothing')
|
println('Do nothing')
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
fn C.func(arg int) int
|
||||||
|
|
||||||
fn fn_variadic(arg int, args... string) {
|
fn fn_variadic(arg int, args... string) {
|
||||||
println('Do nothing')
|
println('Do nothing')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue