mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix _ = ...
This commit is contained in:
parent
7406abe3b6
commit
2fbed2f880
@ -22,7 +22,6 @@ fn cerror(e string){
|
|||||||
eprintln('\nerror: $e')
|
eprintln('\nerror: $e')
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
|
||||||
fn vmod_content(name, desc string) string {
|
fn vmod_content(name, desc string) string {
|
||||||
return [
|
return [
|
||||||
'#V Project#\n',
|
'#V Project#\n',
|
||||||
@ -34,7 +33,6 @@ fn vmod_content(name, desc string) string {
|
|||||||
].join('\n')
|
].join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
|
||||||
fn main_content() string {
|
fn main_content() string {
|
||||||
return [
|
return [
|
||||||
'module main\n',
|
'module main\n',
|
||||||
@ -44,7 +42,6 @@ fn main_content() string {
|
|||||||
].join('\n')
|
].join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
|
||||||
fn gen_gitignore(name string) string {
|
fn gen_gitignore(name string) string {
|
||||||
return [
|
return [
|
||||||
'main',
|
'main',
|
||||||
|
@ -14,7 +14,6 @@ const (
|
|||||||
'vlib/cli/flag_test.v',
|
'vlib/cli/flag_test.v',
|
||||||
'vlib/clipboard/clipboard_test.v', // Linux only
|
'vlib/clipboard/clipboard_test.v', // Linux only
|
||||||
'vlib/crypto/aes/aes_test.v',
|
'vlib/crypto/aes/aes_test.v',
|
||||||
'vlib/crypto/md5/md5_test.v',
|
|
||||||
'vlib/crypto/rand/rand_test.v',
|
'vlib/crypto/rand/rand_test.v',
|
||||||
'vlib/crypto/rc4/rc4_test.v',
|
'vlib/crypto/rc4/rc4_test.v',
|
||||||
'vlib/crypto/sha1/sha1_test.v',
|
'vlib/crypto/sha1/sha1_test.v',
|
||||||
@ -54,7 +53,6 @@ const (
|
|||||||
'vlib/v/tests/fn_variadic_test.v',
|
'vlib/v/tests/fn_variadic_test.v',
|
||||||
'vlib/v/tests/live_test.v', // Linux only
|
'vlib/v/tests/live_test.v', // Linux only
|
||||||
'vlib/v/tests/match_test.v',
|
'vlib/v/tests/match_test.v',
|
||||||
'vlib/v/tests/module_test.v',
|
|
||||||
'vlib/v/tests/msvc_test.v',
|
'vlib/v/tests/msvc_test.v',
|
||||||
'vlib/v/tests/mut_test.v',
|
'vlib/v/tests/mut_test.v',
|
||||||
'vlib/v/tests/num_lit_call_method_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_array_of_structs_test.v',
|
||||||
'vlib/v/tests/string_interpolation_struct_test.v',
|
'vlib/v/tests/string_interpolation_struct_test.v',
|
||||||
'vlib/v/tests/string_interpolation_variadic_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/type_test.v',
|
||||||
'vlib/v/tests/typeof_test.v',
|
'vlib/v/tests/typeof_test.v',
|
||||||
'vlib/v/tests/valgrind/valgrind_test.v', // ubuntu-musl only
|
'vlib/v/tests/valgrind/valgrind_test.v', // ubuntu-musl only
|
||||||
|
@ -15,9 +15,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
c_reserved = ['delete', 'exit', 'unix', 'error', 'calloc', 'malloc', 'free', 'panic', 'auto',
|
c_reserved = ['delete', 'exit', 'unix', 'error', 'calloc', 'malloc', 'free', 'panic', 'auto',
|
||||||
'char', 'default', 'do', 'double', 'extern', 'float', 'inline', 'int', 'long', 'register',
|
'char', 'default', 'do', 'double', 'extern', 'float', 'inline', 'int', 'long', 'register',
|
||||||
'restrict', 'short', 'signed', 'sizeof', 'static', 'switch', 'typedef', 'union', 'unsigned',
|
'restrict', 'short', 'signed', 'sizeof', 'static', 'switch', 'typedef', 'union', 'unsigned',
|
||||||
'void', 'volatile', 'while']
|
'void', 'volatile', 'while']
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ mut:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
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']
|
'\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
|
indent: -1
|
||||||
}
|
}
|
||||||
g.init()
|
g.init()
|
||||||
//
|
//
|
||||||
mut autofree_used := false
|
mut autofree_used := false
|
||||||
for file in files {
|
for file in files {
|
||||||
g.file = file
|
g.file = file
|
||||||
@ -115,9 +115,9 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string
|
|||||||
if g.is_test {
|
if g.is_test {
|
||||||
g.write_tests_main()
|
g.write_tests_main()
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
g.finish()
|
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()
|
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_sorted_types()
|
||||||
g.write_multi_return_types()
|
g.write_multi_return_types()
|
||||||
g.definitions.writeln('// end of definitions #endif')
|
g.definitions.writeln('// end of definitions #endif')
|
||||||
//
|
//
|
||||||
g.stringliterals.writeln('')
|
g.stringliterals.writeln('')
|
||||||
g.stringliterals.writeln('// >> string literal consts')
|
g.stringliterals.writeln('// >> string literal consts')
|
||||||
g.stringliterals.writeln('void vinit_string_literals(){')
|
g.stringliterals.writeln('void vinit_string_literals(){')
|
||||||
@ -205,7 +205,7 @@ pub fn (g mut Gen) typ(t table.Type) string {
|
|||||||
return styp
|
return styp
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
pub fn (g mut Gen) write_typedef_types() {
|
pub fn (g mut Gen) write_typedef_types() {
|
||||||
for typ in g.table.types {
|
for typ in g.table.types {
|
||||||
match typ.kind {
|
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)
|
g.fn_args(it.args, it.is_variadic)
|
||||||
if it.no_body {
|
if it.no_body {
|
||||||
// Just a function header.
|
// Just a function header.
|
||||||
@ -1236,7 +1236,8 @@ fn (g mut Gen) assign_expr(node ast.AssignExpr) {
|
|||||||
if is_call {
|
if is_call {
|
||||||
g.expr(node.val)
|
g.expr(node.val)
|
||||||
} else {
|
} else {
|
||||||
g.write('{${g.typ(node.left_type)} _ = ')
|
// g.write('{${g.typ(node.left_type)} _ = ')
|
||||||
|
g.write('{')
|
||||||
g.expr(node.val)
|
g.expr(node.val)
|
||||||
g.writeln(';}')
|
g.writeln(';}')
|
||||||
}
|
}
|
||||||
@ -1451,7 +1452,7 @@ fn (g mut Gen) match_expr(node ast.MatchExpr) {
|
|||||||
// sum_type_str
|
// sum_type_str
|
||||||
} else if type_sym.kind == .string {
|
} else if type_sym.kind == .string {
|
||||||
g.write('string_eq(')
|
g.write('string_eq(')
|
||||||
//
|
//
|
||||||
g.expr(node.cond)
|
g.expr(node.cond)
|
||||||
g.write(', ')
|
g.write(', ')
|
||||||
// g.write('string_eq($tmp, ')
|
// 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) {
|
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)
|
1], .variadic)
|
||||||
mut arg_no := 0
|
mut arg_no := 0
|
||||||
for arg in args {
|
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('EMPTY_STRUCT_DECLARATION;')
|
||||||
}
|
}
|
||||||
// g.definitions.writeln('} $name;\n')
|
// g.definitions.writeln('} $name;\n')
|
||||||
//
|
//
|
||||||
g.definitions.writeln('};\n')
|
g.definitions.writeln('};\n')
|
||||||
}
|
}
|
||||||
table.Alias {
|
table.Alias {
|
||||||
@ -2198,8 +2199,8 @@ fn (g Gen) sort_structs(typesa []table.TypeSymbol) []table.TypeSymbol {
|
|||||||
// sort graph
|
// sort graph
|
||||||
dep_graph_sorted := dep_graph.resolve()
|
dep_graph_sorted := dep_graph.resolve()
|
||||||
if !dep_graph_sorted.acyclic {
|
if !dep_graph_sorted.acyclic {
|
||||||
verror('cgen.sort_structs(): the following structs form a dependency cycle:\n' + dep_graph_sorted.display_cycles() +
|
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' +
|
'\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')
|
'\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
|
// sort types
|
||||||
@ -2341,7 +2342,7 @@ fn (g mut Gen) method_call(node ast.CallExpr) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO performance, detect `array` method differently
|
// 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'] {
|
'trim', 'first', 'last', 'clone', 'reverse', 'slice'] {
|
||||||
// && rec_sym.name == 'array' {
|
// && rec_sym.name == 'array' {
|
||||||
// && rec_sym.name == 'array' && receiver_name.starts_with('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.write('/*rec*/*')
|
||||||
}
|
}
|
||||||
g.expr(node.left)
|
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)
|
1], .variadic)
|
||||||
if node.args.len > 0 || is_variadic {
|
if node.args.len > 0 || is_variadic {
|
||||||
g.write(', ')
|
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 {
|
fn type_to_fmt(typ table.Type) string {
|
||||||
n := int(typ)
|
n := int(typ)
|
||||||
if n == table.string_type {
|
if n == table.string_type {
|
||||||
return '\'%.*s\''
|
return "\'%.*s\'"
|
||||||
} else if n == table.bool_type {
|
} else if n == table.bool_type {
|
||||||
return '%.*s'
|
return '%.*s'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user