summaryrefslogtreecommitdiff
path: root/source4/pidl
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-10-05 14:52:35 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:39:25 -0500
commit5df3b426ee691adaaaa65424aa2cee22dcc10607 (patch)
tree880508a1ec2edf0d3650577e180990bf2c9fbdca /source4/pidl
parent7838e13e917041fa3786eaa442765ab88b9f0039 (diff)
downloadsamba-5df3b426ee691adaaaa65424aa2cee22dcc10607.tar.gz
samba-5df3b426ee691adaaaa65424aa2cee22dcc10607.tar.bz2
samba-5df3b426ee691adaaaa65424aa2cee22dcc10607.zip
r10732: Generate _ctr structures for unions
(This used to be commit bd8fcb05003ad75f521783ad9603c923eacafc1a)
Diffstat (limited to 'source4/pidl')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/Header.pm27
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm35
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/Types.pm11
3 files changed, 65 insertions, 8 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm
index 5b7fddc14f..6254abaa2d 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm
@@ -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 "";
}
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm
index 702835c378..49c7cf5e81 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm
@@ -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--;";
}
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm
index 9a7a31a6bb..38e740189b 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm
@@ -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) = @_;