@@ -71,21 +71,21 @@ fn main() {
7171 }
7272 file_path = file_path[project_folder.len + 1 ..] // will remove the / too
7373 }
74- path := '${tmp_folder }/${file_path }'
74+ full_file_path := '${tmp_folder }/${file_path }'
7575 if command == default_command {
76- command = '${default_command } ${path }'
76+ command = '${default_command } ${full_file_path }'
7777 } else {
7878 command = command.replace ('PATH' , '${tmp_folder }/' )
7979 }
8080
8181 // start tests
8282 tmp_code := create_code (parse (content))
83- warn_on_false (string_reproduces (tmp_code, error_msg, command, path , true , timeout) ,
84- 'string_reproduces' , @LOCATION)
83+ warn_on_false (string_reproduces (tmp_code, error_msg, command, full_file_path , true ,
84+ timeout), 'string_reproduces' , @LOCATION)
8585 show_code_stats (tmp_code, label: 'Code size without comments' )
8686
8787 // reduce the code
88- reduce_scope (content, error_msg, command, do_fmt, path , timeout)
88+ reduce_scope (content, error_msg, command, do_fmt, full_file_path , timeout)
8989
9090 // cleanse
9191 if os.exists (tmp_folder) {
@@ -94,11 +94,11 @@ fn main() {
9494}
9595
9696// Return true if the command ran on the file produces the pattern
97- fn string_reproduces (file_content string , pattern string , command string , dir string , debug bool , timeout int ) bool {
97+ fn string_reproduces (file_content string , pattern string , command string , file_path string , debug bool , timeout int ) bool {
9898 if ! os.exists (tmp_folder) {
9999 os.mkdir (tmp_folder) or { panic (err) }
100100 }
101- os.write_file (dir , file_content) or { panic (err) }
101+ os.write_file (file_path , file_content) or { panic (err) }
102102 mut output := ''
103103 if timeout == 0 {
104104 res := os.execute (command)
@@ -165,24 +165,24 @@ mut:
165165}
166166
167167// Parse a V file and create a scope tree to represent it
168- fn parse (file string ) Scope { // The parser is surely incomplete for the V syntax, but should work for most of the cases, if not, please open an issue or submit a PR
168+ fn parse (file_content string ) Scope { // The parser is surely incomplete for the V syntax, but should work for most of the cases, if not, please open an issue or submit a PR
169169 mut stack := []& Scope{} // add the last parent to the stack
170170 stack << & Scope{}
171171 mut top := stack[0 ] // stores stack[stack.len-1] (the element on the top of the stack)
172- mut scope_level := 0 // Counts the scope depth of the current position in the file
173- mut i := 0 // index of the current char in the file
172+ mut scope_level := 0 // Counts the scope depth of the current position in the file_content
173+ mut i := 0 // index of the current char in the file_content
174174 mut current_string := ''
175- for i < file .len {
175+ for i < file_content .len {
176176 top = stack[stack.len - 1 ] // the element on the top of the stack
177- if file [i] == `/` && file [i + 1 ] == `/` {
178- for file [i] != `\n ` { // comment -> skip until newline
177+ if file_content [i] == `/` && file_content [i + 1 ] == `/` {
178+ for file_content [i] != `\n ` { // comment -> skip until newline
179179 i++
180180 }
181- } else if file [i] == `\n ` && file [i - 1 ] == `\n ` {
181+ } else if file_content [i] == `\n ` && file_content [i - 1 ] == `\n ` {
182182 i++ // remove excess newlines
183- } else if file [i] == `\t ` {
183+ } else if file_content [i] == `\t ` {
184184 i++ // remove tabs for easier processing
185- } else if file [i] == `f` && file [i + 1 ] == `n` && file [i + 2 ] == ` ` && file [i - 1 ] or {
185+ } else if file_content [i] == `f` && file_content [i + 1 ] == `n` && file_content [i + 2 ] == ` ` && file_content [i - 1 ] or {
186186 `\n `
187187 } == `\n ` {
188188 top.children << current_string
@@ -192,54 +192,57 @@ fn parse(file string) Scope { // The parser is surely incomplete for the V synta
192192 fn_scope: true
193193 }
194194 stack << & (top.children[top.children.len - 1 ] as Scope )
195- current_string + = file [i].ascii_str () // f
195+ current_string + = file_content [i].ascii_str () // f
196196 i++
197- current_string + = file [i].ascii_str () // n
197+ current_string + = file_content [i].ascii_str () // n
198198 i++
199- } else if file [i] == `/` && file [i + 1 ] == `*` {
199+ } else if file_content [i] == `/` && file_content [i + 1 ] == `*` {
200200 i++
201201 i++
202202 i++
203- for ! (file [i - 1 ] == `*` && file [i] == `/` ) { // multiline comment -> skip next multiline end sequence
203+ for ! (file_content [i - 1 ] == `*` && file_content [i] == `/` ) { // multiline comment -> skip next multiline end sequence
204204 i++
205205 }
206206 i++
207- } else if file [i] == `\` ` && file [i - 1 ] != `\\ ` {
208- current_string + = file [i].ascii_str ()
207+ } else if file_content [i] == `\` ` && file_content [i - 1 ] != `\\ ` {
208+ current_string + = file_content [i].ascii_str ()
209209 i++
210- for file[i] != `\` ` || (file[i - 1 ] == `\\ ` && file[i - 2 ] != `\\ ` ) { // string -> skip until next `
211- current_string + = file[i].ascii_str ()
210+ for file_content[i] != `\` `
211+ || (file_content[i - 1 ] == `\\ ` && file_content[i - 2 ] != `\\ ` ) { // string -> skip until next `
212+ current_string + = file_content[i].ascii_str ()
212213 i++
213214 }
214- current_string + = file [i].ascii_str () // `
215+ current_string + = file_content [i].ascii_str () // `
215216 i++
216- } else if file [i] == `'` {
217- current_string + = file [i].ascii_str () // '
217+ } else if file_content [i] == `'` {
218+ current_string + = file_content [i].ascii_str () // '
218219 i++
219- for file[i] != `'` || (file[i - 1 ] == `\\ ` && file[i - 2 ] != `\\ ` ) { // string -> skip until next '
220- current_string + = file[i].ascii_str ()
220+ for file_content[i] != `'`
221+ || (file_content[i - 1 ] == `\\ ` && file_content[i - 2 ] != `\\ ` ) { // string -> skip until next '
222+ current_string + = file_content[i].ascii_str ()
221223 i++
222224 }
223- current_string + = file [i].ascii_str () // '
225+ current_string + = file_content [i].ascii_str () // '
224226 i++
225- } else if file [i] == `"` {
226- current_string + = file [i].ascii_str () // "
227+ } else if file_content [i] == `"` {
228+ current_string + = file_content [i].ascii_str () // "
227229 i++
228- for file[i] != `"` || (file[i - 1 ] == `\\ ` && file[i - 2 ] != `\\ ` ) { // string -> skip until next "
229- current_string + = file[i].ascii_str ()
230+ for file_content[i] != `"`
231+ || (file_content[i - 1 ] == `\\ ` && file_content[i - 2 ] != `\\ ` ) { // string -> skip until next "
232+ current_string + = file_content[i].ascii_str ()
230233 i++
231234 }
232- current_string + = file [i].ascii_str () // "
235+ current_string + = file_content [i].ascii_str () // "
233236 i++
234- } else if file [i] == `{` {
235- current_string + = file [i].ascii_str ()
237+ } else if file_content [i] == `{` {
238+ current_string + = file_content [i].ascii_str ()
236239 i++
237240 top.children << current_string
238241 scope_level + = 1
239242 current_string = ''
240243 top.children << & Scope{}
241244 stack << & (top.children[top.children.len - 1 ] as Scope )
242- } else if file [i] == `}` {
245+ } else if file_content [i] == `}` {
243246 scope_level - = 1
244247 assert scope_level > = 0 , 'The scopes are not well detected ${stack [0 ]}'
245248 if current_string != '' {
@@ -251,7 +254,7 @@ fn parse(file string) Scope { // The parser is surely incomplete for the V synta
251254 stack.pop ()
252255 top = stack[stack.len - 1 ]
253256 current_string = ''
254- current_string + = file [i].ascii_str () // }
257+ current_string + = file_content [i].ascii_str () // }
255258 i++
256259 if scope_level == 0 && stack.len == 2 { // the function and the body scope
257260 top.children << current_string
@@ -260,7 +263,7 @@ fn parse(file string) Scope { // The parser is surely incomplete for the V synta
260263 current_string = ''
261264 }
262265 } else {
263- current_string + = file [i].ascii_str ()
266+ current_string + = file_content [i].ascii_str ()
264267 i++
265268 }
266269 // nothing here: to avoid complexity, no need to predict what happened before in the ifs, everything will be handled properly by the ifs
@@ -296,7 +299,7 @@ fn create_code(sc Scope) string {
296299}
297300
298301// Reduces the code contained in the scope tree and writes the reduced code to `rpdc_file_name.v`
299- fn reduce_scope (content string , error_msg string , command string , do_fmt bool , path string , timeout int ) {
302+ fn reduce_scope (content string , error_msg string , command string , do_fmt bool , file_path string , timeout int ) {
300303 mut sc := parse ('' ) // will get filled in the start of the loop
301304 log.info ('Cleaning the scopes' )
302305 mut text_code := content
@@ -322,7 +325,9 @@ fn reduce_scope(content string, error_msg string, command string, do_fmt bool, p
322325 item.tmp_ignored = true // try to ignore it
323326 code := create_code (sc)
324327 item.tmp_ignored = false // dont need it anymore
325- if string_reproduces (code, error_msg, command, path, false , timeout) {
328+ if string_reproduces (code, error_msg, command, file_path, false ,
329+ timeout)
330+ {
326331 item.ignored = true
327332 modified_smth = true
328333 outer_modified_smth = true
@@ -371,7 +376,7 @@ fn reduce_scope(content string, error_msg string, command string, do_fmt bool, p
371376
372377 // Traverse the tree and prune the useless lines / line groups for the reproduction
373378 mut line_tree := * line_stack[0 ]
374- warn_on_false (string_reproduces (create_code (line_tree), error_msg, command, path ,
379+ warn_on_false (string_reproduces (create_code (line_tree), error_msg, command, file_path ,
375380 true , timeout), 'string_reproduces' , @LOCATION) // should be the same
376381 log.info ('Pruning the lines/line groups' )
377382 modified_smth = true
@@ -392,7 +397,9 @@ fn reduce_scope(content string, error_msg string, command string, do_fmt bool, p
392397 item.tmp_ignored = true
393398 code := create_code (line_tree)
394399 item.tmp_ignored = false // dont need it anymore
395- if string_reproduces (code, error_msg, command, path, false , timeout) {
400+ if string_reproduces (code, error_msg, command, file_path, false ,
401+ timeout)
402+ {
396403 item.ignored = true
397404 modified_smth = true
398405 outer_modified_smth = true
@@ -411,9 +418,9 @@ fn reduce_scope(content string, error_msg string, command string, do_fmt bool, p
411418 text_code = create_code (line_tree)
412419 }
413420
414- warn_on_false (string_reproduces (text_code, error_msg, command, path , true , timeout),
421+ warn_on_false (string_reproduces (text_code, error_msg, command, file_path , true , timeout),
415422 'string_reproduces' , @LOCATION)
416- rpdc_file_path := 'rpdc_${os .file_name (path )#[..- 2 ]}.v'
423+ rpdc_file_path := 'rpdc_${os .file_name (file_path )#[..- 2 ]}.v'
417424 os.write_file (rpdc_file_path, text_code) or { panic (err) }
418425 if do_fmt {
419426 os.execute ('v fmt -w ${rpdc_file_path }' )
0 commit comments