compiler: blank ident error fixes + other small cflag / parser fixes (#2418)

* merge master
* fix blank ident & add cflag error
* undo cflag changes
* fix gen_js
* undo gen_js changes
* fix
* fix
pull/2417/head^2
joe-conigliaro 2019-10-19 08:00:47 +11:00 committed by GitHub
parent c18578af6f
commit 28b24eeef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 14 deletions

View File

@ -93,7 +93,7 @@ fn (table mut Table) parse_cflag(cflag string, mod string) {
if flag[0] == `-` {
for f in allowed_flags {
i := 1+f.len
if i < flag.len && f == flag.substr(1,i) {
if i <= flag.len && f == flag.substr(1,i) {
name = flag.left(i).trim_space()
flag = flag.right(i).trim_space()
break
@ -137,6 +137,7 @@ fn (table mut Table) parse_cflag(cflag string, mod string) {
break
}
}
return
}
//TODO: implement msvc specific c_options_before_target and c_options_after_target ...

View File

@ -179,12 +179,14 @@ fn (p mut Parser) chash() {
// println('chsh() file=$p.file hash="$hash"')
p.next()
if hash.starts_with('flag ') {
mut flag := hash.right(5)
// expand `@VROOT` `@VMOD` to absolute path
flag = flag.replace('@VROOT', p.vroot)
flag = flag.replace('@VMOD', v_modules_path)
//p.log('adding flag "$flag"')
p.table.parse_cflag(flag, p.mod)
p.first_pass() {
mut flag := hash.right(5)
// expand `@VROOT` `@VMOD` to absolute path
flag = flag.replace('@VROOT', p.vroot)
flag = flag.replace('@VMOD', v_modules_path)
//p.log('adding flag "$flag"')
p.table.parse_cflag(flag, p.mod)
}
return
}
if hash.starts_with('include') {

View File

@ -92,14 +92,23 @@ fn (p mut Parser) gen_blank_identifier_assign() {
assign_error_tok_idx := p.token_idx
p.check_name()
p.check_space(.assign)
expr := p.lit
is_indexer := p.peek() == .lsbr
is_fn_call := p.peek() == .lpar || (p.peek() == .dot && p.tokens[p.token_idx+2].tok == .lpar)
if !is_indexer && !is_fn_call {
p.error_with_token_index('assigning `$expr` to `_` is redundant', assign_error_tok_idx)
mut expr := p.lit
mut is_fn_call := p.peek() == .lpar
if !is_fn_call {
mut i := p.token_idx+1
for (p.tokens[i].tok == .dot || p.tokens[i].tok == .name) &&
p.tokens[i].lit != '_' {
expr += if p.tokens[i].tok == .dot { '.' } else { p.tokens[i].lit }
i++
}
is_fn_call = p.tokens[i].tok == .lpar
}
pos := p.cgen.add_placeholder()
mut typ := p.bool_expression()
if !is_indexer && !is_fn_call {
p.error_with_token_index('assigning `$expr` to `_` is redundant', assign_error_tok_idx)
}
tmp := p.get_tmp()
// handle or
if p.tok == .key_orelse {

View File

@ -38,13 +38,22 @@ fn (p mut Parser) gen_blank_identifier_assign() {
assign_error_tok_idx := p.token_idx
p.check_name()
p.check_space(.assign)
expr := p.lit
is_indexer := p.peek() == .lsbr
is_fn_call := p.peek() == .lpar || (p.peek() == .dot && p.tokens[p.token_idx+2].tok == .lpar)
mut expr := p.lit
mut is_fn_call := p.peek() == .lpar
if !is_fn_call {
mut i := p.token_idx+1
for (p.tokens[i].tok == .dot || p.tokens[i].tok == .name) &&
p.tokens[i].lit != '_' {
expr += if p.tokens[i].tok == .dot { '.' } else { p.tokens[i].lit }
i++
}
is_fn_call = p.tokens[i].tok == .lpar
}
p.bool_expression()
if !is_indexer && !is_fn_call {
p.error_with_token_index('assigning `$expr` to `_` is redundant', assign_error_tok_idx)
}
p.bool_expression()
or_else := p.tok == .key_orelse
//tmp := p.get_tmp()
if or_else {