add some error checking to proxy template processor

debugging is a lot easier when the unconsumed (and therefore likely
mistyped) replacements are complained about.
This commit is contained in:
Oswald Buddenhagen 2020-12-17 22:03:06 +01:00
parent cd6f18fd2b
commit bf66f210bd
2 changed files with 27 additions and 22 deletions

View File

@ -134,7 +134,7 @@ static @type@proxy_@name@( store_t *gctx@decl_args@ )
//# END //# END
//# TEMPLATE REGULAR_VOID //# 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; 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 ); proxy_cmd_done( &cmd->gen );
} }
static void static @type@proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), void *aux )
proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), void *aux )
{ {
proxy_store_t *ctx = (proxy_store_t *)gctx; proxy_store_t *ctx = (proxy_store_t *)gctx;

View File

@ -144,6 +144,10 @@ for (@ptypes) {
$replace{'name'} = $cmd_name; $replace{'name'} = $cmd_name;
$replace{'type'} = $cmd_type; $replace{'type'} = $cmd_type;
$cmd_args =~ s/^store_t \*ctx// or die("Arguments '$cmd_args' don't start with 'store_t *ctx'\n"); $cmd_args =~ s/^store_t \*ctx// or die("Arguments '$cmd_args' don't start with 'store_t *ctx'\n");
if ($cmd_name =~ /^get_/) {
$template = "GETTER";
$replace{'fmt'} = type_to_format($cmd_type);
} else {
if ($cmd_type eq "void " && $cmd_args =~ s/, void \(\*cb\)\( (.*)void \*aux \), void \*aux$//) { if ($cmd_type eq "void " && $cmd_args =~ s/, void \(\*cb\)\( (.*)void \*aux \), void \*aux$//) {
my $cmd_cb_args = $1; my $cmd_cb_args = $1;
$replace{'decl_cb_args'} = $cmd_cb_args; $replace{'decl_cb_args'} = $cmd_cb_args;
@ -152,9 +156,6 @@ for (@ptypes) {
$replace{'print_pass_cb_args'} = make_args($cmd_print_cb_args); $replace{'print_pass_cb_args'} = make_args($cmd_print_cb_args);
$replace{'print_fmt_cb_args'} = make_format($cmd_print_cb_args); $replace{'print_fmt_cb_args'} = make_format($cmd_print_cb_args);
$template = "CALLBACK"; $template = "CALLBACK";
} elsif ($cmd_name =~ /^get_/) {
$template = "GETTER";
$replace{'fmt'} = type_to_format($cmd_type);
} elsif ($cmd_type eq "void ") { } elsif ($cmd_type eq "void ") {
$template = "REGULAR_VOID"; $template = "REGULAR_VOID";
} else { } else {
@ -164,14 +165,19 @@ for (@ptypes) {
$replace{'decl_args'} = $cmd_args; $replace{'decl_args'} = $cmd_args;
$replace{'print_pass_args'} = $replace{'pass_args'} = make_args($cmd_args); $replace{'print_pass_args'} = $replace{'pass_args'} = make_args($cmd_args);
$replace{'print_fmt_args'} = make_format($cmd_args); $replace{'print_fmt_args'} = make_format($cmd_args);
}
for (keys %defines) { for (keys %defines) {
$replace{$1} = $defines{$_} if (/^${cmd_name}_(.*)$/); $replace{$1} = delete $defines{$_} if (/^${cmd_name}_(.*)$/);
} }
my %used;
my $text = $templates{$template}; my $text = $templates{$template};
$text =~ s/^(\h*)\@(\w+)\@\n/indent($replace{$2} \/\/ "", $1)/smeg; $text =~ s/^(\h*)\@(\w+)\@\n/$used{$2} = 1; indent($replace{$2} \/\/ "", $1)/smeg;
$text =~ s/\@(\w+)\@/$replace{$1} \/\/ ""/eg; $text =~ s/\@(\w+)\@/$used{$1} = 1; $replace{$1} \/\/ ""/eg;
print $outh $text."\n"; 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"; print $outh "struct driver proxy_driver = {\n".join("", map { "\t$_,\n" } @cmd_table)."};\n";
close $outh; close $outh;