diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-02-21 12:35:21 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:48:43 -0500 |
commit | b76461f425fbfe425a7c0773626f53e394b48386 (patch) | |
tree | 37767f57cd126e7dc5c391660575f19c16e7f708 /source4/pidl | |
parent | 19afd524443f9ebc0f986d6e8bf6874b477ac176 (diff) | |
download | samba-b76461f425fbfe425a7c0773626f53e394b48386.tar.gz samba-b76461f425fbfe425a7c0773626f53e394b48386.tar.bz2 samba-b76461f425fbfe425a7c0773626f53e394b48386.zip |
r21490: Add some tests for the EJS code
More work on supporting nested types in EJS.
(This used to be commit cb7faeab88952b59add1c814e1881ee9bb88b7ec)
Diffstat (limited to 'source4/pidl')
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm | 105 | ||||
-rwxr-xr-x | source4/pidl/tests/samba-ejs.pl | 42 |
2 files changed, 75 insertions, 72 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm index 0d2f0fc8f2..910b47a4a1 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm @@ -6,16 +6,23 @@ package Parse::Pidl::Samba4::EJS; +use Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(get_pointer_to get_value_of check_null_pointer $res + $res_hdr fn_declare); + use strict; use Parse::Pidl::Typelist; use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel); +use Parse::Pidl::Samba4::NDR::Parser qw(GenerateStructEnv GenerateFunctionInEnv + GenerateFunctionOutEnv); use vars qw($VERSION); $VERSION = '0.01'; -my $res; -my $res_hdr; +our $res; +our $res_hdr; my %constants; @@ -46,52 +53,6 @@ sub deindent() $tabs = substr($tabs, 0, -1); } -sub GenerateStructEnv($) -{ - my $x = shift; - my %env; - - foreach my $e (@{$x->{ELEMENTS}}) { - if ($e->{NAME}) { - $env{$e->{NAME}} = "r->$e->{NAME}"; - } - } - - $env{"this"} = "r"; - - return \%env; -} - -sub GenerateFunctionInEnv($) -{ - my $fn = shift; - my %env; - - foreach my $e (@{$fn->{ELEMENTS}}) { - if (grep (/in/, @{$e->{DIRECTION}})) { - $env{$e->{NAME}} = "r->in.$e->{NAME}"; - } - } - - return \%env; -} - -sub GenerateFunctionOutEnv($) -{ - my $fn = shift; - my %env; - - foreach my $e (@{$fn->{ELEMENTS}}) { - if (grep (/out/, @{$e->{DIRECTION}})) { - $env{$e->{NAME}} = "r->out.$e->{NAME}"; - } elsif (grep (/in/, @{$e->{DIRECTION}})) { - $env{$e->{NAME}} = "r->in.$e->{NAME}"; - } - } - - return \%env; -} - sub get_pointer_to($) { my $var_name = shift; @@ -127,7 +88,6 @@ sub check_null_pointer($) } } - ##################################################################### # work out is a parse function should be declared static or not sub fn_declare($$) @@ -291,7 +251,7 @@ sub EjsPullElementTop($$) sub EjsStructPull($$) { my ($name, $d) = @_; - my $env = GenerateStructEnv($d); + my $env = GenerateStructEnv($d, "r"); fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, struct $name *r)"); pidl "{"; indent; @@ -391,7 +351,6 @@ sub EjsBitmapPull($$) pidl "}"; } - ########################### # generate a structure pull sub EjsTypedefPull($) @@ -580,7 +539,7 @@ sub EjsPushElementTop($$) sub EjsStructPush($$) { my ($name, $d) = @_; - my $env = GenerateStructEnv($d); + my $env = GenerateStructEnv($d, "r"); fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const struct $name *r)"); pidl "{"; indent; @@ -879,32 +838,25 @@ sub NeededFunction($$) } } -sub NeededTypedef($$) +sub NeededType($$$) { - my ($t,$needed) = @_; + sub NeededType($$$); + my ($t,$needed,$req) = @_; - if (has_property($t, "public")) { - $needed->{"pull_$t->{NAME}"} = not has_property($t, "noejs"); - $needed->{"push_$t->{NAME}"} = not has_property($t, "noejs"); - } + NeededType($t->{DATA}, $needed, $req) if ($t->{TYPE} eq "TYPEDEF"); - return if (($t->{DATA}->{TYPE} ne "STRUCT") and - ($t->{DATA}->{TYPE} ne "UNION")); + return if (($t->{TYPE} ne "STRUCT") and + ($t->{TYPE} ne "UNION")); - foreach (@{$t->{DATA}->{ELEMENTS}}) { + foreach (@{$t->{ELEMENTS}}) { next if (has_property($_, "subcontext")); #FIXME: Support subcontexts my $n; - if (ref($_->{TYPE}) eq "HASH") { - $n = "$_->{TYPE}->{TYPE}_$_->{TYPE}->{NAME}"; - } else { - $n = $_->{TYPE}; - } - unless (defined($needed->{"pull_$n"})) { - $needed->{"pull_$n"} = $needed->{"pull_$t->{NAME}"}; - } - unless (defined($needed->{"push_$n"})) { - $needed->{"push_$n"} = $needed->{"push_$t->{NAME}"}; + if (ref($_->{TYPE}) eq "HASH" and defined($_->{TYPE}->{NAME})) { + $needed->{"$req\_$_->{TYPE}->{TYPE}_$_->{TYPE}->{NAME}"} = 1; + } elsif (ref($_->{TYPE}) ne "HASH") { + $needed->{$req."_".$_->{TYPE}} = 1; } + NeededType($_->{TYPE}, $needed, $req) if (ref($_->{TYPE}) eq "HASH"); } } @@ -915,7 +867,16 @@ sub NeededInterface($$) my ($interface,$needed) = @_; NeededFunction($_, $needed) foreach (@{$interface->{FUNCTIONS}}); - NeededTypedef($_, $needed) foreach (reverse @{$interface->{TYPES}}); + + foreach (reverse @{$interface->{TYPES}}) { + if (has_property($_, "public")) { + $needed->{"pull_$_->{NAME}"} = not has_property($_, "noejs"); + $needed->{"push_$_->{NAME}"} = not has_property($_, "noejs"); + } + + NeededType($_, $needed, "pull") if ($needed->{"pull_$_->{NAME}"}); + NeededType($_, $needed, "push") if ($needed->{"push_$_->{NAME}"}); + } } 1; diff --git a/source4/pidl/tests/samba-ejs.pl b/source4/pidl/tests/samba-ejs.pl new file mode 100755 index 0000000000..350cba571c --- /dev/null +++ b/source4/pidl/tests/samba-ejs.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl +# (C) 2007 Jelmer Vernooij <jelmer@samba.org> +# Published under the GNU General Public License +use strict; +use warnings; + +use Test::More tests => 13; +use FindBin qw($RealBin); +use lib "$RealBin"; +use Util; +use Parse::Pidl::Util qw(MyDumper); +use Parse::Pidl::Samba4::EJS qw(get_pointer_to get_value_of check_null_pointer + $res $res_hdr fn_declare); + +is("&foo", get_pointer_to("foo")); +is("&(&foo)", get_pointer_to(get_pointer_to("foo"))); +is("*foo", get_pointer_to("**foo")); +is("foo", get_pointer_to("*foo")); + +is("foo", get_value_of("&foo")); +is("*foo", get_value_of("foo")); +is("**foo", get_value_of("*foo")); + +$res = ""; +check_null_pointer("bla"); +is($res, ""); + +$res = ""; +check_null_pointer("*bla"); +is($res, "if (bla == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;\n"); + +$res = ""; +$res_hdr = ""; +fn_declare({ PROPERTIES => { public => 1 } }, "myproto(int x)"); +is($res, "_PUBLIC_ myproto(int x)\n"); +is($res_hdr, "myproto(int x);\n"); + +$res = ""; +$res_hdr = ""; +fn_declare({ PROPERTIES => {} }, "mybla(int foo)"); +is($res, "static mybla(int foo)\n"); +is($res_hdr, ""); |