From a3086a2ef3ffd57b3b7424fe5f39ca8f99f66f1e Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Tue, 30 Jun 2020 13:45:52 +1000 Subject: [PATCH] cgen: optimize generic struct name replacement (temp solution) --- vlib/v/gen/cgen.v | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 4ddd3d01c1..3e521af70a 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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 ) - name = name.replace('<', '_T_').replace('>', '').replace(',', '_') - if name.contains('_T_') { + // TODO: yuck + if name.contains('<') { + name = name.replace('<', '_T_').replace('>', '').replace(',', '_') g.typedefs.writeln('typedef struct $name $name;') } // TODO avoid buffer manip