summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm105
-rwxr-xr-xsource4/pidl/tests/samba-ejs.pl42
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, "");