cgen: fix _ = ...

pull/4289/head^2
Alexander Medvednikov 2020-04-08 00:46:16 +02:00
parent 7406abe3b6
commit 2fbed2f880
3 changed files with 20 additions and 25 deletions

View File

@ -22,7 +22,6 @@ fn cerror(e string){
eprintln('\nerror: $e')
}
[inline]
fn vmod_content(name, desc string) string {
return [
'#V Project#\n',
@ -34,7 +33,6 @@ fn vmod_content(name, desc string) string {
].join('\n')
}
[inline]
fn main_content() string {
return [
'module main\n',
@ -44,7 +42,6 @@ fn main_content() string {
].join('\n')
}
[inline]
fn gen_gitignore(name string) string {
return [
'main',

View File

@ -14,7 +14,6 @@ const (
'vlib/cli/flag_test.v',
'vlib/clipboard/clipboard_test.v', // Linux only
'vlib/crypto/aes/aes_test.v',
'vlib/crypto/md5/md5_test.v',
'vlib/crypto/rand/rand_test.v',
'vlib/crypto/rc4/rc4_test.v',
'vlib/crypto/sha1/sha1_test.v',
@ -54,7 +53,6 @@ const (
'vlib/v/tests/fn_variadic_test.v',
'vlib/v/tests/live_test.v', // Linux only
'vlib/v/tests/match_test.v',
'vlib/v/tests/module_test.v',
'vlib/v/tests/msvc_test.v',
'vlib/v/tests/mut_test.v',
'vlib/v/tests/num_lit_call_method_test.v',
@ -67,7 +65,6 @@ const (
'vlib/v/tests/string_interpolation_array_of_structs_test.v',
'vlib/v/tests/string_interpolation_struct_test.v',
'vlib/v/tests/string_interpolation_variadic_test.v',
'vlib/v/tests/struct_test.v',
'vlib/v/tests/type_test.v',
'vlib/v/tests/typeof_test.v',
'vlib/v/tests/valgrind/valgrind_test.v', // ubuntu-musl only

View File

@ -15,9 +15,9 @@ import (
)
const (
c_reserved = ['delete', 'exit', 'unix', 'error', 'calloc', 'malloc', 'free', 'panic', 'auto',
'char', 'default', 'do', 'double', 'extern', 'float', 'inline', 'int', 'long', 'register',
'restrict', 'short', 'signed', 'sizeof', 'static', 'switch', 'typedef', 'union', 'unsigned',
c_reserved = ['delete', 'exit', 'unix', 'error', 'calloc', 'malloc', 'free', 'panic', 'auto',
'char', 'default', 'do', 'double', 'extern', 'float', 'inline', 'int', 'long', 'register',
'restrict', 'short', 'signed', 'sizeof', 'static', 'switch', 'typedef', 'union', 'unsigned',
'void', 'volatile', 'while']
)
@ -58,7 +58,7 @@ mut:
}
const (
tabs = ['', '\t', '\t\t', '\t\t\t', '\t\t\t\t', '\t\t\t\t\t', '\t\t\t\t\t\t', '\t\t\t\t\t\t\t',
tabs = ['', '\t', '\t\t', '\t\t\t', '\t\t\t\t', '\t\t\t\t\t', '\t\t\t\t\t\t', '\t\t\t\t\t\t\t',
'\t\t\t\t\t\t\t\t']
)
@ -86,7 +86,7 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string
indent: -1
}
g.init()
//
//
mut autofree_used := false
for file in files {
g.file = file
@ -115,9 +115,9 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string
if g.is_test {
g.write_tests_main()
}
//
//
g.finish()
return g.hashes() + g.includes.str() + g.typedefs.str() + g.typedefs2.str() + g.definitions.str() +
return g.hashes() + g.includes.str() + g.typedefs.str() + g.typedefs2.str() + g.definitions.str() +
g.gowrappers.str() + g.stringliterals.str() + g.out.str()
}
@ -141,7 +141,7 @@ pub fn (g mut Gen) init() {
g.write_sorted_types()
g.write_multi_return_types()
g.definitions.writeln('// end of definitions #endif')
//
//
g.stringliterals.writeln('')
g.stringliterals.writeln('// >> string literal consts')
g.stringliterals.writeln('void vinit_string_literals(){')
@ -205,7 +205,7 @@ pub fn (g mut Gen) typ(t table.Type) string {
return styp
}
//
//
pub fn (g mut Gen) write_typedef_types() {
for typ in g.table.types {
match typ.kind {
@ -817,7 +817,7 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
}
}
*/
//
//
g.fn_args(it.args, it.is_variadic)
if it.no_body {
// Just a function header.
@ -1236,7 +1236,8 @@ fn (g mut Gen) assign_expr(node ast.AssignExpr) {
if is_call {
g.expr(node.val)
} else {
g.write('{${g.typ(node.left_type)} _ = ')
// g.write('{${g.typ(node.left_type)} _ = ')
g.write('{')
g.expr(node.val)
g.writeln(';}')
}
@ -1451,7 +1452,7 @@ fn (g mut Gen) match_expr(node ast.MatchExpr) {
// sum_type_str
} else if type_sym.kind == .string {
g.write('string_eq(')
//
//
g.expr(node.cond)
g.write(', ')
// g.write('string_eq($tmp, ')
@ -1950,7 +1951,7 @@ fn (g mut Gen) assoc(node ast.Assoc) {
}
fn (g mut Gen) call_args(args []ast.CallArg, expected_types []table.Type) {
is_variadic := expected_types.len > 0 && table.type_is(expected_types[expected_types.len -
is_variadic := expected_types.len > 0 && table.type_is(expected_types[expected_types.len -
1], .variadic)
mut arg_no := 0
for arg in args {
@ -2131,7 +2132,7 @@ fn (g mut Gen) write_types(types []table.TypeSymbol) {
g.definitions.writeln('EMPTY_STRUCT_DECLARATION;')
}
// g.definitions.writeln('} $name;\n')
//
//
g.definitions.writeln('};\n')
}
table.Alias {
@ -2198,8 +2199,8 @@ fn (g Gen) sort_structs(typesa []table.TypeSymbol) []table.TypeSymbol {
// sort graph
dep_graph_sorted := dep_graph.resolve()
if !dep_graph_sorted.acyclic {
verror('cgen.sort_structs(): the following structs form a dependency cycle:\n' + dep_graph_sorted.display_cycles() +
'\nyou can solve this by making one or both of the dependant struct fields references, eg: field &MyStruct' +
verror('cgen.sort_structs(): the following structs form a dependency cycle:\n' + dep_graph_sorted.display_cycles() +
'\nyou can solve this by making one or both of the dependant struct fields references, eg: field &MyStruct' +
'\nif you feel this is an error, please create a new issue here: https://github.com/vlang/v/issues and tag @joe-conigliaro')
}
// sort types
@ -2341,7 +2342,7 @@ fn (g mut Gen) method_call(node ast.CallExpr) {
return
}
// TODO performance, detect `array` method differently
if typ_sym.kind == .array && node.name in ['repeat', 'sort_with_compare', 'free', 'push_many',
if typ_sym.kind == .array && node.name in ['repeat', 'sort_with_compare', 'free', 'push_many',
'trim', 'first', 'last', 'clone', 'reverse', 'slice'] {
// && rec_sym.name == 'array' {
// && rec_sym.name == 'array' && receiver_name.starts_with('array') {
@ -2367,7 +2368,7 @@ fn (g mut Gen) method_call(node ast.CallExpr) {
g.write('/*rec*/*')
}
g.expr(node.left)
is_variadic := node.expected_arg_types.len > 0 && table.type_is(node.expected_arg_types[node.expected_arg_types.len -
is_variadic := node.expected_arg_types.len > 0 && table.type_is(node.expected_arg_types[node.expected_arg_types.len -
1], .variadic)
if node.args.len > 0 || is_variadic {
g.write(', ')
@ -2966,7 +2967,7 @@ fn (g mut Gen) gen_str_for_type(sym table.TypeSymbol, styp string) {
fn type_to_fmt(typ table.Type) string {
n := int(typ)
if n == table.string_type {
return '\'%.*s\''
return "\'%.*s\'"
} else if n == table.bool_type {
return '%.*s'
}