summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-11-22 12:25:20 +0000
committerAndrew Tridgell <tridge@samba.org>2003-11-22 12:25:20 +0000
commit277322b9d4b9d009782f1a47baf09ee4033c8328 (patch)
tree934b8b7b8921f4c691be02324f2931a3c0a1b0df
parentbe77d9c60d17e0ef2ed0b51ea0814c42a41a40a3 (diff)
downloadsamba-277322b9d4b9d009782f1a47baf09ee4033c8328.tar.gz
samba-277322b9d4b9d009782f1a47baf09ee4033c8328.tar.bz2
samba-277322b9d4b9d009782f1a47baf09ee4033c8328.zip
added the beginnings of an IDL validator, to give clearer errors when
IDL is not valid (This used to be commit c1b708708e262350d697829d444d0fb6a981a80f)
-rwxr-xr-xsource4/build/pidl/pidl.pl3
-rw-r--r--source4/build/pidl/validator.pm101
2 files changed, 104 insertions, 0 deletions
diff --git a/source4/build/pidl/pidl.pl b/source4/build/pidl/pidl.pl
index 73d2378612..b4710e5756 100755
--- a/source4/build/pidl/pidl.pl
+++ b/source4/build/pidl/pidl.pl
@@ -18,6 +18,7 @@ use header;
use parser;
use eparser;
use client;
+use validator;
use util;
my($opt_help) = 0;
@@ -111,6 +112,8 @@ if ($opt_parse) {
my($idl) = IdlParse($idl_file);
defined $idl || die "Failed to parse $idl_file";
util::SaveStructure($pidl_file, $idl) || die "Failed to save $pidl_file";
+
+ IdlValidator::Validate($idl);
}
if ($opt_dump) {
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;