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

cgen: optimize generic struct name replacement (temp solution)

This commit is contained in:
joe-conigliaro 2020-06-30 13:45:52 +10:00
parent 73da3c9e4c
commit a3086a2ef3

View File

@ -394,22 +394,21 @@ fn (g &Gen) cc_type(t table.Type) string {
sym := g.table.get_type_symbol(g.unwrap_generic(t))
mut styp := sym.name.replace('.', '__')
if sym.kind == .struct_ {
// TODO: maybe keep c name in info ( this is yuck )
info := sym.info as table.Struct
if info.generic_types.len > 0 {
mut sgts := '_T'
mut sgtyps := '_T'
for gt in info.generic_types {
gts := g.table.get_type_symbol(if gt.has_flag(.generic) {
g.unwrap_generic(gt)
} else {
gt
})
sgts += '_$gts.name'
sgtyps += '_$gts.name'
}
styp += sgts
styp += sgtyps
}
else {
// TODO: maybe keep c name in info ( this is yuck )
else if styp.contains('<') {
// TODO: yuck
styp = styp.replace('<', '_T_').replace('>', '').replace(',', '_')
}
}
@ -2842,9 +2841,9 @@ fn (mut g Gen) write_types(types []table.TypeSymbol) {
if info.generic_types.len > 0 {
continue
}
// TODO: maybe keep c name in info ( this is yuck )
// TODO: yuck
if name.contains('<') {
name = name.replace('<', '_T_').replace('>', '').replace(',', '_')
if name.contains('_T_') {
g.typedefs.writeln('typedef struct $name $name;')
}
// TODO avoid buffer manip