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/Types.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/Types.pm')
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm new file mode 100644 index 0000000000..68bea0d024 --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -0,0 +1,169 @@ +################################################### +# Samba3 common helper functions +# Copyright jelmer@samba.org 2005 +# released under the GNU GPL + +package Parse::Pidl::Samba3::Types; + +require Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType); + +use strict; +use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); + +use vars qw($VERSION); +$VERSION = '0.01'; + +sub init_scalar($$$$) +{ + my ($e,$l,$n,$v) = @_; + + return "$n = $v;"; +} + +sub dissect_scalar($$$) +{ + my ($e,$l,$n) = @_; + + my $t = lc($e->{TYPE}); + + return "prs_$t(\"$e->{NAME}\", ps, depth, &$n)"; +} + +sub decl_string($) +{ + my $e = shift; + + return "UNISTR2"; +} + +sub init_string($$$$) +{ + my ($e,$l,$n,$v) = @_; + + return "init_unistr2(&$n, $v, UNI_FLAGS_NONE);"; +} + +sub dissect_string($$$) +{ + my ($e,$l,$n) = @_; + + return "FIXME"; +} + +my $known_types = { + uint8 => { + DECL => "uint8", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, + uint16 => { + DECL => "uint16", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, + uint32 => { + DECL => "uint32", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, + string => { + DECL => \&decl_string, + INIT => \&init_string, + DISSECT => \&dissect_string, + }, + NTSTATUS => { + DECL => "NTSTATUS", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, + WERROR => { + DECL => "WERROR", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, +}; + +sub AddType($$) +{ + my ($t,$d) = @_; + + warn("Reregistering type $t") if (defined($known_types->{$t})); + + $known_types->{$t} = $d; +} + +sub GetType($) +{ + my $e = shift; + + my $t = $known_types->{$e->{TYPE}}; + + return undef if not $t; + + # DECL can be a function + if (ref($t->{DECL}) eq "CODE") { + return $t->{DECL}->($e); + } else { + return $t->{DECL}; + } +} + +# Return type without special stuff, as used in +# struct declarations +sub DeclShort($) +{ + my $e = shift; + + my $t = GetType($e); + return undef if not $t; + + return "$t $e->{NAME}"; +} + +sub DeclLong($) +{ + my $e = shift; + + my $t = GetType($e); + + return undef if not $t; + + return "$t $e->{NAME}"; +} + +sub InitType($$$$) +{ + my ($e, $l, $varname, $value) = @_; + + my $t = $known_types->{$l->{DATA_TYPE}}; + + return undef if not $t; + + # INIT can be a function + if (ref($t->{INIT}) eq "CODE") { + return $t->{INIT}->($e, $l, $varname, $value); + } else { + return $t->{INIT}; + } +} + +sub DissectType($$$) +{ + my ($e, $l, $varname) = @_; + + my $t = $known_types->{$l->{DATA_TYPE}}; + + return undef if not $t; + + # DISSECT can be a function + if (ref($t->{DISSECT}) eq "CODE") { + return $t->{DISSECT}->($e, $l, $varname); + } else { + return $t->{DISSECT}; + } +} + +1; |