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

snake_case consts

This commit is contained in:
Alexander Medvednikov
2019-10-12 22:31:05 +03:00
parent 81f8b26127
commit a76165828b
17 changed files with 124 additions and 125 deletions

View File

@@ -65,11 +65,11 @@ fn (v mut V) cc() {
if v.pref.build_mode == .build_module {
// Create the modules & out directory if it's not there.
mut out_dir := if v.dir.starts_with('vlib') {
'$v_modules_path${os.PathSeparator}cache${os.PathSeparator}$v.dir'
'$v_modules_path${os.path_separator}cache${os.path_separator}$v.dir'
} else {
'$v_modules_path${os.PathSeparator}$v.dir'
'$v_modules_path${os.path_separator}$v.dir'
}
pdir := out_dir.all_before_last(os.PathSeparator)
pdir := out_dir.all_before_last(os.path_separator)
if !os.dir_exists(pdir) {
os.mkdir_all(pdir)
}
@@ -118,25 +118,25 @@ fn (v mut V) cc() {
}
else if v.pref.is_cache {
vexe := os.executable()
builtin_o_path := '$v_modules_path${os.PathSeparator}cache${os.PathSeparator}vlib${os.PathSeparator}builtin.o'
builtin_o_path := '$v_modules_path${os.path_separator}cache${os.path_separator}vlib${os.path_separator}builtin.o'
if os.file_exists(builtin_o_path) {
libs = builtin_o_path
} else {
println('$builtin_o_path not found... building module builtin')
os.system('$vexe build module vlib${os.PathSeparator}builtin')
os.system('$vexe build module vlib${os.path_separator}builtin')
}
for imp in v.table.imports {
if imp.contains('vweb') { continue } // not working
if imp == 'webview' { continue }
imp_path := imp.replace('.', os.PathSeparator)
path := '$v_modules_path${os.PathSeparator}cache${os.PathSeparator}vlib${os.PathSeparator}${imp_path}.o'
imp_path := imp.replace('.', os.path_separator)
path := '$v_modules_path${os.path_separator}cache${os.path_separator}vlib${os.path_separator}${imp_path}.o'
//println('adding ${imp_path}.o')
if os.file_exists(path) {
libs += ' ' + path
} else {
println('$path not found... building module $imp')
os.system('$vexe build module vlib${os.PathSeparator}$imp_path')
os.system('$vexe build module vlib${os.path_separator}$imp_path')
}
}
}

View File

@@ -254,7 +254,7 @@ fn build_thirdparty_obj_file(path string, moduleflags []CFlag) {
mut cfiles := ''
for file in files {
if file.ends_with('.c') {
cfiles += '"' + os.realpath( parent + os.PathSeparator + file ) + '" '
cfiles += '"' + os.realpath( parent + os.path_separator + file ) + '" '
}
}
cc := find_c_compiler()

View File

@@ -610,7 +610,7 @@ fn (v &V) v_files_from_dir(dir string) []string {
if file.ends_with('_c.v') && v.os == .js {
continue
}
res << '$dir${os.PathSeparator}$file'
res << '$dir${os.path_separator}$file'
}
return res
}
@@ -619,7 +619,7 @@ fn (v &V) v_files_from_dir(dir string) []string {
fn (v mut V) add_v_files_to_compile() {
mut builtin_files := v.get_builtin_files()
// Builtin cache exists? Use it.
builtin_vh := '$v_modules_path${os.PathSeparator}vlib${os.PathSeparator}builtin.vh'
builtin_vh := '$v_modules_path${os.path_separator}vlib${os.path_separator}builtin.vh'
if v.pref.is_cache && os.file_exists(builtin_vh) {
v.cached_mods << 'builtin'
builtin_files = [builtin_vh]
@@ -638,7 +638,7 @@ fn (v mut V) add_v_files_to_compile() {
mut p := v.new_parser_from_file(file)
// set mod so we dont have to resolve submodule
if v.pref.build_mode == .build_module &&
file.contains(v.mod.replace('.', os.PathSeparator)) {
file.contains(v.mod.replace('.', os.path_separator)) {
p.mod = v.mod
}
p.parse(.imports)
@@ -662,8 +662,8 @@ fn (v mut V) add_v_files_to_compile() {
// use cached built module if exists
if v.pref.build_mode != .build_module && !mod.contains('vweb') {
mod_path := mod.replace('.', os.PathSeparator)
vh_path := '$v_modules_path${os.PathSeparator}vlib${os.PathSeparator}${mod_path}.vh'
mod_path := mod.replace('.', os.path_separator)
vh_path := '$v_modules_path${os.path_separator}vlib${os.path_separator}${mod_path}.vh'
if v.pref.is_cache && os.file_exists(vh_path) {
println('using cached module `$mod`: $vh_path')
v.cached_mods << mod
@@ -689,9 +689,9 @@ fn (v &V) get_builtin_files() []string {
// .vh cache exists? Use it
$if js {
return v.v_files_from_dir('$v.vroot${os.PathSeparator}vlib${os.PathSeparator}builtin${os.PathSeparator}js')
return v.v_files_from_dir('$v.vroot${os.path_separator}vlib${os.path_separator}builtin${os.path_separator}js')
}
return v.v_files_from_dir('$v.vroot${os.PathSeparator}vlib${os.PathSeparator}builtin')
return v.v_files_from_dir('$v.vroot${os.path_separator}vlib${os.path_separator}builtin')
}
// get user files
@@ -703,22 +703,22 @@ fn (v &V) get_user_files() []string {
mut user_files := []string
if v.pref.is_test && v.pref.is_stats {
user_files << [v.vroot, 'vlib', 'benchmark', 'tests', 'always_imported.v'].join( os.PathSeparator )
user_files << [v.vroot, 'vlib', 'benchmark', 'tests', 'always_imported.v'].join( os.path_separator )
}
// v volt/slack_test.v: compile all .v files to get the environment
// I need to implement user packages! TODO
is_test_with_imports := dir.ends_with('_test.v') &&
(dir.contains('${os.PathSeparator}volt') || dir.contains('${os.PathSeparator}c2volt'))// TODO
(dir.contains('${os.path_separator}volt') || dir.contains('${os.path_separator}c2volt'))// TODO
if is_test_with_imports {
user_files << dir
pos := dir.last_index(os.PathSeparator)
dir = dir.left(pos) + os.PathSeparator// TODO WHY IS THIS .neEDED?
pos := dir.last_index(os.path_separator)
dir = dir.left(pos) + os.path_separator// TODO WHY IS THIS .neEDED?
}
if dir.ends_with('.v') {
// Just compile one file and get parent dir
user_files << dir
dir = dir.all_before('${os.PathSeparator}')
dir = dir.all_before('${os.path_separator}')
}
else {
// Add .v files from the directory being compiled
@@ -815,7 +815,7 @@ fn new_v(args[]string) &V {
// Create modules dirs if they are missing
if !os.dir_exists(v_modules_path) {
os.mkdir(v_modules_path)
os.mkdir('$v_modules_path${os.PathSeparator}cache')
os.mkdir('$v_modules_path${os.path_separator}cache')
}
mut vgen_buf := strings.new_builder(1000)
@@ -829,10 +829,10 @@ fn new_v(args[]string) &V {
if 'run' in args {
dir = get_param_after(joined_args, 'run', '')
}
if dir.ends_with(os.PathSeparator) {
dir = dir.all_before_last(os.PathSeparator)
if dir.ends_with(os.path_separator) {
dir = dir.all_before_last(os.path_separator)
}
if dir.starts_with('.$os.PathSeparator') {
if dir.starts_with('.$os.path_separator') {
dir = dir.right(2)
}
if args.len < 2 {
@@ -845,17 +845,17 @@ fn new_v(args[]string) &V {
build_mode = .build_module
// v build module ~/v/os => os.o
mod_path := if dir.contains('vlib') {
dir.all_after('vlib'+os.PathSeparator)
dir.all_after('vlib'+os.path_separator)
}
else if dir.starts_with('.\\') || dir.starts_with('./') {
dir.right(2)
}
else if dir.starts_with(os.PathSeparator) {
dir.all_after(os.PathSeparator)
else if dir.starts_with(os.path_separator) {
dir.all_after(os.path_separator)
} else {
dir
}
mod = mod_path.replace(os.PathSeparator, '.')
mod = mod_path.replace(os.path_separator, '.')
println('Building module "${mod}" (dir="$dir")...')
//out_name = '$TmpPath/vlib/${base}.o'
out_name = mod
@@ -881,7 +881,7 @@ fn new_v(args[]string) &V {
}
// if we are in `/foo` and run `v .`, the executable should be `foo`
if dir == '.' && out_name == 'a.out' {
base := os.getwd().all_after(os.PathSeparator)
base := os.getwd().all_after(os.path_separator)
out_name = base.trim_space()
}
mut _os := OS.mac
@@ -976,7 +976,7 @@ fn new_v(args[]string) &V {
println('C compiler=$pref.ccompiler')
}
if pref.is_so {
out_name_c = out_name.all_after(os.PathSeparator) + '_shared_lib.c'
out_name_c = out_name.all_after(os.path_separator) + '_shared_lib.c'
}
return &V{
os: _os

View File

@@ -106,14 +106,14 @@ fn v_type_str(typ_ string) string {
fn (v &V) generate_vh() {
println('\n\n\n\nGenerating a V header file for module `$v.mod`')
mod_path := v.mod.replace('.', os.PathSeparator)
mod_path := v.mod.replace('.', os.path_separator)
dir := if v.dir.starts_with('vlib') {
'$v_modules_path${os.PathSeparator}$v.dir'
'$v_modules_path${os.path_separator}$v.dir'
} else {
'$v_modules_path${os.PathSeparator}$mod_path'
'$v_modules_path${os.path_separator}$mod_path'
}
path := dir + '.vh'
pdir := dir.all_before_last(os.PathSeparator)
pdir := dir.all_before_last(os.path_separator)
if !os.dir_exists(pdir) {
os.mkdir_all(pdir)
// os.mkdir(os.realpath(dir))

View File

@@ -33,7 +33,7 @@ pub fn(graph &DepGraph) imports() []string {
fn (v &V) module_path(mod string) string {
// submodule support
if mod.contains('.') {
return mod.replace('.', os.PathSeparator)
return mod.replace('.', os.path_separator)
// return mod.replace('.', '/')
}
return mod
@@ -45,15 +45,15 @@ fn (v &V) module_path(mod string) string {
fn (v &V) find_module_path(mod string) ?string {
mod_path := v.module_path(mod)
// First check for local modules in the same directory
mut import_path := os.getwd() + '${os.PathSeparator}$mod_path'
mut import_path := os.getwd() + '${os.path_separator}$mod_path'
// Now search in vlib/
if !os.dir_exists(import_path) {
import_path = '$v.lang_dir${os.PathSeparator}vlib${os.PathSeparator}$mod_path'
import_path = '$v.lang_dir${os.path_separator}vlib${os.path_separator}$mod_path'
}
//println('ip=$import_path')
// Finally try modules installed with vpm (~/.vmodules)
if !os.dir_exists(import_path) {
import_path = '$v_modules_path${os.PathSeparator}$mod_path'
import_path = '$v_modules_path${os.path_separator}$mod_path'
if !os.dir_exists(import_path){
return error('module "$mod" not found')
}
@@ -67,4 +67,4 @@ fn mod_gen_name(mod string) string {
fn mod_gen_name_rev(mod string) string {
return mod.replace('_dot_', '.')
}
}

View File

@@ -191,7 +191,7 @@ fn find_msvc() ?MsvcResult {
}
return MsvcResult {
full_cl_exe_path: os.realpath( vs.exe_path + os.PathSeparator + 'cl.exe' )
full_cl_exe_path: os.realpath( vs.exe_path + os.path_separator + 'cl.exe' )
exe_path: vs.exe_path,
um_lib_path: wk.um_lib_path,
@@ -388,7 +388,7 @@ fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) {
mut cfiles := ''
for file in files {
if file.ends_with('.c') {
cfiles += '"' + os.realpath( parent + os.PathSeparator + file ) + '" '
cfiles += '"' + os.realpath( parent + os.path_separator + file ) + '" '
}
}
@@ -441,7 +441,7 @@ fn (cflags []CFlag) msvc_string_flags() MsvcStringFlags {
}
else if flag.name == '-L' {
lib_paths << flag.value
lib_paths << flag.value + os.PathSeparator + 'msvc'
lib_paths << flag.value + os.path_separator + 'msvc'
// The above allows putting msvc specific .lib files in a subfolder msvc/ ,
// where gcc will NOT find them, but cl will do...
// NB: gcc is smart enough to not need .lib files at all in most cases, the .dll is enough.

View File

@@ -122,7 +122,7 @@ fn (v mut V) new_parser_from_file(path string) Parser {
mut p := v.new_parser(new_scanner_file(path), path)
p = { p|
file_path: path,
file_name: path.all_after(os.PathSeparator),
file_name: path.all_after(os.path_separator),
file_platform: path_platform,
file_pcguard: path_pcguard,
is_script: (v.pref.is_script && os.realpath(path) == os.realpath(path)),
@@ -518,8 +518,8 @@ fn (p mut Parser) const_decl() {
continue
}
mut name := p.check_name() // `Age = 20`
if p.mod != 'os' && contains_capital(name) {
//p.warn('const names cannot contain uppercase letters, use snake_case instead')
if !p.pref.building_v && p.mod != 'os' && contains_capital(name) {
p.warn('const names cannot contain uppercase letters, use snake_case instead')
}
name = p.prepend_mod(name)
mut typ := ''

View File

@@ -725,7 +725,7 @@ fn (s mut Scanner) debug_tokens() {
s.started = false
s.debug = true
fname := s.file_path.all_after(os.PathSeparator)
fname := s.file_path.all_after(os.path_separator)
println('\n===DEBUG TOKENS $fname===')
for {

View File

@@ -778,14 +778,14 @@ fn (table &Table) cgen_name_type_pair(name, typ string) string {
fn is_valid_int_const(val, typ string) bool {
x := val.int()
switch typ {
case 'byte': return 0 <= x && x <= math.MaxU8
case 'u16': return 0 <= x && x <= math.MaxU16
case 'byte': return 0 <= x && x <= math.max_u8
case 'u16': return 0 <= x && x <= math.max_u16
//case 'u32': return 0 <= x && x <= math.MaxU32
//case 'u64': return 0 <= x && x <= math.MaxU64
//////////////
case 'i8': return math.MinI8 <= x && x <= math.MaxI8
case 'i16': return math.MinI16 <= x && x <= math.MaxI16
case 'int': return math.MinI32 <= x && x <= math.MaxI32
case 'i8': return math.min_i8 <= x && x <= math.max_i8
case 'i16': return math.min_i16 <= x && x <= math.max_i16
case 'int': return math.min_i32 <= x && x <= math.max_i32
//case 'i64':
//x64 := val.i64()
//return i64(-(1<<63)) <= x64 && x64 <= i64((1<<63)-1)
@@ -870,7 +870,7 @@ fn (table &Table) qualify_module(mod string, file_path string) string {
for m in table.imports {
if m.contains('.') && m.contains(mod) {
m_parts := m.split('.')
m_path := m_parts.join(os.PathSeparator)
m_path := m_parts.join(os.path_separator)
if mod == m_parts[m_parts.len-1] && file_path.contains(m_path) {
return m
}

View File

@@ -11,12 +11,12 @@ pub:
pub fn full_path_to_v() string {
vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' }
vexec := os.dir(os.dir(os.dir(os.dir( os.executable() )))) + os.PathSeparator + vname
vexec := os.dir(os.dir(os.dir(os.dir( os.executable() )))) + os.path_separator + vname
/*
args := os.args
vreal := os.realpath('v')
myself := os.realpath( os.executable() )
wd := os.getwd() + os.PathSeparator
wd := os.getwd() + os.path_separator
println('args are: $args')
println('vreal : $vreal')
println('myself : $myself')
@@ -76,7 +76,7 @@ $diff
}
pub fn new_options() RunnerOptions {
wd := os.getwd() + os.PathSeparator
wd := os.getwd() + os.path_separator
vexec := full_path_to_v()
mut files := []string
if os.args.len > 1 {

View File

@@ -56,7 +56,7 @@ fn test_v() {
}
if os.dir_exists(targ) {
ts.files << os.walk_ext( targ.trim_right(os.PathSeparator), '_test.v')
ts.files << os.walk_ext( targ.trim_right(os.path_separator), '_test.v')
continue
}
println('Unrecognized test file $targ .')