From eb85f634378e3bb2a037bd0cde9fd43296629583 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Tue, 17 Dec 2024 20:00:45 +0300 Subject: [PATCH] Splitting one huge output autobind file to many files presumed to be stored under non VCS directory --- src/bind.inc.php | 24 ++++++++++++++--- tpl/bhl_bind_macro.twig | 15 ----------- tpl/codegen_decl_units.twig | 26 +++++++++++++++++++ ...en_autobind.twig => codegen_register.twig} | 25 ++++-------------- tpl/codegen_register_slice.twig | 26 +++++++++++++++++++ tpl/codegen_types.twig | 24 +++++++++++++++++ 6 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 tpl/codegen_decl_units.twig rename tpl/{codegen_autobind.twig => codegen_register.twig} (62%) create mode 100644 tpl/codegen_register_slice.twig create mode 100644 tpl/codegen_types.twig diff --git a/src/bind.inc.php b/src/bind.inc.php index d76cbd2..47f31f9 100644 --- a/src/bind.inc.php +++ b/src/bind.inc.php @@ -29,7 +29,7 @@ function codegen( $tpl_cache_dir, \mtgMetaInfo $meta, array $options = array() -) +) : array { validate_meta($meta); @@ -57,14 +57,30 @@ function codegen( $twig->addGlobal('plugins', $options['plugins']); - $str = $twig->render('codegen_autobind.twig', $options); + $sliced_units = slice_units($meta->getUnits(), 20); + $options['sliced_units'] = $sliced_units; + + $output = array(); + + $output['types.cs'] = $twig->render('codegen_types.twig', $options); + $output['decl_units.cs'] = $twig->render('codegen_decl_units.twig', $options); + + foreach($sliced_units as $slice_idx => $slice_units) + { + $slice_options = $options; + $slice_options['slice_idx'] = $slice_idx; + $slice_options['slice_units'] = $slice_units; + $output['register_'.$slice_idx.'.cs'] = $twig->render('codegen_register_slice.twig', $slice_options); + } + + $output['register.cs'] = $twig->render('codegen_register.twig', $options); print_warnings(); - return $str; + return $output; } -function get_twig(array $inc_path = []) +function get_twig(array $inc_path = []) : \Twig\Environment { array_unshift($inc_path, __DIR__ . "/../tpl/"); $loader = new \Twig\Loader\FilesystemLoader($inc_path); diff --git a/tpl/bhl_bind_macro.twig b/tpl/bhl_bind_macro.twig index f5a2b3d..2fe0698 100644 --- a/tpl/bhl_bind_macro.twig +++ b/tpl/bhl_bind_macro.twig @@ -917,21 +917,6 @@ public partial class Script_{{u.object.name}} { {%- endmacro -%} -{%- macro call_reg_units(sliced_units) ~%} - {%- for idx,units in sliced_units -%} - Register_{{idx}}(types); - {%~ endfor -%} -{%- endmacro -%} - -{%- macro decl_reg_units(sliced_units) ~%} - {%- for idx,units in sliced_units -%} - public static void Register_{{idx}}(Types types) - { - {{ _self.reg_units(units) }} - } - {%~ endfor -%} -{%- endmacro -%} - {%- macro reg_units(units) ~%} {%- for u in units -%} diff --git a/tpl/codegen_decl_units.twig b/tpl/codegen_decl_units.twig new file mode 100644 index 0000000..2292cf4 --- /dev/null +++ b/tpl/codegen_decl_units.twig @@ -0,0 +1,26 @@ +#pragma warning disable CS0162 + +using System; +using System.Collections; +using System.Collections.Generic; +using bhl; +#if !BHL_FRONT +{%- for imp in imports ~%} +using {{imp}}; +{%- endfor ~%} +#endif +using Types = bhl.Types; + +{% import "bhl_bind_macro.twig" as macro %} + +namespace {{namespace}} { + +#if !BHL_FRONT + +{{ macro.decl_units(meta.units) }} + +{{ plugins_codegen_decls() }} + +#endif + +} diff --git a/tpl/codegen_autobind.twig b/tpl/codegen_register.twig similarity index 62% rename from tpl/codegen_autobind.twig rename to tpl/codegen_register.twig index 9c400cb..7054fdd 100644 --- a/tpl/codegen_autobind.twig +++ b/tpl/codegen_register.twig @@ -9,6 +9,7 @@ using bhl; using {{imp}}; {%- endfor ~%} #endif +using Types = bhl.Types; {{custom_code}} @@ -16,23 +17,7 @@ using {{imp}}; namespace {{namespace}} { -{%- for u in meta.units ~%} - {%- if u.object is instanceof('\\mtgMetaStruct') or u.object is instanceof('\\mtgMetaInterface') ~%} -static public class Types_{{u.object.name|norm_name}} { - static public IType Value; -} - {%- endif ~%} -{%- endfor ~%} - -#if !BHL_FRONT - -{{ macro.decl_units(meta.units) }} - -{{ plugins_codegen_decls() }} - -#endif - -static public class {{register_class}} { +static public partial class {{register_class}} { {%- for mk,mv in get_modules(meta) ~%} static public Module Module{{mv}}; @@ -55,7 +40,9 @@ public static void RegisterBegin(Types types) types.RegisterModule(Module{{mv}}); {%- endfor ~%} -{{ macro.call_reg_units(slice_units(meta.units, 20)) }} + {%- for idx,units in sliced_units -%} + Register_{{idx}}(types); + {%~ endfor -%} } public static void RegisterEnd(Types types) @@ -63,8 +50,6 @@ public static void RegisterEnd(Types types) {{ macro.setup_global_types(meta.units) }} } -{{ macro.decl_reg_units(slice_units(meta.units, 20)) }} - } } diff --git a/tpl/codegen_register_slice.twig b/tpl/codegen_register_slice.twig new file mode 100644 index 0000000..be1286e --- /dev/null +++ b/tpl/codegen_register_slice.twig @@ -0,0 +1,26 @@ +#pragma warning disable CS0162 + +using System; +using System.Collections; +using System.Collections.Generic; +using bhl; +#if !BHL_FRONT +{%- for imp in imports ~%} +using {{imp}}; +{%- endfor ~%} +#endif +using Types = bhl.Types; + +{% import "bhl_bind_macro.twig" as macro %} + +namespace {{namespace}} { + +static public partial class {{register_class}} { + + public static void Register_{{slice_idx}}(Types types) + { + {{ macro.reg_units(slice_units) }} + } +} + +} diff --git a/tpl/codegen_types.twig b/tpl/codegen_types.twig new file mode 100644 index 0000000..4a8ddd3 --- /dev/null +++ b/tpl/codegen_types.twig @@ -0,0 +1,24 @@ +#pragma warning disable CS0162 + +using System; +using System.Collections; +using System.Collections.Generic; +using bhl; +#if !BHL_FRONT +{%- for imp in imports ~%} +using {{imp}}; +{%- endfor ~%} +#endif +using Types = bhl.Types; + +namespace {{namespace}} { + +{%- for u in meta.units ~%} + {%- if u.object is instanceof('\\mtgMetaStruct') or u.object is instanceof('\\mtgMetaInterface') ~%} +static public class Types_{{u.object.name|norm_name}} { + static public IType Value; +} + {%- endif ~%} +{%- endfor ~%} + +}