Gradually adding support for all features

This commit is contained in:
Pavel Shevaev 2022-12-07 15:39:44 +03:00
parent f38eed25f3
commit 9fa57439db
2 changed files with 25 additions and 14 deletions

View File

@ -122,10 +122,10 @@ function _add_twig_support(\Twig\Environment $twig)
return is_primary_field($o, $f);
}
));
$twig->addFunction(new \Twig\TwigFunction('get_diff_class_units',
function($meta, $o)
$twig->addFunction(new \Twig\TwigFunction('get_diff_related_units',
function($o)
{
return get_diff_class_units($meta, $o);
return get_diff_related_units($o);
}
));
}
@ -440,7 +440,18 @@ function is_nullable_type(\mtgType $type)
($type instanceof \mtgMetaStruct && !$type->hasToken('POD'));
}
function get_diff_class_units(\mtgMetaInfo $meta, \mtgMetaStruct $struct)
function get_diff_units(\mtgMetaStruct $struct)
{
return [];
$result = array();
foreach($struct->getFields() as $field)
{
if($field->hasToken('nodiff'))
continue;
if($field->getType() instanceof mtgMetaStruct)
$result[] = $field->getType();
else if($field->getType() instanceof mtgArrType)
$result[] = $field->getType()->getValue();
}
return $result;
}

View File

@ -3,17 +3,17 @@
{%- 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, extra = '') %}
{% macro decl_struct(o, extra = '') %}
{%- if o.parent and has_token(o, 'POD') -%}
{{Error("@POD structs can't have a parent: " ~ o.name)}}
{%- endif -%}
@ -108,7 +108,7 @@ public {{_self.struct_type(o)}} {{o.name}} {{_self.base_struct_class(o)}}
{%- endif -%}
{%- if has_token(o, 'diffable') ~%}
{{_self.diffable_support(meta, o)}}
{{_self.diffable_support(o)}}
{%- endif -%}
{{extra}}
@ -293,10 +293,10 @@ public enum {{o.name}}
}
{% endmacro %}
{% macro decl_rpc(meta, o) %}
{% macro decl_rpc(o) %}
{{_self.decl_struct(meta, o.req)}}
{{_self.decl_struct(meta, o.rsp)}}
{{_self.decl_struct(o.req)}}
{{_self.decl_struct(o.rsp)}}
public class {{o.name}} : IRpc
{
@ -332,9 +332,9 @@ public class {{o.name}} : IRpc
{% endmacro %}
{%- macro diffable_support(meta, o) -%}
{%- macro diffable_support(o) -%}
{% for u in get_diff_class_units(meta, o) %}
{% for u in get_diff_related_units(o) %}
{{_self.diff_methods(u)}}
{% endfor %}