diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-01-04 23:25:25 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:08:17 -0500 |
commit | 3acf026603944b2de6e55e1d3068f6c9cdde9429 (patch) | |
tree | 2bfcfb01cb8e1749d31b305dd3a604b2a26495f5 | |
parent | 328e260ca9378e83e253f5622ca84ea36b3ebf3a (diff) | |
download | samba-3acf026603944b2de6e55e1d3068f6c9cdde9429.tar.gz samba-3acf026603944b2de6e55e1d3068f6c9cdde9429.tar.bz2 samba-3acf026603944b2de6e55e1d3068f6c9cdde9429.zip |
r4518: added proper support for "typedef enum" in pidl. We can now use enums as types in switch
statements and variable types, and the value will be printed with its string name and value
(This used to be commit 1852033f2ec7584657d586e44d25a280959e4d81)
-rw-r--r-- | source4/build/pidl/header.pm | 5 | ||||
-rw-r--r-- | source4/build/pidl/idl.pm | 506 | ||||
-rw-r--r-- | source4/build/pidl/idl.yp | 11 | ||||
-rw-r--r-- | source4/build/pidl/parser.pm | 119 | ||||
-rw-r--r-- | source4/build/pidl/util.pm | 20 |
5 files changed, 403 insertions, 258 deletions
diff --git a/source4/build/pidl/header.pm b/source4/build/pidl/header.pm index 21565a0f37..ccb302be89 100644 --- a/source4/build/pidl/header.pm +++ b/source4/build/pidl/header.pm @@ -97,6 +97,9 @@ sub HeaderEnum($$) { my($enum) = shift; my($name) = shift; + + util::register_enum($name); + $res .= "\nenum $name {\n"; $tab_depth++; my $els = \@{$enum->{ELEMENTS}}; @@ -160,6 +163,8 @@ sub HeaderType($$$) } if ($data =~ "string") { $res .= "const char *"; + } elsif (util::is_enum($e->{TYPE})) { + $res .= "enum $data"; } elsif (util::is_scalar_type($data)) { $res .= "$data"; } elsif (util::has_property($e, "switch_is")) { diff --git a/source4/build/pidl/idl.pm b/source4/build/pidl/idl.pm index 487b53160e..8c2b989567 100644 --- a/source4/build/pidl/idl.pm +++ b/source4/build/pidl/idl.pm @@ -881,19 +881,9 @@ sub new { DEFAULT => -54 }, {#State 47 - ACTIONS => { - 'IDENTIFIER' => 9, - "enum" => 69, - 'void' => 70 - }, DEFAULT => -49, GOTOS => { - 'identifier' => 72, - 'struct' => 73, - 'enum' => 74, - 'type' => 75, - 'union' => 76, - 'property_list' => 71 + 'property_list' => 69 } }, {#State 48 @@ -901,7 +891,7 @@ sub new { }, {#State 49 ACTIONS => { - "}" => 77, + "}" => 70, "typedef" => 47, "const" => 53 }, @@ -910,25 +900,25 @@ sub new { 'const' => 52, 'function' => 48, 'typedef' => 54, - 'definition' => 78, + 'definition' => 71, 'property_list' => 50 } }, {#State 50 ACTIONS => { 'IDENTIFIER' => 9, - "enum" => 69, + "enum" => 72, "[" => 7, - 'void' => 70 + 'void' => 73 }, DEFAULT => -49, GOTOS => { - 'identifier' => 72, - 'struct' => 73, - 'enum' => 74, - 'type' => 79, - 'union' => 76, - 'property_list' => 71 + 'identifier' => 75, + 'struct' => 76, + 'enum' => 77, + 'type' => 78, + 'union' => 79, + 'property_list' => 74 } }, {#State 51 @@ -1046,52 +1036,58 @@ sub new { }, {#State 69 ACTIONS => { - "{" => 84 + 'IDENTIFIER' => 9, + "enum" => 72, + "[" => 7, + 'void' => 73 + }, + DEFAULT => -49, + GOTOS => { + 'identifier' => 75, + 'struct' => 76, + 'enum' => 77, + 'type' => 84, + 'union' => 79, + 'property_list' => 74 } }, {#State 70 - DEFAULT => -23 - }, - {#State 71 ACTIONS => { - "union" => 85, - "[" => 7, - "struct" => 86 + ";" => 56 + }, + DEFAULT => -76, + GOTOS => { + 'optional_semicolon' => 85 } }, + {#State 71 + DEFAULT => -11 + }, {#State 72 - DEFAULT => -22 + ACTIONS => { + "{" => 86 + } }, {#State 73 - DEFAULT => -19 + DEFAULT => -23 }, {#State 74 - DEFAULT => -21 - }, - {#State 75 ACTIONS => { - 'IDENTIFIER' => 9 - }, - GOTOS => { - 'identifier' => 87 + "union" => 87, + "[" => 7, + "struct" => 88 } }, + {#State 75 + DEFAULT => -22 + }, {#State 76 - DEFAULT => -20 + DEFAULT => -19 }, {#State 77 - ACTIONS => { - ";" => 56 - }, - DEFAULT => -76, - GOTOS => { - 'optional_semicolon' => 88 - } + DEFAULT => -21 }, {#State 78 - DEFAULT => -11 - }, - {#State 79 ACTIONS => { 'IDENTIFIER' => 9 }, @@ -1099,6 +1095,9 @@ sub new { 'identifier' => 89 } }, + {#State 79 + DEFAULT => -20 + }, {#State 80 ACTIONS => { 'IDENTIFIER' => 9 @@ -1154,45 +1153,44 @@ sub new { 'IDENTIFIER' => 9 }, GOTOS => { - 'identifier' => 94, - 'enum_element' => 95, - 'enum_elements' => 96 + 'identifier' => 94 } }, {#State 85 - ACTIONS => { - "{" => 97 - } + DEFAULT => -7 }, {#State 86 ACTIONS => { - "{" => 98 + 'IDENTIFIER' => 9 + }, + GOTOS => { + 'identifier' => 95, + 'enum_element' => 96, + 'enum_elements' => 97 } }, {#State 87 ACTIONS => { - "[" => 100 - }, - DEFAULT => -46, - GOTOS => { - 'array_len' => 99 + "{" => 98 } }, {#State 88 - DEFAULT => -7 + ACTIONS => { + "{" => 99 + } }, {#State 89 ACTIONS => { - "(" => 101 + "(" => 100 } }, {#State 90 ACTIONS => { - "[" => 100, - "=" => 103 + "[" => 103, + "=" => 102 }, GOTOS => { - 'array_len' => 102 + 'array_len' => 101 } }, {#State 91 @@ -1233,88 +1231,97 @@ sub new { }, {#State 94 ACTIONS => { - "=" => 104 + "[" => 103 }, - DEFAULT => -27 + DEFAULT => -46, + GOTOS => { + 'array_len' => 104 + } }, {#State 95 - DEFAULT => -25 + ACTIONS => { + "=" => 105 + }, + DEFAULT => -27 }, {#State 96 - ACTIONS => { - "}" => 105, - "," => 106 - } + DEFAULT => -25 }, {#State 97 ACTIONS => { - "[" => 109 - }, - GOTOS => { - 'union_elements' => 107, - 'union_element' => 108 + "}" => 106, + "," => 107 } }, {#State 98 - DEFAULT => -40, + ACTIONS => { + "[" => 110 + }, GOTOS => { - 'element_list1' => 110 + 'union_elements' => 108, + 'union_element' => 109 } }, {#State 99 - ACTIONS => { - ";" => 111 + DEFAULT => -40, + GOTOS => { + 'element_list1' => 111 } }, {#State 100 ACTIONS => { - 'IDENTIFIER' => 9, - 'CONSTANT' => 28, - 'TEXT' => 22, - "]" => 113 + "," => -42, + "void" => 114, + ")" => -42 }, - DEFAULT => -59, + DEFAULT => -49, GOTOS => { - 'identifier' => 23, - 'text' => 24, - 'anytext' => 112, - 'constant' => 27 + 'base_element' => 112, + 'element_list2' => 115, + 'property_list' => 113 } }, {#State 101 ACTIONS => { - "," => -42, - "void" => 116, - ")" => -42 - }, - DEFAULT => -49, - GOTOS => { - 'base_element' => 114, - 'element_list2' => 117, - 'property_list' => 115 + "=" => 116 } }, {#State 102 ACTIONS => { - "=" => 118 + 'IDENTIFIER' => 9, + 'CONSTANT' => 28, + 'TEXT' => 22 + }, + DEFAULT => -59, + GOTOS => { + 'identifier' => 23, + 'text' => 24, + 'anytext' => 117, + 'constant' => 27 } }, {#State 103 ACTIONS => { 'IDENTIFIER' => 9, 'CONSTANT' => 28, - 'TEXT' => 22 + 'TEXT' => 22, + "]" => 119 }, DEFAULT => -59, GOTOS => { 'identifier' => 23, 'text' => 24, - 'anytext' => 119, + 'anytext' => 118, 'constant' => 27 } }, {#State 104 ACTIONS => { + ";" => 120 + } + }, + {#State 105 + ACTIONS => { 'CONSTANT' => 28, 'TEXT' => 22, 'IDENTIFIER' => 9 @@ -1323,101 +1330,80 @@ sub new { GOTOS => { 'identifier' => 23, 'text' => 24, - 'anytext' => 120, + 'anytext' => 121, 'constant' => 27 } }, - {#State 105 + {#State 106 DEFAULT => -24 }, - {#State 106 + {#State 107 ACTIONS => { 'IDENTIFIER' => 9 }, GOTOS => { - 'identifier' => 94, - 'enum_element' => 121 + 'identifier' => 95, + 'enum_element' => 122 } }, - {#State 107 + {#State 108 ACTIONS => { - "}" => 122, - "[" => 109 + "}" => 123, + "[" => 110 }, GOTOS => { - 'union_element' => 123 + 'union_element' => 124 } }, - {#State 108 + {#State 109 DEFAULT => -31 }, - {#State 109 + {#State 110 ACTIONS => { - "case" => 124, - "default" => 125 + "case" => 125, + "default" => 126 } }, - {#State 110 + {#State 111 ACTIONS => { - "}" => 126 + "}" => 127 }, DEFAULT => -49, GOTOS => { - 'base_element' => 127, - 'property_list' => 115 + 'base_element' => 128, + 'property_list' => 113 } }, - {#State 111 - DEFAULT => -18 - }, {#State 112 - ACTIONS => { - "-" => 35, - "+" => 36, - "&" => 38, - "{" => 37, - "/" => 39, - "(" => 41, - "|" => 40, - "*" => 42, - "." => 43, - "]" => 128, - ">" => 44 - } - }, - {#State 113 - DEFAULT => -47 - }, - {#State 114 DEFAULT => -44 }, - {#State 115 + {#State 113 ACTIONS => { 'IDENTIFIER' => 9, - "enum" => 69, + "enum" => 72, "[" => 7, - 'void' => 70 + 'void' => 73 }, DEFAULT => -49, GOTOS => { - 'identifier' => 72, - 'struct' => 73, - 'enum' => 74, + 'identifier' => 75, + 'struct' => 76, + 'enum' => 77, 'type' => 129, - 'union' => 76, - 'property_list' => 71 + 'union' => 79, + 'property_list' => 74 } }, - {#State 116 + {#State 114 DEFAULT => -43 }, - {#State 117 + {#State 115 ACTIONS => { "," => 130, ")" => 131 } }, - {#State 118 + {#State 116 ACTIONS => { 'IDENTIFIER' => 9, 'CONSTANT' => 28, @@ -1431,7 +1417,7 @@ sub new { 'constant' => 27 } }, - {#State 119 + {#State 117 ACTIONS => { "-" => 35, ";" => 133, @@ -1446,7 +1432,28 @@ sub new { ">" => 44 } }, + {#State 118 + ACTIONS => { + "-" => 35, + "+" => 36, + "&" => 38, + "{" => 37, + "/" => 39, + "(" => 41, + "|" => 40, + "*" => 42, + "." => 43, + "]" => 134, + ">" => 44 + } + }, + {#State 119 + DEFAULT => -47 + }, {#State 120 + DEFAULT => -18 + }, + {#State 121 ACTIONS => { "-" => 35, "+" => 36, @@ -1461,58 +1468,55 @@ sub new { }, DEFAULT => -28 }, - {#State 121 + {#State 122 DEFAULT => -26 }, - {#State 122 + {#State 123 DEFAULT => -30 }, - {#State 123 + {#State 124 DEFAULT => -32 }, - {#State 124 + {#State 125 ACTIONS => { - "(" => 134 + "(" => 135 } }, - {#State 125 + {#State 126 ACTIONS => { - "]" => 135 + "]" => 136 } }, - {#State 126 + {#State 127 DEFAULT => -29 }, - {#State 127 + {#State 128 ACTIONS => { - ";" => 136 + ";" => 137 } }, - {#State 128 - DEFAULT => -48 - }, {#State 129 DEFAULT => -38, GOTOS => { - 'pointers' => 137 + 'pointers' => 138 } }, {#State 130 DEFAULT => -49, GOTOS => { - 'base_element' => 138, - 'property_list' => 115 + 'base_element' => 139, + 'property_list' => 113 } }, {#State 131 ACTIONS => { - ";" => 139 + ";" => 140 } }, {#State 132 ACTIONS => { "-" => 35, - ";" => 140, + ";" => 141, "+" => 36, "&" => 38, "{" => 37, @@ -1528,6 +1532,9 @@ sub new { DEFAULT => -15 }, {#State 134 + DEFAULT => -48 + }, + {#State 135 ACTIONS => { 'IDENTIFIER' => 9, 'CONSTANT' => 28, @@ -1537,42 +1544,42 @@ sub new { GOTOS => { 'identifier' => 23, 'text' => 24, - 'anytext' => 141, + 'anytext' => 142, 'constant' => 27 } }, - {#State 135 + {#State 136 ACTIONS => { - ";" => 142 + ";" => 143 }, DEFAULT => -49, GOTOS => { - 'base_element' => 143, - 'property_list' => 115 + 'base_element' => 144, + 'property_list' => 113 } }, - {#State 136 + {#State 137 DEFAULT => -41 }, - {#State 137 + {#State 138 ACTIONS => { 'IDENTIFIER' => 9, - "*" => 145 + "*" => 146 }, GOTOS => { - 'identifier' => 144 + 'identifier' => 145 } }, - {#State 138 + {#State 139 DEFAULT => -45 }, - {#State 139 + {#State 140 DEFAULT => -17 }, - {#State 140 + {#State 141 DEFAULT => -16 }, - {#State 141 + {#State 142 ACTIONS => { "-" => 35, "+" => 36, @@ -1583,60 +1590,60 @@ sub new { "|" => 40, "*" => 42, "." => 43, - ")" => 146, + ")" => 147, ">" => 44 } }, - {#State 142 + {#State 143 DEFAULT => -36 }, - {#State 143 + {#State 144 ACTIONS => { - ";" => 147 + ";" => 148 } }, - {#State 144 + {#State 145 ACTIONS => { - "[" => 100 + "[" => 103 }, DEFAULT => -46, GOTOS => { - 'array_len' => 148 + 'array_len' => 149 } }, - {#State 145 + {#State 146 DEFAULT => -39 }, - {#State 146 + {#State 147 ACTIONS => { - "]" => 149 + "]" => 150 } }, - {#State 147 + {#State 148 DEFAULT => -35 }, - {#State 148 + {#State 149 DEFAULT => -37 }, - {#State 149 + {#State 150 ACTIONS => { - ";" => 150 + ";" => 151 }, DEFAULT => -49, GOTOS => { - 'base_element' => 151, - 'property_list' => 115 + 'base_element' => 152, + 'property_list' => 113 } }, - {#State 150 + {#State 151 DEFAULT => -34 }, - {#State 151 + {#State 152 ACTIONS => { - ";" => 152 + ";" => 153 } }, - {#State 152 + {#State 153 DEFAULT => -33 } ], @@ -1758,14 +1765,15 @@ sub }} ], [#Rule 18 - 'typedef', 5, + 'typedef', 6, sub #line 90 "build/pidl/idl.yp" {{ - "TYPE" => "TYPEDEF", - "NAME" => $_[3], - "DATA" => $_[2], - "ARRAY_LEN" => $_[4] + "TYPE" => "TYPEDEF", + "PROPERTIES" => $_[2], + "NAME" => $_[4], + "DATA" => $_[3], + "ARRAY_LEN" => $_[5] }} ], [#Rule 19 @@ -1783,13 +1791,13 @@ sub [#Rule 23 'type', 1, sub -#line 99 "build/pidl/idl.yp" +#line 100 "build/pidl/idl.yp" { "void" } ], [#Rule 24 'enum', 4, sub -#line 104 "build/pidl/idl.yp" +#line 105 "build/pidl/idl.yp" {{ "TYPE" => "ENUM", "ELEMENTS" => $_[3] @@ -1798,13 +1806,13 @@ sub [#Rule 25 'enum_elements', 1, sub -#line 111 "build/pidl/idl.yp" +#line 112 "build/pidl/idl.yp" { [ $_[1] ] } ], [#Rule 26 'enum_elements', 3, sub -#line 112 "build/pidl/idl.yp" +#line 113 "build/pidl/idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], [#Rule 27 @@ -1813,13 +1821,13 @@ sub [#Rule 28 'enum_element', 3, sub -#line 116 "build/pidl/idl.yp" +#line 117 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 29 'struct', 5, sub -#line 120 "build/pidl/idl.yp" +#line 121 "build/pidl/idl.yp" {{ "TYPE" => "STRUCT", "PROPERTIES" => $_[1], @@ -1829,7 +1837,7 @@ sub [#Rule 30 'union', 5, sub -#line 128 "build/pidl/idl.yp" +#line 129 "build/pidl/idl.yp" {{ "TYPE" => "UNION", "PROPERTIES" => $_[1], @@ -1839,19 +1847,19 @@ sub [#Rule 31 'union_elements', 1, sub -#line 136 "build/pidl/idl.yp" +#line 137 "build/pidl/idl.yp" { [ $_[1] ] } ], [#Rule 32 'union_elements', 2, sub -#line 137 "build/pidl/idl.yp" +#line 138 "build/pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 33 'union_element', 8, sub -#line 142 "build/pidl/idl.yp" +#line 143 "build/pidl/idl.yp" {{ "TYPE" => "UNION_ELEMENT", "CASE" => $_[4], @@ -1861,7 +1869,7 @@ sub [#Rule 34 'union_element', 7, sub -#line 148 "build/pidl/idl.yp" +#line 149 "build/pidl/idl.yp" {{ "TYPE" => "EMPTY", "CASE" => $_[4], @@ -1870,7 +1878,7 @@ sub [#Rule 35 'union_element', 5, sub -#line 153 "build/pidl/idl.yp" +#line 154 "build/pidl/idl.yp" {{ "TYPE" => "UNION_ELEMENT", "CASE" => "default", @@ -1880,7 +1888,7 @@ sub [#Rule 36 'union_element', 4, sub -#line 159 "build/pidl/idl.yp" +#line 160 "build/pidl/idl.yp" {{ "TYPE" => "EMPTY", "CASE" => "default", @@ -1889,7 +1897,7 @@ sub [#Rule 37 'base_element', 5, sub -#line 166 "build/pidl/idl.yp" +#line 167 "build/pidl/idl.yp" {{ "NAME" => $_[4], "TYPE" => $_[2], @@ -1901,13 +1909,13 @@ sub [#Rule 38 'pointers', 0, sub -#line 178 "build/pidl/idl.yp" +#line 179 "build/pidl/idl.yp" { 0 } ], [#Rule 39 'pointers', 2, sub -#line 179 "build/pidl/idl.yp" +#line 180 "build/pidl/idl.yp" { $_[1]+1 } ], [#Rule 40 @@ -1916,7 +1924,7 @@ sub [#Rule 41 'element_list1', 3, sub -#line 186 "build/pidl/idl.yp" +#line 187 "build/pidl/idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], [#Rule 42 @@ -1928,13 +1936,13 @@ sub [#Rule 44 'element_list2', 1, sub -#line 192 "build/pidl/idl.yp" +#line 193 "build/pidl/idl.yp" { [ $_[1] ] } ], [#Rule 45 'element_list2', 3, sub -#line 193 "build/pidl/idl.yp" +#line 194 "build/pidl/idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], [#Rule 46 @@ -1943,13 +1951,13 @@ sub [#Rule 47 'array_len', 2, sub -#line 198 "build/pidl/idl.yp" +#line 199 "build/pidl/idl.yp" { "*" } ], [#Rule 48 'array_len', 3, sub -#line 199 "build/pidl/idl.yp" +#line 200 "build/pidl/idl.yp" { "$_[2]" } ], [#Rule 49 @@ -1958,31 +1966,31 @@ sub [#Rule 50 'property_list', 4, sub -#line 205 "build/pidl/idl.yp" +#line 206 "build/pidl/idl.yp" { util::FlattenHash([$_[1],$_[3]]); } ], [#Rule 51 'properties', 1, sub -#line 208 "build/pidl/idl.yp" +#line 209 "build/pidl/idl.yp" { $_[1] } ], [#Rule 52 'properties', 3, sub -#line 209 "build/pidl/idl.yp" +#line 210 "build/pidl/idl.yp" { util::FlattenHash([$_[1], $_[3]]); } ], [#Rule 53 'property', 1, sub -#line 212 "build/pidl/idl.yp" +#line 213 "build/pidl/idl.yp" {{ "$_[1]" => "1" }} ], [#Rule 54 'property', 4, sub -#line 213 "build/pidl/idl.yp" +#line 214 "build/pidl/idl.yp" {{ "$_[1]" => "$_[3]" }} ], [#Rule 55 @@ -1991,7 +1999,7 @@ sub [#Rule 56 'listtext', 3, sub -#line 218 "build/pidl/idl.yp" +#line 219 "build/pidl/idl.yp" { "$_[1] $_[3]" } ], [#Rule 57 @@ -2000,13 +2008,13 @@ sub [#Rule 58 'commalisttext', 3, sub -#line 223 "build/pidl/idl.yp" +#line 224 "build/pidl/idl.yp" { "$_[1],$_[3]" } ], [#Rule 59 'anytext', 0, sub -#line 227 "build/pidl/idl.yp" +#line 228 "build/pidl/idl.yp" { "" } ], [#Rule 60 @@ -2021,61 +2029,61 @@ sub [#Rule 63 'anytext', 3, sub -#line 229 "build/pidl/idl.yp" +#line 230 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 64 'anytext', 3, sub -#line 230 "build/pidl/idl.yp" +#line 231 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 65 'anytext', 3, sub -#line 231 "build/pidl/idl.yp" +#line 232 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 66 'anytext', 3, sub -#line 232 "build/pidl/idl.yp" +#line 233 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 67 'anytext', 3, sub -#line 233 "build/pidl/idl.yp" +#line 234 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 68 'anytext', 3, sub -#line 234 "build/pidl/idl.yp" +#line 235 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 69 'anytext', 3, sub -#line 235 "build/pidl/idl.yp" +#line 236 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 70 'anytext', 3, sub -#line 236 "build/pidl/idl.yp" +#line 237 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]" } ], [#Rule 71 'anytext', 5, sub -#line 237 "build/pidl/idl.yp" +#line 238 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]$_[4]$_[5]" } ], [#Rule 72 'anytext', 5, sub -#line 238 "build/pidl/idl.yp" +#line 239 "build/pidl/idl.yp" { "$_[1]$_[2]$_[3]$_[4]$_[5]" } ], [#Rule 73 @@ -2087,7 +2095,7 @@ sub [#Rule 75 'text', 1, sub -#line 247 "build/pidl/idl.yp" +#line 248 "build/pidl/idl.yp" { "\"$_[1]\"" } ], [#Rule 76 @@ -2101,7 +2109,7 @@ sub bless($self,$class); } -#line 258 "build/pidl/idl.yp" +#line 259 "build/pidl/idl.yp" use util; diff --git a/source4/build/pidl/idl.yp b/source4/build/pidl/idl.yp index fb2433ee72..664192f4b4 100644 --- a/source4/build/pidl/idl.yp +++ b/source4/build/pidl/idl.yp @@ -86,12 +86,13 @@ function: property_list type identifier '(' element_list2 ')' ';' }} ; -typedef: 'typedef' type identifier array_len ';' +typedef: 'typedef' property_list type identifier array_len ';' {{ - "TYPE" => "TYPEDEF", - "NAME" => $_[3], - "DATA" => $_[2], - "ARRAY_LEN" => $_[4] + "TYPE" => "TYPEDEF", + "PROPERTIES" => $_[2], + "NAME" => $_[4], + "DATA" => $_[3], + "ARRAY_LEN" => $_[5] }} ; diff --git a/source4/build/pidl/parser.pm b/source4/build/pidl/parser.pm index 83a6e06820..fb4cc8af5e 100644 --- a/source4/build/pidl/parser.pm +++ b/source4/build/pidl/parser.pm @@ -117,6 +117,18 @@ sub check_null_pointer($) } } +##################################################################### +# check that a variable we get from find_size_var isn't a null pointer +# void return varient +sub check_null_pointer_void($) +{ + my $size = shift; + if ($size =~ /^\*/) { + my $size2 = substr($size, 1); + pidl "\tif ($size2 == NULL) return;\n"; + } +} + ##################################################################### # work out is a parse function should be declared static or not @@ -457,7 +469,11 @@ sub ParseElementPullSwitch($$$$) !util::has_property($utype->{DATA}, "nodiscriminant")) { my $e2 = find_sibling($e, $switch); pidl "\tif (($ndr_flags) & NDR_SCALARS) {\n"; - pidl "\t\t $e2->{TYPE} _level;\n"; + if (util::is_enum($e2->{TYPE})) { + pidl "\t\t enum $e2->{TYPE} _level;\n"; + } else { + pidl "\t\t $e2->{TYPE} _level;\n"; + } pidl "\t\tNDR_CHECK(ndr_pull_$e2->{TYPE}(ndr, &_level));\n"; if ($switch_var =~ /r->in/) { pidl "\t\tif (!(ndr->flags & LIBNDR_FLAG_REF_ALLOC) && _level != $switch_var) {\n"; @@ -526,7 +542,7 @@ sub ParseElementPrintSwitch($$$) my $switch_var = find_size_var($e, $switch, $var_prefix); my $cprefix = util::c_push_prefix($e); - check_null_pointer($switch_var); + check_null_pointer_void($switch_var); pidl "\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $switch_var, $cprefix$var_prefix$e->{NAME});\n"; } @@ -777,6 +793,72 @@ sub ParseStructPush($) end_flags($struct); } + +##################################################################### +# generate a push function for an enum +sub ParseEnumPush($) +{ + my($enum) = shift; + + start_flags($enum); + + if (util::has_property($enum->{PARENT}, "v1_enum")) { + pidl "\tNDR_CHECK(ndr_push_uint32(ndr, r));\n"; + } else { + pidl "\tNDR_CHECK(ndr_push_uint16(ndr, r));\n"; + } + + end_flags($enum); +} + +##################################################################### +# generate a pull function for an enum +sub ParseEnumPull($) +{ + my($enum) = shift; + + start_flags($enum); + + if (util::has_property($enum->{PARENT}, "v1_enum")) { + pidl "\tuint32_t v;\n"; + pidl "\tNDR_CHECK(ndr_pull_uint32(ndr, &v));\n"; + } else { + pidl "\tuint16_t v;\n"; + pidl "\tNDR_CHECK(ndr_pull_uint16(ndr, &v));\n"; + } + pidl "\t*r = v;\n"; + + end_flags($enum); +} + +##################################################################### +# generate a print function for an enum +sub ParseEnumPrint($) +{ + my($enum) = shift; + + start_flags($enum); + + pidl "\tconst char *val = NULL;\n\n"; + + pidl "\tswitch (r) {\n"; + my $els = \@{$enum->{ELEMENTS}}; + foreach my $i (0 .. $#{$els}) { + my $e = ${$els}[$i]; + chomp $e; + if ($e =~ /^(.*)=/) { + $e = $1; + } + pidl "\t\tcase $e: val = \"$e\"; break;\n"; + } + + pidl "\t}\n\n\tndr_print_enum(ndr, name, \"$enum->{TYPE}\", val, r);\n"; + + end_flags($enum); +} + + + ##################################################################### # generate a struct print function sub ParseStructPrint($) @@ -1128,6 +1210,8 @@ sub ParseTypePush($) ParseStructPush($data); ($data->{TYPE} eq "UNION") && ParseUnionPush($data); + ($data->{TYPE} eq "ENUM") && + ParseEnumPush($data); } } @@ -1142,6 +1226,8 @@ sub ParseTypePrint($) ParseStructPrint($data); ($data->{TYPE} eq "UNION") && ParseUnionPrint($data); + ($data->{TYPE} eq "ENUM") && + ParseEnumPrint($data); } } @@ -1156,6 +1242,8 @@ sub ParseTypePull($) ParseStructPull($data); ($data->{TYPE} eq "UNION") && ParseUnionPull($data); + ($data->{TYPE} eq "ENUM") && + ParseEnumPull($data); } } @@ -1172,7 +1260,7 @@ sub ParseTypedefPush($) } if ($e->{DATA}->{TYPE} eq "STRUCT") { - pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, struct $e->{NAME} *r)"; + pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, const struct $e->{NAME} *r)"; pidl "\n{\n"; ParseTypePush($e->{DATA}); pidl "\treturn NT_STATUS_OK;\n"; @@ -1180,7 +1268,15 @@ sub ParseTypedefPush($) } if ($e->{DATA}->{TYPE} eq "UNION") { - pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, int level, union $e->{NAME} *r)"; + pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, int level, const union $e->{NAME} *r)"; + pidl "\n{\n"; + ParseTypePush($e->{DATA}); + pidl "\treturn NT_STATUS_OK;\n"; + pidl "}\n\n"; + } + + if ($e->{DATA}->{TYPE} eq "ENUM") { + pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, enum $e->{NAME} r)"; pidl "\n{\n"; ParseTypePush($e->{DATA}); pidl "\treturn NT_STATUS_OK;\n"; @@ -1216,6 +1312,14 @@ sub ParseTypedefPull($) pidl "\treturn NT_STATUS_OK;\n"; pidl "}\n\n"; } + + if ($e->{DATA}->{TYPE} eq "ENUM") { + pidl $static . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, enum $e->{NAME} *r)"; + pidl "\n{\n"; + ParseTypePull($e->{DATA}); + pidl "\treturn NT_STATUS_OK;\n"; + pidl "}\n\n"; + } } @@ -1240,6 +1344,13 @@ sub ParseTypedefPrint($) ParseTypePrint($e->{DATA}); pidl "}\n\n"; } + + if ($e->{DATA}->{TYPE} eq "ENUM") { + pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, enum $e->{NAME} r)"; + pidl "\n{\n"; + ParseTypePrint($e->{DATA}); + pidl "}\n\n"; + } } ##################################################################### diff --git a/source4/build/pidl/util.pm b/source4/build/pidl/util.pm index 7293a903d5..0f09a8571f 100644 --- a/source4/build/pidl/util.pm +++ b/source4/build/pidl/util.pm @@ -4,6 +4,8 @@ # released under the GNU GPL package util; +my %is_enum; + ##################################################################### # load a data structure from a file (as saved with SaveStructure) sub LoadStructure($) @@ -200,6 +202,20 @@ sub property_matches($$$) return undef; } +my %enum_list; + +sub register_enum($) +{ + my $name = shift; + $enum_list{$name} = 1; +} + +sub is_enum($) +{ + my $name = shift; + return defined $enum_list{$name} +} + sub is_scalar_type($) { my($type) = shift; @@ -213,6 +229,10 @@ sub is_scalar_type($) return 1; } + if (is_enum($type)) { + return 1; + } + return 0; } |