1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/cmd/tools/vnames.v

90 lines
1.9 KiB
V
Raw Normal View History

module main
2020-04-04 17:39:08 +03:00
/*
QTODO
2019-12-23 13:09:22 +03:00
import (
os
flag
strings
compiler
2020-02-09 12:08:04 +03:00
v.pref
2019-12-23 13:09:22 +03:00
)
const (
tool_version = '0.0.1'
tool_description = ' Extracts the function names declared in a v file.'
)
fn f_to_string(fmod string, f compiler.Fn) ?string {
svisibility := if f.is_public {
'public'
}else{
'private'
}
if fmod != f.v_fn_module() { return none }
if fmod == 'builtin' {
return '$svisibility\t' + f.v_fn_name()
}
return '$svisibility\t' + f.v_fn_module() + '.' + f.v_fn_name()
}
fn analyze_v_file(file string) {
println('')
hash := strings.repeat(`#`, (76 - file.len) / 2)
println('$hash $file $hash')
// main work:
2020-02-09 12:08:04 +03:00
mut pref := &pref.Preferences{
path: file
}
pref.fill_with_defaults()
mut v := compiler.new_v(pref)
v.add_v_files_to_compile()
for f in v.files { v.parse(f, .decl) }
fi := v.get_file_parser_index( file ) or { panic(err) }
fmod := v.parsers[fi].mod
2020-03-08 00:26:26 +03:00
// output:
mut fns :=[]string
for _, f in v.table.fns {
fname := f_to_string(fmod, f) or { continue }
fns << fname
}
fns.sort()
for f in fns { println(f) }
2020-03-08 00:26:26 +03:00
}
fn main(){
toolexe := os.executable()
2020-03-08 00:26:26 +03:00
compiler.set_vroot_folder(os.dir(os.dir(os.dir(toolexe))))
2019-12-23 13:09:22 +03:00
mut fp := flag.new_flag_parser(os.args)
2020-03-19 17:49:07 +03:00
fp.application(os.file_name(toolexe))
fp.version( tool_version )
fp.description( tool_description )
fp.arguments_description('FILE.v/FOLDER [FILE.v/FOLDER]...')
fp.limit_free_args_to_at_least(1)
fp.skip_executable()
2020-03-19 09:06:37 +03:00
show_help:=fp.bool('help', `h`, false, 'Show this help screen\n')
if( show_help ){
println( fp.usage() )
exit(0)
}
2020-03-08 00:26:26 +03:00
mut files := []string
locations := fp.finalize() or { eprintln('Error: ' + err) exit(1) }
for xloc in locations {
2020-03-20 18:41:18 +03:00
loc := os.real_path(xloc)
xfiles := if os.is_dir(loc){ os.walk_ext(loc,'.v') } else { [loc] }
filtered_files := xfiles.filter(!it.ends_with('_js.v'))
files << filtered_files
}
for file in files {
analyze_v_file(file)
}
}
2020-04-04 17:39:08 +03:00
*/
fn main() {}