r5475: Move some existing and new type information functions to typelist.pm
authorJelmer Vernooij <jelmer@samba.org>
Sun, 20 Feb 2005 20:35:07 +0000 (20:35 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:10:49 +0000 (13:10 -0500)
(This used to be commit 280df525380d06d67ce33938c4760807d5466966)

source4/build/pidl/header.pm
source4/build/pidl/ndr.pm
source4/build/pidl/typelist.pm
source4/build/pidl/util.pm

index efcd2dbb45c7fa0018390219e837592a0e61deba..803916a79c2234104aeb70a587c8decc6ddd525c 100644 (file)
@@ -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();
index df756e2f30ca1de1da1cd752697b8d23aee283ce..185067e526f4b638d1dead34a987cf92a3c24c03 100644 (file)
@@ -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)); }
 };
 
 #####################################################################
index e5d6a81355ea451675d3371299249ef486ac3588..66a8a41dd2d23593912658e50b12a6d183fc2aab 100644 (file)
@@ -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;
index 1a908e92e3f37a1bddf721e83aed5ed5174992ed..a662ed005ef8f6435baacd085d2b7a04cd76ecb8 100644 (file)
@@ -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;