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

ast, checker: change check(ast.file &ast.File) to check(mut ast.file ast.File) (#18729)

This commit is contained in:
yuyi 2023-07-02 14:41:04 +08:00 committed by GitHub
parent a27f2ddcc3
commit 44a6741bc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 16 deletions

View File

@ -1850,13 +1850,13 @@ pub:
scope &Scope = unsafe { nil } scope &Scope = unsafe { nil }
left Expr left Expr
is_vweb bool is_vweb bool
vweb_tmpl File
is_embed bool is_embed bool
is_env bool is_env bool
env_pos token.Pos env_pos token.Pos
is_pkgconfig bool is_pkgconfig bool
or_block OrExpr or_block OrExpr
pub mut: pub mut:
vweb_tmpl File
left_type Type left_type Type
result_type Type result_type Type
env_value string env_value string

View File

@ -166,8 +166,7 @@ fn (mut c Checker) reset_checker_state_at_start_of_new_file() {
c.inside_if_guard = false c.inside_if_guard = false
} }
pub fn (mut c Checker) check(ast_file_ &ast.File) { pub fn (mut c Checker) check(mut ast_file ast.File) {
mut ast_file := unsafe { ast_file_ }
c.reset_checker_state_at_start_of_new_file() c.reset_checker_state_at_start_of_new_file()
c.change_current_file(ast_file) c.change_current_file(ast_file)
for i, ast_import in ast_file.imports { for i, ast_import in ast_file.imports {
@ -266,7 +265,7 @@ pub fn (mut c Checker) check_scope_vars(sc &ast.Scope) {
} }
// not used right now // not used right now
pub fn (mut c Checker) check2(ast_file &ast.File) []errors.Error { pub fn (mut c Checker) check2(mut ast_file ast.File) []errors.Error {
c.change_current_file(ast_file) c.change_current_file(ast_file)
for stmt in ast_file.stmts { for stmt in ast_file.stmts {
c.stmt(stmt) c.stmt(stmt)
@ -290,7 +289,7 @@ pub fn (mut c Checker) check_files(ast_files []&ast.File) {
for i in 0 .. ast_files.len { for i in 0 .. ast_files.len {
mut file := ast_files[i] mut file := ast_files[i]
c.timers.start('checker_check ${file.path}') c.timers.start('checker_check ${file.path}')
c.check(file) c.check(mut file)
if file.mod.name == 'main' { if file.mod.name == 'main' {
files_from_main_module << file files_from_main_module << file
has_main_mod_file = true has_main_mod_file = true

View File

@ -126,7 +126,7 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) ast.Type {
} }
mut c2 := new_checker(c.table, pref2) mut c2 := new_checker(c.table, pref2)
c2.comptime_call_pos = node.pos.pos c2.comptime_call_pos = node.pos.pos
c2.check(node.vweb_tmpl) c2.check(mut node.vweb_tmpl)
c.warnings << c2.warnings c.warnings << c2.warnings
c.errors << c2.errors c.errors << c2.errors
c.notices << c2.notices c.notices << c2.notices

View File

@ -446,15 +446,15 @@ pub fn (mut d Doc) generate() ! {
} }
file_asts << parser.parse_file(file_path, d.table, comments_mode, d.prefs) file_asts << parser.parse_file(file_path, d.table, comments_mode, d.prefs)
} }
return d.file_asts(file_asts) return d.file_asts(mut file_asts)
} }
// file_asts has the same function as the `file_ast` function but // file_asts has the same function as the `file_ast` function but
// accepts an array of `ast.File` and throws an error if necessary. // accepts an array of `ast.File` and throws an error if necessary.
pub fn (mut d Doc) file_asts(file_asts []ast.File) ! { pub fn (mut d Doc) file_asts(mut file_asts []ast.File) ! {
mut fname_has_set := false mut fname_has_set := false
d.orig_mod_name = file_asts[0].mod.name d.orig_mod_name = file_asts[0].mod.name
for i, file_ast in file_asts { for i, mut file_ast in file_asts {
if d.filename.len > 0 && file_ast.path.contains(d.filename) && !fname_has_set { if d.filename.len > 0 && file_ast.path.contains(d.filename) && !fname_has_set {
d.filename = file_ast.path d.filename = file_ast.path
fname_has_set = true fname_has_set = true
@ -473,7 +473,7 @@ pub fn (mut d Doc) file_asts(file_asts []ast.File) ! {
continue continue
} }
if file_ast.path == d.filename { if file_ast.path == d.filename {
d.checker.check(file_ast) d.checker.check(mut file_ast)
d.scoped_contents = d.file_ast_with_pos(file_ast, d.pos) d.scoped_contents = d.file_ast_with_pos(file_ast, d.pos)
} }
contents := d.file_ast(file_ast) contents := d.file_ast(file_ast)

View File

@ -76,9 +76,9 @@ x := 10
' '
table := ast.new_table() table := ast.new_table()
vpref := &pref.Preferences{} vpref := &pref.Preferences{}
prog := parse_file(s, table, .skip_comments, vpref) mut prog := parse_file(s, table, .skip_comments, vpref)
mut checker_ := checker.new_checker(table, vpref) mut checker_ := checker.new_checker(table, vpref)
checker_.check(prog) checker_.check(mut prog)
res, _, _, _ := c.gen([prog], table, vpref) res, _, _, _ := c.gen([prog], table, vpref)
println(res) println(res)
} }
@ -100,13 +100,13 @@ fn test_one() {
for line in input { for line in input {
e << parse_stmt(line, table, scope) e << parse_stmt(line, table, scope)
} }
program := &ast.File{ mut program := &ast.File{
stmts: e stmts: e
scope: scope scope: scope
global_scope: scope global_scope: scope
} }
mut checker_ := checker.new_checker(table, vpref) mut checker_ := checker.new_checker(table, vpref)
checker_.check(program) checker_.check(mut program)
mut res, _, _, _ := c.gen([program], table, vpref) mut res, _, _, _ := c.gen([program], table, vpref)
res = res.replace('\n', '').trim_space().after('#endif') res = res.replace('\n', '').trim_space().after('#endif')
println(res) println(res)
@ -143,12 +143,12 @@ fn test_parse_expr() {
println('\n\nst="${s}"') println('\n\nst="${s}"')
e << parse_stmt(s, table, scope) e << parse_stmt(s, table, scope)
} }
program := &ast.File{ mut program := &ast.File{
stmts: e stmts: e
scope: scope scope: scope
global_scope: scope global_scope: scope
} }
chk.check(program) chk.check(mut program)
mut res, _, _, _ := c.gen([program], table, vpref) mut res, _, _, _ := c.gen([program], table, vpref)
res = res.after('#endif') res = res.after('#endif')
println('========') println('========')