From 5c0ccfd8cbe812f5b058410dfd0d9f5e922ff886 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 5 Oct 2010 08:09:22 +0200 Subject: [PATCH] TODO pidl/IDL: give anonymous structs and unions a name... TODO fix aligment --- pidl/idl.yp | 29 ++- pidl/lib/Parse/Pidl/IDL.pm | 439 ++++++++++++++++++++----------------- 2 files changed, 266 insertions(+), 202 deletions(-) diff --git a/pidl/idl.yp b/pidl/idl.yp index c8a65f6f6293..52f2bddad0d6 100644 --- a/pidl/idl.yp +++ b/pidl/idl.yp @@ -301,7 +301,7 @@ opt_struct_body: ; struct: - property_list 'struct' optional_identifier opt_struct_body + property_list 'struct' optional_anonymous_identifier opt_struct_body {{ "TYPE" => "STRUCT", "PROPERTIES" => $_[1], @@ -351,7 +351,7 @@ opt_union_body: ; union: - property_list 'union' optional_identifier opt_union_body + property_list 'union' optional_anonymous_identifier opt_union_body {{ "TYPE" => "UNION", "PROPERTIES" => $_[1], @@ -523,6 +523,12 @@ optional_identifier: IDENTIFIER ; +optional_anonymous_identifier: + { anonymous_identifier($_[0]) } + | + IDENTIFIER +; + constant: CONSTANT ; @@ -543,6 +549,7 @@ optional_semicolon: %% use Parse::Pidl qw(error); +use File::Basename; ##################################################################### # flatten an array of hashes into a single hash @@ -587,6 +594,23 @@ sub CleanData($) return $v; } +sub anonymous_identifier($) +{ + my($parser)=shift; + my $name = "__pidl_anonymous_"; + $name .= basename($parser->YYData->{FILE}); + $name .= "_"; + $name .= $parser->YYData->{LINE}; + $name .= "_"; + $name .= $parser->YYData->{ANONYMOUS_COUNTER}++; + + $name =~ s/\./_/g; + $name =~ s/\//_/g; + $name =~ s/\\/_/g; + + return $name; +} + sub _Error { if (exists $_[0]->YYData->{ERRMSG}) { error($_[0]->YYData, $_[0]->YYData->{ERRMSG}); @@ -666,6 +690,7 @@ sub parse_string $self->YYData->{INPUT} = $data; $self->YYData->{LINE} = 0; $self->YYData->{LAST_TOKEN} = "NONE"; + $self->YYData->{ANONYMOUS_COUNTER} = 0; my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error ); diff --git a/pidl/lib/Parse/Pidl/IDL.pm b/pidl/lib/Parse/Pidl/IDL.pm index 6927c892556b..f9867bd042a2 100644 --- a/pidl/lib/Parse/Pidl/IDL.pm +++ b/pidl/lib/Parse/Pidl/IDL.pm @@ -124,7 +124,7 @@ sub new { } }, {#State 16 - DEFAULT => -120 + DEFAULT => -122 }, {#State 17 DEFAULT => -11 @@ -330,7 +330,7 @@ sub new { DEFAULT => -99 }, {#State 48 - DEFAULT => -119 + DEFAULT => -121 }, {#State 49 ACTIONS => { @@ -348,7 +348,7 @@ sub new { ACTIONS => { ";" => 86 }, - DEFAULT => -121, + DEFAULT => -123, GOTOS => { 'optional_semicolon' => 85 } @@ -686,7 +686,7 @@ sub new { DEFAULT => -13 }, {#State 86 - DEFAULT => -122 + DEFAULT => -124 }, {#State 87 ACTIONS => { @@ -697,7 +697,7 @@ sub new { ACTIONS => { ";" => 86 }, - DEFAULT => -121, + DEFAULT => -123, GOTOS => { 'optional_semicolon' => 124 } @@ -734,9 +734,9 @@ sub new { ACTIONS => { 'IDENTIFIER' => 126 }, - DEFAULT => -117, + DEFAULT => -119, GOTOS => { - 'optional_identifier' => 127 + 'optional_anonymous_identifier' => 127 } }, {#State 93 @@ -770,9 +770,9 @@ sub new { ACTIONS => { 'IDENTIFIER' => 126 }, - DEFAULT => -117, + DEFAULT => -119, GOTOS => { - 'optional_identifier' => 129 + 'optional_anonymous_identifier' => 129 } }, {#State 99 @@ -783,20 +783,20 @@ sub new { }, {#State 101 ACTIONS => { - 'IDENTIFIER' => 126 + 'IDENTIFIER' => 130 }, DEFAULT => -117, GOTOS => { - 'optional_identifier' => 130 + 'optional_identifier' => 131 } }, {#State 102 ACTIONS => { - 'IDENTIFIER' => 126 + 'IDENTIFIER' => 130 }, DEFAULT => -117, GOTOS => { - 'optional_identifier' => 131 + 'optional_identifier' => 132 } }, {#State 103 @@ -816,7 +816,7 @@ sub new { 'identifier' => 96, 'struct' => 62, 'enum' => 65, - 'type' => 132, + 'type' => 133, 'union' => 67, 'sign' => 97 } @@ -829,13 +829,13 @@ sub new { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 133 + 'identifier' => 134 } }, {#State 106 DEFAULT => -75, GOTOS => { - 'pointers' => 134 + 'pointers' => 135 } }, {#State 107 @@ -942,7 +942,7 @@ sub new { }, {#State 113 ACTIONS => { - "}" => 135, + "}" => 136, "," => 83 } }, @@ -991,7 +991,7 @@ sub new { {#State 117 ACTIONS => { "," => 83, - ")" => 136 + ")" => 137 } }, {#State 118 @@ -1067,20 +1067,20 @@ sub new { {#State 125 DEFAULT => -75, GOTOS => { - 'pointers' => 137 + 'pointers' => 138 } }, {#State 126 - DEFAULT => -118 + DEFAULT => -120 }, {#State 127 ACTIONS => { - "{" => 139 + "{" => 140 }, DEFAULT => -71, GOTOS => { - 'union_body' => 140, - 'opt_union_body' => 138 + 'union_body' => 141, + 'opt_union_body' => 139 } }, {#State 128 @@ -1088,52 +1088,55 @@ sub new { }, {#State 129 ACTIONS => { - "{" => 142 + "{" => 143 }, DEFAULT => -61, GOTOS => { - 'struct_body' => 141, - 'opt_struct_body' => 143 + 'struct_body' => 142, + 'opt_struct_body' => 144 } }, {#State 130 + DEFAULT => -118 + }, + {#State 131 ACTIONS => { - "{" => 144 + "{" => 145 }, DEFAULT => -44, GOTOS => { - 'opt_enum_body' => 146, - 'enum_body' => 145 + 'opt_enum_body' => 147, + 'enum_body' => 146 } }, - {#State 131 + {#State 132 ACTIONS => { - "{" => 148 + "{" => 149 }, DEFAULT => -52, GOTOS => { - 'bitmap_body' => 149, - 'opt_bitmap_body' => 147 + 'bitmap_body' => 150, + 'opt_bitmap_body' => 148 } }, - {#State 132 + {#State 133 DEFAULT => -77 }, - {#State 133 + {#State 134 ACTIONS => { - "(" => 150 + "(" => 151 } }, - {#State 134 + {#State 135 ACTIONS => { 'IDENTIFIER' => 26, - "*" => 152 + "*" => 153 }, GOTOS => { - 'identifier' => 151 + 'identifier' => 152 } }, - {#State 135 + {#State 136 ACTIONS => { 'CONSTANT' => 48, 'TEXT' => 16, @@ -1142,12 +1145,12 @@ sub new { DEFAULT => -97, GOTOS => { 'identifier' => 50, - 'anytext' => 153, + 'anytext' => 154, 'text' => 51, 'constant' => 47 } }, - {#State 136 + {#State 137 ACTIONS => { 'CONSTANT' => 48, 'TEXT' => 16, @@ -1156,104 +1159,104 @@ sub new { DEFAULT => -97, GOTOS => { 'identifier' => 50, - 'anytext' => 154, + 'anytext' => 155, 'text' => 51, 'constant' => 47 } }, - {#State 137 + {#State 138 ACTIONS => { 'IDENTIFIER' => 26, - "*" => 152 + "*" => 153 }, GOTOS => { - 'identifier' => 155 + 'identifier' => 156 } }, - {#State 138 + {#State 139 DEFAULT => -73 }, - {#State 139 + {#State 140 DEFAULT => -68, GOTOS => { - 'union_elements' => 156 + 'union_elements' => 157 } }, - {#State 140 + {#State 141 DEFAULT => -72 }, - {#State 141 + {#State 142 DEFAULT => -62 }, - {#State 142 + {#State 143 DEFAULT => -78, GOTOS => { - 'element_list1' => 157 + 'element_list1' => 158 } }, - {#State 143 + {#State 144 DEFAULT => -63 }, - {#State 144 + {#State 145 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 158, - 'enum_element' => 159, - 'enum_elements' => 160 + 'identifier' => 159, + 'enum_element' => 160, + 'enum_elements' => 161 } }, - {#State 145 + {#State 146 DEFAULT => -45 }, - {#State 146 + {#State 147 DEFAULT => -46 }, - {#State 147 + {#State 148 DEFAULT => -54 }, - {#State 148 + {#State 149 ACTIONS => { 'IDENTIFIER' => 26 }, DEFAULT => -57, GOTOS => { - 'identifier' => 163, - 'bitmap_element' => 162, - 'bitmap_elements' => 161, - 'opt_bitmap_elements' => 164 + 'identifier' => 164, + 'bitmap_element' => 163, + 'bitmap_elements' => 162, + 'opt_bitmap_elements' => 165 } }, - {#State 149 + {#State 150 DEFAULT => -53 }, - {#State 150 + {#State 151 ACTIONS => { "," => -82, - "void" => 168, - "const" => 166, + "void" => 169, + "const" => 167, ")" => -82 }, DEFAULT => -80, GOTOS => { - 'optional_const' => 165, - 'element_list2' => 167 + 'optional_const' => 166, + 'element_list2' => 168 } }, - {#State 151 + {#State 152 ACTIONS => { - "[" => 169, - "=" => 171 + "[" => 170, + "=" => 172 }, GOTOS => { - 'array_len' => 170 + 'array_len' => 171 } }, - {#State 152 + {#State 153 DEFAULT => -76 }, - {#State 153 + {#State 154 ACTIONS => { "-" => 69, ":" => 68, @@ -1273,7 +1276,7 @@ sub new { }, DEFAULT => -115 }, - {#State 154 + {#State 155 ACTIONS => { ":" => 68, "<" => 71, @@ -1284,109 +1287,109 @@ sub new { }, DEFAULT => -114 }, - {#State 155 + {#State 156 ACTIONS => { - "[" => 169 + "[" => 170 }, DEFAULT => -86, GOTOS => { - 'array_len' => 172 + 'array_len' => 173 } }, - {#State 156 + {#State 157 ACTIONS => { - "}" => 173 + "}" => 174 }, DEFAULT => -89, GOTOS => { - 'optional_base_element' => 175, - 'property_list' => 174 + 'optional_base_element' => 176, + 'property_list' => 175 } }, - {#State 157 + {#State 158 ACTIONS => { - "}" => 176 + "}" => 177 }, DEFAULT => -89, GOTOS => { - 'base_element' => 177, - 'property_list' => 178 + 'base_element' => 178, + 'property_list' => 179 } }, - {#State 158 + {#State 159 ACTIONS => { - "=" => 179 + "=" => 180 }, DEFAULT => -49 }, - {#State 159 + {#State 160 DEFAULT => -47 }, - {#State 160 + {#State 161 ACTIONS => { - "}" => 180, - "," => 181 + "}" => 181, + "," => 182 } }, - {#State 161 + {#State 162 ACTIONS => { - "," => 182 + "," => 183 }, DEFAULT => -58 }, - {#State 162 + {#State 163 DEFAULT => -55 }, - {#State 163 + {#State 164 ACTIONS => { - "=" => 183 + "=" => 184 } }, - {#State 164 + {#State 165 ACTIONS => { - "}" => 184 + "}" => 185 } }, - {#State 165 + {#State 166 DEFAULT => -89, GOTOS => { - 'base_element' => 185, - 'property_list' => 178 + 'base_element' => 186, + 'property_list' => 179 } }, - {#State 166 + {#State 167 DEFAULT => -81 }, - {#State 167 + {#State 168 ACTIONS => { - "," => 186, - ")" => 187 + "," => 187, + ")" => 188 } }, - {#State 168 + {#State 169 DEFAULT => -83 }, - {#State 169 + {#State 170 ACTIONS => { 'CONSTANT' => 48, 'TEXT' => 16, - "]" => 188, + "]" => 189, 'IDENTIFIER' => 26 }, DEFAULT => -97, GOTOS => { 'identifier' => 50, - 'anytext' => 189, + 'anytext' => 190, 'text' => 51, 'constant' => 47 } }, - {#State 170 + {#State 171 ACTIONS => { - "=" => 190 + "=" => 191 } }, - {#State 171 + {#State 172 ACTIONS => { 'CONSTANT' => 48, 'TEXT' => 16, @@ -1395,43 +1398,43 @@ sub new { DEFAULT => -97, GOTOS => { 'identifier' => 50, - 'anytext' => 191, + 'anytext' => 192, 'text' => 51, 'constant' => 47 } }, - {#State 172 + {#State 173 ACTIONS => { - ";" => 192 + ";" => 193 } }, - {#State 173 + {#State 174 DEFAULT => -70 }, - {#State 174 + {#State 175 ACTIONS => { "[" => 20 }, DEFAULT => -89, GOTOS => { - 'base_or_empty' => 193, - 'base_element' => 194, - 'empty_element' => 195, - 'property_list' => 196 + 'base_or_empty' => 194, + 'base_element' => 195, + 'empty_element' => 196, + 'property_list' => 197 } }, - {#State 175 + {#State 176 DEFAULT => -69 }, - {#State 176 + {#State 177 DEFAULT => -60 }, - {#State 177 + {#State 178 ACTIONS => { - ";" => 197 + ";" => 198 } }, - {#State 178 + {#State 179 ACTIONS => { 'IDENTIFIER' => 26, "signed" => 100, @@ -1449,12 +1452,12 @@ sub new { 'identifier' => 96, 'struct' => 62, 'enum' => 65, - 'type' => 198, + 'type' => 199, 'union' => 67, 'sign' => 97 } }, - {#State 179 + {#State 180 ACTIONS => { 'CONSTANT' => 48, 'TEXT' => 16, @@ -1463,33 +1466,33 @@ sub new { DEFAULT => -97, GOTOS => { 'identifier' => 50, - 'anytext' => 199, + 'anytext' => 200, 'text' => 51, 'constant' => 47 } }, - {#State 180 + {#State 181 DEFAULT => -43 }, - {#State 181 + {#State 182 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 158, - 'enum_element' => 200 + 'identifier' => 159, + 'enum_element' => 201 } }, - {#State 182 + {#State 183 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 163, - 'bitmap_element' => 201 + 'identifier' => 164, + 'bitmap_element' => 202 } }, - {#State 183 + {#State 184 ACTIONS => { 'CONSTANT' => 48, 'TEXT' => 16, @@ -1498,41 +1501,41 @@ sub new { DEFAULT => -97, GOTOS => { 'identifier' => 50, - 'anytext' => 202, + 'anytext' => 203, 'text' => 51, 'constant' => 47 } }, - {#State 184 + {#State 185 DEFAULT => -51 }, - {#State 185 + {#State 186 DEFAULT => -84 }, - {#State 186 + {#State 187 ACTIONS => { - "const" => 166 + "const" => 167 }, DEFAULT => -80, GOTOS => { - 'optional_const' => 203 + 'optional_const' => 204 } }, - {#State 187 + {#State 188 ACTIONS => { - ";" => 204 + ";" => 205 } }, - {#State 188 + {#State 189 ACTIONS => { - "[" => 169 + "[" => 170 }, DEFAULT => -86, GOTOS => { - 'array_len' => 205 + 'array_len' => 206 } }, - {#State 189 + {#State 190 ACTIONS => { "-" => 69, ":" => 68, @@ -1548,11 +1551,11 @@ sub new { "(" => 78, "*" => 80, "." => 81, - "]" => 206, + "]" => 207, ">" => 82 } }, - {#State 190 + {#State 191 ACTIONS => { 'CONSTANT' => 48, 'TEXT' => 16, @@ -1561,18 +1564,18 @@ sub new { DEFAULT => -97, GOTOS => { 'identifier' => 50, - 'anytext' => 207, + 'anytext' => 208, 'text' => 51, 'constant' => 47 } }, - {#State 191 + {#State 192 ACTIONS => { "-" => 69, ":" => 68, "?" => 70, "<" => 71, - ";" => 208, + ";" => 209, "+" => 73, "~" => 72, "&" => 75, @@ -1586,25 +1589,25 @@ sub new { ">" => 82 } }, - {#State 192 + {#State 193 DEFAULT => -29 }, - {#State 193 + {#State 194 DEFAULT => -67 }, - {#State 194 + {#State 195 ACTIONS => { - ";" => 209 + ";" => 210 } }, - {#State 195 + {#State 196 DEFAULT => -66 }, - {#State 196 + {#State 197 ACTIONS => { 'IDENTIFIER' => 26, "signed" => 100, - ";" => 210, + ";" => 211, 'void' => 93, "unsigned" => 104, "[" => 20 @@ -1619,21 +1622,21 @@ sub new { 'identifier' => 96, 'struct' => 62, 'enum' => 65, - 'type' => 198, + 'type' => 199, 'union' => 67, 'sign' => 97 } }, - {#State 197 + {#State 198 DEFAULT => -79 }, - {#State 198 + {#State 199 DEFAULT => -75, GOTOS => { - 'pointers' => 211 + 'pointers' => 212 } }, - {#State 199 + {#State 200 ACTIONS => { "-" => 69, ":" => 68, @@ -1653,13 +1656,13 @@ sub new { }, DEFAULT => -50 }, - {#State 200 + {#State 201 DEFAULT => -48 }, - {#State 201 + {#State 202 DEFAULT => -56 }, - {#State 202 + {#State 203 ACTIONS => { "-" => 69, ":" => 68, @@ -1679,35 +1682,35 @@ sub new { }, DEFAULT => -59 }, - {#State 203 + {#State 204 DEFAULT => -89, GOTOS => { - 'base_element' => 212, - 'property_list' => 178 + 'base_element' => 213, + 'property_list' => 179 } }, - {#State 204 + {#State 205 DEFAULT => -28 }, - {#State 205 + {#State 206 DEFAULT => -87 }, - {#State 206 + {#State 207 ACTIONS => { - "[" => 169 + "[" => 170 }, DEFAULT => -86, GOTOS => { - 'array_len' => 213 + 'array_len' => 214 } }, - {#State 207 + {#State 208 ACTIONS => { "-" => 69, ":" => 68, "?" => 70, "<" => 71, - ";" => 214, + ";" => 215, "+" => 73, "~" => 72, "&" => 75, @@ -1721,43 +1724,43 @@ sub new { ">" => 82 } }, - {#State 208 + {#State 209 DEFAULT => -26 }, - {#State 209 + {#State 210 DEFAULT => -65 }, - {#State 210 + {#State 211 DEFAULT => -64 }, - {#State 211 + {#State 212 ACTIONS => { 'IDENTIFIER' => 26, - "*" => 152 + "*" => 153 }, GOTOS => { - 'identifier' => 215 + 'identifier' => 216 } }, - {#State 212 + {#State 213 DEFAULT => -85 }, - {#State 213 + {#State 214 DEFAULT => -88 }, - {#State 214 + {#State 215 DEFAULT => -27 }, - {#State 215 + {#State 216 ACTIONS => { - "[" => 169 + "[" => 170 }, DEFAULT => -86, GOTOS => { - 'array_len' => 216 + 'array_len' => 217 } }, - {#State 216 + {#State 217 DEFAULT => -74 } ], @@ -2486,18 +2489,31 @@ sub 'optional_identifier', 1, undef ], [#Rule 119 - 'constant', 1, undef + 'optional_anonymous_identifier', 0, +sub +#line 503 "idl.yp" +{ anonymous_identifier($_[0]) } ], [#Rule 120 + 'optional_anonymous_identifier', 1, undef + ], + [#Rule 121 + 'constant', 1, undef + ], + [#Rule 122 'text', 1, sub +<<<<<<< HEAD #line 531 "idl.yp" +======= +#line 513 "idl.yp" +>>>>>>> 239255a... TODO pidl/IDL: give anonymous structs and unions a name... { "\"$_[1]\"" } ], - [#Rule 121 + [#Rule 123 'optional_semicolon', 0, undef ], - [#Rule 122 + [#Rule 124 'optional_semicolon', 1, undef ] ], @@ -2505,10 +2521,15 @@ sub bless($self,$class); } +<<<<<<< HEAD #line 543 "idl.yp" +======= +#line 525 "idl.yp" +>>>>>>> 239255a... TODO pidl/IDL: give anonymous structs and unions a name... use Parse::Pidl qw(error); +use File::Basename; ##################################################################### # flatten an array of hashes into a single hash @@ -2553,6 +2574,23 @@ sub CleanData($) return $v; } +sub anonymous_identifier($) +{ + my($parser)=shift; + my $name = "__pidl_anonymous_"; + $name .= basename($parser->YYData->{FILE}); + $name .= "_"; + $name .= $parser->YYData->{LINE}; + $name .= "_"; + $name .= $parser->YYData->{ANONYMOUS_COUNTER}++; + + $name =~ s/\./_/g; + $name =~ s/\//_/g; + $name =~ s/\\/_/g; + + return $name; +} + sub _Error { if (exists $_[0]->YYData->{ERRMSG}) { error($_[0]->YYData, $_[0]->YYData->{ERRMSG}); @@ -2632,6 +2670,7 @@ sub parse_string $self->YYData->{INPUT} = $data; $self->YYData->{LINE} = 0; $self->YYData->{LAST_TOKEN} = "NONE"; + $self->YYData->{ANONYMOUS_COUNTER} = 0; my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error ); -- 2.34.1