mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: add varg str method & varg / parser optimizations
This commit is contained in:

committed by
Alexander Medvednikov

parent
7b1993b1e4
commit
4120982da1
@ -331,7 +331,32 @@ fn (p mut Parser) gen_struct_str(typ Type) {
|
||||
p.v.vgen_buf.writeln(sb.str())
|
||||
// Need to manually add the definition to `fns` so that it stays
|
||||
// at the top of the file.
|
||||
// This function will get parsee by V after the main pass.
|
||||
// This function will get parsed by V after the main pass.
|
||||
p.cgen.fns << 'string ${typ.name}_str();'
|
||||
}
|
||||
|
||||
fn (p mut Parser) gen_varg_str(typ Type) {
|
||||
elm_type := typ.name[5..]
|
||||
elm_type2 := p.table.find_type(elm_type)
|
||||
is_array := elm_type.starts_with('array_')
|
||||
if is_array {
|
||||
p.gen_array_str(elm_type2)
|
||||
} else if elm_type2.cat == .struct_ {
|
||||
p.gen_struct_str(elm_type2)
|
||||
}
|
||||
p.v.vgen_buf.writeln('
|
||||
fn (a $typ.name) str() string {
|
||||
mut sb := strings.new_builder(a.len * 3)
|
||||
sb.write("[")
|
||||
for i, elm in a {
|
||||
sb.write(elm.str())
|
||||
if i < a.len - 1 {
|
||||
sb.write(", ")
|
||||
}
|
||||
}
|
||||
sb.write("]")
|
||||
return sb.str()
|
||||
}')
|
||||
p.cgen.fns << 'string ${typ.name}_str();'
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user