Skip to content

Commit 144b57c

Browse files
authored
ast,token,scanner,parser,checker,cgen: add file_idx to token.Pos (#25490)
1 parent fb338d2 commit 144b57c

16 files changed

Lines changed: 114 additions & 83 deletions

File tree

‎cmd/tools/measure/fmt_speed.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn process_files(files []string) ! {
8989

9090
fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser {
9191
mut p := &parser.Parser{
92-
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
92+
scanner: scanner.new_scanner_file(path, -1, comments_mode, pref_) or { panic(err) }
9393
table: table
9494
pref: pref_
9595
scope: &ast.Scope{

‎cmd/tools/measure/parser_speed.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn process_files(files []string) ! {
8787

8888
fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser {
8989
mut p := &parser.Parser{
90-
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
90+
scanner: scanner.new_scanner_file(path, -1, comments_mode, pref_) or { panic(err) }
9191
table: table
9292
pref: pref_
9393
scope: &ast.Scope{

‎cmd/tools/measure/scanner_speed.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn process_files(files []string) ! {
5555
}
5656
total_files++
5757
sw.restart()
58-
s := scanner.new_scanner_file(f, comments_mode, pref_)!
58+
s := scanner.new_scanner_file(f, -1, comments_mode, pref_)!
5959
f_us := sw.elapsed().microseconds()
6060
total_us += f_us
6161
total_bytes += s.text.len

‎vlib/v/ast/ast.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2478,7 +2478,7 @@ pub fn (node Node) pos() token.Pos {
24782478
line_nr: -1
24792479
pos: -1
24802480
last_line: -1
2481-
col: -1
2481+
col: 0
24822482
}
24832483
}
24842484
}

‎vlib/v/ast/table.v‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub mut:
102102
new_int bool // use 64bit/32bit platform dependent `int`
103103
new_int_fmt_fix bool // vfmt will fix `int` to `i32`
104104
export_names map[string]string // @[export] names
105+
filelist []string // all files list
105106
}
106107

107108
pub struct ComptTimeCondResult {

‎vlib/v/checker/errors.v‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ fn (mut c Checker) add_error_detail(s string) {
1414
}
1515

1616
fn (mut c Checker) add_error_detail_with_pos(msg string, pos token.Pos) {
17-
c.add_error_detail(util.formatted_error('details:', msg, c.file.path, pos))
17+
file_path := if pos.file_idx < 0 { c.file.path } else { c.table.filelist[pos.file_idx] }
18+
c.add_error_detail(util.formatted_error('details:', msg, file_path, pos))
1819
}
1920

2021
fn (mut c Checker) add_instruction_for_option_type() {
@@ -90,13 +91,14 @@ fn (mut c Checker) note(message string, pos token.Pos) {
9091
c.error_details = []
9192
}
9293
// deduplicate notices for the same line
93-
kpos := '${c.file.path}:${pos.line_nr}:${message}'
94+
file_path := if pos.file_idx < 0 { c.file.path } else { c.table.filelist[pos.file_idx] }
95+
kpos := '${file_path}:${pos.line_nr}:${message}'
9496
if kpos !in c.notice_lines {
9597
c.notice_lines[kpos] = true
9698
note := errors.Notice{
9799
reporter: errors.Reporter.checker
98100
pos: pos
99-
file_path: c.file.path
101+
file_path: file_path
100102
message: message
101103
details: details
102104
}
@@ -122,20 +124,21 @@ fn (mut c Checker) warn_or_error(message string, pos token.Pos, warn bool) {
122124
details = c.error_details.join('\n')
123125
c.error_details = []
124126
}
127+
file_path := if pos.file_idx < 0 { c.file.path } else { c.table.filelist[pos.file_idx] }
125128
if warn && !c.pref.skip_warnings {
126129
c.nr_warnings++
127130
if c.pref.message_limit >= 0 && c.nr_warnings >= c.pref.message_limit {
128131
c.should_abort = true
129132
return
130133
}
131134
// deduplicate warnings for the same line
132-
kpos := '${c.file.path}:${pos.line_nr}:${message}'
135+
kpos := '${file_path}:${pos.line_nr}:${message}'
133136
if kpos !in c.warning_lines {
134137
c.warning_lines[kpos] = true
135138
wrn := errors.Warning{
136139
reporter: errors.Reporter.checker
137140
pos: pos
138-
file_path: c.file.path
141+
file_path: file_path
139142
message: message
140143
details: details
141144
}
@@ -148,7 +151,7 @@ fn (mut c Checker) warn_or_error(message string, pos token.Pos, warn bool) {
148151
if c.pref.fatal_errors {
149152
util.show_compiler_message('error:', errors.CompilerMessage{
150153
pos: pos
151-
file_path: c.file.path
154+
file_path: file_path
152155
message: message
153156
details: details
154157
})
@@ -160,13 +163,13 @@ fn (mut c Checker) warn_or_error(message string, pos token.Pos, warn bool) {
160163
return
161164
}
162165
// deduplicate errors for the same line
163-
kpos := '${c.file.path}:${pos.line_nr}:${message}'
166+
kpos := '${file_path}:${pos.line_nr}:${message}'
164167
if kpos !in c.error_lines {
165168
c.error_lines[kpos] = true
166169
err := errors.Error{
167170
reporter: errors.Reporter.checker
168171
pos: pos
169-
file_path: c.file.path
172+
file_path: file_path
170173
message: message
171174
details: details
172175
}

‎vlib/v/checker/str.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn (mut c Checker) string_lit(mut node ast.StringLiteral) ast.Type {
145145
`\\` {
146146
mut start_pos := token.Pos{
147147
...node.pos
148-
col: node.pos.col + 1 + idx
148+
col: u16(node.pos.col + 1 + idx)
149149
}
150150
start_idx := idx
151151
idx++

‎vlib/v/gen/c/cgen.v‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6609,7 +6609,8 @@ fn verror(s string) {
66096609

66106610
@[noreturn]
66116611
fn (g &Gen) error(s string, pos token.Pos) {
6612-
util.show_compiler_message('cgen error:', pos: pos, file_path: g.file.path, message: s)
6612+
file_path := if pos.file_idx < 0 { g.file.path } else { g.table.filelist[pos.file_idx] }
6613+
util.show_compiler_message('cgen error:', pos: pos, file_path: file_path, message: s)
66136614
exit(1)
66146615
}
66156616

‎vlib/v/parser/fn.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr {
6161
ok_arg_pos := (args[params.len - 1] or { args[0] }).pos
6262
pos := token.Pos{
6363
...ok_arg_pos
64-
col: ok_arg_pos.col + ok_arg_pos.len
64+
col: u16(ok_arg_pos.col + ok_arg_pos.len)
6565
}
6666
p.unexpected_with_pos(pos.extend(p.tok.pos()), expecting: '`)`')
6767
} else {

‎vlib/v/parser/messages.v‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,21 @@ fn (mut p Parser) note(s string) {
6868
fn (mut p Parser) error_with_pos(s string, pos token.Pos) ast.NodeError {
6969
// print_backtrace()
7070
mut kind := 'error:'
71+
file_path := if pos.file_idx < 0 { p.file_path } else { p.table.filelist[pos.file_idx] }
7172
if p.pref.fatal_errors {
72-
util.show_compiler_message(kind, pos: pos, file_path: p.file_path, message: s)
73+
util.show_compiler_message(kind, pos: pos, file_path: file_path, message: s)
7374
exit(1)
7475
}
7576
if p.pref.output_mode == .stdout && !p.pref.check_only && !p.is_vls {
7677
if p.pref.is_verbose {
7778
print_backtrace()
7879
kind = 'parser error:'
7980
}
80-
util.show_compiler_message(kind, pos: pos, file_path: p.file_path, message: s)
81+
util.show_compiler_message(kind, pos: pos, file_path: file_path, message: s)
8182
exit(1)
8283
} else {
8384
p.errors << errors.Error{
84-
file_path: p.file_path
85+
file_path: file_path
8586
pos: pos
8687
reporter: .parser
8788
message: s
@@ -145,15 +146,16 @@ fn (mut p Parser) warn_with_pos(s string, pos token.Pos) {
145146
if p.pref.skip_warnings {
146147
return
147148
}
149+
file_path := if pos.file_idx < 0 { p.file_path } else { p.table.filelist[pos.file_idx] }
148150
if p.pref.output_mode == .stdout && !p.pref.check_only {
149-
util.show_compiler_message('warning:', pos: pos, file_path: p.file_path, message: s)
151+
util.show_compiler_message('warning:', pos: pos, file_path: file_path, message: s)
150152
} else {
151153
if p.pref.message_limit >= 0 && p.warnings.len >= p.pref.message_limit {
152154
p.should_abort = true
153155
return
154156
}
155157
p.warnings << errors.Warning{
156-
file_path: p.file_path
158+
file_path: file_path
157159
pos: pos
158160
reporter: .parser
159161
message: s
@@ -175,11 +177,12 @@ fn (mut p Parser) note_with_pos(s string, pos token.Pos) {
175177
p.error_with_pos(s, pos)
176178
return
177179
}
180+
file_path := if pos.file_idx < 0 { p.file_path } else { p.table.filelist[pos.file_idx] }
178181
if p.pref.output_mode == .stdout && !p.pref.check_only {
179-
util.show_compiler_message('notice:', pos: pos, file_path: p.file_path, message: s)
182+
util.show_compiler_message('notice:', pos: pos, file_path: file_path, message: s)
180183
} else {
181184
p.notices << errors.Notice{
182-
file_path: p.file_path
185+
file_path: file_path
183186
pos: pos
184187
reporter: .parser
185188
message: s

0 commit comments

Comments
 (0)