pidl: Add function for determining whether a type has a body.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 12 Jan 2008 22:10:28 +0000 (23:10 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 12 Jan 2008 22:10:28 +0000 (23:10 +0100)
(This used to be commit 893f4102c93c1c2cd6b836f12644d06d9e31800c)

source4/pidl/lib/Parse/Pidl/NDR.pm
source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
source4/pidl/lib/Parse/Pidl/Typelist.pm
source4/pidl/tests/ndr.pl
source4/pidl/tests/typelist.pl

index 80ecec938aad694765229a1ce86737b70a8f7713..1d059ebdf797d8d7c9ab176b11b653c81f230cf4 100644 (file)
@@ -633,7 +633,7 @@ sub FindNestedTypes($$)
        sub FindNestedTypes($$);
        my ($l, $t) = @_;
 
-       return if not defined($t->{ELEMENTS});
+       return unless defined($t->{ELEMENTS});
        return if ($t->{TYPE} eq "ENUM");
        return if ($t->{TYPE} eq "BITMAP");
 
index abbfe2259b5290fd1b4bae088a81587f3f22d4e3..cfd16c7b409dfd18dbf4698c3b44f34922c5f00f 100644 (file)
@@ -12,7 +12,7 @@ require Exporter;
 @EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv NeededFunction NeededElement NeededType $res NeededInterface TypeFunctionName ParseElementPrint);
 
 use strict;
-use Parse::Pidl::Typelist qw(hasType getType mapTypeName);
+use Parse::Pidl::Typelist qw(hasType getType mapTypeName typeHasBody);
 use Parse::Pidl::Util qw(has_property ParseExpr ParseExprExt print_uuid);
 use Parse::Pidl::CUtil qw(get_pointer_to get_value_of);
 use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
@@ -2543,6 +2543,7 @@ sub ParseInterface($$$)
 
        # Typedefs
        foreach my $d (@{$interface->{TYPES}}) {
+               next unless typeHasBody($d);
                ($needed->{TypeFunctionName("ndr_push", $d)}) && $self->ParseTypePushFunction($d, "r");
                ($needed->{TypeFunctionName("ndr_pull", $d)}) && $self->ParseTypePullFunction($d, "r");
                ($needed->{TypeFunctionName("ndr_print", $d)}) && $self->ParseTypePrintFunction($d, "r");
index 3721800b970e780ab54ae1b219145e6a7436187f..aad0cf426c8e4a4ede8a92e4d7615d47cc248897 100644 (file)
@@ -9,7 +9,7 @@ require Exporter;
 @ISA = qw(Exporter);
 @EXPORT_OK = qw(hasType getType mapTypeName scalar_is_reference expandAlias
                            mapScalarType addType typeIs is_scalar enum_type_fn
-                               bitmap_type_fn mapType
+                               bitmap_type_fn mapType typeHasBody
 );
 use vars qw($VERSION);
 $VERSION = '0.01';
@@ -207,6 +207,19 @@ sub bitmap_type_fn($)
        return "uint32";
 }
 
+sub typeHasBody($)
+{
+       sub typeHasBody($);
+       my ($e) = @_;
+
+       if ($e->{TYPE} eq "TYPEDEF") {
+               return 0 unless(defined($e->{DATA}));
+               return typeHasBody($e->{DATA});
+       }
+
+       return defined($e->{ELEMENTS});
+}
+
 sub mapType($$)
 {
        sub mapType($$);
index 09f1d4969babe44430f2c1fbdffd2d08200cf3e6..ba7fef361b7b25f0af67311587c150436cda0c6b 100755 (executable)
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 37;
+use Test::More tests => 39;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
@@ -275,3 +275,7 @@ ok(not can_contain_deferred({ TYPE => "TYPEDEF",
                ELEMENTS => [ { TYPE => "uint32" } ]}}));
 ok(can_contain_deferred({ TYPE => "STRUCT", 
                ELEMENTS => [ { TYPE => "someunknowntype" } ]}));
+# Make sure the elements for a enum without body aren't filled in
+ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, "ref")->{ELEMENTS}));
+# Make sure the elements for a bitmap without body aren't filled in
+ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, "ref")->{ELEMENTS}));
index 90cb853a5256291578b849d0b8921abe9e634a5b..54f4d345865d2d82bb04bfa5a735539b895977dd 100755 (executable)
@@ -4,11 +4,11 @@
 use strict;
 use warnings;
 
-use Test::More tests => 52;
+use Test::More tests => 54;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
-use Parse::Pidl::Typelist qw(hasType getType mapTypeName expandAlias
+use Parse::Pidl::Typelist qw(hasType typeHasBody getType mapTypeName expandAlias
        mapScalarType addType typeIs is_scalar scalar_is_reference
        enum_type_fn bitmap_type_fn mapType);
 
@@ -80,3 +80,6 @@ is("uint32_t", mapType({TYPE => "TYPEDEF", DATA => {TYPE => "SCALAR"}}, "uint32"
 is("void", mapTypeName(undef));
 is("uint32_t", mapTypeName("uint32"));
 is("int32_t", mapTypeName("int"));
+
+ok(not typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT" }}));
+ok(typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT", ELEMENTS => [] }}));