summaryrefslogtreecommitdiff
path: root/source4/build/pidl
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-02-20 20:35:07 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:10:49 -0500
commit73477e05dec40e44f78a8673f79b627e904fd696 (patch)
tree4a97be690e5fb2ded0179012041d03a2dff4024f /source4/build/pidl
parent595228c4c3a724e8ed257f78d48e24f6575cd366 (diff)
downloadsamba-73477e05dec40e44f78a8673f79b627e904fd696.tar.gz
samba-73477e05dec40e44f78a8673f79b627e904fd696.tar.bz2
samba-73477e05dec40e44f78a8673f79b627e904fd696.zip
r5475: Move some existing and new type information functions to typelist.pm
(This used to be commit 280df525380d06d67ce33938c4760807d5466966)
Diffstat (limited to 'source4/build/pidl')
-rw-r--r--source4/build/pidl/header.pm38
-rw-r--r--source4/build/pidl/ndr.pm36
-rw-r--r--source4/build/pidl/typelist.pm84
-rw-r--r--source4/build/pidl/util.pm75
4 files changed, 108 insertions, 125 deletions
diff --git a/source4/build/pidl/header.pm b/source4/build/pidl/header.pm
index efcd2dbb45..803916a79c 100644
--- a/source4/build/pidl/header.pm
+++ b/source4/build/pidl/header.pm
@@ -60,8 +60,7 @@ sub HeaderElement($)
pidl tabs();
HeaderType($element, $element->{TYPE}, "");
pidl " ";
- if ($element->{POINTERS} &&
- $element->{TYPE} ne "string") {
+ if ($element->{POINTERS} && $element->{TYPE} ne "string") {
my($n) = $element->{POINTERS};
for (my($i)=$n; $i > 0; $i--) {
pidl "*";
@@ -91,10 +90,10 @@ sub HeaderStruct($$)
$tab_depth++;
my $el_count=0;
if (defined $struct->{ELEMENTS}) {
- foreach my $e (@{$struct->{ELEMENTS}}) {
- HeaderElement($e);
- $el_count++;
- }
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ HeaderElement($e);
+ $el_count++;
+ }
}
if ($el_count == 0) {
# some compilers can't handle empty structures
@@ -195,30 +194,7 @@ sub HeaderType($$$)
return;
}
- my $dt;
- if (my $t = typelist::getType($e->{TYPE})) {
- $dt = $t->{DATA};
- }
-
- if ($data =~ "string") {
- pidl "const char *";
- } elsif (not defined($dt->{TYPE})) {
- pidl "struct $data";
- } else {
- if ($dt->{TYPE} eq "ENUM") {
- pidl "enum $data";
- } elsif ($dt->{TYPE} eq "BITMAP") {
- pidl util::bitmap_type_decl($dt);
- } elsif ($dt->{TYPE} eq "SCALAR") {
- pidl util::map_type($data);
- } elsif ($dt->{TYPE} eq "UNION") {
- pidl "union $data";
- } elsif ($dt->{TYPE} eq "STRUCT") {
- pidl "struct $data";
- } else {
- print "Unknown data type type $dt->{TYPE}\n";
- }
- }
+ pidl typelist::mapType($e);
}
#####################################################################
@@ -334,7 +310,7 @@ sub HeaderFunction($)
HeaderFunctionInOut($fn, "out");
if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
tabs();
- pidl util::map_type($fn->{RETURN_TYPE}) . " result;\n";
+ pidl typelist::mapScalarType($fn->{RETURN_TYPE}) . " result;\n";
}
$tab_depth--;
tabs();
diff --git a/source4/build/pidl/ndr.pm b/source4/build/pidl/ndr.pm
index df756e2f30..185067e526 100644
--- a/source4/build/pidl/ndr.pm
+++ b/source4/build/pidl/ndr.pm
@@ -716,13 +716,13 @@ sub ParseElementPullSwitch($$$$)
if (!defined $utype ||
!util::has_property($utype, "nodiscriminant")) {
my $e2 = find_sibling($e, $switch);
- my $type_decl = util::map_type($e2->{TYPE});
+ my $type_decl = typelist::mapType($e2);
pidl "if (($ndr_flags) & NDR_SCALARS) {";
indent;
if (typelist::getType($e2->{TYPE})->{DATA}->{TYPE} eq "ENUM") {
- $type_decl = util::enum_type_decl($e2);
+ $type_decl = typelist::mapType($e2);
} elsif (typelist::getType($e2->{TYPE})->{DATA}->{TYPE} eq "BITMAP") {
- $type_decl = util::bitmap_type_decl($e2);
+ $type_decl = typelist::mapType($e2);
}
pidl "$type_decl _level;";
pidl "NDR_CHECK(ndr_pull_$e2->{TYPE}(ndr, NDR_SCALARS, &_level));";
@@ -1022,7 +1022,7 @@ sub ParseStructPush($)
sub ParseEnumPush($)
{
my($enum) = shift;
- my($type_fn) = util::enum_type_fn($enum);
+ my($type_fn) = typelist::enum_type_fn($enum);
start_flags($enum);
@@ -1036,8 +1036,8 @@ sub ParseEnumPush($)
sub ParseEnumPull($)
{
my($enum) = shift;
- my($type_fn) = util::enum_type_fn($enum);
- my($type_v_decl) = util::map_type(util::enum_type_fn($enum));
+ my($type_fn) = typelist::enum_type_fn($enum);
+ my($type_v_decl) = typelist::mapScalarType(typelist::enum_type_fn($enum));
pidl "$type_v_decl v;";
start_flags($enum);
@@ -1103,7 +1103,7 @@ $typefamily{ENUM} = {
PULL_FN_ARGS => \&ArgsEnumPull,
PRINT_FN_BODY => \&ParseEnumPrint,
PRINT_FN_ARGS => \&ArgsEnumPrint,
- ALIGN => sub { return align_type(util::enum_type_fn(shift)); }
+ ALIGN => sub { return align_type(typelist::enum_type_fn(shift)); }
};
#####################################################################
@@ -1111,7 +1111,7 @@ $typefamily{ENUM} = {
sub ParseBitmapPush($)
{
my($bitmap) = shift;
- my($type_fn) = util::bitmap_type_fn($bitmap);
+ my($type_fn) = typelist::bitmap_type_fn($bitmap);
start_flags($bitmap);
@@ -1125,8 +1125,8 @@ sub ParseBitmapPush($)
sub ParseBitmapPull($)
{
my($bitmap) = shift;
- my($type_fn) = util::bitmap_type_fn($bitmap);
- my($type_decl) = util::bitmap_type_decl($bitmap);
+ my($type_fn) = typelist::bitmap_type_fn($bitmap);
+ my($type_decl) = typelist::mapType($bitmap);
pidl "$type_decl v;";
start_flags($bitmap);
@@ -1142,8 +1142,8 @@ sub ParseBitmapPrintElement($$)
{
my($e) = shift;
my($bitmap) = shift;
- my($type_decl) = util::bitmap_type_decl($bitmap);
- my($type_fn) = util::bitmap_type_fn($bitmap);
+ my($type_decl) = typelist::mapType($bitmap);
+ my($type_fn) = typelist::bitmap_type_fn($bitmap);
my($name) = $bitmap->{PARENT}->{NAME};
my($flag);
@@ -1161,8 +1161,8 @@ sub ParseBitmapPrintElement($$)
sub ParseBitmapPrint($)
{
my($bitmap) = shift;
- my($type_decl) = util::bitmap_type_decl($bitmap);
- my($type_fn) = util::bitmap_type_fn($bitmap);
+ my($type_decl) = typelist::mapType($bitmap);
+ my($type_fn) = typelist::bitmap_type_fn($bitmap);
start_flags($bitmap);
@@ -1180,21 +1180,21 @@ sub ParseBitmapPrint($)
sub ArgsBitmapPush($)
{
my $e = shift;
- my $type_decl = util::bitmap_type_decl($e->{DATA});
+ my $type_decl = typelist::mapType($e->{DATA});
return "struct ndr_push *ndr, int ndr_flags, $type_decl r";
}
sub ArgsBitmapPrint($)
{
my $e = shift;
- my $type_decl = util::bitmap_type_decl($e->{DATA});
+ my $type_decl = typelist::mapType($e->{DATA});
return "struct ndr_print *ndr, const char *name, $type_decl r";
}
sub ArgsBitmapPull($)
{
my $e = shift;
- my $type_decl = util::bitmap_type_decl($e->{DATA});
+ my $type_decl = typelist::mapType($e->{DATA});
return "struct ndr_pull *ndr, int ndr_flags, $type_decl *r";
}
@@ -1205,7 +1205,7 @@ $typefamily{BITMAP} = {
PULL_FN_ARGS => \&ArgsBitmapPull,
PRINT_FN_BODY => \&ParseBitmapPrint,
PRINT_FN_ARGS => \&ArgsBitmapPrint,
- ALIGN => sub { return align_type(util::bitmap_type_fn(shift)); }
+ ALIGN => sub { return align_type(typelist::bitmap_type_fn(shift)); }
};
#####################################################################
diff --git a/source4/build/pidl/typelist.pm b/source4/build/pidl/typelist.pm
index e5d6a81355..66a8a41dd2 100644
--- a/source4/build/pidl/typelist.pm
+++ b/source4/build/pidl/typelist.pm
@@ -7,7 +7,7 @@ package typelist;
use strict;
-my %typedefs;
+my %typedefs = ();
sub addType($)
{
@@ -51,6 +51,88 @@ sub RegisterPrimitives()
}
}
+sub enum_type_fn($)
+{
+ my $enum = shift;
+ if (util::has_property($enum->{PARENT}, "enum8bit")) {
+ return "uint8";
+ } elsif (util::has_property($enum->{PARENT}, "v1_enum")) {
+ return "uint32";
+ }
+ return "uint16";
+}
+
+sub bitmap_type_fn($)
+{
+ my $bitmap = shift;
+
+ if (util::has_property($bitmap, "bitmap8bit")) {
+ return "uint8";
+ } elsif (util::has_property($bitmap, "bitmap16bit")) {
+ return "uint16";
+ } elsif (util::has_property($bitmap, "bitmap64bit")) {
+ return "uint64";
+ }
+ return "uint32";
+}
+
+# provide mappings between IDL base types and types in our headers
+my %scalar_type_mappings =
+ (
+ "int8" => "int8_t",
+ "uint8" => "uint8_t",
+ "short" => "int16_t",
+ "wchar_t" => "uint16_t",
+ "int16" => "int16_t",
+ "uint16" => "uint16_t",
+ "int32" => "int32_t",
+ "uint32" => "uint32_t",
+ "int64" => "int64_t",
+ "uint64" => "uint64_t",
+ "dlong" => "int64_t",
+ "udlong" => "uint64_t",
+ "udlongr" => "uint64_t",
+ "hyper" => "uint64_t",
+ "NTTIME_1sec" => "NTTIME",
+ "NTTIME_hyper" => "NTTIME",
+ "ipv4address" => "const char *"
+ );
+
+# map from a IDL type to a C header type
+sub mapScalarType($)
+{
+ my $name = shift;
+ if (my $ret = $scalar_type_mappings{$name}) {
+ return $ret;
+ }
+ return $name;
+}
+
+sub mapType($)
+{
+ my $e = shift;
+ my $dt;
+
+ return "const char *" if ($e->{TYPE} =~ "string");
+
+ if ($e->{TYPE} eq "ENUM" or $e->{TYPE} eq "BITMAP") {
+ $dt = getType($e->{PARENT}->{NAME});
+ }
+
+ unless ($dt or $dt = getType($e->{TYPE})) {
+ # Best guess
+ return "struct $e->{TYPE}";
+ }
+ return mapScalarType($e->{TYPE}) if ($dt->{DATA}->{TYPE} eq "SCALAR");
+ return "enum $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "ENUM");
+ return "struct $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "STRUCT");
+ return "union $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "UNION");
+ return mapScalarType(bitmap_type_fn($dt->{DATA})) if ($dt->{DATA}->{TYPE} eq "BITMAP");
+
+ die("Unknown type $dt->{DATA}->{TYPE}");
+}
+
RegisterPrimitives();
+
1;
diff --git a/source4/build/pidl/util.pm b/source4/build/pidl/util.pm
index 1a908e92e3..a662ed005e 100644
--- a/source4/build/pidl/util.pm
+++ b/source4/build/pidl/util.pm
@@ -200,48 +200,6 @@ sub property_matches($$$)
return undef;
}
-my %enum_list;
-
-sub enum_type_decl($)
-{
- my $enum = shift;
- return "enum $enum->{TYPE}";
-}
-
-sub enum_type_fn($)
-{
- my $enum = shift;
- if (util::has_property($enum->{PARENT}, "enum8bit")) {
- return "uint8";
- } elsif (util::has_property($enum->{PARENT}, "v1_enum")) {
- return "uint32";
- }
- return "uint16";
-}
-
-my %bitmap_list;
-
-sub bitmap_type_fn($)
-{
- my $bitmap = shift;
-
- if (util::has_property($bitmap->{PARENT}, "bitmap8bit")) {
- return "uint8";
- } elsif (util::has_property($bitmap->{PARENT}, "bitmap16bit")) {
- return "uint16";
- } elsif (util::has_property($bitmap->{PARENT}, "bitmap64bit")) {
- return "uint64";
- }
- return "uint32";
-}
-
-sub bitmap_type_decl($)
-{
- my $bitmap = shift;
- return map_type(bitmap_type_fn($bitmap));
-}
-
-
# determine if an element is a pass-by-reference structure
sub is_ref_struct($)
{
@@ -288,37 +246,4 @@ sub make_str($)
return "\"" . $str . "\"";
}
-
-# provide mappings between IDL base types and types in our headers
-my %type_mappings =
- (
- "int8" => "int8_t",
- "uint8" => "uint8_t",
- "short" => "int16_t",
- "wchar_t" => "uint16_t",
- "int16" => "int16_t",
- "uint16" => "uint16_t",
- "int32" => "int32_t",
- "uint32" => "uint32_t",
- "int64" => "int64_t",
- "uint64" => "uint64_t",
- "dlong" => "int64_t",
- "udlong" => "uint64_t",
- "udlongr" => "uint64_t",
- "hyper" => "uint64_t",
- "NTTIME_1sec" => "NTTIME",
- "NTTIME_hyper" => "NTTIME",
- "ipv4address" => "const char *"
- );
-
-# map from a IDL type to a C header type
-sub map_type($)
-{
- my $name = shift;
- if (my $ret = $type_mappings{$name}) {
- return $ret;
- }
- return $name;
-}
-
1;