fmt: process C function declarations correctly

pull/4237/head
Alexey 2020-04-04 16:36:46 +03:00 committed by GitHub
parent 1960c6f4cb
commit 6455e57e82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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
if !it.is_c {
f.writeln(' {')
f.stmts(it.stmts)
f.writeln('}\n')
} else {
f.writeln('\n')
}
}
ast.ForInStmt {
f.write('for ')

View File

@ -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()

View File

@ -1,3 +1,5 @@
fn C.func(arg int) int
fn fn_variadic(arg int, args ...string) {
println('Do nothing')
}

View File

@ -1,3 +1,5 @@
fn C.func(arg int) int
fn fn_variadic(arg int, args... string) {
println('Do nothing')
}