1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

r10734: Generate ptr, size, offset, and length elements in unions just once.

(This used to be commit 12bfa5d01b)
This commit is contained in:
Jelmer Vernooij 2005-10-05 17:13:29 +00:00 committed by Gerald (Jerry) Carter
parent 5df3b426ee
commit 4bbb584ff0
2 changed files with 30 additions and 12 deletions

View File

@ -15,7 +15,10 @@ use vars qw($VERSION);
$VERSION = '0.01';
my $res = "";
sub pidl($) { my $x = shift; $res .= "$x\n"; }
my $tabs = "";
sub indent() { $tabs.="\t"; }
sub deindent() { $tabs = substr($tabs, 1); }
sub pidl($) { $res .= $tabs.(shift)."\n"; }
sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); }
sub warning($$) { my ($e,$s) = @_; warn("$e->{FILE}:$e->{LINE}: $s\n"); }
@ -101,7 +104,11 @@ sub ParseUnion($$$)
{
my ($if,$u,$n) = @_;
my $extra = {"switch_value" => 1};
my $extra = {};
unless (has_property($u, "nodiscriminant")) {
$extra->{switch_value} = 1;
}
foreach my $e (@{$u->{ELEMENTS}}) {
foreach my $l (@{$e->{LEVELS}}) {
@ -121,10 +128,17 @@ sub ParseUnion($$$)
}
pidl "typedef struct $if->{NAME}_$n\_ctr {";
pidl "\tuint32 $_;" foreach (keys %$extra);
pidl "\tunion {";
ParseElement($_) foreach (@{$u->{ELEMENTS}});
pidl "\t} u;";
indent;
pidl "uint32 $_;" foreach (keys %$extra);
pidl "union {";
indent;
foreach (@{$u->{ELEMENTS}}) {
next if ($_->{TYPE} eq "EMPTY");
pidl "\t" . DeclShort($_) . ";";
}
deindent;
pidl "} u;";
deindent;
pidl "} ".uc("$if->{NAME}_$n\_ctr") .";";
pidl "";
}
@ -185,6 +199,7 @@ sub Parse($$)
my($ndr,$filename) = @_;
$res = "";
$tabs = "";
pidl "/*";
pidl " * Unix SMB/CIFS implementation.";

View File

@ -75,6 +75,7 @@ sub ParseElementLevelArray($$$$$$)
if ($l->{IS_ZERO_TERMINATED}) {
fatal($e, "[string] attribute not supported for Samba3 yet");
#FIXME
}
@ -123,12 +124,6 @@ sub ParseElementLevelSwitch($$$$$$)
{
my ($e,$l,$nl,$env,$varname,$what) = @_;
if ($what == PRIMITIVES) {
pidl "if (!prs_uint32(\"level\", ps, depth, &" . ParseExpr("level_$e->{NAME}", $env) . "))";
pidl "\treturn False;";
pidl "";
}
ParseElementLevel($e,$nl,$env,$varname,$what);
}
@ -353,6 +348,14 @@ sub ParseUnion($$$)
pidl "\treturn False;";
pidl "";
if (has_property($u, "nodiscriminant")) {
pidl "if (!prs_uint32(\"switch_value\", ps, depth, &v->switch_value))";
pidl "\treturn False;";
pidl "";
}
# Maybe check here that level and v->switch_value are equal?
pidl "switch (level) {";
indent;