mirror of
https://github.com/vlang/v.git
synced 2025-09-16 07:52:32 +03:00
v2: as
cast
This commit is contained in:
parent
bb60b3081f
commit
f241945d70
5 changed files with 44 additions and 4 deletions
|
@ -84,6 +84,8 @@ fn (p mut Parser) bool_expression() string {
|
|||
if typ == cast_typ {
|
||||
p.warn('casting `$typ` to `$cast_typ` is not needed')
|
||||
}
|
||||
is_byteptr := typ == 'byte*' || typ == 'byteptr'
|
||||
is_bytearr := typ == 'array_byte'
|
||||
if typ in p.table.sum_types {
|
||||
T := p.table.find_type(cast_typ)
|
||||
if T.parent != typ {
|
||||
|
@ -104,7 +106,28 @@ exit(1);
|
|||
')
|
||||
*/
|
||||
|
||||
} else {
|
||||
} else if cast_typ == 'string' {
|
||||
if is_byteptr || is_bytearr {
|
||||
if p.tok == .comma {
|
||||
p.check(.comma)
|
||||
p.cgen.set_placeholder(start_ph, 'tos((byte *)')
|
||||
if is_bytearr {
|
||||
p.gen('.data')
|
||||
}
|
||||
p.gen(', ')
|
||||
p.check_types(p.expression(), 'int')
|
||||
}
|
||||
else {
|
||||
if is_bytearr {
|
||||
p.gen('.data')
|
||||
}
|
||||
p.cgen.set_placeholder(start_ph, '/*!!!*/tos2((byte *)')
|
||||
p.gen(')')
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
p.cgen.set_placeholder(start_ph, '($cast_typ)(')
|
||||
p.gen(')')
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue