Rev 11612: Use utility function to determine function names in ejs code. in file:///home/jelmer/bzr.samba/SAMBA_4_0/

Jelmer Vernooij jelmer at samba.org
Wed Feb 28 01:59:21 GMT 2007


At file:///home/jelmer/bzr.samba/SAMBA_4_0/

------------------------------------------------------------
revno: 11612
revision-id: jelmer at samba.org-20070228015909-td0bfe324fsicupz
parent: svn-v2:21578 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: SAMBA_4_0
timestamp: Wed 2007-02-28 02:59:09 +0100
message:
  Use utility function to determine function names in ejs code.
modified:
  source/pidl/lib/Parse/Pidl/Samba4/EJS.pm svn-v2:12463 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fSamba4%2fEJS.pm
  source/pidl/tests/samba-ejs.pl svn-v2:21490 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fsamba%2dejs.pl
=== modified file 'source/pidl/lib/Parse/Pidl/Samba4/EJS.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba4/EJS.pm	2007-02-21 14:35:25 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba4/EJS.pm	2007-02-28 01:59:09 +0000
@@ -9,7 +9,7 @@
 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 @@
 	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 @@
 {
 	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 @@
 	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 @@
 
 	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;

=== modified file 'source/pidl/tests/samba-ejs.pl'
--- a/source/pidl/tests/samba-ejs.pl	2007-02-21 12:35:21 +0000
+++ b/source/pidl/tests/samba-ejs.pl	2007-02-28 01:59:09 +0000
@@ -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 @@
 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");



More information about the samba-cvs mailing list