From 3bc13d6eeda1a8e5e0ebec8c85c3aaf2ded2b111 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 28 Feb 2007 02:01:58 +0000 Subject: r21579: Use utility function to determine function names in ejs code. (This used to be commit 1736de4c73a82be8357808dc8ec93d3917213449) --- source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm | 40 +++++++++++++++++++------------ source4/pidl/tests/samba-ejs.pl | 9 +++++-- 2 files changed, 32 insertions(+), 17 deletions(-) (limited to 'source4/pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm index 9edd2a4a33..c254bfad38 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm @@ -9,7 +9,7 @@ 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); + $res_hdr fn_declare TypeFunctionName); use strict; use Parse::Pidl::Typelist; @@ -737,8 +737,8 @@ sub EjsInterface($$) pidl_hdr "\n"; foreach my $d (@{$interface->{TYPES}}) { - ($needed->{"push_$d->{NAME}"}) && EjsTypePushFunction($d, $d->{NAME}); - ($needed->{"pull_$d->{NAME}"}) && EjsTypePullFunction($d, $d->{NAME}); + ($needed->{TypeFunctionName("ejs_push", $d)}) && EjsTypePushFunction($d, $d->{NAME}); + ($needed->{TypeFunctionName("ejs_pull", $d)}) && EjsTypePullFunction($d, $d->{NAME}); } foreach my $d (@{$interface->{FUNCTIONS}}) { @@ -831,16 +831,16 @@ sub NeededFunction($$) { my ($fn,$needed) = @_; - $needed->{"pull_$fn->{NAME}"} = 1; - $needed->{"push_$fn->{NAME}"} = 1; + $needed->{"ejs_pull_$fn->{NAME}"} = 1; + $needed->{"ejs_push_$fn->{NAME}"} = 1; foreach (@{$fn->{ELEMENTS}}) { next if (has_property($_, "subcontext")); #FIXME: Support subcontexts if (grep(/in/, @{$_->{DIRECTION}})) { - $needed->{"pull_$_->{TYPE}"} = 1; + $needed->{TypeFunctionName("ejs_pull", $_->{TYPE})} = 1; } if (grep(/out/, @{$_->{DIRECTION}})) { - $needed->{"push_$_->{TYPE}"} = 1; + $needed->{TypeFunctionName("ejs_push", $_->{TYPE})} = 1; } } } @@ -858,10 +858,8 @@ sub NeededType($$$) foreach (@{$t->{ELEMENTS}}) { next if (has_property($_, "subcontext")); #FIXME: Support subcontexts my $n; - 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; + if (ref($_->{TYPE}) ne "HASH" or defined($_->{TYPE}->{NAME})) { + $needed->{TypeFunctionName("ejs_$req", $_->{TYPE})} = 1; } NeededType($_->{TYPE}, $needed, $req) if (ref($_->{TYPE}) eq "HASH"); } @@ -877,13 +875,25 @@ sub NeededInterface($$) foreach (reverse @{$interface->{TYPES}}) { if (has_property($_, "public")) { - $needed->{"pull_$_->{NAME}"} = not has_property($_, "noejs"); - $needed->{"push_$_->{NAME}"} = not has_property($_, "noejs"); + $needed->{TypeFunctionName("ejs_pull", $_)} = not has_property($_, "noejs"); + $needed->{TypeFunctionName("ejs_push", $_)} = not has_property($_, "noejs"); } - NeededType($_, $needed, "pull") if ($needed->{"pull_$_->{NAME}"}); - NeededType($_, $needed, "push") if ($needed->{"push_$_->{NAME}"}); + NeededType($_, $needed, "pull") if ($needed->{TypeFunctionName("ejs_pull", $_)}); + NeededType($_, $needed, "push") if ($needed->{TypeFunctionName("ejs_push", $_)}); } } +sub TypeFunctionName($$) +{ + my ($prefix, $t) = @_; + + return "$prefix\_$t->{NAME}" if (ref($t) eq "HASH" and + ($t->{TYPE} eq "TYPEDEF" or $t->{TYPE} eq "DECLARE")); + return "$prefix\_$t->{TYPE}_$t->{NAME}" if (ref($t) eq "HASH"); + return "$prefix\_$t"; +} + + + 1; diff --git a/source4/pidl/tests/samba-ejs.pl b/source4/pidl/tests/samba-ejs.pl index 350cba571c..39fc22329c 100755 --- a/source4/pidl/tests/samba-ejs.pl +++ b/source4/pidl/tests/samba-ejs.pl @@ -4,13 +4,13 @@ use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 17; 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); + $res $res_hdr fn_declare TypeFunctionName); is("&foo", get_pointer_to("foo")); is("&(&foo)", get_pointer_to(get_pointer_to("foo"))); @@ -40,3 +40,8 @@ $res_hdr = ""; fn_declare({ PROPERTIES => {} }, "mybla(int foo)"); is($res, "static mybla(int foo)\n"); is($res_hdr, ""); + +is(TypeFunctionName("ejs_pull", "uint32"), "ejs_pull_uint32"); +is(TypeFunctionName("ejs_pull", {TYPE => "ENUM", NAME => "bar"}), "ejs_pull_ENUM_bar"); +is(TypeFunctionName("ejs_pull", {TYPE => "TYPEDEF", NAME => "bar", DATA => undef}), "ejs_pull_bar"); +is(TypeFunctionName("ejs_push", {TYPE => "STRUCT", NAME => "bar"}), "ejs_push_STRUCT_bar"); -- cgit