pidl: Introduce new dirrective: relative_short
[ira/wip.git] / pidl / lib / Parse / Pidl / NDR.pm
index a36f6380924977dd1285e0099e7ae16e988fc0c0..d326f6704097944daacdefe300b74df6292f90d6 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,8 +50,12 @@ 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,
@@ -347,6 +351,7 @@ sub pointer_type($)
        return "sptr" if (has_property($e, "sptr"));
        return "unique" if (has_property($e, "unique"));
        return "relative" if (has_property($e, "relative"));
+       return "relative_short" if (has_property($e, "relative_short"));
        return "ignore" if (has_property($e, "ignore"));
 
        return undef;
@@ -363,7 +368,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")) {
@@ -401,6 +409,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") {
@@ -506,7 +516,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);
@@ -530,6 +541,11 @@ sub ParseUnion($$)
                push @elements, $t;
        }
 
+       my $align = undef;
+       if ($e->{NAME}) {
+               $align = align_type($e->{NAME});
+       }
+
        return {
                TYPE => "UNION",
                NAME => $e->{NAME},
@@ -537,7 +553,8 @@ sub ParseUnion($$)
                ELEMENTS => \@elements,
                PROPERTIES => $e->{PROPERTIES},
                HAS_DEFAULT => $hasdefault,
-               ORIGINAL => $e
+               ORIGINAL => $e,
+               ALIGN => $align
        };
 }
 
@@ -886,6 +903,7 @@ my %property_list = (
        "unique"                => ["ELEMENT"],
        "ignore"                => ["ELEMENT"],
        "relative"              => ["ELEMENT"],
+       "relative_short"        => ["ELEMENT"],
        "null_is_ffffffff" => ["ELEMENT"],
        "relative_base"         => ["TYPEDEF", "STRUCT", "UNION"],
 
@@ -994,13 +1012,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");
                        }
@@ -1043,6 +1061,7 @@ sub ValidElement($)
                has_property($e, "ptr") or
                has_property($e, "unique") or
                has_property($e, "relative") or
+               has_property($e, "relative_short") or
                has_property($e, "ref"))) {
                fatal($e, el_name($e) . " : pointer properties on non-pointer element\n");      
        }