parser: show location of a previously defined function
parent
dd534fde57
commit
0d3f133436
|
@ -212,10 +212,8 @@ fn (b &Builder) print_warnings_and_errors() {
|
||||||
if b.checker.nr_errors > 0 {
|
if b.checker.nr_errors > 0 {
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.pref.is_verbose && b.checker.nr_warnings > 1 {
|
if b.pref.is_verbose && b.checker.nr_warnings > 1 {
|
||||||
println('$b.checker.nr_warnings warnings')
|
println('$b.checker.nr_warnings warnings')
|
||||||
}
|
}
|
||||||
|
@ -246,6 +244,24 @@ fn (b &Builder) print_warnings_and_errors() {
|
||||||
}
|
}
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
if b.table.redefined_fns.len > 0 {
|
||||||
|
for fn_name in b.table.redefined_fns {
|
||||||
|
eprintln('redefinition of function `$fn_name`')
|
||||||
|
// eprintln('previous declaration at')
|
||||||
|
// Find where this function was already declared
|
||||||
|
for file in b.parsed_files {
|
||||||
|
for stmt in file.stmts {
|
||||||
|
if stmt is ast.FnDecl {
|
||||||
|
f := stmt as ast.FnDecl
|
||||||
|
if f.name == fn_name {
|
||||||
|
println(file.path + ':' + f.pos.line_nr.str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verror(s string) {
|
fn verror(s string) {
|
||||||
|
|
|
@ -456,7 +456,8 @@ fn (mut p Parser) fn_redefinition_error(name string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
p.error('redefinition of function `$name`')
|
p.table.redefined_fns << name
|
||||||
|
// p.error('redefinition of function `$name`')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn have_fn_main(stmts []ast.Stmt) bool {
|
fn have_fn_main(stmts []ast.Stmt) bool {
|
||||||
|
|
|
@ -1044,7 +1044,11 @@ fn (mut p Parser) string_expr() ast.Expr {
|
||||||
node = ast.StringLiteral{
|
node = ast.StringLiteral{
|
||||||
val: val
|
val: val
|
||||||
is_raw: is_raw
|
is_raw: is_raw
|
||||||
language: if is_cstr { table.Language.c } else { table.Language.v }
|
language: if is_cstr {
|
||||||
|
table.Language.c
|
||||||
|
} else {
|
||||||
|
table.Language.v
|
||||||
|
}
|
||||||
pos: pos
|
pos: pos
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub mut:
|
||||||
imports []string // List of all imports
|
imports []string // List of all imports
|
||||||
modules []string // List of all modules registered by the application
|
modules []string // List of all modules registered by the application
|
||||||
cflags []cflag.CFlag
|
cflags []cflag.CFlag
|
||||||
|
redefined_fns []string
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Fn {
|
pub struct Fn {
|
||||||
|
|
Loading…
Reference in New Issue