Removing @optional support

This commit is contained in:
Pavel Shevaev 2023-07-26 13:09:50 +03:00
parent 49ae517e9b
commit 56ae2f6620
3 changed files with 6 additions and 20 deletions

View File

@ -47,7 +47,6 @@ function supported_tokens()
'alias',
'default',
'optional',
'virtual',
'statist',
@ -218,16 +217,6 @@ function addTwigFunctions(\Twig\Environment $twig)
'get_all_fields',
fn(mtgMetaStruct $s): array => \mtg_get_all_fields($s),
));
$twig->addFunction(new TwigFunction(
'count_optional',
function($os) {
$opts = 0;
foreach($os as $o)
if($o->hasToken('optional'))
++$opts;
return $opts;
}
));
$twig->addFunction(new TwigFunction(
'arr_fill',
fn($value, int $count): array => array_fill(0, $count, $value)
@ -520,8 +509,6 @@ function buf2var($name, $fname, mtgType $type, $buf, array $tokens = array(), $i
$offset = "\n ";
$str .= "/*[]{$name}*/";
$str .= $offset . _read_op($tokens, "{$buf}.BeginContainer(\"$name\")");
//we don't want to propagate 'optionalness' below
unset($tokens['optional']);
$str .= $offset . "_{$name}_size, err := {$buf}.GetContainerSize()";
$str .= $offset . "if err != nil { return err }";
@ -585,7 +572,7 @@ function _write_op($op)
function _read_op(array $tokens, $op)
{
return "if err := $op; err != nil { return " . (array_key_exists("optional", $tokens) ? "/*optional*/nil" : "err"). " }";
return "if err := $op; err != nil { return err }";
}
function rpc_invert($name)

View File

@ -190,8 +190,8 @@ self.fieldsMask = meta.FieldsMask{}
return err
}
if _cont_size < {{(o.fields|length) - count_optional(o.fields)}} {
_cont_size = {{(o.fields|length) - count_optional(o.fields)}}
if _cont_size < {{(o.fields|length)}} {
_cont_size = {{(o.fields|length)}}
}
{%- if o.parent ~%}

View File

@ -598,7 +598,6 @@ func (s *{{ name|default(o.name) }}) Reset() {
{% macro meta_read(s, name) %}
{% set fields_len = s.fields|length %}
{% set opt_fields_len = count_optional(s.fields) %}
func (s *{{ name|default(s.name) }}) Read(reader meta.Reader) error {
if err := reader.BeginContainer(""); err != nil {
@ -626,8 +625,8 @@ func (s *{{ name|default(s.name) }}) ReadFields(reader meta.Reader) error {
return err
}
if contSize < {{ fields_len - opt_fields_len }} {
contSize = {{ fields_len - opt_fields_len }}
if contSize < {{ fields_len }} {
contSize = {{ fields_len }}
}
{% if s.parent %}
@ -1069,4 +1068,4 @@ func (s *{{ name|default(s.name) }}) readFieldsAssociative(reader meta.Reader) e
return nil
}
{% endmacro meta_read_assoc %}
{% endmacro meta_read_assoc %}