Skip to content

Commit

Permalink
v: make all .trace() methods generic on the type of the passed expres…
Browse files Browse the repository at this point in the history
…sion

That is more efficient, than always converting the expression to a string
at the callsites, since most of the times the file selector will not match,
and in those cases, the expression will not have to be converted to a string at all.
  • Loading branch information
spytheman committed Aug 18, 2023
1 parent c862394 commit 68d962f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions vlib/v/checker/checker.v
Expand Up @@ -4618,9 +4618,9 @@ fn (mut c Checker) fetch_field_name(field ast.StructField) string {
return name
}

fn (mut c Checker) trace(fbase string, message string) {
fn (mut c Checker) trace[T](fbase string, x &T) {
if c.file.path_base == fbase {
println('> c.trace | ${fbase:-10s} | ${message}')
println('> c.trace | ${fbase:-10s} | ${x}')
}
}

Expand Down
4 changes: 2 additions & 2 deletions vlib/v/fmt/fmt.v
Expand Up @@ -3006,8 +3006,8 @@ pub fn (mut f Fmt) unsafe_expr(node ast.UnsafeExpr) {
f.write('}')
}

fn (mut f Fmt) trace(fbase string, message string) {
fn (mut f Fmt) trace[T](fbase string, x &T) {
if f.file.path_base == fbase {
println('> f.trace | ${fbase:-10s} | ${message}')
println('> f.trace | ${fbase:-10s} | ${voidptr(x):16} | ${x}')
}
}
4 changes: 2 additions & 2 deletions vlib/v/gen/c/cgen.v
Expand Up @@ -6945,9 +6945,9 @@ pub fn get_guarded_include_text(iname string, imessage string) string {
return res
}

fn (mut g Gen) trace(fbase string, message string) {
fn (mut g Gen) trace[T](fbase string, x &T) {
if g.file.path_base == fbase {
println('> g.trace | ${fbase:-10s} | ${message}')
println('> g.trace | ${fbase:-10s} | ${voidptr(x):16} | ${x}')
}
}

Expand Down
6 changes: 0 additions & 6 deletions vlib/v/gen/golang/golang.v
Expand Up @@ -2283,12 +2283,6 @@ pub fn (mut f Gen) unsafe_expr(node ast.UnsafeExpr) {
f.write('}')
}

fn (mut f Gen) trace(fbase string, message string) {
// if f.file.path_base == fbase {
// println('> f.trace | ${fbase:-10s} | $message')
//}
}

pub fn (mut g Gen) error(s string) {
util.verror('golang backend error', s)
}
4 changes: 2 additions & 2 deletions vlib/v/parser/parser.v
Expand Up @@ -4358,9 +4358,9 @@ fn (mut p Parser) disallow_declarations_in_script_mode() bool {
return false
}

fn (mut p Parser) trace(fbase string, message string) {
fn (mut p Parser) trace[T](fbase string, x &T) {
if p.file_base == fbase {
println('> p.trace | ${fbase:-10s} | ${message}')
println('> p.trace | ${fbase:-10s} | ${voidptr(x):16} | ${x}')
}
}

Expand Down
4 changes: 2 additions & 2 deletions vlib/v/scanner/scanner.v
Expand Up @@ -1685,8 +1685,8 @@ fn (mut s Scanner) vet_error(msg string, fix vet.FixKind) {
s.vet_errors << ve
}

fn (mut s Scanner) trace(fbase string, message string) {
fn (mut s Scanner) trace[T](fbase string, x &T) {
if s.file_base == fbase {
println('> s.trace | ${fbase:-10s} | ${message}')
println('> s.trace | ${fbase:-10s} | ${voidptr(x):16} | ${x}')
}
}
8 changes: 8 additions & 0 deletions vlib/v/transformer/transformer.v
Expand Up @@ -9,11 +9,18 @@ pub struct Transformer {
pub mut:
index &IndexState
table &ast.Table = unsafe { nil }
file &ast.File = unsafe { nil }
mut:
is_assert bool
inside_dump bool
}

fn (mut t Transformer) trace[T](fbase string, x &T) {
if t.file.path_base == fbase {
println('> t.trace | ${fbase:-10s} | ${voidptr(x):16} | ${x}')
}
}

pub fn new_transformer(pref_ &pref.Preferences) &Transformer {
return &Transformer{
pref: pref_
Expand All @@ -38,6 +45,7 @@ pub fn (mut t Transformer) transform_files(ast_files []&ast.File) {
}

pub fn (mut t Transformer) transform(mut ast_file ast.File) {
t.file = ast_file
for mut stmt in ast_file.stmts {
stmt = t.stmt(mut stmt)
}
Expand Down

0 comments on commit 68d962f

Please sign in to comment.