From f46072d2232c76b8ec29ce7d76b81fe7bbb4bc26 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 19 Dec 2003 00:40:40 +0000 Subject: added code to the IDL validator to check for common errors with pointers are arrays (This used to be commit e67cbfff6c1041671711e4f73894e6e13151d57e) --- source4/build/pidl/util.pm | 13 +++++++++++-- source4/build/pidl/validator.pm | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/source4/build/pidl/util.pm b/source4/build/pidl/util.pm index b732c185b2..2a4c0de74d 100644 --- a/source4/build/pidl/util.pm +++ b/source4/build/pidl/util.pm @@ -133,14 +133,23 @@ sub ChangeExtension($$) return "$fname$ext"; } +##################################################################### +# a dumper wrapper to prevent dependence on the Data::Dumper module +# unless we actually need it +sub MyDumper($) +{ + require Data::Dumper; + my $s = shift; + return Data::Dumper::Dumper($s); +} + ##################################################################### # save a data structure into a file sub SaveStructure($$) { - require Data::Dumper; my($filename) = shift; my($v) = shift; - FileSave($filename, Data::Dumper::Dumper($v)); + FileSave($filename, MyDumper($v)); } ##################################################################### diff --git a/source4/build/pidl/validator.pm b/source4/build/pidl/validator.pm index 79f1c6be88..ee1c33ef4c 100644 --- a/source4/build/pidl/validator.pm +++ b/source4/build/pidl/validator.pm @@ -16,6 +16,38 @@ sub fatal($) die "IDL is not valid\n"; } +sub el_name($) +{ + my $e = shift; + + if ($e->{PARENT} && $e->{PARENT}->{NAME}) { + return "$e->{PARENT}->{NAME}.$e->{NAME}"; + } + + if ($e->{PARENT} && $e->{PARENT}->{PARENT}->{NAME}) { + return "$e->{PARENT}->{PARENT}->{NAME}.$e->{NAME}"; + } + + if ($e->{PARENT}) { + return "$e->{PARENT}->{NAME}.$e->{NAME}"; + } + return $e->{NAME}; +} + +##################################################################### +# parse a struct +sub ValidElement($) +{ + my $e = shift; + if ($e->{POINTERS} && $e->{POINTERS} > 1) { + fatal(el_name($e) . " : pidl cannot handle multiple pointer levels. Use a sub-structure containing a pointer instead\n"); + } + + if ($e->{POINTERS} && $e->{ARRAY_LEN}) { + fatal(el_name($e) . " : pidl cannot handle pointers to arrays. Use a substructure instead\n"); + } +} + ##################################################################### # parse a struct sub ValidStruct($) @@ -23,7 +55,8 @@ sub ValidStruct($) my($struct) = shift; foreach my $e (@{$struct->{ELEMENTS}}) { - + $e->{PARENT} = $struct; + ValidElement($e); } } @@ -34,6 +67,8 @@ sub ValidUnion($) { my($union) = shift; foreach my $e (@{$union->{DATA}}) { + $e->{PARENT} = $union; + ValidElement($e); } } @@ -44,6 +79,8 @@ sub ValidTypedef($) my($typedef) = shift; my $data = $typedef->{DATA}; + $data->{PARENT} = $typedef; + if (ref($data) eq "HASH") { if ($data->{TYPE} eq "STRUCT") { ValidStruct($data); @@ -62,9 +99,11 @@ sub ValidFunction($) my($fn) = shift; foreach my $e (@{$fn->{DATA}}) { + $e->{PARENT} = $fn; if (util::has_property($e, "ref") && !$e->{POINTERS}) { fatal "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})\n"; } + ValidElement($e); } } -- cgit