v: show the number of processed bytes and lines for V source code with -stats

pull/9629/head
Delyan Angelov 2021-04-07 18:12:27 +03:00
parent fef4e1e700
commit de5cf4ac5e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 10 additions and 0 deletions

View File

@ -543,6 +543,8 @@ pub struct File {
pub:
path string // absolute path of the source file - '/projects/v/file.v'
path_base string // file name - 'file.v' (useful for tracing)
lines int // number of source code lines in the file (including newlines and comments)
bytes int // number of processed source code bytes
mod Module // the module of the source file (from `module xyz` at the top)
global_scope &Scope
pub mut:

View File

@ -48,6 +48,12 @@ pub fn (mut b Builder) build_c(v_files []string, out_file string) {
if b.pref.is_stats {
slines := util.bold((output2.count('\n') + 1).str())
sbytes := util.bold(output2.len.str())
mut all_v_source_lines, mut all_v_source_bytes := 0, 0
for mut pf in b.parsed_files {
all_v_source_lines += pf.lines
all_v_source_bytes += pf.bytes
}
println(' V source code size: ${util.bold(all_v_source_lines.str())} lines, ${util.bold(all_v_source_bytes.str())} bytes')
println('generated C source code size: $slines lines, $sbytes bytes')
}
// os.write_file(out_file, b.gen_c(v_files))

View File

@ -272,6 +272,8 @@ pub fn (mut p Parser) parse() ast.File {
return ast.File{
path: p.file_name
path_base: p.file_base
lines: p.scanner.line_nr
bytes: p.scanner.text.len
mod: module_decl
imports: p.ast_imports
imported_symbols: p.imported_symbols