pidl: don't warn for compatible scalar types in unions
[ira/wip.git] / pidl / lib / Parse / Pidl / NDR.pm
index 5ee26d16b68c76f611c4fedc832aab5671f513e1..4e680b336f1bdf4646c31ca46f6883bdec4919a7 100644 (file)
@@ -39,7 +39,7 @@ $VERSION = '0.01';
 
 use strict;
 use Parse::Pidl qw(warning fatal);
-use Parse::Pidl::Typelist qw(hasType getType expandAlias);
+use Parse::Pidl::Typelist qw(hasType getType expandAlias mapScalarType);
 use Parse::Pidl::Util qw(has_property property_matches);
 
 # Alignment of the built-in scalar types
@@ -50,9 +50,14 @@ my $scalar_alignment = {
        'uint8' => 1,
        'int16' => 2,
        'uint16' => 2,
+       'int1632' => 3,
+       'uint1632' => 3,
        'int32' => 4,
        'uint32' => 4,
+       'int3264' => 5,
+       'uint3264' => 5,
        'hyper' => 8,
+       'double' => 8,
        'pointer' => 8,
        'dlong' => 4,
        'udlong' => 4,
@@ -141,6 +146,13 @@ sub GetElementLevelTable($$)
                $is_fixed = 1 if (not $is_conformant and Parse::Pidl::Util::is_constant($size));
                $is_inline = 1 if (not $is_conformant and not Parse::Pidl::Util::is_constant($size));
 
+               if ($i == 0 and $is_fixed and has_property($e, "string")) {
+                       $is_fixed = 0;
+                       $is_varying = 1;
+                       $is_string = 1;
+                       delete($e->{PROPERTIES}->{string});
+               }
+
                push (@$order, {
                        TYPE => "ARRAY",
                        SIZE_IS => $size,
@@ -355,7 +367,10 @@ sub find_largest_alignment($)
                my $a = 1;
 
                if ($e->{POINTERS}) {
-                       $a = 4; 
+                       # this is a hack for NDR64
+                       # the NDR layer translates this into
+                       # an alignment of 4 for NDR and 8 for NDR64
+                       $a = 5;
                } elsif (has_property($e, "subcontext")) { 
                        $a = 1;
                } elsif (has_property($e, "transmit_as")) {
@@ -393,6 +408,8 @@ sub align_type($)
 
        if ($dt->{TYPE} eq "TYPEDEF") {
                return align_type($dt->{DATA});
+       } elsif ($dt->{TYPE} eq "CONFORMANCE") {
+               return $dt->{DATA}->{ALIGN};
        } elsif ($dt->{TYPE} eq "ENUM") {
                return align_type(Parse::Pidl::Typelist::enum_type_fn($dt));
        } elsif ($dt->{TYPE} eq "BITMAP") {
@@ -498,7 +515,8 @@ sub ParseUnion($$)
                ELEMENTS => undef,
                PROPERTIES => $e->{PROPERTIES},
                HAS_DEFAULT => $hasdefault,
-               ORIGINAL => $e
+               ORIGINAL => $e,
+               ALIGN => undef
        } unless defined($e->{ELEMENTS});
 
        CheckPointerTypes($e, $pointer_default);
@@ -522,6 +540,11 @@ sub ParseUnion($$)
                push @elements, $t;
        }
 
+       my $align = undef;
+       if ($e->{NAME}) {
+               $align = align_type($e->{NAME});
+       }
+
        return {
                TYPE => "UNION",
                NAME => $e->{NAME},
@@ -529,7 +552,8 @@ sub ParseUnion($$)
                ELEMENTS => \@elements,
                PROPERTIES => $e->{PROPERTIES},
                HAS_DEFAULT => $hasdefault,
-               ORIGINAL => $e
+               ORIGINAL => $e,
+               ALIGN => $align
        };
 }
 
@@ -920,7 +944,7 @@ my %property_list = (
        "bitmap64bit"           => ["BITMAP"],
 
        # array
-       "range"                 => ["ELEMENT"],
+       "range"                 => ["ELEMENT", "PIPE"],
        "size_is"               => ["ELEMENT"],
        "string"                => ["ELEMENT"],
        "noheader"              => ["ELEMENT"],
@@ -986,13 +1010,13 @@ sub ValidElement($)
                        my $discriminator_type = has_property($type->{DATA}, "switch_type");
                        $discriminator_type = "uint32" unless defined ($discriminator_type);
 
-                       my $t1 = mapToScalar($discriminator_type);
+                       my $t1 = mapScalarType(mapToScalar($discriminator_type));
 
                        if (not defined($t1)) {
                                fatal($e, el_name($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
                        }
 
-                       my $t2 = mapToScalar($e2->{TYPE});
+                       my $t2 = mapScalarType(mapToScalar($e2->{TYPE}));
                        if (not defined($t2)) {
                                fatal($e, el_name($e) . ": unable to map variable used for switch_is() to scalar");
                        }
@@ -1111,6 +1135,18 @@ sub ValidUnion($)
        }
 }
 
+#####################################################################
+# validate a pipe
+sub ValidPipe($)
+{
+       my ($pipe) = @_;
+       my $data = $pipe->{DATA};
+
+       ValidProperties($pipe, "PIPE");
+
+       fatal($pipe, $pipe->{NAME} . ": 'pipe' is not yet supported by pidl");
+}
+
 #####################################################################
 # parse a typedef
 sub ValidTypedef($)
@@ -1156,7 +1192,8 @@ sub ValidType($)
                STRUCT => \&ValidStruct,
                UNION => \&ValidUnion,
                ENUM => \&ValidEnum,
-               BITMAP => \&ValidBitmap
+               BITMAP => \&ValidBitmap,
+               PIPE => \&ValidPipe
        }->{$t->{TYPE}}->($t);
 }
 
@@ -1198,7 +1235,8 @@ sub ValidInterface($)
                 $d->{TYPE} eq "STRUCT" or
                 $d->{TYPE} eq "UNION" or 
                 $d->{TYPE} eq "ENUM" or
-                $d->{TYPE} eq "BITMAP") && ValidType($d);
+                $d->{TYPE} eq "BITMAP" or
+                $d->{TYPE} eq "PIPE") && ValidType($d);
        }
 
 }