1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

clean up generic structs

This commit is contained in:
joe-conigliaro
2019-12-21 13:33:59 +11:00
committed by Alexander Medvednikov
parent ecd46d381c
commit f7c1b78ec2
3 changed files with 39 additions and 48 deletions

View File

@ -105,10 +105,10 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
kind := if is_union { 'union' } else { 'struct' }
p.gen_typedef('typedef $kind $name $name;')
}
// TODO: handle error
parser_idx := p.v.get_file_parser_index(p.file_path) or { 0 }
//if !p.scanner.is_vh {
// parser_idx = p.v.get_file_parser_index(p.file_path) or { panic('cant find parser idx for $p.file_path') }
// println('HERE: $parser_idx')
//}
// Register the type
mut is_ph := false
@ -145,17 +145,20 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
p.table.register_type(typ)
return
}
// generic template
if is_generic && !is_generic_instance {
p.table.register_type(typ)
p.table.generic_struct_params[typ.name] = generic_types.keys()
//}
// TODO: re are skipping genrcic struct in gen (cgen.v) we can go as normal and remove this
p.skip_block(false)
return
}
if is_generic_instance {
typ.rename_generic_struct(generic_types)
// generic struct
if is_generic {
// template
if !is_generic_instance {
p.table.register_type(typ)
p.table.generic_struct_params[typ.name] = generic_types.keys()
// NOTE: remove to store fields in generic struct template
p.skip_block(false)
return
}
// instance
else {
typ.rename_generic_struct(generic_types)
}
}
p.fspace()
p.check(.lcbr)