summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2005-08-07 18:04:34 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:31:29 -0500
commitd8a490ab1bff8e62e76e34b7a16eb27a74b30f66 (patch)
treec64d37d7a7ed3d3aaa619fb5431e423eb312af68
parenta663d2110678b6c059737eecf7929cd5e5d46160 (diff)
downloadsamba-d8a490ab1bff8e62e76e34b7a16eb27a74b30f66.tar.gz
samba-d8a490ab1bff8e62e76e34b7a16eb27a74b30f66.tar.bz2
samba-d8a490ab1bff8e62e76e34b7a16eb27a74b30f66.zip
r9185: Make second pass over the parser tree and tidy things up to make it a
bit easier for the code generator. (This used to be commit a6f1f251e86bac43b894d551e93536256bab7329)
-rwxr-xr-xsource4/script/build_smb_interfaces.pl86
1 files changed, 84 insertions, 2 deletions
diff --git a/source4/script/build_smb_interfaces.pl b/source4/script/build_smb_interfaces.pl
index 7358eab85a..192a7d7094 100755
--- a/source4/script/build_smb_interfaces.pl
+++ b/source4/script/build_smb_interfaces.pl
@@ -6,13 +6,95 @@
use File::Basename;
use Data::Dumper;
-my $file = shift;
-my $basename = basename($file, ".h");
+#
+# Generate parse tree for header file
+#
+my $file = shift;
require smb_interfaces;
my $parser = new smb_interfaces;
$header = $parser->parse($file);
+#
+# Make second pass over tree to make it easier to process. Ugh - this
+# is all done in place as the parser generates references.
+#
+
+my $newheader = [];
+
+sub flatten_names($) {
+ my $obj = shift;
+
+ # Map NAME, STRUCT_NAME and UNION_NAME elements into a more likeable
+ # property.
+
+ if ($obj->{TYPE} eq "struct" or $obj->{TYPE} eq "union") {
+
+ # struct foo {};
+ # struct {} bar;
+ # struct foo {} bar;
+
+ $obj->{TYPE_NAME} = defined($obj->{STRUCT_NAME}) ? $obj->{STRUCT_NAME}
+ : $obj->{UNION_NAME};
+
+ delete $obj->{STRUCT_NAME};
+ delete $obj->{UNION_NAME};
+ }
+
+ # Convert DATA array to a hash by field name
+
+ foreach my $elt (@{$obj->{DATA}}) {
+ foreach my $name (@{$elt->{NAME}}) {
+ $obj->{FIELDS}{$name} = $elt;
+ delete $obj->{FIELDS}{$name}{NAME};
+ }
+ }
+
+ # Recurse down into substructures
+
+ foreach my $elt (@{$obj->{DATA}}) {
+ flatten_names($elt);
+ }
+
+ delete $obj->{DATA};
+}
+
+foreach my $s (@{$header}) { # For each parsed structure
+ flatten_names($s);
+}
+
+print Dumper($header);
+
+exit;
+
+foreach my $s (@{$header}) { # For each parsed structure
+ print Dumper($s);
+ my $newdata;
+ foreach my $e (@{$s->{DATA}}) { # For each element in structure
+ foreach my $n (@{$e->{NAME}}) { # For each field in element
+
+ my $newdata2;
+ foreach my $e2 (@{$e->{DATA}}) {
+ foreach my $n2 (@{$e2->{NAME}}) {
+ my $d = $e2;
+ $d->{NAME} = $n2;
+ push(@{$newdata2}, $d);
+ }
+ }
+
+ push(@{$newdata}, {"NAME" => $n, "DATA" => $newdata2});
+ }
+ }
+ my $newstruct = $s;
+ $newstruct->{DATA} = $newdata;
+ push(@{$newheader}, $newstruct);
+}
+
+print Dumper($newheader);
+exit 0;
+
+
+my $basename = basename($file, ".h");
stat "libcli/gen_raw" || mkdir("libcli/gen_raw") || die("mkdir");
# Create header