diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-10-04 13:07:23 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:39:23 -0500 |
commit | 55065d27cede4e2cdc0e1240b1b5952fa5697391 (patch) | |
tree | abad2501607f5bbae945af043e09edd47a0651e6 /source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | |
parent | 49dd5e4b1d8f0bcffa3fd8134e03d162a3507739 (diff) | |
download | samba-55065d27cede4e2cdc0e1240b1b5952fa5697391.tar.gz samba-55065d27cede4e2cdc0e1240b1b5952fa5697391.tar.bz2 samba-55065d27cede4e2cdc0e1240b1b5952fa5697391.zip |
r10713: Couple more updates to the Samba3 parser generators.
Unions and enums have been improved, init functions are now generated
properly, some other small improvements.
(This used to be commit 8a60e79175eb27ef9fa4b8dea72a518bbaab900f)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl/Samba3/Header.pm')
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index be7f1ca5c4..13f506a7da 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -9,7 +9,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Util qw(MapSamba3Type); +use Parse::Pidl::Samba3::Types qw(DeclShort); use vars qw($VERSION); $VERSION = '0.01'; @@ -17,24 +17,30 @@ $VERSION = '0.01'; my $res = ""; sub pidl($) { my $x = shift; $res .= "$x\n"; } sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } +sub warning($$) { my ($e,$s) = @_; warn("$e->{FILE}:$e->{LINE}: $s\n"); } + +sub ParseElement($) +{ + my $e = shift; + + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "POINTER") { + return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "top"); + pidl "\tuint32 ptr_$e->{NAME};"; + } elsif ($l->{TYPE} eq "SWITCH") { + pidl "\tuint32 level_$e->{NAME};"; + } elsif ($l->{TYPE} eq "DATA") { + pidl "\t" . DeclShort($e) . ";"; + } + } +} sub CreateStruct($$$$) { my ($if,$fn,$n,$t) = @_; pidl "typedef struct $n {"; - foreach my $e (@$t) { - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "POINTER") { - return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "top"); - pidl "\tuint32 ptr_$e->{NAME};"; - } elsif ($l->{TYPE} eq "SWITCH") { - pidl "\tuint32 level_$e->{NAME};"; - } elsif ($l->{TYPE} eq "DATA") { - pidl "\t" . MapSamba3Type($e) . ";"; - } - } - } + ParseElement($_) foreach (@$t); if (not @$t) { # Some compilers don't like empty structs @@ -83,16 +89,23 @@ sub ParseStruct($$$) CreateStruct($if, $s, "$if->{NAME}_$n", $s->{ELEMENTS}); } +sub ParseUnion($$$) +{ + my ($if,$u,$n) = @_; + + pidl "typedef union {"; + #FIXME: What about elements that require more then one variable? + ParseElement($_) foreach (@{$u->{ELEMENTS}}); + pidl "} $n;"; + pidl ""; +} + sub ParseEnum($$$) { my ($if,$s,$n) = @_; pidl "typedef enum {"; - - foreach (@{$s->{ELEMENTS}}) { - pidl "$_,"; - } - + pidl "$_," foreach (@{$s->{ELEMENTS}}); pidl "} $n;"; } @@ -122,15 +135,15 @@ sub ParseInterface($) pidl ""; - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); - foreach (@{$if->{TYPEDEFS}}) { - ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "STRUCT"); - ParseEnum($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "ENUM"); - ParseBitmap($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "BITMAP"); - fatal($_, "Unions not supported for Samba3 yet") if ($_->{TYPE} eq "STRUCT"); + ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); + ParseEnum($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "ENUM"); + ParseBitmap($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "BITMAP"); + ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "UNION"); } + ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); + foreach (@{$if->{CONSTS}}) { pidl "$_->{NAME} ($_->{VALUE})"; } |