From f9dd0263553c4f04fbc0d067e5384a9e46cd98bc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 21:36:15 +0000 Subject: r15585: Revive pidl's SWIG file generator. It now generates simple object oriented wrappers for the interfaces (still need to fix the actual function calls) (This used to be commit bf5da20869eae29aea92386cbb13413b507fc55f) --- source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm | 129 ++++++++++++++++++----------- source4/pidl/pidl | 14 ++-- 2 files changed, 88 insertions(+), 55 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm b/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm index b6c268edeb..d42960be28 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm @@ -1,6 +1,7 @@ ################################################### # Samba4 parser generator for swig wrappers # Copyright tpot@samba.org 2004,2005 +# Copyright jelmer@samba.org 2006 # released under the GNU GPL package Parse::Pidl::Samba4::SWIG; @@ -10,70 +11,100 @@ $VERSION = '0.01'; use strict; +my $ret = ""; +my $tabs = ""; + sub pidl($) { - print OUT shift; + my $p = shift; + $ret .= $tabs. $p . "\n"; } -##################################################################### -# rewrite autogenerated header file -sub RewriteHeader($$$) -{ - my($idl) = shift; - my($input) = shift; - my($output) = shift; - - open(IN, "<$input") || die "can't open $input for reading"; - open(OUT, ">$output") || die "can't open $output for writing"; - - pidl "%{\n"; - pidl "#define data_in in\n"; - pidl "#define data_out out\n"; - pidl "%}\n\n"; - - while() { +sub indent() { $tabs.="\t"; } +sub deindent() { $tabs = substr($tabs,0,-1); } - # Rename dom_sid2 to dom_sid as we don't care about the difference - # for the swig wrappers. - - s/dom_sid2/dom_sid/g; +sub ParseInterface($) +{ + my $if = shift; + + pidl "\%{"; + pidl "struct $if->{NAME} {"; + indent; + pidl "struct dcerpc_pipe *pipe;"; + deindent; + pidl "};"; + pidl "%}"; + pidl ""; + + # FIXME: Generate ignores for all manual functions + + pidl "\%extend $if->{NAME} {"; + indent(); + pidl "struct $if->{NAME} *$if->{NAME} (const char *binding, struct cli_credentials *cred = NULL, TALLOC_CTX *mem_ctx = NULL, struct event_context *event = NULL)"; + pidl "{"; + indent; + pidl "struct $if->{NAME} *ret = talloc(mem_ctx, struct $if->{NAME});"; + pidl "NTSTATUS status;"; + pidl ""; + pidl "status = dcerpc_pipe_connect(mem_ctx, &ret->pipe, &dcerpc_table_$if->{NAME}, cred, event);"; + pidl "if (NT_STATUS_IS_ERR(status)) {"; + pidl "\tsamba_nt_status_exception(status);"; + pidl "\treturn NULL;"; + pidl "}"; + pidl ""; + pidl "return ret;"; + deindent; + pidl "}"; + pidl ""; + pidl "~$if->{NAME}() {"; + pidl "\ttalloc_free(self);"; + pidl "}"; + pidl ""; + + foreach (@{$if->{FUNCTIONS}}) { + pidl "/* $_->{NAME} */"; + } - # Copy structure and union definitions + deindent(); + pidl "}"; + pidl ""; - if (/^(struct|union) .*? {$/ .. /^\};$/) { - s/\} (in|out);/\} data_$1;/; # "in" is a Python keyword - pidl $_; - next; + foreach (@{$if->{TYPES}}) { + pidl "/* $_->{NAME} */"; } + + pidl ""; +} - # Copy dcerpc functions - - pidl $_ if /^NTSTATUS dcerpc_.*?\(struct dcerpc_pipe/; +sub Parse($$$$) +{ + my($ndr,$basename,$header,$gen_header) = @_; - # Copy interface definitions + $ret = ""; - pidl $_ - if /^\#define DCERPC_.*?_UUID/ or /^\#define DCERPC_.*?_VERSION/; - } + pidl "/* This file is autogenerated by pidl. DO NOT EDIT */"; - close(OUT); -} + pidl "\%module $basename"; + + pidl ""; -##################################################################### -# rewrite autogenerated header file -sub RewriteC($$$) -{ - my($idl) = shift; - my($input) = shift; - my($output) = shift; + pidl "\%{"; + pidl "#include \"includes.h\""; + pidl "#include \"$header\""; + pidl "%}"; + pidl "\%include \"samba.i\""; + pidl "\%include \"$gen_header\""; - open(IN, "<$input") || die "can't open $input for reading"; - open(OUT, ">>$output") || die "can't open $output for writing"; - - while() { - } + pidl ""; - close(OUT); + foreach (@$ndr) { + ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + } + #FIXME: Foreach ref pointer, set NONNULL + #FIXME: Foreach unique/full pointer, set MAYBENULL + #FIXME: Foreach [out] parameter, set OUTPARAM + # + return $ret; } 1; diff --git a/source4/pidl/pidl b/source4/pidl/pidl index e3fd434e9b..a7838791b5 100755 --- a/source4/pidl/pidl +++ b/source4/pidl/pidl @@ -661,7 +661,7 @@ sub process_file($) defined($opt_dump_ndr_tree) or defined($opt_samba3_header) or defined($opt_samba3_parser) or defined($opt_samba3_server) or defined($opt_samba3_template) or defined($opt_samba3_client) or - defined($opt_samba3_ndr_client)) { + defined($opt_swig) or defined($opt_samba3_ndr_client)) { require Parse::Pidl::NDR; $ndr = Parse::Pidl::NDR::Parse($pidl); } @@ -691,6 +691,13 @@ sub process_file($) FileSave($c_header, $hdrd); } + if (defined($opt_swig)) { + require Parse::Pidl::Samba4::SWIG; + my($filename) = ($opt_swig or "$outputdir/$basename.i"); + my $code = Parse::Pidl::Samba4::SWIG::Parse($ndr, $basename, "$outputdir/ndr_$basename\_c.h", $gen_header); + FileSave($filename, $code); + } + if (defined($opt_ejs)) { require Parse::Pidl::Samba4::EJS; my ($hdr,$prsr) = Parse::Pidl::Samba4::EJS::Parse($ndr, $h_filename); @@ -735,11 +742,6 @@ $dcom FileSave($parser_fname, $parser); FileSave($h_filename, $header); - if (defined($opt_swig)) { - require Parse::Pidl::Samba4::SWIG; - my($filename) = ($opt_swig or "$outputdir/$basename.i"); - Parse::Pidl::Samba4::SWIG::RewriteHeader($pidl, $h_filename, $filename); - } } if (defined($opt_eth_parser)) { -- cgit