vfmt: fix multiline comments

pull/4253/head
Alexander Medvednikov 2020-04-05 19:35:10 +02:00
parent 8260236331
commit 08bbc251ff
3 changed files with 83 additions and 66 deletions

View File

@ -93,7 +93,11 @@ fn (f mut Fmt) imports(imports []ast.Import) {
fn (f Fmt) imp_stmt_str(imp ast.Import) string { fn (f Fmt) imp_stmt_str(imp ast.Import) string {
is_diff := imp.alias != imp.mod && !imp.mod.ends_with('.' + imp.alias) is_diff := imp.alias != imp.mod && !imp.mod.ends_with('.' + imp.alias)
imp_alias_suffix := if is_diff { ' as ${imp.alias}' } else { '' } imp_alias_suffix := if is_diff {
' as ${imp.alias}'
} else {
''
}
return '${imp.mod}${imp_alias_suffix}' return '${imp.mod}${imp_alias_suffix}'
} }
@ -271,7 +275,11 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
f.writeln('') f.writeln('')
} }
ast.CompIf { ast.CompIf {
inversion := if it.is_not { '!' } else { '' } inversion := if it.is_not {
'!'
} else {
''
}
f.writeln('\$if ${inversion}${it.val} {') f.writeln('\$if ${inversion}${it.val} {')
f.stmts(it.stmts) f.stmts(it.stmts)
if it.has_else { if it.has_else {
@ -538,7 +546,11 @@ fn (f mut Fmt) expr(node ast.Expr) {
f.write(it.field) f.write(it.field)
} }
ast.StringLiteral { ast.StringLiteral {
if it.val.contains("'") { f.write('"$it.val"') } else { f.write("'$it.val'") } if it.val.contains("'") {
f.write('"$it.val"')
} else {
f.write("'$it.val'")
}
} }
ast.StringInterLiteral { ast.StringInterLiteral {
f.write("'") f.write("'")
@ -637,6 +649,7 @@ fn (f mut Fmt) comment(node ast.Comment) {
f.writeln('/*') f.writeln('/*')
for line in lines { for line in lines {
f.writeln(line) f.writeln(line)
f.empty_line = false
} }
f.writeln('*/') f.writeln('*/')
} }
@ -669,7 +682,11 @@ fn (f mut Fmt) if_expr(it ast.IfExpr) {
} else if i == it.branches.len - 1 && it.has_else { } else if i == it.branches.len - 1 && it.has_else {
f.write('} else {') f.write('} else {')
} }
if single_line { f.write(' ') } else { f.writeln('') } if single_line {
f.write(' ')
} else {
f.writeln('')
}
f.stmts(branch.stmts) f.stmts(branch.stmts)
if single_line { if single_line {
f.write(' ') f.write(' ')

View File

@ -834,7 +834,7 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
g.definitions.write(', ') g.definitions.write(', ')
} }
} }
*/ */
// //
g.fn_args(it.args, it.is_variadic) g.fn_args(it.args, it.is_variadic)
if it.no_body { if it.no_body {
@ -1754,7 +1754,7 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
g.write(', ') g.write(', ')
g.expr(node.index) g.expr(node.index)
g.write('))') g.write('))')
*/ */
zero := g.type_default(info.value_type) zero := g.type_default(info.value_type)
g.write('(*($elem_type_str*)map_get3(') g.write('(*($elem_type_str*)map_get3(')
g.expr(node.left) g.expr(node.left)
@ -2401,8 +2401,8 @@ fn (g mut Gen) method_call(node ast.CallExpr) {
print('$sym.name ') print('$sym.name ')
} }
println('') println('')
} }
*/ */
// /////// // ///////
g.call_args(node.args, node.expected_arg_types) g.call_args(node.args, node.expected_arg_types)
g.write(')') g.write(')')
@ -2438,7 +2438,7 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
g.writeln('; //memory') g.writeln('; //memory')
} }
} }
*/ */
if is_print && node.args[0].typ != table.string_type_idx { if is_print && node.args[0].typ != table.string_type_idx {
typ := node.args[0].typ typ := node.args[0].typ
mut styp := g.typ(typ) mut styp := g.typ(typ)
@ -2728,7 +2728,7 @@ fn (g Gen) type_default(typ table.Type) string {
} }
else {} else {}
} }
*/ */
match sym.name { match sym.name {
'string' { 'string' {
return 'tos3("")' return 'tos3("")'
@ -2760,8 +2760,8 @@ fn (g Gen) type_default(typ table.Type) string {
'byteptr'{ '0'} 'byteptr'{ '0'}
'voidptr'{ '0'} 'voidptr'{ '0'}
else { '{0} '} else { '{0} '}
} }
*/ */
} }
pub fn (g mut Gen) write_tests_main() { pub fn (g mut Gen) write_tests_main() {

View File

@ -36,7 +36,7 @@ mut:
returns bool returns bool
inside_match_case bool // to separate `match_expr { }` from `Struct{}` inside_match_case bool // to separate `match_expr { }` from `Struct{}`
comments []ast.Comment //comments []ast.Comment
} }
// for tests // for tests