v2: as cast

This commit is contained in:
Alexander Medvednikov 2020-02-07 09:19:45 +01:00
parent bb60b3081f
commit f241945d70
5 changed files with 44 additions and 4 deletions

View file

@ -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(')')
}