From 8cf122c2d2a0913fd9a7c55032c549598844111c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 Feb 2007 16:21:28 +0000 Subject: r21430: Support tagged types without typedef. This means: struct foo { ... }; in IDL will now work. This is the first step towards nested types and using typedefs for partial types (such as "typedef int *bar;"), a requirement for complex uses of represent_as(). (This used to be commit a716aa70f0c90898e6fcf57d63a2cf4c40e7d4df) --- source4/pidl/lib/Parse/Pidl/Samba4/Header.pm | 10 +- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 213 ++++++++++++++--------- 2 files changed, 137 insertions(+), 86 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba4') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm index 110a483fc4..fbc00d7c13 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm @@ -219,8 +219,6 @@ sub HeaderTypedef($) { my($typedef) = shift; HeaderType($typedef, $typedef->{DATA}, $typedef->{NAME}); - pidl ";\n\n" unless ($typedef->{DATA}->{TYPE} eq "BITMAP" or - $typedef->{DATA}->{TYPE} eq "ENUM"); } ##################################################################### @@ -354,8 +352,12 @@ sub HeaderInterface($) } foreach my $d (@{$interface->{DATA}}) { - next if ($d->{TYPE} ne "TYPEDEF"); - HeaderTypedef($d); + HeaderTypedef($d) if ($d->{TYPE} eq "TYPEDEF"); + HeaderStruct($d, $d->{NAME}) if ($d->{TYPE} eq "STRUCT"); + HeaderUnion($d, $d->{NAME}) if ($d->{TYPE} eq "UNION"); + HeaderEnum($d, $d->{NAME}) if ($d->{TYPE} eq "ENUM"); + HeaderBitmap($d, $d->{NAME}) if ($d->{TYPE} eq "BITMAP"); + pidl ";\n\n"; } foreach my $d (@{$interface->{DATA}}) { diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index 6e4d5825d0..15618bb534 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -12,7 +12,7 @@ require Exporter; @EXPORT = qw(is_charset_array); @EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv NeededFunction - NeededElement NeededTypedef); + NeededElement NeededType); use strict; use Parse::Pidl::Typelist qw(hasType getType mapType); @@ -1335,10 +1335,10 @@ sub ParseEnumPrint($$) end_flags($enum); } -sub DeclEnum($) +sub DeclEnum($$$) { - my ($e,$t) = @_; - return "enum $e->{NAME} " . + my ($e,$t,$name) = @_; + return "enum $name " . ($t eq "pull"?"*":"") . "r"; } @@ -1418,10 +1418,10 @@ sub ParseBitmapPrint($$) end_flags($bitmap); } -sub DeclBitmap($$) +sub DeclBitmap($$$) { - my ($e,$t) = @_; - return mapType(Parse::Pidl::Typelist::bitmap_type_fn($e->{DATA})) . + my ($e,$t,$name) = @_; + return mapType(Parse::Pidl::Typelist::bitmap_type_fn($e)) . ($t eq "pull"?" *":" ") . "r"; } @@ -1581,27 +1581,27 @@ sub ParseStructPull($$) ##################################################################### # calculate size of ndr struct -sub ParseStructNdrSize($) +sub ParseStructNdrSize($$) { - my $t = shift; + my ($t, $name) = @_; my $sizevar; if (my $flags = has_property($t, "flag")) { pidl "flags |= $flags;"; } - pidl "return ndr_size_struct(r, flags, (ndr_push_flags_fn_t)ndr_push_$t->{NAME});"; + pidl "return ndr_size_struct(r, flags, (ndr_push_flags_fn_t)ndr_push_$name);"; } -sub DeclStruct($) +sub DeclStruct($$$) { - my ($e,$t) = @_; - return ($t ne "pull"?"const ":"") . "struct $e->{NAME} *r"; + my ($e,$t,$name) = @_; + return ($t ne "pull"?"const ":"") . "struct $name *r"; } -sub ArgsStructNdrSize($) +sub ArgsStructNdrSize($$) { - my $d = shift; - return "const struct $d->{NAME} *r, int flags"; + my ($d, $name) = @_; + return "const struct $name *r, int flags"; } $typefamily{STRUCT} = { @@ -1615,16 +1615,16 @@ $typefamily{STRUCT} = { ##################################################################### # calculate size of ndr struct -sub ParseUnionNdrSize($) +sub ParseUnionNdrSize($$) { - my $t = shift; + my ($t, $name) = @_; my $sizevar; if (my $flags = has_property($t, "flag")) { pidl "flags |= $flags;"; } - pidl "return ndr_size_union(r, flags, level, (ndr_push_flags_fn_t)ndr_push_$t->{NAME});"; + pidl "return ndr_size_union(r, flags, level, (ndr_push_flags_fn_t)ndr_push_$name);"; } ##################################################################### @@ -1864,16 +1864,16 @@ sub ParseUnionPull($$) pidl "ndr_pull_restore_relative_base_offset(ndr, _save_relative_base_offset);" if defined($e->{PROPERTIES}{relative_base}); } -sub DeclUnion($$) +sub DeclUnion($$$) { - my ($e,$t) = @_; - return ($t ne "pull"?"const ":"") . "union $e->{NAME} *r"; + my ($e,$t,$name) = @_; + return ($t ne "pull"?"const ":"") . "union $name *r"; } -sub ArgsUnionNdrSize($) +sub ArgsUnionNdrSize($$) { - my $d = shift; - return "const union $d->{NAME} *r, uint32_t level, int flags"; + my ($d,$name) = @_; + return "const union $name *r, uint32_t level, int flags"; } $typefamily{UNION} = { @@ -1887,81 +1887,62 @@ $typefamily{UNION} = { ##################################################################### # parse a typedef - push side -sub ParseTypedefPush($) +sub ParseTypedefPush($$) { - my($e) = shift; - - my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"push"); - fn_declare("push", $e, "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)") or return; + my($e,$name) = @_; - pidl "{"; - indent; - $typefamily{$e->{DATA}->{TYPE}}->{PUSH_FN_BODY}->($e->{DATA}, $e->{NAME}); - pidl "return NT_STATUS_OK;"; - deindent; - pidl "}"; - pidl "";; + $typefamily{$e->{DATA}->{TYPE}}->{PUSH_FN_BODY}->($e->{DATA}, $name); } ##################################################################### # parse a typedef - pull side -sub ParseTypedefPull($) +sub ParseTypedefPull($$) { - my($e) = shift; - - my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"pull"); - - fn_declare("pull", $e, "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)") or return; + my($e,$name) = @_; - pidl "{"; - indent; - $typefamily{$e->{DATA}->{TYPE}}->{PULL_FN_BODY}->($e->{DATA}, $e->{NAME}); - pidl "return NT_STATUS_OK;"; - deindent; - pidl "}"; - pidl ""; + $typefamily{$e->{DATA}->{TYPE}}->{PULL_FN_BODY}->($e->{DATA}, $name); } ##################################################################### # parse a typedef - print side -sub ParseTypedefPrint($) +sub ParseTypedefPrint($$) { - my($e) = shift; - - my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"print"); - - pidl_hdr "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args);"; - - return if (has_property($e, "noprint")); + my($e,$name) = @_; - pidl "_PUBLIC_ void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args)"; - pidl "{"; - indent; - $typefamily{$e->{DATA}->{TYPE}}->{PRINT_FN_BODY}->($e->{DATA}, $e->{NAME}); - deindent; - pidl "}"; - pidl ""; + $typefamily{$e->{DATA}->{TYPE}}->{PRINT_FN_BODY}->($e->{DATA}, $name); } ##################################################################### ## calculate the size of a structure -sub ParseTypedefNdrSize($) +sub ParseTypedefNdrSize($$) { - my($t) = shift; + my($t,$name) = @_; - my $tf = $typefamily{$t->{DATA}->{TYPE}}; - my $args = $tf->{SIZE_FN_ARGS}->($t); + $typefamily{$t->{DATA}->{TYPE}}->{SIZE_FN_BODY}->($t->{DATA}, $name); +} - fn_declare("size", $t, "size_t ndr_size_$t->{NAME}($args)") or return; +sub DeclTypedef($$$) +{ + my ($e, $t, $name) = @_; + + return $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e->{DATA}, $t, $name); +} - pidl "{"; - indent; - $typefamily{$t->{DATA}->{TYPE}}->{SIZE_FN_BODY}->($t); - deindent; - pidl "}"; - pidl ""; +sub ArgsTypedefNdrSize($$) +{ + my ($d, $name) = @_; + return $typefamily{$d->{DATA}->{TYPE}}->{SIZE_FN_ARGS}->($d->{DATA}, $name); } +$typefamily{TYPEDEF} = { + PUSH_FN_BODY => \&ParseTypedefPush, + DECL => \&DeclTypedef, + PULL_FN_BODY => \&ParseTypedefPull, + PRINT_FN_BODY => \&ParseTypedefPrint, + SIZE_FN_ARGS => \&ArgsTypedefNdrSize, + SIZE_FN_BODY => \&ParseTypedefNdrSize, +}; + ##################################################################### # parse a function - print side sub ParseFunctionPrint($) @@ -2379,6 +2360,74 @@ sub HeaderInterface($) } +sub ParseTypePush($) +{ + my ($e) = @_; + + my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "push", $e->{NAME}); + fn_declare("push", $e, "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)") or return; + + pidl "{"; + indent; + $typefamily{$e->{TYPE}}->{PUSH_FN_BODY}->($e, $e->{NAME}); + pidl "return NT_STATUS_OK;"; + deindent; + pidl "}"; + pidl "";; +} + +sub ParseTypePull($) +{ + my ($e) = @_; + + my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "pull", $e->{NAME}); + + fn_declare("pull", $e, "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)") or return; + + pidl "{"; + indent; + $typefamily{$e->{TYPE}}->{PULL_FN_BODY}->($e, $e->{NAME}); + pidl "return NT_STATUS_OK;"; + deindent; + pidl "}"; + pidl ""; +} + +sub ParseTypePrint($) +{ + my ($e) = @_; + my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "print", $e->{NAME}); + + pidl_hdr "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args);"; + + return if (has_property($e, "noprint")); + + pidl "_PUBLIC_ void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args)"; + pidl "{"; + indent; + $typefamily{$e->{TYPE}}->{PRINT_FN_BODY}->($e, $e->{NAME}); + deindent; + pidl "}"; + pidl ""; +} + +sub ParseTypeNdrSize($) +{ + my ($t) = @_; + + my $tf = $typefamily{$t->{TYPE}}; + my $args = $tf->{SIZE_FN_ARGS}->($t, $t->{NAME}); + + fn_declare("size", $t, "size_t ndr_size_$t->{NAME}($args)") or return; + + pidl "{"; + indent; + $typefamily{$t->{TYPE}}->{SIZE_FN_BODY}->($t, $t->{NAME}); + deindent; + pidl "}"; + pidl ""; +} + ##################################################################### # parse the interface definitions sub ParseInterface($$) @@ -2398,15 +2447,15 @@ sub ParseInterface($$) # Typedefs foreach my $d (@{$interface->{TYPES}}) { - ($needed->{"push_$d->{NAME}"}) && ParseTypedefPush($d); - ($needed->{"pull_$d->{NAME}"}) && ParseTypedefPull($d); - ($needed->{"print_$d->{NAME}"}) && ParseTypedefPrint($d); + ($needed->{"push_$d->{NAME}"}) && ParseTypePush($d); + ($needed->{"pull_$d->{NAME}"}) && ParseTypePull($d); + ($needed->{"print_$d->{NAME}"}) && ParseTypePrint($d); # Make sure we don't generate a function twice... $needed->{"push_$d->{NAME}"} = $needed->{"pull_$d->{NAME}"} = $needed->{"print_$d->{NAME}"} = 0; - ($needed->{"ndr_size_$d->{NAME}"}) && ParseTypedefNdrSize($d); + ($needed->{"ndr_size_$d->{NAME}"}) && ParseTypeNdrSize($d); } # Functions @@ -2524,7 +2573,7 @@ sub NeededFunction($$) } } -sub NeededTypedef($$) +sub NeededType($$) { my ($t,$needed) = @_; if (has_property($t, "public")) { @@ -2556,7 +2605,7 @@ sub NeededInterface($$) { my ($interface,$needed) = @_; NeededFunction($_, $needed) foreach (@{$interface->{FUNCTIONS}}); - NeededTypedef($_, $needed) foreach (reverse @{$interface->{TYPES}}); + NeededType($_, $needed) foreach (reverse @{$interface->{TYPES}}); } 1; -- cgit