svn commit: samba r9185 - in branches/SAMBA_4_0/source/script: .
tpot at samba.org
tpot at samba.org
Sun Aug 7 18:04:34 GMT 2005
Author: tpot
Date: 2005-08-07 18:04:34 +0000 (Sun, 07 Aug 2005)
New Revision: 9185
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9185
Log:
Make second pass over the parser tree and tidy things up to make it a
bit easier for the code generator.
Modified:
branches/SAMBA_4_0/source/script/build_smb_interfaces.pl
Changeset:
Modified: branches/SAMBA_4_0/source/script/build_smb_interfaces.pl
===================================================================
--- branches/SAMBA_4_0/source/script/build_smb_interfaces.pl 2005-08-07 15:53:54 UTC (rev 9184)
+++ branches/SAMBA_4_0/source/script/build_smb_interfaces.pl 2005-08-07 18:04:34 UTC (rev 9185)
@@ -6,13 +6,95 @@
use File::Basename;
use Data::Dumper;
+#
+# Generate parse tree for header file
+#
+
my $file = shift;
-my $basename = basename($file, ".h");
-
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
More information about the samba-cvs
mailing list