r7022: Add support for parsing definitions of multi-dimension arrays.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 27 May 2005 14:01:22 +0000 (14:01 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:17:07 +0000 (13:17 -0500)
This will also be required for supporting
parsing pointers to arrays and arrays of pointers simultaneously.

source/build/pidl/com_header.pm
source/build/pidl/dump.pm
source/build/pidl/eth_header.pm
source/build/pidl/eth_parser.pm
source/build/pidl/idl.pm
source/build/pidl/idl.yp
source/build/pidl/ndr.pm
source/build/pidl/ndr_header.pm
source/build/pidl/util.pm

index 95bbc9c720c9a9d1fbb8c3ec5329386f40bebceb..1e5f338828efa38957750dddbfbf074f48c95fc3 100644 (file)
@@ -22,14 +22,14 @@ sub GetArgumentProtoList($)
                        $res .= "*";
                }
 
-               if (defined $a->{ARRAY_LEN} && 
-               !util::is_constant($a->{ARRAY_LEN}) &&
+               if (defined $a->{ARRAY_LEN}[0] && 
+               !util::is_constant($a->{ARRAY_LEN}[0]) &&
                !$a->{POINTERS}) {
                        $res .= "*";
                }
                $res .= $a->{NAME};
-               if (defined $a->{ARRAY_LEN} && util::is_constant($a->{ARRAY_LEN})) {
-                       $res .= "[$a->{ARRAY_LEN}]";
+               if (defined $a->{ARRAY_LEN}[0] && util::is_constant($a->{ARRAY_LEN}[0])) {
+                       $res .= "[$a->{ARRAY_LEN}[0]]";
                }
        }
 
index 9e896cd256756cbdad166f7cd122366a560dec14..2cd0c140a589ebb73ec4f56e71b6d3e49fe5a2a5 100644 (file)
@@ -51,7 +51,9 @@ sub DumpElement($)
            $res .= "*";
     }
     $res .= "$element->{NAME}";
-    (defined $element->{ARRAY_LEN}) && ($res .= "[$element->{ARRAY_LEN}]");
+       foreach (@{$element->{ARRAY_LEN}}) {
+               $res .= "[$_]";
+       }
 
     return $res;
 }
index f0a577885448df215ca2722a9cd91860a1a651cd..2e0397df37a95933ee1201f9baa3e761a46d013f 100644 (file)
@@ -44,7 +44,7 @@ sub HeaderTypedefProto($)
 sub HeaderConst($)
 {
     my($const) = shift;
-    if (!defined($const->{ARRAY_LEN})) {
+    if (!defined($const->{ARRAY_LEN}[0])) {
        pidl "#define $const->{NAME}\t( $const->{VALUE} )\n";
     } else {
        pidl "#define $const->{NAME}\t $const->{VALUE}\n";
index a2e1bf051cebb3a2a590ea07bda4d083da90a33b..d0a4ae7c66f8e0d62d1a5c5f48446fc735d5dea5 100644 (file)
@@ -29,43 +29,19 @@ sub NeededFunction($$)
                }
 
                # for Ethereal
-               if (Ndr::is_scalar_type($e->{TYPE})) {
-                   
-                   if (defined($e->{ARRAY_LEN}) or 
-                       util::has_property($e, "size_is")) {
-                       
-                       # Array of scalar types
-                       
-                       $needed->{"hf_$fn->{NAME}_$e->{NAME}_array"} = {
-                           'name' => field2name($e->{NAME}),
-                           'type' => $e->{TYPE},
-                           'ft'   => "FT_BYTES",
-                           'base' => elementbase($e)
-                           };
-                       
-                   } else {                            
-                       $needed->{"hf_$fn->{NAME}_$e->{NAME}"} = {
-                           'name' => field2name($e->{NAME}),
-                           'type' => $e->{TYPE},
-                           'ft'   => type2ft($e->{TYPE}),
-                           'base' => elementbase($e)
-                           };
-                   }
-               } else {
-                   $needed->{"hf_$fn->{NAME}_$e->{NAME}"} = {
+           $needed->{"hf_$fn->{NAME}_$e->{NAME}"} = {
                        'name' => field2name($e->{NAME}),
                        'type' => $e->{TYPE},
                        'ft'   => type2ft($e->{TYPE}),
                        'base' => elementbase($e)
-                       };
-                   $needed->{"hf_$e->{TYPE}"} = {
+               };
+           $needed->{"hf_$e->{TYPE}"} = {
                        'name' => field2name($e->{NAME}),
                        'type' => $e->{TYPE},
                        'ft'   => type2ft($e->{TYPE}),
                        'base' => elementbase($e)
-                       };
-                   $needed->{"ett_$e->{TYPE}"} = 1;
-               }
+               };
+           $needed->{"ett_$e->{TYPE}"} = 1;
        }
 
        # Add entry for return value
@@ -97,43 +73,13 @@ sub NeededTypedef($$)
                                $needed->{"pull_$e->{TYPE}"} = 1;
                        }
 
-                       if (Ndr::is_scalar_type($e->{TYPE})) {
-                               if (defined($e->{ARRAY_LEN}) or 
-                               util::has_property($e, "size_is")) {
-
-                                       # Arrays of scalar types are FT_BYTES
-                                   
-                                   $needed->{"hf_$t->{NAME}_$e->{NAME}_array"} = {
-                                       'name' => field2name($e->{NAME}),
-                                       'type' => $e->{TYPE},
-                                       'ft'   => "FT_BYTES",
-                                       'base' => elementbase($e)
-                                       };
-
-                               } else {
-                                   $needed->{"hf_$t->{NAME}_$e->{NAME}"} = {
-                                       'name' => field2name($e->{NAME}),
-                                       'type' => $e->{TYPE},
-                                       'ft'   => type2ft($e->{TYPE}),
-                                       'base' => elementbase($e)
-                                       };
-                               }
-
-                               $e->{PARENT} = $t->{DATA};
-
-                               if ($needed->{"pull_$t->{NAME}"}) {
-                                       $needed->{"pull_$e->{TYPE}"} = 1;
-                               }
-
-                       } else {
-                               $needed->{"hf_$t->{NAME}_$e->{NAME}"} = {
-                                       'name' => field2name($e->{NAME}),
-                                       'type' => $e->{TYPE},
-                                       'ft'   => type2ft($e->{TYPE}),
-                                       'base' => elementbase($e)
-                                       };
-                               $needed->{"ett_$e->{TYPE}"} = 1;
-                           }
+               $needed->{"hf_$t->{NAME}_$e->{NAME}"} = {
+                               'name' => field2name($e->{NAME}),
+                               'type' => $e->{TYPE},
+                               'ft'   => type2ft($e->{TYPE}),
+                               'base' => elementbase($e)
+                       };
+                       $needed->{"ett_$e->{TYPE}"} = 1;
                 }
        }
 
@@ -1319,7 +1265,7 @@ sub RegisterInterfaceHandoff($)
        indent;
        pidl "dcerpc_init_uuid(proto_dcerpc_pidl_$x->{NAME}, ett_dcerpc_$x->{NAME},";
        pidl "\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},";
-       pidl "\tdcerpc_dissectors, hf_opnum);";
+       pidl "\tdcerpc_dissectors, hf_$x->{NAME}_opnum);";
        deindent;
        pidl "}";
 }
index d5100812ed6f3cf6b36d58ebd83087e4758580e8..1e15db18c8c8a2a23723c1a9a7495c0cb479d6bc 100644 (file)
@@ -1622,7 +1622,13 @@ sub new {
                }
        },
        {#State 143
-               DEFAULT => -58
+               ACTIONS => {
+                       "[" => 122
+               },
+               DEFAULT => -57,
+               GOTOS => {
+                       'array_len' => 160
+               }
        },
        {#State 144
                DEFAULT => -24
@@ -1632,7 +1638,7 @@ sub new {
        },
        {#State 146
                ACTIONS => {
-                       ";" => 160
+                       ";" => 161
                }
        },
        {#State 147
@@ -1642,7 +1648,7 @@ sub new {
                ACTIONS => {
                        'IDENTIFIER' => 9,
                        "union" => 76,
-                       ";" => 161,
+                       ";" => 162,
                        "enum" => 77,
                        "[" => 7,
                        'void' => 79,
@@ -1699,19 +1705,19 @@ sub new {
        {#State 153
                DEFAULT => -49,
                GOTOS => {
-                       'pointers' => 162
+                       'pointers' => 163
                }
        },
        {#State 154
                DEFAULT => -60,
                GOTOS => {
-                       'base_element' => 163,
+                       'base_element' => 164,
                        'property_list' => 134
                }
        },
        {#State 155
                ACTIONS => {
-                       ";" => 164
+                       ";" => 165
                }
        },
        {#State 156
@@ -1721,7 +1727,7 @@ sub new {
                ACTIONS => {
                        "-" => 34,
                        "<" => 35,
-                       ";" => 165,
+                       ";" => 166,
                        "+" => 36,
                        "&" => 38,
                        "{" => 37,
@@ -1737,45 +1743,57 @@ sub new {
                DEFAULT => -16
        },
        {#State 159
-               DEFAULT => -59
+               ACTIONS => {
+                       "[" => 122
+               },
+               DEFAULT => -57,
+               GOTOS => {
+                       'array_len' => 167
+               }
        },
        {#State 160
-               DEFAULT => -42
+               DEFAULT => -58
        },
        {#State 161
-               DEFAULT => -41
+               DEFAULT => -42
        },
        {#State 162
+               DEFAULT => -41
+       },
+       {#State 163
                ACTIONS => {
                        'IDENTIFIER' => 9,
-                       "*" => 167
+                       "*" => 169
                },
                GOTOS => {
-                       'identifier' => 166
+                       'identifier' => 168
                }
        },
-       {#State 163
+       {#State 164
                DEFAULT => -56
        },
-       {#State 164
+       {#State 165
                DEFAULT => -18
        },
-       {#State 165
+       {#State 166
                DEFAULT => -17
        },
-       {#State 166
+       {#State 167
+               DEFAULT => -59
+       },
+       {#State 168
                ACTIONS => {
                        "[" => 122
                },
                DEFAULT => -57,
                GOTOS => {
-                       'array_len' => 168
+                       'array_len' => 170
                }
        },
-       {#State 167
+       {#State 169
                DEFAULT => -50
        },
-       {#State 168
+       {#State 170
                DEFAULT => -48
        }
 ],
@@ -2054,6 +2072,7 @@ sub
                 "TYPE" => "EMPTY",
                 "PROPERTIES" => $_[1],
                 "POINTERS" => 0,
+                "ARRAY_LEN" => [],
                 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
                 "LINE" => $_[0]->YYData->{LINE},
         }}
@@ -2067,7 +2086,7 @@ sub
        [#Rule 44
                 'optional_base_element', 2,
 sub
-#line 194 "build/pidl/idl.yp"
+#line 195 "build/pidl/idl.yp"
 { $_[2]->{PROPERTIES} = util::FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] }
        ],
        [#Rule 45
@@ -2076,13 +2095,13 @@ sub
        [#Rule 46
                 'union_elements', 2,
 sub
-#line 199 "build/pidl/idl.yp"
+#line 200 "build/pidl/idl.yp"
 { push(@{$_[1]}, $_[2]); $_[1] }
        ],
        [#Rule 47
                 'union', 4,
 sub
-#line 203 "build/pidl/idl.yp"
+#line 204 "build/pidl/idl.yp"
 {{
                      "TYPE" => "UNION", 
                     "ELEMENTS" => $_[3]
@@ -2091,7 +2110,7 @@ sub
        [#Rule 48
                 'base_element', 5,
 sub
-#line 210 "build/pidl/idl.yp"
+#line 211 "build/pidl/idl.yp"
 {{
                           "NAME" => $_[4],
                           "TYPE" => $_[2],
@@ -2105,13 +2124,13 @@ sub
        [#Rule 49
                 'pointers', 0,
 sub
-#line 224 "build/pidl/idl.yp"
+#line 225 "build/pidl/idl.yp"
 { 0 }
        ],
        [#Rule 50
                 'pointers', 2,
 sub
-#line 225 "build/pidl/idl.yp"
+#line 226 "build/pidl/idl.yp"
 { $_[1]+1 }
        ],
        [#Rule 51
@@ -2120,7 +2139,7 @@ sub
        [#Rule 52
                 'element_list1', 3,
 sub
-#line 230 "build/pidl/idl.yp"
+#line 231 "build/pidl/idl.yp"
 { push(@{$_[1]}, $_[2]); $_[1] }
        ],
        [#Rule 53
@@ -2132,29 +2151,29 @@ sub
        [#Rule 55
                 'element_list2', 1,
 sub
-#line 236 "build/pidl/idl.yp"
+#line 237 "build/pidl/idl.yp"
 { [ $_[1] ] }
        ],
        [#Rule 56
                 'element_list2', 3,
 sub
-#line 237 "build/pidl/idl.yp"
+#line 238 "build/pidl/idl.yp"
 { push(@{$_[1]}, $_[3]); $_[1] }
        ],
        [#Rule 57
                 'array_len', 0, undef
        ],
        [#Rule 58
-                'array_len', 2,
+                'array_len', 3,
 sub
-#line 242 "build/pidl/idl.yp"
-{ "*" }
+#line 243 "build/pidl/idl.yp"
+{ push(@{$_[3]}, "*"); $_[3] }
        ],
        [#Rule 59
-                'array_len', 3,
+                'array_len', 4,
 sub
-#line 243 "build/pidl/idl.yp"
-{ "$_[2]" }
+#line 244 "build/pidl/idl.yp"
+{ push(@{$_[4]}, "$_[2]"); $_[4] }
        ],
        [#Rule 60
                 'property_list', 0, undef
@@ -2162,31 +2181,31 @@ sub
        [#Rule 61
                 'property_list', 4,
 sub
-#line 249 "build/pidl/idl.yp"
+#line 250 "build/pidl/idl.yp"
 { util::FlattenHash([$_[1],$_[3]]); }
        ],
        [#Rule 62
                 'properties', 1,
 sub
-#line 252 "build/pidl/idl.yp"
+#line 253 "build/pidl/idl.yp"
 { $_[1] }
        ],
        [#Rule 63
                 'properties', 3,
 sub
-#line 253 "build/pidl/idl.yp"
+#line 254 "build/pidl/idl.yp"
 { util::FlattenHash([$_[1], $_[3]]); }
        ],
        [#Rule 64
                 'property', 1,
 sub
-#line 256 "build/pidl/idl.yp"
+#line 257 "build/pidl/idl.yp"
 {{ "$_[1]" => "1"     }}
        ],
        [#Rule 65
                 'property', 4,
 sub
-#line 257 "build/pidl/idl.yp"
+#line 258 "build/pidl/idl.yp"
 {{ "$_[1]" => "$_[3]" }}
        ],
        [#Rule 66
@@ -2195,7 +2214,7 @@ sub
        [#Rule 67
                 'listtext', 3,
 sub
-#line 262 "build/pidl/idl.yp"
+#line 263 "build/pidl/idl.yp"
 { "$_[1] $_[3]" }
        ],
        [#Rule 68
@@ -2204,13 +2223,13 @@ sub
        [#Rule 69
                 'commalisttext', 3,
 sub
-#line 267 "build/pidl/idl.yp"
+#line 268 "build/pidl/idl.yp"
 { "$_[1],$_[3]" }
        ],
        [#Rule 70
                 'anytext', 0,
 sub
-#line 271 "build/pidl/idl.yp"
+#line 272 "build/pidl/idl.yp"
 { "" }
        ],
        [#Rule 71
@@ -2225,67 +2244,67 @@ sub
        [#Rule 74
                 'anytext', 3,
 sub
-#line 273 "build/pidl/idl.yp"
+#line 274 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]" }
        ],
        [#Rule 75
                 'anytext', 3,
 sub
-#line 274 "build/pidl/idl.yp"
+#line 275 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]" }
        ],
        [#Rule 76
                 'anytext', 3,
 sub
-#line 275 "build/pidl/idl.yp"
+#line 276 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]" }
        ],
        [#Rule 77
                 'anytext', 3,
 sub
-#line 276 "build/pidl/idl.yp"
+#line 277 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]" }
        ],
        [#Rule 78
                 'anytext', 3,
 sub
-#line 277 "build/pidl/idl.yp"
+#line 278 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]" }
        ],
        [#Rule 79
                 'anytext', 3,
 sub
-#line 278 "build/pidl/idl.yp"
+#line 279 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]" }
        ],
        [#Rule 80
                 'anytext', 3,
 sub
-#line 279 "build/pidl/idl.yp"
+#line 280 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]" }
        ],
        [#Rule 81
                 'anytext', 3,
 sub
-#line 280 "build/pidl/idl.yp"
+#line 281 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]" }
        ],
        [#Rule 82
                 'anytext', 3,
 sub
-#line 281 "build/pidl/idl.yp"
+#line 282 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]" }
        ],
        [#Rule 83
                 'anytext', 5,
 sub
-#line 282 "build/pidl/idl.yp"
+#line 283 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]$_[4]$_[5]" }
        ],
        [#Rule 84
                 'anytext', 5,
 sub
-#line 283 "build/pidl/idl.yp"
+#line 284 "build/pidl/idl.yp"
 { "$_[1]$_[2]$_[3]$_[4]$_[5]" }
        ],
        [#Rule 85
@@ -2297,7 +2316,7 @@ sub
        [#Rule 87
                 'text', 1,
 sub
-#line 292 "build/pidl/idl.yp"
+#line 293 "build/pidl/idl.yp"
 { "\"$_[1]\"" }
        ],
        [#Rule 88
@@ -2311,7 +2330,7 @@ sub
     bless($self,$class);
 }
 
-#line 303 "build/pidl/idl.yp"
+#line 304 "build/pidl/idl.yp"
 
 
 use util;
index d58dc9d0233d27b19b41704c632c6d3d25399696..f81316cd9fe0e1a2a7da6ca5eb28ab647137d3a4 100644 (file)
@@ -183,6 +183,7 @@ empty_element: property_list ';'
                 "TYPE" => "EMPTY",
                 "PROPERTIES" => $_[1],
                 "POINTERS" => 0,
+                "ARRAY_LEN" => [],
                 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
                 "LINE" => $_[0]->YYData->{LINE},
         }}
@@ -238,9 +239,9 @@ element_list2:
 ;
 
 array_len: 
-    #empty 
-    | '[' ']'            { "*" }
-    | '[' anytext ']'    { "$_[2]" }
+    #empty                        { [] }
+    | '[' ']' array_len           { push(@{$_[3]}, "*"); $_[3] }
+    | '[' anytext ']' array_len   { push(@{$_[4]}, "$_[2]"); $_[4] }
 ;
 
 
index 5c39578f404c0771e230809f238f2b4ce5fa43e0..a350a834eb9a989738a4f3cc7e2ab85171d0b18d 100644 (file)
@@ -50,22 +50,27 @@ sub GetElementLevelTable($)
                # FIXME: Process array here possibly (in case of multi-dimensional arrays, etc)
        }
 
-       if (defined($e->{ARRAY_LEN}) or util::has_property($e, "size_is")) {
-               my $length = util::has_property($e, "length_is");
-               my $size = util::has_property($e, "size_is");
-
-               if (not defined($size) and defined($e->{ARRAY_LEN})) { 
-                       $size = $e->{ARRAY_LEN};
+       if ((defined($e->{ARRAY_LEN}) and scalar(@{$e->{ARRAY_LEN}})) or 
+                util::has_property($e, "size_is")) {
+               my @length;
+               my @size;
+
+               if (util::has_property($e, "size_is")) {
+                       @size = split /,/, util::has_property($e, "size_is");
+               } elsif (defined($e->{ARRAY_LEN})) { 
+                       @size = @{$e->{ARRAY_LEN}};
                }
 
-               if (not defined($length)) {
-                       $length = $size;
+               if (util::has_property($e, "length_is")) {
+                       @length = split /,/, util::has_property($e, "length_is");
+               } else {
+                       @length = @size;
                }
 
                push (@$order, {
                        TYPE => "ARRAY",
-                       SIZE_IS => $size,
-                       LENGTH_IS => $length,
+                       SIZE_IS => $size[0],
+                       LENGTH_IS => $length[0],
                        IS_DEFERRED => "$is_deferred",
                        # Inline arrays (which are a pidl extension) are never encoded
                        # as surrounding the struct they're part of
@@ -169,7 +174,7 @@ sub pointer_type($)
 sub is_fixed_array($)
 {
        my $e = shift;
-       my $len = $e->{"ARRAY_LEN"};
+       my $len = $e->{"ARRAY_LEN"}[0];
        return 1 if (defined $len && util::is_constant($len));
        return 0;
 }
@@ -186,7 +191,7 @@ sub is_conformant_array($)
 sub is_inline_array($)
 {
        my $e = shift;
-       my $len = $e->{ARRAY_LEN};
+       my $len = $e->{ARRAY_LEN}[0];
        if (defined $len && $len ne "*" && !is_fixed_array($e)) {
                return 1;
        }
@@ -208,8 +213,8 @@ sub is_surrounding_array($)
        my $e = shift;
 
        return ($e->{POINTERS} == 0 
-               and defined $e->{ARRAY_LEN} 
-               and     $e->{ARRAY_LEN} eq "*"
+               and defined $e->{ARRAY_LEN}[0] 
+               and     $e->{ARRAY_LEN}[0] eq "*"
                and $e == $e->{PARENT}->{ELEMENTS}[-1] 
                and $e->{PARENT}->{TYPE} ne "FUNCTION");
 }
index bebf6937ae4bd955e6e4b8736c40f4cb400320dc..05c2f1f55c3d0660ae7cb2adb0b9d04588556c81 100644 (file)
@@ -77,8 +77,8 @@ sub HeaderElement($)
                }
        }
        
-    if (defined $element->{ARRAY_LEN} && util::is_constant($element->{ARRAY_LEN})) {
-           pidl "[$element->{ARRAY_LEN}]";
+    if (defined $element->{ARRAY_LEN}[0] && util::is_constant($element->{ARRAY_LEN}[0])) {
+           pidl "[$element->{ARRAY_LEN}[0]]";
     }
     pidl ";\n";
 }
@@ -230,7 +230,7 @@ sub HeaderTypedefProto($)
 sub HeaderConst($)
 {
     my($const) = shift;
-    if (!defined($const->{ARRAY_LEN})) {
+    if (!defined($const->{ARRAY_LEN}[0])) {
        pidl "#define $const->{NAME}\t( $const->{VALUE} )\n";
     } else {
        pidl "#define $const->{NAME}\t $const->{VALUE}\n";
index 0037de8713ac6c976ccebc8c1b58144382103b53..537714adf3609f3b0c87695d8e6bbaf5af21e7e2 100644 (file)
@@ -212,21 +212,6 @@ sub is_ref_struct($)
        return 0;
 }
 
-# determine the array size (size_is() or ARRAY_LEN)
-sub array_size($)
-{
-       my $e = shift;
-       my $size = has_property($e, "size_is");
-       if ($size) {
-               return $size;
-       }
-       $size = $e->{ARRAY_LEN};
-       if ($size) {
-               return $size;
-       }
-       return undef;
-}
-
 # return 1 if the string is a C constant
 sub is_constant($)
 {