1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

r12481: Move parser-specific utility functions to idl.yp, remove some unused functions

Allow the use of non-typedef structs and unions when declaring variables. Allow the
use of the 'signed' and 'unsigned' qualifiers for integer types
This commit is contained in:
Jelmer Vernooij 2005-12-25 14:59:21 +00:00 committed by Gerald (Jerry) Carter
parent 1fa6c3568b
commit bc6b45e242
3 changed files with 926 additions and 777 deletions

View File

@ -140,15 +140,22 @@ usertype: struct | union | enum | bitmap;
typedecl: usertype ';' { $_[1] };
type: usertype | identifier
| void { "void" }
sign: 'signed' | 'unsigned';
existingtype:
| sign identifier { "$_[1] $_[2]" }
| identifier
;
enum: 'enum' optional_identifier '{' enum_elements '}'
type: usertype | existingtype | void { "void" } ;
enum_body: '{' enum_elements '}' { $_[2] };
opt_enum_body: | enum_body;
enum: 'enum' optional_identifier opt_enum_body
{{
"TYPE" => "ENUM",
"NAME" => $_[2],
"ELEMENTS" => $_[4]
"ELEMENTS" => $_[3]
}}
;
@ -161,11 +168,13 @@ enum_element: identifier
| identifier '=' anytext { "$_[1]$_[2]$_[3]" }
;
bitmap: 'bitmap' optional_identifier '{' bitmap_elements '}'
bitmap_body: '{' bitmap_elements '}' { $_[2] };
opt_bitmap_body: | bitmap_body;
bitmap: 'bitmap' optional_identifier opt_bitmap_body
{{
"TYPE" => "BITMAP",
"NAME" => $_[2],
"ELEMENTS" => $_[4]
"ELEMENTS" => $_[3]
}}
;
@ -177,11 +186,14 @@ bitmap_elements:
bitmap_element: identifier '=' anytext { "$_[1] ( $_[3] )" }
;
struct: 'struct' optional_identifier '{' element_list1 '}'
struct_body: '{' element_list1 '}' { $_[2] };
opt_struct_body: | struct_body;
struct: 'struct' optional_identifier opt_struct_body
{{
"TYPE" => "STRUCT",
"NAME" => $_[2],
"ELEMENTS" => $_[4]
"ELEMENTS" => $_[3]
}}
;
@ -200,7 +212,7 @@ empty_element: property_list ';'
base_or_empty: base_element ';' | empty_element;
optional_base_element:
property_list base_or_empty { $_[2]->{PROPERTIES} = Parse::Pidl::Util::FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] }
property_list base_or_empty { $_[2]->{PROPERTIES} = FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] }
;
union_elements:
@ -208,11 +220,14 @@ union_elements:
| union_elements optional_base_element { push(@{$_[1]}, $_[2]); $_[1] }
;
union: 'union' optional_identifier '{' union_elements '}'
union_body: '{' union_elements '}' { $_[2] };
opt_union_body: | union_body;
union: 'union' optional_identifier opt_union_body
{{
"TYPE" => "UNION",
"NAME" => $_[2],
"ELEMENTS" => $_[4]
"ELEMENTS" => $_[3]
}}
;
@ -256,11 +271,11 @@ array_len:
property_list:
#empty
| property_list '[' properties ']' { Parse::Pidl::Util::FlattenHash([$_[1],$_[3]]); }
| property_list '[' properties ']' { FlattenHash([$_[1],$_[3]]); }
;
properties: property { $_[1] }
| properties ',' property { Parse::Pidl::Util::FlattenHash([$_[1], $_[3]]); }
| properties ',' property { FlattenHash([$_[1], $_[3]]); }
;
property: identifier {{ "$_[1]" => "1" }}
@ -321,7 +336,21 @@ optional_semicolon:
# start code
%%
use Parse::Pidl::Util;
#####################################################################
# flatten an array of hashes into a single hash
sub FlattenHash($)
{
my $a = shift;
my %b;
for my $d (@{$a}) {
for my $k (keys %{$d}) {
$b{$k} = $d->{$k};
}
}
return \%b;
}
#####################################################################
# traverse a perl data structure removing any empty arrays or
@ -405,7 +434,7 @@ again:
$parser->YYData->{LAST_TOKEN} = $1;
if ($1 =~
/^(coclass|interface|const|typedef|declare|union
|struct|enum|bitmap|void)$/x) {
|struct|enum|bitmap|void|unsigned|signed)$/x) {
return $1;
}
return('IDENTIFIER',$1);

File diff suppressed because it is too large Load Diff

View File

@ -12,48 +12,6 @@ $VERSION = '0.01';
use strict;
#####################################################################
# flatten an array of arrays into a single array
sub FlattenArray2($)
{
my $a = shift;
my @b;
for my $d (@{$a}) {
for my $d1 (@{$d}) {
push(@b, $d1);
}
}
return \@b;
}
#####################################################################
# flatten an array of arrays into a single array
sub FlattenArray($)
{
my $a = shift;
my @b;
for my $d (@{$a}) {
for my $d1 (@{$d}) {
push(@b, $d1);
}
}
return \@b;
}
#####################################################################
# flatten an array of hashes into a single hash
sub FlattenHash($)
{
my $a = shift;
my %b;
for my $d (@{$a}) {
for my $k (keys %{$d}) {
$b{$k} = $d->{$k};
}
}
return \%b;
}
#####################################################################
# a dumper wrapper to prevent dependence on the Data::Dumper module
# unless we actually need it