fmt: fix array receivers; cmd/v: -showcc

pull/4321/head
Alexander Medvednikov 2020-04-09 15:05:06 +02:00
parent d7ae9d7279
commit f3c917e0aa
7 changed files with 18 additions and 12 deletions

View File

@ -7,7 +7,6 @@ import v.pref
const (
skip_test_files = [
'vlib/arrays/arrays_test.v',
'vlib/builtin/map_test.v',
'vlib/cli/command_test.v',
'vlib/cli/flag_test.v',
'vlib/clipboard/clipboard_test.v', // Linux only

View File

@ -129,6 +129,7 @@ fn parse_args(args []string) (&pref.Preferences, string) {
'-stats' { res.is_stats = true }
'-obfuscate' { res.obfuscate = true }
'-translated' { res.translated = true }
'-showcc' { res.show_cc = true }
//'-x64' { res.translated = true }
'-os' {
//TODO Remove `tmp` variable when it doesn't error out in C.

View File

@ -16,6 +16,13 @@ pub fn (node &FnDecl) str(t &table.Table) string {
}
mut receiver := ''
if node.is_method {
mut styp := t.type_to_str(node.receiver.typ)
mut m := if node.rec_mut { 'mut ' } else { '' }
if node.rec_mut {
styp = styp[1..] // remove &
}
receiver = '($node.receiver.name $m$styp) '
/*
sym := t.get_type_symbol(node.receiver.typ)
name := sym.name.after('.')
mut m := if node.rec_mut { 'mut ' } else { '' }
@ -23,6 +30,7 @@ pub fn (node &FnDecl) str(t &table.Table) string {
m = '&'
}
receiver = '($node.receiver.name $m$name) '
*/
}
name := node.name.after('.')
if node.is_c {
@ -35,8 +43,8 @@ pub fn (node &FnDecl) str(t &table.Table) string {
continue
}
is_last_arg := i == node.args.len - 1
should_add_type := is_last_arg || node.args[i + 1].typ != arg.typ || (node.is_variadic && i ==
node.args.len - 2)
should_add_type := is_last_arg || node.args[i + 1].typ != arg.typ || (node.is_variadic &&
i == node.args.len - 2)
f.write(arg.name)
mut s := t.type_to_str(arg.typ)
if arg.is_mut {

View File

@ -323,7 +323,7 @@ start:
// TODO remove
cmd := '${v.pref.ccompiler} $args'
// Run
if v.pref.is_verbose {
if v.pref.is_verbose || v.pref.show_cc {
println('\n==========')
println(cmd)
}

View File

@ -4,6 +4,7 @@
module builder
import os
// parsed cflag
struct CFlag {
mod string // the module in which the flag was given
@ -23,9 +24,8 @@ fn (v &Builder) get_os_cflags() []CFlag {
if v.pref.compile_defines.len > 0 {
ctimedefines << v.pref.compile_defines
}
// QTODO
/*
// QTODO
/*
for flag in v.table.cflags {
if flag.os == '' || (flag.os == 'linux' && v.pref.os == .linux) || (flag.os == 'darwin' && v.pref.os == .mac) || (flag.os == 'freebsd' && v.pref.os == .freebsd) || (flag.os == 'windows' && v.pref.os == .windows) || (flag.os == 'mingw' && v.pref.os == .windows && v.pref.ccompiler != 'msvc') || (flag.os == 'solaris' && v.pref.os == .solaris) {
flags << flag
@ -34,7 +34,7 @@ fn (v &Builder) get_os_cflags() []CFlag {
flags << flag
}
}
*/
*/
return flags
}
@ -152,7 +152,6 @@ fn (table mut Table) parse_cflag(cflag string, mod string, ctimedefines []string
return true
}
*/
// TODO: implement msvc specific c_options_before_target and c_options_after_target ...
fn (cflags []CFlag) c_options_before_target_msvc() string {
return ''
@ -204,4 +203,3 @@ fn (cflags []CFlag) c_options_only_object_files() string {
}
return args.join(' ')
}

View File

@ -327,8 +327,7 @@ pub fn (p mut Parser) top_stmt() ast.Stmt {
p.next()
p.next()
return p.top_stmt()
}
else {
} else {
p.error('bad top level statement ' + p.tok.str())
return ast.Stmt{}
}

View File

@ -42,6 +42,7 @@ pub mut:
is_debug bool // false by default, turned on by -g or -cg, it tells v to pass -g to the C backend compiler.
is_vlines bool // turned on by -g, false by default (it slows down .tmp.c generation slightly).
is_keep_c bool // -keep_c , tell v to leave the generated .tmp.c alone (since by default v will delete them after c backend finishes)
show_cc bool // -showcc, print cc command
// NB: passing -cg instead of -g will set is_vlines to false and is_g to true, thus making v generate cleaner C files,
// which are sometimes easier to debug / inspect manually than the .tmp.c files by plain -g (when/if v line number generation breaks).
is_cache bool // turns on v usage of the module cache to speed up compilation.