r7122: Some cleanups, simplification of the code.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 30 May 2005 23:59:29 +0000 (23:59 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:17:19 +0000 (13:17 -0500)
source/build/pidl/ndr.pm
source/build/pidl/odl.pm
source/build/pidl/util.pm
source/build/pidl/validator.pm

index 629d413db265cdb5167084c7569fba00202f4840..69e65c0697cc861c6e29f8f06756a9aff46afe60 100644 (file)
@@ -216,7 +216,6 @@ sub is_surrounding_string($)
                and $e->{PARENT}->{TYPE} ne "FUNCTION";
 }
 
-
 #####################################################################
 # work out the correct alignment for a structure or union
 sub find_largest_alignment($)
@@ -227,7 +226,7 @@ sub find_largest_alignment($)
        for my $e (@{$s->{ELEMENTS}}) {
                my $a = 1;
 
-               if (Ndr::need_wire_pointer($e)) {
+               if ($e->{POINTERS}) {
                        $a = 4; 
                } else { 
                        $a = align_type($e->{TYPE}); 
@@ -266,26 +265,6 @@ sub align_type
        die("Unknown data type type $dt->{TYPE}");
 }
 
-# determine if an element needs a reference pointer on the wire
-# in its NDR representation
-sub need_wire_pointer($)
-{
-       my $e = shift;
-
-       my $n = $e->{POINTERS};
-       my $pt = pointer_type($e);
-
-       # Top level "ref" pointers do not have a referrent identifier
-       if (    defined($pt) 
-               and $pt eq "ref" 
-               and $e->{PARENT}->{TYPE} eq "FUNCTION") 
-       {
-               $n--;
-       }
-
-       return $n;
-}
-
 sub ParseElement($)
 {
        my $e = shift;
@@ -387,13 +366,6 @@ sub ParseBitmap($)
        };
 }
 
-sub ParseDeclare($$)
-{
-       my $ndr = shift;
-       my $d = shift;
-
-}
-
 sub ParseTypedef($$)
 {
        my $ndr = shift;
@@ -458,14 +430,8 @@ sub ParseFunction($$$)
 
        foreach my $x (@{$d->{ELEMENTS}}) {
                my $e = ParseElement($x);
-               if (util::has_property($x, "in")) {
-                       push (@{$e->{DIRECTION}}, "in");
-               }
-
-               if (util::has_property($x, "out")) {
-                       push (@{$e->{DIRECTION}}, "out");
-               }
-
+               push (@{$e->{DIRECTION}}, "in") if (util::has_property($x, "in"));
+               push (@{$e->{DIRECTION}}, "out") if (util::has_property($x, "out"));
                push (@elements, $e);
        }
 
@@ -489,14 +455,8 @@ sub CheckPointerTypes($$)
        my $default = shift;
 
        foreach my $e (@{$s->{ELEMENTS}}) {
-               if ($e->{POINTERS}) {
-                       if (not defined(Ndr::pointer_type($e))) {
-                               $e->{PROPERTIES}->{$default} = 1;
-                       }
-
-                       if (Ndr::pointer_type($e) eq "ptr") {
-                               print "Warning: ptr is not supported by pidl yet\n";
-                       }
+               if ($e->{POINTERS} and not defined(Ndr::pointer_type($e))) {
+                       $e->{PROPERTIES}->{$default} = 1;
                }
        }
 }
@@ -528,7 +488,7 @@ sub ParseInterface($)
                }
 
                if ($d->{TYPE} eq "DECLARE") {
-                       push (@declares, ParseDeclare($idl, $d));
+                       push (@declares, $d);
                }
 
                if ($d->{TYPE} eq "FUNCTION") {
@@ -569,27 +529,7 @@ sub ParseInterface($)
 
 # Convert a IDL tree to a NDR tree
 # Gives a result tree describing all that's necessary for easily generating
-# NDR parsers
-# - list of interfaces
-#  - list with functions
-#   - list with in elements
-#   - list with out elements
-#  - list of typedefs
-#   - list with structs
-#    - alignment of structure
-#    - list with elements
-#   - list with unions
-#    - alignment of union
-#    - list with elements
-#   - list with enums
-#    - base type
-#   - list with bitmaps
-#    - base type
-# per element: 
-#  - alignment
-#  - "level" table
-# properties are saved
-# pointer types explicitly specified
+# NDR parsers / generators
 sub Parse($)
 {
        my $idl = shift;
@@ -644,5 +584,4 @@ sub ContainsDeferred($$)
        return 0;
 }
 
-
 1;
index 5ed508dc9397af647d6eaea37c2838b1580f02cf..d40f8fbcca1fd4d3d6cf7ab0cdcd802d47c9f043 100644 (file)
@@ -6,6 +6,20 @@ package ODL;
 
 use strict;
 
+#####################################################################
+# find an interface in an array of interfaces
+sub get_interface($$)
+{
+       my($if) = shift;
+       my($n) = shift;
+
+       foreach(@{$if}) {
+               if($_->{NAME} eq $n) { return $_; }
+       }
+       
+       return 0;
+}
+
 sub FunctionAddObjArgs($)
 {
        my $e = shift;
@@ -60,7 +74,7 @@ sub ODL2IDL($)
                }
 
                if ($x->{BASE}) {
-                       my $base = util::get_interface($odl, $x->{BASE});
+                       my $base = get_interface($odl, $x->{BASE});
 
                        foreach my $fn (reverse @{$base->{DATA}}) {
                                next unless ($fn->{TYPE} eq "FUNCTION");
index 537714adf3609f3b0c87695d8e6bbaf5af21e7e2..c26ab2dd041b512b64862ff12d448ca4c434c61a 100644 (file)
@@ -58,7 +58,6 @@ sub FlattenHash($)
     return \%b;
 }
 
-
 #####################################################################
 # traverse a perl data structure removing any empty arrays or
 # hashes and any hash elements that map to undef
@@ -86,7 +85,6 @@ sub CleanData($)
        return $v;
 }
 
-
 #####################################################################
 # return the modification time of a file
 sub FileModtime($)
@@ -95,7 +93,6 @@ sub FileModtime($)
     return (stat($filename))[9];
 }
 
-
 #####################################################################
 # read a file into a string
 sub FileLoad($)
@@ -154,20 +151,6 @@ sub SaveStructure($$)
        FileSave($filename, MyDumper($v));
 }
 
-#####################################################################
-# find an interface in an array of interfaces
-sub get_interface($$)
-{
-       my($if) = shift;
-       my($n) = shift;
-
-       foreach(@{$if}) {
-               if($_->{NAME} eq $n) { return $_; }
-       }
-       
-       return 0;
-}
-
 #####################################################################
 # see if a pidl property list contains a given property
 sub has_property($$)
@@ -201,17 +184,6 @@ sub property_matches($$$)
        return undef;
 }
 
-# determine if an element is a pass-by-reference structure
-sub is_ref_struct($)
-{
-       my $e = shift;
-       if (!is_scalar_type($e->{TYPE}) &&
-           has_property($e, "ref")) {
-               return 1;
-       }
-       return 0;
-}
-
 # return 1 if the string is a C constant
 sub is_constant($)
 {
@@ -232,23 +204,4 @@ sub make_str($)
        return "\"" . $str . "\"";
 }
 
-###################################
-# find a sibling var in a structure
-sub find_sibling($$)
-{
-       my($e) = shift;
-       my($name) = shift;
-       my($fn) = $e->{PARENT};
-
-       if ($name =~ /\*(.*)/) {
-               $name = $1;
-       }
-
-       for my $e2 (@{$fn->{ELEMENTS}}) {
-               return $e2 if ($e2->{NAME} eq $name);
-       }
-
-       return undef;
-}
-
 1;
index 3c7e1f51d06adf9009632da138c7fd4ebcddf5b7..ec4ad4503b89da5bb13eecff109ad596d793d094 100644 (file)
@@ -42,128 +42,93 @@ sub el_name($)
        return $e->{NAME};
 }
 
+###################################
+# find a sibling var in a structure
+sub find_sibling($$)
+{
+       my($e) = shift;
+       my($name) = shift;
+       my($fn) = $e->{PARENT};
+
+       if ($name =~ /\*(.*)/) {
+               $name = $1;
+       }
+
+       for my $e2 (@{$fn->{ELEMENTS}}) {
+               return $e2 if ($e2->{NAME} eq $name);
+       }
+
+       return undef;
+}
+
+
 my %property_list = (
        # interface
-       "helpstring"            => {INTERFACE   => 1,
-                                   FUNCTION    => 1,
-                                   },
-       "version"               => {INTERFACE   => 1,
-                                   },
-       "uuid"                  => {INTERFACE   => 1,
-                                   },
-       "endpoint"              => {INTERFACE   => 1,
-                                   },
-       "pointer_default"       => {INTERFACE   => 1,
-                                   },
-       "pointer_default_top"   => {INTERFACE   => 1,
-                                   },
-       "depends"               => {INTERFACE   => 1,
-                                   },
-       "authservice"           => {INTERFACE   => 1,
-                                   },
+       "helpstring" => ["INTERFACE", "FUNCTION"],
+       "version" => ["INTERFACE"],
+       "uuid" => ["INTERFACE"],
+       "endpoint" => ["INTERFACE"],
+       "pointer_default" => ["INTERFACE"],
+       "pointer_default_top" => ["INTERFACE"],
+       "depends" => ["INTERFACE"],
+       "authservice" => ["INTERFACE"],
 
        # dcom
-       "object"                => {INTERFACE   => 1,
-                                   },
-       "local"                 => {INTERFACE   => 1,
-                                   FUNCTION    => 1,
-                                   },
-       "iid_is"                => {ELEMENT     => 1,
-                                   },
-       "call_as"               => {FUNCTION    => 1,
-                                   },
-       "idempotent"            => {FUNCTION    => 1,
-                                   },
+       "object" => ["INTERFACE"],
+       "local"  => ["INTERFACE", "FUNCTION"],
+       "iid_is" => ["ELEMENT"],
+       "call_as" => ["FUNCTION"],
+       "idempotent" => ["FUNCTION"],
 
        # function
-       "noopnum"               => {FUNCTION    => 1,
-                                   },
-       "in"                    => {ELEMENT     => 1,
-                                   },
-       "out"                   => {ELEMENT     => 1,
-                                   },
+       "noopnum" => ["FUNCTION"],
+       "in" => ["ELEMENT"],
+       "out" => ["ELEMENT"],
 
        # pointer
-       "ref"                   => {ELEMENT     => 1,
-                                   },
-       "ptr"                   => {ELEMENT     => 1,
-                                   },
-       "unique"                => {ELEMENT     => 1,
-                                   },
-       "relative"              => {ELEMENT     => 1,
-                                   },
-
-       # ndr_size
-       "gensize"               => {TYPEDEF     => 1,
-                                   },
-       "value"                 => {ELEMENT     => 1,
-                                   },
-       "flag"                  => {ELEMENT     => 1,
-                                   TYPEDEF     => 1,
-                                   },
+       "ref" => ["ELEMENT"],
+       "ptr" => ["ELEMENT"],
+       "unique" => ["ELEMENT"],
+       "relative" => ["ELEMENT"],
+
+       "gensize"       => ["TYPEDEF"],
+       "value"         => ["ELEMENT"],
+       "flag"          => ["ELEMENT", "TYPEDEF"],
 
        # generic
-       "public"                => {FUNCTION    => 1,
-                                   TYPEDEF     => 1,
-                                   },
-       "nopush"                => {FUNCTION    => 1,
-                                   TYPEDEF     => 1,
-                                   },
-       "nopull"                => {FUNCTION    => 1,
-                                   TYPEDEF     => 1,
-                                   },
-       "noprint"               => {FUNCTION    => 1,
-                                   TYPEDEF     => 1,
-                                   },
+       "public"        => ["FUNCTION", "TYPEDEF"],
+       "nopush"        => ["FUNCTION", "TYPEDEF"],
+       "nopull"        => ["FUNCTION", "TYPEDEF"],
+       "noprint"       => ["FUNCTION", "TYPEDEF"],
 
        # union
-       "switch_is"             => {ELEMENT     => 1,
-                                   },
-       "switch_type"           => {ELEMENT     => 1,
-                                   TYPEDEF     => 1,
-                                   },
-       "nodiscriminant"        => {TYPEDEF     => 1,
-                                   },
-       "case"                  => {ELEMENT     => 1,
-                                   },
-       "default"               => {ELEMENT     => 1,
-                                   },
+       "switch_is"      => ["ELEMENT"],
+       "switch_type"   => ["ELEMENT", "TYPEDEF"],
+       "nodiscriminant" => ["TYPEDEF"],
+       "case"                  => ["ELEMENT"],
+       "default"               => ["ELEMENT"],
 
        # subcontext
-       "subcontext"            => {ELEMENT     => 1,
-                                   },
-       "subcontext_size"       => {ELEMENT     => 1,
-                                   },
-       "compression"           => {ELEMENT     => 1,
-                                   },
-       "obfuscation"           => {ELEMENT     => 1,
-                                   },
+       "subcontext" => ["ELEMENT"],
+       "subcontext_size"       => ["ELEMENT"],
+       "compression"           => ["ELEMENT"],
+       "obfuscation"           => ["ELEMENT"],
 
        # enum
-       "enum8bit"              => {TYPEDEF     => 1,
-                                   },
-       "enum16bit"             => {TYPEDEF     => 1,
-                                   },
-       "v1_enum"               => {TYPEDEF     => 1,
-                                   },
+       "enum8bit"              => ["TYPEDEF"],
+       "enum16bit"             => ["TYPEDEF"],
+       "v1_enum"               => ["TYPEDEF"],
 
        # bitmap
-       "bitmap8bit"            => {TYPEDEF     => 1,
-                                   },
-       "bitmap16bit"           => {TYPEDEF     => 1,
-                                   },
-       "bitmap32bit"           => {TYPEDEF     => 1,
-                                   },
-       "bitmap64bit"           => {TYPEDEF     => 1,
-                                   },
+       "bitmap8bit"    => ["TYPEDEF"],
+       "bitmap16bit"   => ["TYPEDEF"],
+       "bitmap32bit"   => ["TYPEDEF"],
+       "bitmap64bit"   => ["TYPEDEF"],
 
        # array
-       "range"                 => {ELEMENT     => 1,
-                                   },
-       "size_is"               => {ELEMENT     => 1,
-                                   },
-       "length_is"             => {ELEMENT     => 1,
-                                   },
+       "range"                 => ["ELEMENT"],
+       "size_is"               => ["ELEMENT"],
+       "length_is"             => ["ELEMENT"],
 );
 
 #####################################################################
@@ -177,11 +142,10 @@ sub ValidProperties($$)
 
        foreach my $key (keys %{$e->{PROPERTIES}}) {
                fatal($e, el_name($e) . ": unknown property '$key'\n")
-                       if not defined($property_list{$key});
+                       unless defined($property_list{$key});
 
-               next if defined($property_list{$key}{ANY});
-               fatal($e, el_name($e) . ": property '$key' not allowed on '$t'\n")
-                       if not defined($property_list{$key}{$t});
+               fatal($e, el_name($e) . ": property '$key' not allowed on '$t'\n")
+                       unless grep($t, @{$property_list{$key}});
        }
 }
 
@@ -199,7 +163,7 @@ sub ValidElement($)
 
        # Check whether switches are used correctly.
        if (my $switch = util::has_property($e, "switch_is")) {
-               my $e2 = util::find_sibling($e, $switch);
+               my $e2 = find_sibling($e, $switch);
                my $type = typelist::getType($e->{TYPE});
 
                if (defined($type) and $type->{DATA}->{TYPE} ne "UNION") {