From e303ba80bc7fb19284f027ecdb23bf375b6d3b13 Mon Sep 17 00:00:00 2001 From: Oskari Lemmela Date: Mon, 11 Oct 2021 22:14:32 +0300 Subject: [PATCH] uqmi: update code generator Add support for common-refs and double arrays. Fix error message line and type parsing. Signed-off-by: Oskari Lemmela --- data/gen-code.pl | 11 +++++++++-- data/gen-common.pm | 10 ++++++++++ data/gen-error-list.pl | 2 +- data/gen-header.pl | 5 ++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/data/gen-code.pl b/data/gen-code.pl index f45d28a..4d53471 100755 --- a/data/gen-code.pl +++ b/data/gen-code.pl @@ -75,10 +75,15 @@ sub gen_tlv_parse_field($$$$) { $size = $tlv_get{$prefix}; die "Unknown size element type '$prefix'" if not defined $size; + my $curvar = "$var\_n"; + if (rindex($var,"]") == length($var)-1) { + $curvar = substr($var, 0, index($var, "["))."\_i"; + $data .= $indent."$curvar = 0;\n"; + } ($var_data, $var_iterator) = - gen_tlv_parse_field($var."[$var\_n]", $elem->{"array-element"}, $n_indent + 1, "i$iterator"); + gen_tlv_parse_field($var."[$curvar]", $elem->{"array-element"}, $n_indent + 1, "i$iterator"); - $var_data .= $indent."\t$var\_n++;\n"; + $var_data .= $indent."\t$curvar++;\n"; $data .= $indent."$iterator = $size;\n"; $data .= $indent."$var = __qmi_alloc_static($iterator * sizeof($var\[0]));\n"; $data .= $indent."while($iterator\-- > 0) {\n"; @@ -215,6 +220,7 @@ EOF switch(tlv->type) { EOF foreach my $field (@$data) { + $field = gen_common_ref($field); my $cname = gen_cname($field->{name}); gen_tlv_type($cname, $field, $i++); } @@ -414,6 +420,7 @@ sub gen_set_func($$) EOF foreach my $field (@$fields) { + $field = gen_common_ref($field); my $cname = gen_cname($field->{name}); gen_tlv_attr_set($cname, $field); } diff --git a/data/gen-common.pm b/data/gen-common.pm index 6c3492f..e951776 100644 --- a/data/gen-common.pm +++ b/data/gen-common.pm @@ -17,6 +17,7 @@ our %tlv_types = ( gfloat => "float", gboolean => "bool", ); +our %common_ref = (); $prefix eq 'ctl_' and $ctl = 1; @@ -38,6 +39,7 @@ sub gen_has_types($) { my $data = shift; foreach my $field (@$data) { + $field = gen_common_ref($field); my $type = $field->{"format"}; $type and return 1; } @@ -68,6 +70,12 @@ sub gen_tlv_parse_func($$) { } } +sub gen_common_ref($$) { + my $field = shift; + $field = $common_ref{$field->{'common-ref'}} if $field->{'common-ref'} ne ''; + return $field; +} + sub gen_foreach_message_type($$$) { my $data = shift; @@ -78,6 +86,8 @@ sub gen_foreach_message_type($$$) my $args = []; my $fields = []; + $common_ref{$entry->{'common-ref'}} = $entry if $entry->{'common-ref'} ne ''; + next if $entry->{type} ne 'Message'; next if not defined $entry->{input} and not defined $entry->{output}; diff --git a/data/gen-error-list.pl b/data/gen-error-list.pl index 770c162..40204da 100755 --- a/data/gen-error-list.pl +++ b/data/gen-error-list.pl @@ -22,7 +22,7 @@ while ($line = <>) { }; undef $doc_start; - $line =~ /^\s*\*\s*@(.+): (.+)\./ and push @errors, [ $1, $2 ]; + $line =~ /^.*@([A-Z0-9_]+): ([A-z0-9 ]+)[.].*$/ and push @errors, [ $1, $2 ]; } @errors > 0 or die "No data found\n"; diff --git a/data/gen-header.pl b/data/gen-header.pl index 818adf1..45edb85 100755 --- a/data/gen-header.pl +++ b/data/gen-header.pl @@ -35,7 +35,7 @@ sub gen_tlv_type($$$) { if ($tlv_types{$ptype}) { return $indent.$tlv_types{$ptype}." $cname;"; } elsif ($tlv_types{$type}) { - return $indent."$ptype $cname;"; + return $indent.$tlv_types{$type}." $cname;"; } elsif ($type eq "string") { return $indent."char *$cname;", 1; } elsif ($type eq "array") { @@ -45,12 +45,14 @@ sub gen_tlv_type($$$) { } my ($type, $no_set_field) = gen_tlv_type("*$cname", $elem->{"array-element"}, $indent); return undef if not defined $type; + return $indent."unsigned int ".substr($cname,1)."\_i;$type", 1 if (!rindex($cname,"*",0)); return $indent."unsigned int $cname\_n;$type", 1; } elsif ($type eq "sequence" or $type eq "struct") { my $contents = $elem->{"contents"}; my $data = "struct {"; foreach my $field (@$contents) { + $field = gen_common_ref($field); my $_cname = gen_cname($field->{name}); my ($_data, $no_set_field) = gen_tlv_type($_cname, $field, "$indent\t"); $data .= $_data; @@ -68,6 +70,7 @@ sub gen_tlv_struct($$) { my $_data = ""; foreach my $field (@$data) { + $field = gen_common_ref($field); my $cname = gen_cname($field->{name}); my ($data, $no_set_field) = gen_tlv_type($cname, $field, "\n\t\t"); -- 2.30.2