diff options
Diffstat (limited to 'source4/build/pidl/idl.yp')
-rw-r--r-- | source4/build/pidl/idl.yp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/source4/build/pidl/idl.yp b/source4/build/pidl/idl.yp index acf926dd40..0e505b81fb 100644 --- a/source4/build/pidl/idl.yp +++ b/source4/build/pidl/idl.yp @@ -306,6 +306,33 @@ optional_semicolon: use Parse::Pidl::Util; +##################################################################### +# traverse a perl data structure removing any empty arrays or +# hashes and any hash elements that map to undef +sub CleanData($) +{ + sub CleanData($); + my($v) = shift; + if (ref($v) eq "ARRAY") { + foreach my $i (0 .. $#{$v}) { + CleanData($v->[$i]); + if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) { + $v->[$i] = undef; + next; + } + } + # this removes any undefined elements from the array + @{$v} = grep { defined $_ } @{$v}; + } elsif (ref($v) eq "HASH") { + foreach my $x (keys %{$v}) { + CleanData($v->{$x}); + if (!defined $v->{$x}) { delete($v->{$x}); next; } + if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; } + } + } + return $v; +} + sub _Error { if (exists $_[0]->YYData->{ERRMSG}) { print $_[0]->YYData->{ERRMSG}; @@ -393,5 +420,5 @@ sub parse_idl($$) my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error ); - return Parse::Pidl::Util::CleanData($idl); + return CleanData($idl); } |