From bf66f210bd07030045564ff5050bbce5cf5e97e1 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 17 Dec 2020 22:03:06 +0100 Subject: [PATCH] add some error checking to proxy template processor debugging is a lot easier when the unconsumed (and therefore likely mistyped) replacements are complained about. --- src/drv_proxy.c | 5 ++--- src/drv_proxy_gen.pl | 44 +++++++++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/drv_proxy.c b/src/drv_proxy.c index 84597a3..cd04bbd 100644 --- a/src/drv_proxy.c +++ b/src/drv_proxy.c @@ -134,7 +134,7 @@ static @type@proxy_@name@( store_t *gctx@decl_args@ ) //# END //# TEMPLATE REGULAR_VOID -static void proxy_@name@( store_t *gctx@decl_args@ ) +static @type@proxy_@name@( store_t *gctx@decl_args@ ) { proxy_store_t *ctx = (proxy_store_t *)gctx; @@ -168,8 +168,7 @@ proxy_@name@_cb( @decl_cb_args@void *aux ) proxy_cmd_done( &cmd->gen ); } -static void -proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), void *aux ) +static @type@proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), void *aux ) { proxy_store_t *ctx = (proxy_store_t *)gctx; diff --git a/src/drv_proxy_gen.pl b/src/drv_proxy_gen.pl index 95e4ff5..8d41249 100755 --- a/src/drv_proxy_gen.pl +++ b/src/drv_proxy_gen.pl @@ -144,34 +144,40 @@ for (@ptypes) { $replace{'name'} = $cmd_name; $replace{'type'} = $cmd_type; $cmd_args =~ s/^store_t \*ctx// or die("Arguments '$cmd_args' don't start with 'store_t *ctx'\n"); - if ($cmd_type eq "void " && $cmd_args =~ s/, void \(\*cb\)\( (.*)void \*aux \), void \*aux$//) { - my $cmd_cb_args = $1; - $replace{'decl_cb_args'} = $cmd_cb_args; - $replace{'pass_cb_args'} = make_args($cmd_cb_args); - my $cmd_print_cb_args = $cmd_cb_args =~ s/(.*), $/, $1/r; - $replace{'print_pass_cb_args'} = make_args($cmd_print_cb_args); - $replace{'print_fmt_cb_args'} = make_format($cmd_print_cb_args); - $template = "CALLBACK"; - } elsif ($cmd_name =~ /^get_/) { + if ($cmd_name =~ /^get_/) { $template = "GETTER"; $replace{'fmt'} = type_to_format($cmd_type); - } elsif ($cmd_type eq "void ") { - $template = "REGULAR_VOID"; } else { - $template = "REGULAR"; - $replace{'fmt'} = type_to_format($cmd_type); + if ($cmd_type eq "void " && $cmd_args =~ s/, void \(\*cb\)\( (.*)void \*aux \), void \*aux$//) { + my $cmd_cb_args = $1; + $replace{'decl_cb_args'} = $cmd_cb_args; + $replace{'pass_cb_args'} = make_args($cmd_cb_args); + my $cmd_print_cb_args = $cmd_cb_args =~ s/(.*), $/, $1/r; + $replace{'print_pass_cb_args'} = make_args($cmd_print_cb_args); + $replace{'print_fmt_cb_args'} = make_format($cmd_print_cb_args); + $template = "CALLBACK"; + } elsif ($cmd_type eq "void ") { + $template = "REGULAR_VOID"; + } else { + $template = "REGULAR"; + $replace{'fmt'} = type_to_format($cmd_type); + } + $replace{'decl_args'} = $cmd_args; + $replace{'print_pass_args'} = $replace{'pass_args'} = make_args($cmd_args); + $replace{'print_fmt_args'} = make_format($cmd_args); } - $replace{'decl_args'} = $cmd_args; - $replace{'print_pass_args'} = $replace{'pass_args'} = make_args($cmd_args); - $replace{'print_fmt_args'} = make_format($cmd_args); for (keys %defines) { - $replace{$1} = $defines{$_} if (/^${cmd_name}_(.*)$/); + $replace{$1} = delete $defines{$_} if (/^${cmd_name}_(.*)$/); } + my %used; my $text = $templates{$template}; - $text =~ s/^(\h*)\@(\w+)\@\n/indent($replace{$2} \/\/ "", $1)/smeg; - $text =~ s/\@(\w+)\@/$replace{$1} \/\/ ""/eg; + $text =~ s/^(\h*)\@(\w+)\@\n/$used{$2} = 1; indent($replace{$2} \/\/ "", $1)/smeg; + $text =~ s/\@(\w+)\@/$used{$1} = 1; $replace{$1} \/\/ ""/eg; print $outh $text."\n"; + my @not_used = grep { !defined($used{$_}) } keys %replace; + die("Fatal: unconsumed replacements in $cmd_name: ".join(" ", @not_used)."\n") if (@not_used); } +die("Fatal: unconsumed DEFINEs: ".join(" ", keys %defines)."\n") if (%defines); print $outh "struct driver proxy_driver = {\n".join("", map { "\t$_,\n" } @cmd_table)."};\n"; close $outh;