cgen: clean up ternary

pull/5221/head
yuyi 2020-06-05 14:30:03 +08:00 committed by GitHub
parent 24b263cf87
commit ef46fbb96f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -562,17 +562,17 @@ fn (mut g Gen) decrement_inside_ternary() {
fn (mut g Gen) stmts(stmts []ast.Stmt) { fn (mut g Gen) stmts(stmts []ast.Stmt) {
g.indent++ g.indent++
if g.inside_ternary > 0 { if g.inside_ternary > 0 {
g.writeln('(') g.write('(')
} }
for i, stmt in stmts { for i, stmt in stmts {
g.stmt(stmt) g.stmt(stmt)
if g.inside_ternary > 0 && i < stmts.len - 1 { if g.inside_ternary > 0 && i < stmts.len - 1 {
g.writeln(',') g.write(',')
} }
} }
g.indent-- g.indent--
if g.inside_ternary > 0 { if g.inside_ternary > 0 {
g.writeln('') g.write('')
g.write(')') g.write(')')
} }
} }
@ -932,7 +932,7 @@ fn (mut g Gen) gen_assert_stmt(a ast.AssertStmt) {
g.writeln(' g_test_oks++;') g.writeln(' g_test_oks++;')
metaname_ok := g.gen_assert_metainfo(a) metaname_ok := g.gen_assert_metainfo(a)
g.writeln(' cb_assertion_ok(&${metaname_ok});') g.writeln(' cb_assertion_ok(&${metaname_ok});')
g.writeln('}else{') g.writeln('} else {')
g.writeln(' g_test_fails++;') g.writeln(' g_test_fails++;')
metaname_fail := g.gen_assert_metainfo(a) metaname_fail := g.gen_assert_metainfo(a)
g.writeln(' cb_assertion_failed(&${metaname_fail});') g.writeln(' cb_assertion_failed(&${metaname_fail});')
@ -942,7 +942,7 @@ fn (mut g Gen) gen_assert_stmt(a ast.AssertStmt) {
g.writeln('}') g.writeln('}')
return return
} }
g.writeln('{}else{') g.writeln('{} else {')
metaname_panic := g.gen_assert_metainfo(a) metaname_panic := g.gen_assert_metainfo(a)
g.writeln(' __print_assert_failure(&${metaname_panic});') g.writeln(' __print_assert_failure(&${metaname_panic});')
g.writeln(' v_panic(tos_lit("Assertion failed..."));') g.writeln(' v_panic(tos_lit("Assertion failed..."));')

View File

@ -113,8 +113,9 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
g.write('static ') g.write('static ')
g.definitions.write('static ') g.definitions.write('static ')
} }
g.definitions.write('$type_name $msvc_attrs ${name}(') fn_header := if msvc_attrs.len > 0 { '$type_name $msvc_attrs ${name}(' } else { '$type_name ${name}(' }
g.write('$type_name $msvc_attrs ${name}(') g.definitions.write(fn_header)
g.write(fn_header)
} }
fargs, fargtypes := g.fn_args(it.args, it.is_variadic) fargs, fargtypes := g.fn_args(it.args, it.is_variadic)
if it.no_body || (g.pref.use_cache && it.is_builtin) { if it.no_body || (g.pref.use_cache && it.is_builtin) {
@ -777,4 +778,3 @@ fn (mut g Gen) write_fn_attr() string{
return msvc_attrs return msvc_attrs
} }