From afd942a94b4d7bd92f7bb95c4acb41788ca7cd03 Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 26 Jun 2018 23:45:22 +0300 Subject: [PATCH] ruby: Support automatic array size from index-enum --- plugins/ruby/codegen.pl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/ruby/codegen.pl b/plugins/ruby/codegen.pl index 3f5ea4ffe..ad5f4b239 100755 --- a/plugins/ruby/codegen.pl +++ b/plugins/ruby/codegen.pl @@ -677,6 +677,21 @@ sub get_compound_align { return $al; } +sub get_container_count { + my ($field) = @_; + my $count = $field->getAttribute('count'); + if ($count) { + return $count; + } + my $enum = $field->getAttribute('index-enum'); + if ($enum) { + my $tag = $global_types{$enum}; + return $tag->getAttribute('last-value') + 1; + } + + return 0; +} + sub sizeof { my ($field) = @_; my $meta = $field->getAttribute('ld:meta'); @@ -692,7 +707,7 @@ sub sizeof { return $SIZEOF_PTR; } elsif ($meta eq 'static-array') { - my $count = $field->getAttribute('count'); + my $count = get_container_count($field); my $tg = $field->findnodes('child::ld:item')->[0]; return $count * sizeof($tg); @@ -1038,7 +1053,7 @@ sub render_item_pointer { sub render_item_staticarray { my ($item) = @_; - my $count = $item->getAttribute('count'); + my $count = get_container_count($item); my $tg = $item->findnodes('child::ld:item')->[0]; my $tglen = sizeof($tg) if $tg; my $indexenum = $item->getAttribute('index-enum');