svn commit: samba r10732 - in branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3: .

jelmer at samba.org jelmer at samba.org
Wed Oct 5 14:52:37 GMT 2005


Author: jelmer
Date: 2005-10-05 14:52:35 +0000 (Wed, 05 Oct 2005)
New Revision: 10732

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=10732

Log:
Generate _ctr structures for unions

Modified:
   branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Header.pm
   branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Parser.pm
   branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Types.pm


Changeset:
Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Header.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Header.pm	2005-10-05 14:19:23 UTC (rev 10731)
+++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Header.pm	2005-10-05 14:52:35 UTC (rev 10732)
@@ -101,10 +101,31 @@
 {
 	my ($if,$u,$n) = @_;
 
-	pidl "typedef union $if->{NAME}_$n {";
-	#FIXME: What about elements that require more then one variable?
+	my $extra = {"switch_value" => 1};
+
+	foreach my $e (@{$u->{ELEMENTS}}) {
+		foreach my $l (@{$e->{LEVELS}}) {
+			if ($l->{TYPE} eq "ARRAY") {
+				if ($l->{IS_CONFORMANT}) {
+					$extra->{"size"} = 1;
+				}
+				if ($l->{IS_VARYING}) {
+					$extra->{"length"} = $extra->{"offset"} = 1;
+				}
+			} elsif ($l->{TYPE} eq "POINTER") {
+				$extra->{"ptr"} = 1;
+			} elsif ($l->{TYPE} eq "SWITCH") {
+				$extra->{"level"} = 1;
+			}
+		}
+	}
+
+	pidl "typedef struct $if->{NAME}_$n\_ctr {";
+	pidl "\tuint32 $_;" foreach (keys %$extra);
+	pidl "\tunion {";
 	ParseElement($_) foreach (@{$u->{ELEMENTS}});
-	pidl "} ".uc($if->{NAME}."_".$n) .";";
+	pidl "\t} u;";
+	pidl "} ".uc("$if->{NAME}_$n\_ctr") .";";
 	pidl "";
 }
 

Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Parser.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Parser.pm	2005-10-05 14:19:23 UTC (rev 10731)
+++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Parser.pm	2005-10-05 14:52:35 UTC (rev 10732)
@@ -73,6 +73,11 @@
 {
 	my ($e,$l,$nl,$env,$varname,$what) = @_;
 
+	if ($l->{IS_ZERO_TERMINATED}) {
+		fatal($e, "[string] attribute not supported for Samba3 yet");
+		#FIXME
+	}
+
 	my $len = ParseExpr($l->{LENGTH_IS}, $env);
 	my $size = ParseExpr($l->{SIZE_IS}, $env);
 
@@ -308,12 +313,34 @@
 	pidl "";
 }
 
+sub UnionGenerateEnvElement($)
+{
+	my $e = shift;
+	my $env = {};
+
+	foreach my $l (@{$e->{LEVELS}}) {
+		if ($l->{TYPE} eq "DATA") {
+			$env->{$e->{NAME}} = "v->u.$e->{NAME}";
+		} elsif ($l->{TYPE} eq "POINTER") {
+			$env->{"ptr_$e->{NAME}"} = "v->ptr";
+		} elsif ($l->{TYPE} eq "SWITCH") {
+			$env->{"level_$e->{NAME}"} = "v->level";
+		} elsif ($l->{TYPE} eq "ARRAY") {
+			$env->{"length_$e->{NAME}"} = "v->length";
+			$env->{"size_$e->{NAME}"} = "v->size";
+			$env->{"offset_$e->{NAME}"} = "v->offset";
+		}
+	}
+
+	return $env;
+}
+
 sub ParseUnion($$$)
 {
 	my ($if,$u,$n) = @_;
 
 	my $fn = "$if->{NAME}_io_$n";
-	my $sn = uc("$if->{NAME}_$n");
+	my $sn = uc("$if->{NAME}_$n\_ctr");
 
 	my $pfn = "$fn\_p";
 	my $dfn = "$fn\_d";
@@ -334,8 +361,7 @@
 		indent;
 		if ($_->{TYPE} ne "EMPTY") {
 			pidl "depth++;";
-			my $env = {};
-			GenerateEnvElement($_, $env);
+			my $env = UnionGenerateEnvElement($_);
 			ParseElement($_, $env, PRIMITIVES); 
 			ParseElement($_, $env, DEFERRED); 
 			pidl "depth--;";
@@ -368,8 +394,7 @@
 		indent;
 		if ($_->{TYPE} ne "EMPTY") {
 			pidl "depth++;";
-			my $env = {};
-			GenerateEnvElement($_, $env);
+			my $env = UnionGenerateEnvElement($_);
 			ParseElement($_, $env, DEFERRED); 
 			pidl "depth--;";
 		}

Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Types.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Types.pm	2005-10-05 14:19:23 UTC (rev 10731)
+++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba3/Types.pm	2005-10-05 14:52:35 UTC (rev 10732)
@@ -184,6 +184,15 @@
 			return "smb_io_pol_hnd(\"$e->{NAME}\", &n, ps, depth)";
 		}
 	},
+	hyper => 
+	{
+		DECL => "uint64",
+		INIT => "",
+		DISSECT_P => sub {
+			my ($e,$l,$n) = @_;
+			return "prs_uint64(\"$e->{NAME}\", ps, depth, &$n)";
+		}
+	},
 };
 
 sub AddType($$)
@@ -335,6 +344,7 @@
 
 		foreach my $td (@{$if->{TYPEDEFS}}) {
 			my $decl = uc("$if->{NAME}_$td->{NAME}");
+
 			my $init = sub {
 					my ($e,$l,$n,$v) = @_;
 					return "$n = $v;";
@@ -343,6 +353,7 @@
 			my $dissect_d;
 			my $dissect_p;
 			if ($td->{DATA}->{TYPE} eq "UNION") {
+				$decl.="_CTR";
 				 $dissect_p = sub {
 					my ($e,$l,$n,$w,$s) = @_;
 



More information about the samba-cvs mailing list