mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
parser: multi-level pointers
This commit is contained in:
parent
de5b4f0497
commit
0ab09a57f7
5 changed files with 66 additions and 18 deletions
|
@ -1461,7 +1461,7 @@ fn (p mut Parser) get_struct_type(name_ string, is_c bool, is_ptr bool) string {
|
|||
return p.struct_init(name)
|
||||
}
|
||||
|
||||
fn (p mut Parser) get_var_type(name string, is_ptr bool, is_deref bool) string {
|
||||
fn (p mut Parser) get_var_type(name string, is_ptr bool, deref_nr int) string {
|
||||
v := p.find_var_check_new_var(name) or { return "" }
|
||||
if name == '_' {
|
||||
p.error('cannot use `_` as value')
|
||||
|
@ -1469,9 +1469,11 @@ fn (p mut Parser) get_var_type(name string, is_ptr bool, is_deref bool) string {
|
|||
if is_ptr {
|
||||
p.gen('&')
|
||||
}
|
||||
else if is_deref {
|
||||
p.gen('*')
|
||||
}
|
||||
else if deref_nr > 0 {
|
||||
for _ in 0..deref_nr {
|
||||
p.gen('*')
|
||||
}
|
||||
}
|
||||
if p.pref.autofree && v.typ == 'string' && v.is_arg &&
|
||||
p.assigned_type == 'string' {
|
||||
p.warn('setting moved ' + v.typ)
|
||||
|
@ -1479,7 +1481,7 @@ fn (p mut Parser) get_var_type(name string, is_ptr bool, is_deref bool) string {
|
|||
}
|
||||
mut typ := p.var_expr(v)
|
||||
// *var
|
||||
if is_deref {
|
||||
if deref_nr > 0 {
|
||||
/*
|
||||
if !p.inside_unsafe {
|
||||
p.error('dereferencing can only be done inside an `unsafe` block')
|
||||
|
@ -1489,8 +1491,11 @@ fn (p mut Parser) get_var_type(name string, is_ptr bool, is_deref bool) string {
|
|||
println('name="$name", t=$v.typ')
|
||||
p.error('dereferencing requires a pointer, but got `$typ`')
|
||||
}
|
||||
typ = typ.replace('ptr', '')// TODO
|
||||
typ = typ.replace('*', '')// TODO
|
||||
for _ in 0..deref_nr {
|
||||
typ = typ.replace_once('ptr', '')// TODO
|
||||
typ = typ.replace_once('*', '')// TODO
|
||||
}
|
||||
|
||||
}
|
||||
// &var
|
||||
else if is_ptr {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue