From 2c52f52e02ca1e7286d0faa15d5031f2a4ac11ed Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 05:25:05 +0000 Subject: r3423: auto-generate prototypes for all external functions in pidl (This used to be commit 009488dfe55f5219b24c30222b1a8bf411a7e939) --- source4/build/pidl/header.pm | 52 ++++++++++++++++++++++++- source4/build/pidl/needed.pm | 92 ++++++++++++++++++++++++++++++++++++++++++++ source4/build/pidl/parser.pm | 82 +++------------------------------------ 3 files changed, 147 insertions(+), 79 deletions(-) create mode 100644 source4/build/pidl/needed.pm (limited to 'source4/build') diff --git a/source4/build/pidl/header.pm b/source4/build/pidl/header.pm index f9acc5e222..58707a90a5 100644 --- a/source4/build/pidl/header.pm +++ b/source4/build/pidl/header.pm @@ -6,6 +6,7 @@ package IdlHeader; use strict; +use needed; my($res); my($tab_depth); @@ -177,6 +178,35 @@ sub HeaderTypedef($) $res .= ";\n"; } +##################################################################### +# prototype a typedef +sub HeaderTypedefProto($) +{ + my($d) = shift; + if (!util::has_property($d->{DATA}, "public")) { + return; + } + + if ($d->{DATA}{TYPE} eq "STRUCT") { + $res .= "NTSTATUS ndr_push_$d->{NAME}(struct ndr_push *, int , struct $d->{NAME} *);\n"; + $res .= "NTSTATUS ndr_pull_$d->{NAME}(struct ndr_pull *, int , struct $d->{NAME} *);\n"; + if (!util::has_property($d->{DATA}, "noprint")) { + $res .= "void ndr_print_$d->{NAME}(struct ndr_print *, const char *, struct $d->{NAME} *);\n"; + } + + if (needed::is_needed("ndr_size_$d->{NAME}")) { + $res .= "size_t ndr_size_$d->{NAME}(int , struct $d->{NAME} *, int );\n"; + } + } + if ($d->{DATA}{TYPE} eq "UNION") { + $res .= "NTSTATUS ndr_push_$d->{NAME}(struct ndr_push *, int, int, union $d->{NAME} *);\n"; + $res .= "NTSTATUS ndr_pull_$d->{NAME}(struct ndr_pull *, int, int, union $d->{NAME} *);\n"; + if (!util::has_property($d->{DATA}, "noprint")) { + $res .= "void ndr_print_$d->{NAME}(struct ndr_print *, const char *, int, union $d->{NAME} *);\n"; + } + } +} + ##################################################################### # parse a typedef sub HeaderConst($) @@ -266,6 +296,18 @@ sub HeaderFunction($) $res .= "};\n\n"; } +##################################################################### +# output prototypes for a IDL function +sub HeaderFnProto($) +{ + my $fn = shift; + my $name = $fn->{NAME}; + $res .= "void ndr_print_$name(struct ndr_print *, const char *, int, struct $name *);\n"; + $res .= "struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *, TALLOC_CTX *, struct $name *);\n"; + $res .= "NTSTATUS dcerpc_$name(struct dcerpc_pipe *, TALLOC_CTX *, struct $name *);\n"; + $res .= "\n"; +} + ##################################################################### # parse the interface definitions sub HeaderInterface($) @@ -310,8 +352,12 @@ sub HeaderInterface($) HeaderConst($d); ($d->{TYPE} eq "TYPEDEF") && HeaderTypedef($d); + ($d->{TYPE} eq "TYPEDEF") && + HeaderTypedefProto($d); ($d->{TYPE} eq "FUNCTION") && HeaderFunction($d); + ($d->{TYPE} eq "FUNCTION") && + HeaderFnProto($d); } $res .= "#endif /* _HEADER_NDR_$interface->{NAME} */\n"; @@ -326,8 +372,10 @@ sub Parse($) $res = "/* header auto-generated by pidl */\n\n"; foreach my $x (@{$idl}) { - ($x->{TYPE} eq "INTERFACE") && - HeaderInterface($x); + if ($x->{TYPE} eq "INTERFACE") { + needed::BuildNeeded($x); + HeaderInterface($x); + } } return $res; } diff --git a/source4/build/pidl/needed.pm b/source4/build/pidl/needed.pm new file mode 100644 index 0000000000..301b85e51c --- /dev/null +++ b/source4/build/pidl/needed.pm @@ -0,0 +1,92 @@ +################################################### +# Samba4 parser generator for IDL structures +# Copyright tridge@samba.org 2000-2004 +# Copyright jelmer@samba.org 2004 +# released under the GNU GPL + +package needed; + +use strict; + +# the list of needed functions +my %needed; + +sub NeededFunction($) +{ + my $fn = shift; + $needed{"pull_$fn->{NAME}"} = 1; + $needed{"push_$fn->{NAME}"} = 1; + foreach my $e (@{$fn->{DATA}}) { + $e->{PARENT} = $fn; + $needed{"pull_$e->{TYPE}"} = 1; + $needed{"push_$e->{TYPE}"} = 1; + } +} + +sub NeededTypedef($) +{ + my $t = shift; + if (util::has_property($t->{DATA}, "public")) { + $needed{"pull_$t->{NAME}"} = 1; + $needed{"push_$t->{NAME}"} = 1; + } + + if ($t->{DATA}->{TYPE} eq "STRUCT") { + if (util::has_property($t->{DATA}, "gensize")) { + $needed{"ndr_size_$t->{NAME}"} = 1; + } + + for my $e (@{$t->{DATA}->{ELEMENTS}}) { + $e->{PARENT} = $t->{DATA}; + if ($needed{"pull_$t->{NAME}"}) { + $needed{"pull_$e->{TYPE}"} = 1; + } + if ($needed{"push_$t->{NAME}"}) { + $needed{"push_$e->{TYPE}"} = 1; + } + if ($needed{"ndr_size_$t->{NAME}"}) { + $needed{"ndr_size_$e->{TYPE}"} = 1; + } + } + } + if ($t->{DATA}->{TYPE} eq "UNION") { + for my $e (@{$t->{DATA}->{DATA}}) { + $e->{PARENT} = $t->{DATA}; + if ($e->{TYPE} eq "UNION_ELEMENT") { + if ($needed{"pull_$t->{NAME}"}) { + $needed{"pull_$e->{DATA}->{TYPE}"} = 1; + } + if ($needed{"push_$t->{NAME}"}) { + $needed{"push_$e->{DATA}->{TYPE}"} = 1; + } + if ($needed{"ndr_size_$t->{NAME}"}) { + $needed{"ndr_size_$e->{DATA}->{TYPE}"} = 1; + } + } + } + } +} + +##################################################################### +# work out what parse functions are needed +sub BuildNeeded($) +{ + my($interface) = shift; + my($data) = $interface->{DATA}; + foreach my $d (@{$data}) { + ($d->{TYPE} eq "FUNCTION") && + NeededFunction($d); + } + foreach my $d (reverse @{$data}) { + ($d->{TYPE} eq "TYPEDEF") && + NeededTypedef($d); + } +} + +sub is_needed($) +{ + my $name = shift; + return $needed{$name}; +} + +1; diff --git a/source4/build/pidl/parser.pm b/source4/build/pidl/parser.pm index 15dd1cd70e..cec972911e 100644 --- a/source4/build/pidl/parser.pm +++ b/source4/build/pidl/parser.pm @@ -9,9 +9,9 @@ package IdlParser; use strict; use client; +use needed; # the list of needed functions -my %needed; my %structs; sub pidl($) @@ -1127,7 +1127,7 @@ sub ParseTypedefPush($) my($e) = shift; my $static = fn_prefix($e); - if (! $needed{"push_$e->{NAME}"}) { + if (! needed::is_needed("push_$e->{NAME}")) { # print "push_$e->{NAME} not needed\n"; return; } @@ -1157,7 +1157,7 @@ sub ParseTypedefPull($) my($e) = shift; my $static = fn_prefix($e); - if (! $needed{"pull_$e->{NAME}"}) { + if (! needed::is_needed("pull_$e->{NAME}")) { # print "pull_$e->{NAME} not needed\n"; return; } @@ -1208,7 +1208,7 @@ sub ParseTypedefPrint($) sub ParseTypedefNdrSize($) { my($t) = shift; - if (! $needed{"ndr_size_$t->{NAME}"}) { + if (! needed::is_needed("ndr_size_$t->{NAME}")) { return; } @@ -1557,78 +1557,6 @@ sub ParseInterface($) } -sub NeededFunction($) -{ - my $fn = shift; - $needed{"pull_$fn->{NAME}"} = 1; - $needed{"push_$fn->{NAME}"} = 1; - foreach my $e (@{$fn->{DATA}}) { - $e->{PARENT} = $fn; - $needed{"pull_$e->{TYPE}"} = 1; - $needed{"push_$e->{TYPE}"} = 1; - } -} - -sub NeededTypedef($) -{ - my $t = shift; - if (util::has_property($t->{DATA}, "public")) { - $needed{"pull_$t->{NAME}"} = 1; - $needed{"push_$t->{NAME}"} = 1; - } - - if ($t->{DATA}->{TYPE} eq "STRUCT") { - if (util::has_property($t->{DATA}, "gensize")) { - $needed{"ndr_size_$t->{NAME}"} = 1; - } - - for my $e (@{$t->{DATA}->{ELEMENTS}}) { - $e->{PARENT} = $t->{DATA}; - if ($needed{"pull_$t->{NAME}"}) { - $needed{"pull_$e->{TYPE}"} = 1; - } - if ($needed{"push_$t->{NAME}"}) { - $needed{"push_$e->{TYPE}"} = 1; - } - if ($needed{"ndr_size_$t->{NAME}"}) { - $needed{"ndr_size_$e->{TYPE}"} = 1; - } - } - } - if ($t->{DATA}->{TYPE} eq "UNION") { - for my $e (@{$t->{DATA}->{DATA}}) { - $e->{PARENT} = $t->{DATA}; - if ($e->{TYPE} eq "UNION_ELEMENT") { - if ($needed{"pull_$t->{NAME}"}) { - $needed{"pull_$e->{DATA}->{TYPE}"} = 1; - } - if ($needed{"push_$t->{NAME}"}) { - $needed{"push_$e->{DATA}->{TYPE}"} = 1; - } - if ($needed{"ndr_size_$t->{NAME}"}) { - $needed{"ndr_size_$e->{DATA}->{TYPE}"} = 1; - } - } - } - } -} - -##################################################################### -# work out what parse functions are needed -sub BuildNeeded($) -{ - my($interface) = shift; - my($data) = $interface->{DATA}; - foreach my $d (@{$data}) { - ($d->{TYPE} eq "FUNCTION") && - NeededFunction($d); - } - foreach my $d (reverse @{$data}) { - ($d->{TYPE} eq "TYPEDEF") && - NeededTypedef($d); - } -} - ##################################################################### # parse a parsed IDL structure back into an IDL file sub Parse($$) @@ -1642,7 +1570,7 @@ sub Parse($$) pidl "#include \"includes.h\"\n\n"; foreach my $x (@{$idl}) { if ($x->{TYPE} eq "INTERFACE") { - BuildNeeded($x); + needed::BuildNeeded($x); ParseInterface($x); } } -- cgit