From 277322b9d4b9d009782f1a47baf09ee4033c8328 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 22 Nov 2003 12:25:20 +0000 Subject: added the beginnings of an IDL validator, to give clearer errors when IDL is not valid (This used to be commit c1b708708e262350d697829d444d0fb6a981a80f) --- source4/build/pidl/validator.pm | 101 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 source4/build/pidl/validator.pm (limited to 'source4/build/pidl/validator.pm') diff --git a/source4/build/pidl/validator.pm b/source4/build/pidl/validator.pm new file mode 100644 index 0000000000..10863872fe --- /dev/null +++ b/source4/build/pidl/validator.pm @@ -0,0 +1,101 @@ +################################################### +# check that a parsed IDL file is valid +# Copyright tridge@samba.org 2003 +# released under the GNU GPL + +package IdlValidator; + +use strict; +use Data::Dumper; + + +##################################################################### +# signal a fatal validation error +sub fatal($) +{ + my $s = shift; + print "$s\n"; + die "IDL is not valid\n"; +} + +##################################################################### +# parse a struct +sub ValidStruct($) +{ + my($struct) = shift; + + foreach my $e (@{$struct->{ELEMENTS}}) { + + } +} + + +##################################################################### +# parse a union +sub ValidUnion($) +{ + my($union) = shift; + foreach my $e (@{$union->{DATA}}) { + } +} + +##################################################################### +# parse a typedef +sub ValidTypedef($) +{ + my($typedef) = shift; + my $data = $typedef->{DATA}; + + if (ref($data) eq "HASH") { + if ($data->{TYPE} eq "STRUCT") { + ValidStruct($data); + } + + if ($data->{TYPE} eq "UNION") { + ValidUnion($data); + } + } +} + +##################################################################### +# parse a function +sub ValidFunction($) +{ + my($fn) = shift; + + foreach my $e (@{$fn->{DATA}}) { + if (util::has_property($e, "ref") && !$e->{POINTERS}) { + fatal "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})\n"; + } + } +} + +##################################################################### +# parse the interface definitions +sub ValidInterface($) +{ + my($interface) = shift; + my($data) = $interface->{DATA}; + + foreach my $d (@{$data}) { + ($d->{TYPE} eq "TYPEDEF") && + ValidTypedef($d); + ($d->{TYPE} eq "FUNCTION") && + ValidFunction($d); + } + +} + +##################################################################### +# parse a parsed IDL into a C header +sub Validate($) +{ + my($idl) = shift; + + foreach my $x (@{$idl}) { + ($x->{TYPE} eq "INTERFACE") && + ValidInterface($x); + } +} + +1; -- cgit