1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-28 01:58:17 +03:00

r10732: Generate _ctr structures for unions

(This used to be commit bd8fcb05003ad75f521783ad9603c923eacafc1a)
This commit is contained in:
Jelmer Vernooij 2005-10-05 14:52:35 +00:00 committed by Gerald (Jerry) Carter
parent 7838e13e91
commit 5df3b426ee
3 changed files with 65 additions and 8 deletions

View File

@ -101,10 +101,31 @@ sub ParseUnion($$$)
{
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 "";
}

View File

@ -73,6 +73,11 @@ sub ParseElementLevelArray($$$$$$)
{
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 @@ sub ParseStruct($$$)
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 @@ sub ParseUnion($$$)
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 @@ sub ParseUnion($$$)
indent;
if ($_->{TYPE} ne "EMPTY") {
pidl "depth++;";
my $env = {};
GenerateEnvElement($_, $env);
my $env = UnionGenerateEnvElement($_);
ParseElement($_, $env, DEFERRED);
pidl "depth--;";
}

View File

@ -184,6 +184,15 @@ my $known_types =
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 @@ sub LoadTypes($)
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 @@ sub LoadTypes($)
my $dissect_d;
my $dissect_p;
if ($td->{DATA}->{TYPE} eq "UNION") {
$decl.="_CTR";
$dissect_p = sub {
my ($e,$l,$n,$w,$s) = @_;