Rev 11616: Support for tagged types has landed! in file:///home/jelmer/bzr.samba/SAMBA_4_0/

Jelmer Vernooij jelmer at samba.org
Wed Feb 28 13:22:48 GMT 2007


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

------------------------------------------------------------
revno: 11616
revision-id: jelmer at samba.org-20070228132131-0pcf9e2ie5xo4hak
parent: svn-v2:21583 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 14:21:31 +0100
message:
  Support for tagged types has landed!
  
  It's now possible to use "struct foo" without a typedef in IDL files.
  
  echo_info4 is the first type that's been converted.
modified:
  source/librpc/idl/echo.idl     svn-v2:6 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flibrpc%2fidl%2fecho.idl
  source/pidl/README             svn-v2:9459 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2fREADME
  source/pidl/lib/Parse/Pidl/NDR.pm svn-v2:9460 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fNDR.pm
  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/lib/Parse/Pidl/Samba4/Header.pm svn-v2:12463 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fSamba4%2fHeader.pm
  source/pidl/tests/header.pl    svn-v2:21253 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fheader.pl
  source/pidl/tests/ndr.pl       svn-v2:20631 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fndr.pl
  source/pidl/tests/typelist.pl  svn-v2:21437 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2ftypelist.pl
=== modified file 'source/librpc/idl/echo.idl'
--- a/source/librpc/idl/echo.idl	2007-02-21 11:51:51 +0000
+++ b/source/librpc/idl/echo.idl	2007-02-28 13:21:31 +0000
@@ -50,9 +50,9 @@
 		uint32 v;
 	} echo_info3;
 
-	typedef struct {
+	struct echo_info4 {
 		hyper v;
-	} echo_info4;
+	};
 
 	typedef struct {
 		uint8 v1;
@@ -66,14 +66,14 @@
 
 	typedef struct {
 		uint8 v1;
-		echo_info4 info4;
+		struct echo_info4 info4;
 	} echo_info7;
 
 	typedef [switch_type(uint16)] union {
 		[case(1)]  echo_info1 info1;
 		[case(2)]  echo_info2 info2;
 		[case(3)]  echo_info3 info3;
-		[case(4)]  echo_info4 info4;
+		[case(4)]  struct echo_info4 info4;
 		[case(5)]  echo_info5 info5;
 		[case(6)]  echo_info6 info6;
 		[case(7)]  echo_info7 info7;

=== modified file 'source/pidl/README'
--- a/source/pidl/README	2007-02-28 01:51:37 +0000
+++ b/source/pidl/README	2007-02-28 13:21:31 +0000
@@ -4,7 +4,7 @@
 compiler for Samba 4. 
 
 The main sources for pidl are available by Subversion on
-svn://svn.samba.org/samba/branches/SAMBA_4_0/source/pidl
+svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/pidl
 
 Pidl works by building a parse tree from a .pidl file (a simple 
 dump of it's internal parse tree) or a .idl file 

=== modified file 'source/pidl/lib/Parse/Pidl/NDR.pm'
--- a/source/pidl/lib/Parse/Pidl/NDR.pm	2007-02-28 00:28:14 +0000
+++ b/source/pidl/lib/Parse/Pidl/NDR.pm	2007-02-28 13:21:31 +0000
@@ -35,7 +35,7 @@
 $VERSION = '0.01';
 @ISA = qw(Exporter);
 @EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString);
- at EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar);
+ at EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType);
 
 use strict;
 use Parse::Pidl qw(warning fatal);
@@ -499,6 +499,7 @@
 	my ($d, $pointer_default) = @_;
 
 	if ($d->{TYPE} eq "STRUCT" or $d->{TYPE} eq "UNION") {
+		return $d if (not defined($d->{ELEMENTS}));
 		CheckPointerTypes($d, $pointer_default);
 	}
 

=== modified file 'source/pidl/lib/Parse/Pidl/Samba4/EJS.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba4/EJS.pm	2007-02-28 02:01:58 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba4/EJS.pm	2007-02-28 13:21:31 +0000
@@ -426,14 +426,7 @@
 					$var = get_pointer_to($var);
 			}
 
-		my $t;
-		if (ref($e->{TYPE}) eq "HASH") {
-			$t = "$e->{TYPE}->{TYPE}_$e->{TYPE}->{NAME}";
-		} else {
-			$t = $e->{TYPE};
-		}
-
-		pidl "NDR_CHECK(ejs_push_$t(ejs, v, $name, $var));";
+		pidl "NDR_CHECK(".TypeFunctionName("ejs_push", $e->{TYPE})."(ejs, v, $name, $var));";
 	}
 }
 
@@ -619,21 +612,22 @@
 	my ($d, $name) = @_;
 	return if (has_property($d, "noejs"));
 
-	if ($d->{TYPE} eq "TYPEDEF") {
-		EjsTypePushFunction($d->{DATA}, $name);
-		return;
-	}
-
-	if ($d->{TYPE} eq "STRUCT") {
-		fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const struct $name *r)");
-	} elsif ($d->{TYPE} eq "UNION") {
-		fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const union $name *r)");
-	} elsif ($d->{TYPE} eq "ENUM") {
-		fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const enum $name *r)");
-	} elsif ($d->{TYPE} eq "BITMAP") {
-		my($type_decl) = Parse::Pidl::Typelist::mapTypeName($d->{BASE_TYPE});
-		fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const $type_decl *r)");
-	}
+	my $var = undef;
+	my $dt = $d;
+	if ($dt->{TYPE} eq "TYPEDEF") {
+		$dt = $dt->{DATA};
+	}
+	if ($dt->{TYPE} eq "STRUCT") {
+		$var = "const struct $name *r";
+	} elsif ($dt->{TYPE} eq "UNION") {
+		$var = "const union $name *r";
+	} elsif ($dt->{TYPE} eq "ENUM") {
+		$var = "const enum $name *r";
+	} elsif ($dt->{TYPE} eq "BITMAP") {
+		my($type_decl) = Parse::Pidl::Typelist::mapTypeName($dt->{BASE_TYPE});
+		$var = "const $type_decl *r";
+	}
+	fn_declare($d, "NTSTATUS ".TypeFunctionName("ejs_push", $d) . "(struct ejs_rpc *ejs, struct MprVar *v, const char *name, $var)");
 	pidl "{";
 	indent;
 	EjsTypePush($d, "r");
@@ -644,6 +638,7 @@
 
 sub EjsTypePush($$)
 {
+	sub EjsTypePush($$);
 	my ($d, $varname) = @_;
 
 	if ($d->{TYPE} eq 'STRUCT') {
@@ -654,6 +649,8 @@
 		EjsEnumPush($d, $varname);
 	} elsif ($d->{TYPE} eq 'BITMAP') {
 		EjsBitmapPush($d, $varname);
+	} elsif ($d->{TYPE} eq 'TYPEDEF') {
+		EjsTypePush($d->{DATA}, $varname);
 	} else {
 		warn "Unhandled push $varname of type $d->{TYPE}";
 	}
@@ -677,8 +674,7 @@
 	}
 
 	if ($d->{RETURN_TYPE}) {
-		my $t = $d->{RETURN_TYPE};
-		pidl "NDR_CHECK(ejs_push_$t(ejs, v, \"result\", &r->out.result));";
+		pidl "NDR_CHECK(".TypeFunctionName("ejs_push", $d->{RETURN_TYPE})."(ejs, v, \"result\", &r->out.result));";
 	}
 
 	pidl "return NT_STATUS_OK;";

=== modified file 'source/pidl/lib/Parse/Pidl/Samba4/Header.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba4/Header.pm	2007-02-21 14:35:25 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba4/Header.pm	2007-02-28 13:21:31 +0000
@@ -57,7 +57,11 @@
 	if (has_property($element, "represent_as")) {
 		pidl mapTypeName($element->{PROPERTIES}->{represent_as})." ";
 	} else {
-		HeaderType($element, $element->{TYPE}, "");
+		if (ref($element->{TYPE}) eq "HASH") {
+			HeaderType($element, $element->{TYPE}, $element->{TYPE}->{NAME});
+		} else {
+			HeaderType($element, $element->{TYPE}, "");
+		}
 		pidl " ";
 		my $numstar = $element->{POINTERS};
 		if ($numstar >= 1) {
@@ -90,14 +94,14 @@
 sub HeaderStruct($$)
 {
     my($struct,$name) = @_;
-	pidl "struct $name {\n";
+	pidl "struct $name";
+    return if (not defined($struct->{ELEMENTS}));
+	pidl " {\n";
     $tab_depth++;
     my $el_count=0;
-    if (defined $struct->{ELEMENTS}) {
-		foreach (@{$struct->{ELEMENTS}}) {
-		    HeaderElement($_);
-		    $el_count++;
-		}
+	foreach (@{$struct->{ELEMENTS}}) {
+		HeaderElement($_);
+		$el_count++;
     }
     if ($el_count == 0) {
 	    # some compilers can't handle empty structures
@@ -174,7 +178,9 @@
 	my($union,$name) = @_;
 	my %done = ();
 
-	pidl "union $name {\n";
+	pidl "union $name";
+	return if (not defined($union->{ELEMENTS}));
+	pidl " {\n";
 	$tab_depth++;
 	foreach my $e (@{$union->{ELEMENTS}}) {
 		if ($e->{TYPE} ne "EMPTY") {

=== modified file 'source/pidl/tests/header.pl'
--- a/source/pidl/tests/header.pl	2007-02-18 16:21:28 +0000
+++ b/source/pidl/tests/header.pl	2007-02-28 13:21:31 +0000
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 12;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
@@ -36,3 +36,9 @@
 like(parse_idl("interface x { void foo (uint32 x); };"), qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} in;\s+struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn with no props implies in,out");
 like(parse_idl("interface p { struct x { int y; }; };"),
      qr/struct x.*{.*int32_t y;.*}.*;/sm, "interface member generated properly");
+
+like(parse_idl("interface p { struct x { struct y z; }; };"),
+     qr/struct x.*{.*struct y z;.*}.*;/sm, "tagged type struct member");
+
+like(parse_idl("interface p { struct x { union y z; }; };"),
+     qr/struct x.*{.*union y z;.*}.*;/sm, "tagged type union member");

=== modified file 'source/pidl/tests/ndr.pl'
--- a/source/pidl/tests/ndr.pl	2007-02-28 00:28:14 +0000
+++ b/source/pidl/tests/ndr.pl	2007-02-28 13:21:31 +0000
@@ -4,12 +4,12 @@
 use strict;
 use warnings;
 
-use Test::More tests => 25;
+use Test::More tests => 26;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
 use Parse::Pidl::Util qw(MyDumper);
-use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement align_type mapToScalar);
+use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement align_type mapToScalar ParseType);
 
 # Case 1
 
@@ -224,3 +224,6 @@
 is(mapToScalar({TYPE => "BITMAP", PROPERTIES => { bitmap64bit => 1 } }),
 	"hyper");
 is(mapToScalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM", PARENT => { PROPERTIES => { enum8bit => 1 } } }}), "uint8");
+
+is_deeply(ParseType({TYPE => "STRUCT", NAME => "foo" }, "ref"), 
+	{TYPE => "STRUCT", NAME => "foo" });

=== modified file 'source/pidl/tests/typelist.pl'
--- a/source/pidl/tests/typelist.pl	2007-02-28 00:35:21 +0000
+++ b/source/pidl/tests/typelist.pl	2007-02-28 13:21:31 +0000
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 52;
+use Test::More tests => 53;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
@@ -60,6 +60,7 @@
 
 is(1, scalar_is_reference("string"));
 is(0, scalar_is_reference("uint32"));
+is(0, scalar_is_reference({TYPE => "STRUCT", NAME => "echo_foobar"}));
 
 is("uint8", enum_type_fn({TYPE => "ENUM", PARENT=>{PROPERTIES => {enum8bit => 1}}}));
 is("uint32", enum_type_fn({TYPE => "ENUM", PARENT=>{PROPERTIES => {v1_enum => 1}}}));



More information about the samba-cvs mailing list