From ed85853be4d461c3f6281b786475c82545df1eff Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Thu, 8 Dec 2022 19:21:43 +0300 Subject: [PATCH] Using newer metagen API --- src/codegen.inc.php | 2 +- tpl/macro.twig | 44 ++++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 058cb30..03416b3 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -84,7 +84,7 @@ function _add_twig_support(\Twig\Environment $twig) $twig->addFunction(new \Twig\TwigFunction('get_all_fields', function($meta, $o) { - return \mtg_get_all_fields($meta, $o); + return \mtg_get_all_fields($o); } )); $twig->addFunction(new \Twig\TwigFunction('count_optional', diff --git a/tpl/macro.twig b/tpl/macro.twig index d9a3f0d..2ead37b 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -1,16 +1,16 @@ {% macro decl_units(meta) %} {%- for u in meta.getunits ~%} {%- if u.object is instanceof('\\mtgMetaStruct') ~%} - {{ _self.decl_struct(meta, u.object) }} + {{ _self.decl_struct(u.object) }} {%- elseif u.object is instanceof('\\mtgMetaEnum') ~%} {{ _self.decl_enum(u.object) }} {%- elseif u.object is instanceof('\\mtgMetaRPC') ~%} - {{ _self.decl_rpc(meta, u.object) }} + {{ _self.decl_rpc(u.object) }} {%- endif ~%} {%- endfor ~%} {% endmacro %} -{% macro decl_struct(meta, o) %} +{% macro decl_struct(o) %} {%- if o.parent and has_token(o, 'POD') -%} {{Error("@POD structs can't have a parent: " ~ o.name)}} {%- endif -%} @@ -28,8 +28,8 @@ type {{o.name}} struct { } var _{{o.name}}_class_props map[string]string = {{_self.props_map(o.tokens)}} -var _{{o.name}}_class_fields []string = {{_self.struct_fields_names(meta, o)}} -var _{{o.name}}_fields_props meta.ClassFieldsProps = {{_self.struct_fields_props(meta, o)}} +var _{{o.name}}_class_fields []string = {{_self.struct_fields_names(o)}} +var _{{o.name}}_fields_props meta.ClassFieldsProps = {{_self.struct_fields_props(o)}} func {{o.name}}_CLASS_ID() uint32 { return {{o.classid}} @@ -111,11 +111,11 @@ func (self *{{o.name}}) WriteFields(writer meta.Writer) error { {% endif %} {% if has_token(o, 'statist') %} -{{_self.stats_methods(meta, o)}} +{{_self.stats_methods(o)}} {% endif %} {% if has_token(o, 'POD') and has_token(o, 'id') and has_token(o, 'table') and has_token(o, 'owner') %} -{{_self.db_item_methods(meta, o)}} +{{_self.db_item_methods(o)}} {% endif %} {% endmacro %} @@ -128,17 +128,17 @@ map[string]string{ } {% endmacro %} -{% macro struct_fields_names(meta, o) %} +{% macro struct_fields_names(o) %} []string{ -{% for f in get_all_fields(meta, o) ~%} +{% for f in get_all_fields(o) ~%} "{{f.name}}", {%- endfor ~%} } {% endmacro %} -{% macro struct_fields_props(meta, o) %} +{% macro struct_fields_props(o) %} map[string]map[string]string{ -{% for f in get_all_fields(meta, o) ~%} +{% for f in get_all_fields(o) ~%} "{{f.name|ucfirst}}" : {{_self.props_map(f.tokens)}}, {%- endfor ~%} } @@ -256,7 +256,7 @@ func(self *{{o.name}}) GetMask() meta.FieldsMask { } {% endmacro %} -{% macro stats_methods(meta, o) %} +{% macro stats_methods(o) %} func (self *{{o.name}}) Table() string { return "{{token(o, 'statist')}}" @@ -264,7 +264,7 @@ func (self *{{o.name}}) Table() string { func (self * {{o.name}}) Columns() []string { return []string{ - {%- for f in get_all_fields(meta, o) ~%} + {%- for f in get_all_fields(o) ~%} {%- if not has_token(f, 'statist_skip') ~%} "{{token_or(f, 'statist_alias', f.name)}}", {%- endif ~%} @@ -274,7 +274,7 @@ func (self * {{o.name}}) Columns() []string { func (self *{{o.name}}) Values() []interface{} { return []interface{}{ - {%- for f in get_all_fields(meta, o) ~%} + {%- for f in get_all_fields(o) ~%} {%- if not has_token(f, 'statist_skip') ~%} self.{{f.name|ucfirst}}, {%- endif ~%} @@ -284,7 +284,7 @@ func (self *{{o.name}}) Values() []interface{} { {% endmacro %} -{% macro db_item_methods(meta, o) %} +{% macro db_item_methods(o) %} func (self *{{o.name}}) NewInstance() meta.IMetaDataItem { return New{{o.name}}() @@ -315,7 +315,7 @@ func (self *{{o.name}}) Import(data interface{}) { case {{o.name}}: { row := data.({{o.name}}) -{%- for f in get_all_fields(meta, o) ~%} +{%- for f in get_all_fields(o) ~%} self.{{f.name|ucfirst}} = row.{{f.name|ucfirst}} {%- endfor ~%} break @@ -326,7 +326,7 @@ func (self *{{o.name}}) Import(data interface{}) { } func (self *{{o.name}}) Export(data []interface{}) { -{%- for f in get_all_fields(meta, o) ~%} +{%- for f in get_all_fields(o) ~%} data[{{loop.index0}}] = self.{{f.name|ucfirst}} {%- endfor ~%} } @@ -390,10 +390,10 @@ func New{{o.name}}ByName(name string) ({{o.name}}, error) { {%- endfor ~%} {% endmacro %} -{% macro decl_rpc(meta, o) %} +{% macro decl_rpc(o) %} -{{_self._decl_rpc_part(meta, o.req, o.code)}} -{{_self._decl_rpc_part(meta, o.rsp, o.code)}} +{{_self._decl_rpc_part(o.req, o.code)}} +{{_self._decl_rpc_part(o.rsp, o.code)}} func New{{o.name}}() *{{o.name}} { rpc := {{o.name}}{} @@ -448,9 +448,9 @@ func (rpc *{{o.name}}) Execute(h interface{}) error{ {% endmacro %} -{% macro _decl_rpc_part(meta, o, code) %} +{% macro _decl_rpc_part(o, code) %} -{{_self.decl_struct(meta, o)}} +{{_self.decl_struct(o)}} var {{o.name}}_ func(interface{}, *{{o.name}}, *{{o.name|rpc_invert}}) error