Rev 11608: Remove more code that assumed all types are typedefs. in file:///home/jelmer/bzr.samba/SAMBA_4_0/

Jelmer Vernooij jelmer at samba.org
Wed Feb 28 00:16:39 GMT 2007


At file:///home/jelmer/bzr.samba/SAMBA_4_0/

------------------------------------------------------------
revno: 11608
revision-id: jelmer at samba.org-20070228001632-63x0t6c7cyowj18c
parent: svn-v2:21572 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: SAMBA_4_0
timestamp: Wed 2007-02-28 01:16:32 +0100
message:
  Remove more code that assumed all types are typedefs.
modified:
  source/pidl/lib/Parse/Pidl/NDR.pm svn-v2:9460 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fNDR.pm
  source/pidl/lib/Parse/Pidl/Typelist.pm svn-v2:9460 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fTypelist.pm
  source/pidl/tests/ndr.pl       svn-v2:20631 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fndr.pl
  source/pidl/tests/typelist.pl  svn-v2:21437 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2ftypelist.pl
=== modified file 'source/pidl/lib/Parse/Pidl/NDR.pm'
--- a/source/pidl/lib/Parse/Pidl/NDR.pm	2007-02-27 23:47:07 +0000
+++ b/source/pidl/lib/Parse/Pidl/NDR.pm	2007-02-28 00:16:32 +0000
@@ -35,7 +35,7 @@
 $VERSION = '0.01';
 @ISA = qw(Exporter);
 @EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString);
- at EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type);
+ at EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar);
 
 use strict;
 use Parse::Pidl qw(warning fatal);
@@ -880,17 +880,19 @@
 
 sub mapToScalar($)
 {
+	sub mapToScalar($);
 	my $t = shift;
+	return $t->{NAME} if (ref($t) eq "HASH" and $t->{TYPE} eq "SCALAR");
 	my $ti = getType($t);
 
 	if (not defined ($ti)) {
 		return undef;
-	} elsif ($ti->{DATA}->{TYPE} eq "ENUM") {
-		return Parse::Pidl::Typelist::enum_type_fn($ti->{DATA});
-	} elsif ($ti->{DATA}->{TYPE} eq "BITMAP") {
-		return Parse::Pidl::Typelist::enum_type_fn($ti->{DATA});
-	} elsif ($ti->{DATA}->{TYPE} eq "SCALAR") {
-		return $t;
+	} elsif ($ti->{TYPE} eq "TYPEDEF") {
+		return mapToScalar($ti->{DATA});
+	} elsif ($ti->{TYPE} eq "ENUM") {
+		return Parse::Pidl::Typelist::enum_type_fn($ti);
+	} elsif ($ti->{TYPE} eq "BITMAP") {
+		return Parse::Pidl::Typelist::bitmap_type_fn($ti);
 	}
 
 	return undef;

=== modified file 'source/pidl/lib/Parse/Pidl/Typelist.pm'
--- a/source/pidl/lib/Parse/Pidl/Typelist.pm	2007-02-27 23:47:07 +0000
+++ b/source/pidl/lib/Parse/Pidl/Typelist.pm	2007-02-28 00:16:32 +0000
@@ -107,8 +107,13 @@
 sub typeIs($$)
 {
 	my ($t,$tt) = @_;
-
-	return 1 if (hasType($t) and getType($t)->{DATA}->{TYPE} eq $tt);
+	
+	if (ref($t) eq "HASH") {
+		return 1 if ($t->{TYPE} eq $tt);
+		return 0;
+	}
+	return 1 if (hasType($t) and getType($t)->{TYPE} eq "TYPEDEF" and 
+		         getType($t)->{DATA}->{TYPE} eq $tt);
 	return 0;
 }
 
@@ -116,6 +121,7 @@
 {
 	my $t = shift;
 	if (ref($t) eq "HASH") {
+		return 1 if (not defined($t->{NAME}));
 		return 1 if (defined($types{$t->{NAME}}) and 
 			$types{$t->{NAME}}->{TYPE} eq $t->{TYPE});
 		return 0;
@@ -128,10 +134,12 @@
 {
 	my $type = shift;
 
-	return 0 unless(hasType($type));
+	return 1 if (ref($type) eq "HASH" and $type->{TYPE} eq "SCALAR");
 
-	if (my $dt = getType($type)->{DATA}->{TYPE}) {
-		return 1 if ($dt eq "SCALAR" or $dt eq "ENUM" or $dt eq "BITMAP");
+	if (my $dt = getType($type)) {
+		return is_scalar($dt->{DATA}) if ($dt->{TYPE} eq "TYPEDEF");
+		return 1 if ($dt->{TYPE} eq "SCALAR" or $dt->{TYPE} eq "ENUM" or 
+			         $dt->{TYPE} eq "BITMAP");
 	}
 
 	return 0;

=== modified file 'source/pidl/tests/ndr.pl'
--- a/source/pidl/tests/ndr.pl	2007-02-27 23:47:07 +0000
+++ b/source/pidl/tests/ndr.pl	2007-02-28 00:16:32 +0000
@@ -4,12 +4,12 @@
 use strict;
 use warnings;
 
-use Test::More tests => 17;
+use Test::More tests => 22;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
 use Parse::Pidl::Util qw(MyDumper);
-use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement align_type);
+use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement align_type mapToScalar);
 
 # Case 1
 
@@ -211,3 +211,10 @@
 			    ELEMENTS => [ { TYPE => "uint16" } ] }), 4);
 is(align_type({ TYPE => "STRUCT", "NAME" => "bla", 
 			    ELEMENTS => [ { TYPE => "uint8" } ] }), 4);
+
+is(mapToScalar("someverymuchnotexistingtype"), undef);
+is(mapToScalar("uint32"), "uint32");
+is(mapToScalar({TYPE => "ENUM", PARENT => { PROPERTIES => { enum8bit => 1 } } }), "uint8");
+is(mapToScalar({TYPE => "BITMAP", PROPERTIES => { bitmap64bit => 1 } }),
+	"hyper");
+is(mapToScalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM", PARENT => { PROPERTIES => { enum8bit => 1 } } }}), "uint8");

=== modified file 'source/pidl/tests/typelist.pl'
--- a/source/pidl/tests/typelist.pl	2007-02-27 23:47:07 +0000
+++ b/source/pidl/tests/typelist.pl	2007-02-28 00:16:32 +0000
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 38;
+use Test::More tests => 50;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
@@ -34,14 +34,27 @@
 		DATA => { NAME => "uint16", TYPE => "SCALAR" }});
 
 is(0, typeIs("someUnknownType", "ENUM"));
+is(0, typeIs("foo", "ENUM"));
+addType({NAME => "mytypedef", TYPE => "TYPEDEF", DATA => { TYPE => "ENUM" }});
+is(1, typeIs("mytypedef", "ENUM"));
+is(0, typeIs("mytypedef", "BITMAP"));
+is(1, typeIs({ TYPE => "ENUM"}, "ENUM"));
+is(0, typeIs({ TYPE => "BITMAP"}, "ENUM"));
+is(1, typeIs("uint32", "SCALAR"));
+is(0, typeIs("uint32", "ENUM"));
 
 is(1, hasType("foo"));
 is(0, hasType("nonexistant"));
 is(0, hasType({TYPE => "ENUM", NAME => "someUnknownType"}));
 is(1, hasType({TYPE => "ENUM", NAME => "foo"}));
+is(1, hasType({TYPE => "ENUM"}));
+is(1, hasType({TYPE => "STRUCT"}));
 
 is(1, is_scalar("uint32"));
 is(0, is_scalar("nonexistant"));
+is(1, is_scalar({TYPE => "ENUM"}));
+is(0, is_scalar({TYPE => "STRUCT"}));
+is(1, is_scalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM" }}));
 
 is(1, scalar_is_reference("string"));
 is(0, scalar_is_reference("uint32"));



More information about the samba-cvs mailing list