From de5cf4ac5e5739f629acac04eab8f0689a469e1c Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 7 Apr 2021 18:12:27 +0300 Subject: [PATCH] v: show the number of processed bytes and lines for V source code with -stats --- vlib/v/ast/ast.v | 2 ++ vlib/v/builder/c.v | 6 ++++++ vlib/v/parser/parser.v | 2 ++ 3 files changed, 10 insertions(+) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index f5501da715..d6f1ef2648 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -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: diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index 51a51ec862..129924f32a 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -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)) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index c89770fba6..446f5fc3e5 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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