mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: test local modules
This commit is contained in:
parent
a707ffc04a
commit
38de6c98fc
@ -21,8 +21,8 @@ pub:
|
||||
os pref.OS // the OS to build for
|
||||
compiled_dir string // contains os.realpath() of the dir of the final file beeing compiled, or the dir itself when doing `v .`
|
||||
module_path string
|
||||
module_search_paths []string
|
||||
mut:
|
||||
module_search_paths []string
|
||||
parsed_files []ast.File
|
||||
}
|
||||
|
||||
@ -76,6 +76,8 @@ pub fn (b mut Builder) parse_imports() {
|
||||
import_path := b.find_module_path(mod) or {
|
||||
// v.parsers[i].error_with_token_index('cannot import module "$mod" (not found)', v.parsers[i].import_table.get_import_tok_idx(mod))
|
||||
// break
|
||||
// println('module_search_paths:')
|
||||
// println(b.module_search_paths)
|
||||
panic('cannot import module "$mod" (not found)')
|
||||
}
|
||||
v_files := b.v_files_from_dir(import_path)
|
||||
@ -171,3 +173,26 @@ pub fn (b &Builder) log(s string) {
|
||||
println(s)
|
||||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn module_path(mod string) string {
|
||||
// submodule support
|
||||
return mod.replace('.', filepath.separator)
|
||||
}
|
||||
|
||||
pub fn (b &Builder) find_module_path(mod string) ?string {
|
||||
mod_path := module_path(mod)
|
||||
for search_path in b.module_search_paths {
|
||||
try_path := filepath.join(search_path,mod_path)
|
||||
if b.pref.is_verbose {
|
||||
println(' >> trying to find $mod in $try_path ..')
|
||||
}
|
||||
if os.is_dir(try_path) {
|
||||
if b.pref.is_verbose {
|
||||
println(' << found $try_path .')
|
||||
}
|
||||
return try_path
|
||||
}
|
||||
}
|
||||
return error('module "$mod" not found')
|
||||
}
|
||||
|
@ -4,26 +4,3 @@ import (
|
||||
os
|
||||
filepath
|
||||
)
|
||||
|
||||
[inline]
|
||||
fn module_path(mod string) string {
|
||||
// submodule support
|
||||
return mod.replace('.', filepath.separator)
|
||||
}
|
||||
|
||||
pub fn (b &Builder) find_module_path(mod string) ?string {
|
||||
mod_path := module_path(mod)
|
||||
for search_path in b.module_search_paths {
|
||||
try_path := filepath.join(search_path,mod_path)
|
||||
if b.pref.is_verbose {
|
||||
println(' >> trying to find $mod in $try_path ..')
|
||||
}
|
||||
if os.is_dir(try_path) {
|
||||
if b.pref.is_verbose {
|
||||
println(' << found $try_path .')
|
||||
}
|
||||
return try_path
|
||||
}
|
||||
}
|
||||
return error('module "$mod" not found')
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
max_nr_errors = 150
|
||||
max_nr_errors = 350
|
||||
)
|
||||
|
||||
pub struct Checker {
|
||||
|
@ -85,8 +85,9 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
||||
}
|
||||
else {
|
||||
type_sym := g.table.get_type_symbol(it.typ)
|
||||
g.write('$type_sym.name ${it.name}(')
|
||||
g.definitions.write('$type_sym.name ${it.name}(')
|
||||
name := it.name.replace('.', '__')
|
||||
g.write('$type_sym.name ${name}(')
|
||||
g.definitions.write('$type_sym.name ${name}(')
|
||||
}
|
||||
for i, arg in it.args {
|
||||
arg_type_sym := g.table.get_type_symbol(arg.typ)
|
||||
@ -283,7 +284,8 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
g.write('}')
|
||||
}
|
||||
ast.CallExpr {
|
||||
g.write('${it.name}(')
|
||||
name := it.name.replace('.', '__')
|
||||
g.write('${name}(')
|
||||
g.call_args(it.args)
|
||||
g.write(')')
|
||||
/*
|
||||
@ -298,7 +300,8 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
}
|
||||
ast.MethodCallExpr {
|
||||
typ := 'TODO'
|
||||
g.write('${typ}_${it.name}(')
|
||||
name := it.name.replace('.', '__')
|
||||
g.write('${typ}_${name}(')
|
||||
g.expr(it.expr)
|
||||
if it.args.len > 0 {
|
||||
g.write(', ')
|
||||
|
@ -16,13 +16,14 @@ fn test_c_files() {
|
||||
vroot := filepath.dir(vexe)
|
||||
term_ok := term.ok_message('OK')
|
||||
term_fail := term.fail_message('FAIL')
|
||||
for i in 1..(nr_tests + 1) {
|
||||
for i in 1 .. (nr_tests + 1) {
|
||||
path := '$vroot/vlib/v/gen/tests/${i}.vv'
|
||||
mut ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or {
|
||||
panic(err)
|
||||
}
|
||||
ctext = ctext // unused warn
|
||||
mut b := builder.new_builder(pref.Preferences{})
|
||||
b.module_search_paths = ['$vroot/vlib/v/gen/tests/']
|
||||
res := b.gen_c([path])
|
||||
if compare_texts(res, ctext) {
|
||||
eprintln('${term_ok} ${i}')
|
||||
|
@ -9,6 +9,7 @@ void ensure_cap(int required, int cap);
|
||||
void println(string s);
|
||||
void matches();
|
||||
void end();
|
||||
void localmod__pub_foo();
|
||||
int pi = 3;
|
||||
int pi2 = pi;
|
||||
|
||||
@ -33,6 +34,7 @@ int main() {
|
||||
int ak = 10;
|
||||
int mypi = pi;
|
||||
Color color = Color_red;
|
||||
localmod__pub_foo();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -141,3 +143,7 @@ void end() {
|
||||
bool x = i != -1 && key == 10;
|
||||
int e = 2 + 3 * 4;
|
||||
}
|
||||
|
||||
void localmod__pub_foo() {
|
||||
int a = 10;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
//import moda
|
||||
//import modb as mb
|
||||
|
||||
import localmod
|
||||
|
||||
const (
|
||||
pi = 3
|
||||
pi2 = pi
|
||||
@ -39,6 +41,7 @@ fn main() {
|
||||
ak := 10
|
||||
mypi := pi
|
||||
color := Color.red
|
||||
localmod.pub_foo()
|
||||
}
|
||||
/*
|
||||
user := User{}
|
||||
|
5
vlib/v/gen/tests/localmod/localmod.v
Normal file
5
vlib/v/gen/tests/localmod/localmod.v
Normal file
@ -0,0 +1,5 @@
|
||||
module localmod
|
||||
|
||||
pub fn pub_foo() {
|
||||
a := 10
|
||||
}
|
Loading…
Reference in New Issue
Block a user