ast: add str for ArrayInit (#8022)

pull/8101/head
zakuro 2021-01-14 10:21:19 +09:00 committed by GitHub
parent 0f2a770b9c
commit fdf5f5003b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -183,6 +183,23 @@ pub fn (lit &StringInterLiteral) get_fspec_braces(i int) (string, bool) {
// string representation of expr
pub fn (x Expr) str() string {
match x {
ArrayInit {
mut fields := []string{}
if x.has_len {
fields << 'len: $x.len_expr.str()'
}
if x.has_cap {
fields << 'cap: $x.cap_expr.str()'
}
if x.has_default {
fields << 'init: $x.default_expr.str()'
}
if fields.len > 0 {
return '[]T{${fields.join(', ')}}'
} else {
return x.exprs.str()
}
}
CTempVar {
return x.orig.str()
}