From b96b3996baba9c3f6d019659dd43db4312d08a93 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Tue, 17 Dec 2024 22:27:09 +0300 Subject: [PATCH] A bit minimizing codegen output for types setup --- tpl/bhl_bind_macro.twig | 13 +------------ tpl/codegen_register.twig | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tpl/bhl_bind_macro.twig b/tpl/bhl_bind_macro.twig index 2fe0698..3345a9a 100644 --- a/tpl/bhl_bind_macro.twig +++ b/tpl/bhl_bind_macro.twig @@ -956,18 +956,7 @@ public partial class Script_{{u.object.name}} { //assign global static types {%- for u in units -%} {%- if u.object is instanceof('\\mtgMetaStruct') or u.object is instanceof('\\mtgMetaInterface') ~%} - { - var tmp = types.T("{{u.object.name}}").Get(); - if(tmp == null) - throw new System.Exception("Type '{{u.object.name}}' not resolved"); - {%- if u.object is instanceof('\\mtgMetaStruct') ~%} - (tmp as ClassSymbolNative)?.Setup(); - {%- endif ~%} - {%- if u.object is instanceof('\\mtgMetaInterface') ~%} - (tmp as InterfaceSymbolNative)?.Setup(); - {%- endif ~%} - Types_{{u.object.name|norm_name}}.Value = tmp; - } + Types_{{u.object.name|norm_name}}.Value = SetupType(types, "{{u.object.name}}"); {%- endif -%} {%- endfor -%} diff --git a/tpl/codegen_register.twig b/tpl/codegen_register.twig index 7054fdd..3a34d69 100644 --- a/tpl/codegen_register.twig +++ b/tpl/codegen_register.twig @@ -45,6 +45,20 @@ public static void RegisterBegin(Types types) {%~ endfor -%} } +static IType SetupType(Types types, string name) +{ + var tmp = types.T(name).Get(); + if(tmp == null) + throw new System.Exception("Type '" + name + "' not resolved"); + + if(tmp is ClassSymbolNative csn) + csn.Setup(); + else if(tmp is InterfaceSymbolNative isn) + isn.Setup(); + + return tmp; +} + public static void RegisterEnd(Types types) { {{ macro.setup_global_types(meta.units) }}