1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

r12462: Hide oo magic from callers of the parser

(This used to be commit 0c225d2978)
This commit is contained in:
Jelmer Vernooij 2005-12-24 21:57:51 +00:00 committed by Gerald (Jerry) Carter
parent 557ad72e7a
commit e791dd73b9
4 changed files with 102 additions and 85 deletions

View File

@ -14,6 +14,6 @@
- replace subcontext() with represent_as() - replace subcontext() with represent_as()
- --explain-ndr option that dumps out parse tree - --explain-ndr option that dumps out parse tree ?
- fix test suite - fix test suite

View File

@ -416,9 +416,24 @@ again:
} }
} }
sub parse_idl($$) sub parse_string($)
{ {
my ($self,$filename) = @_; my ($data) = @_;
my $self = new Parse::Pidl::IDL;
$self->YYData->{INPUT} = $data;
$self->YYData->{LINE} = 0;
$self->YYData->{LAST_TOKEN} = "NONE";
my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error );
return CleanData($idl);
}
sub parse_file($)
{
my ($filename) = @_;
my $saved_delim = $/; my $saved_delim = $/;
undef $/; undef $/;
@ -429,11 +444,5 @@ sub parse_idl($$)
my $data = `$cpp -D__PIDL__ -xc $filename`; my $data = `$cpp -D__PIDL__ -xc $filename`;
$/ = $saved_delim; $/ = $saved_delim;
$self->YYData->{INPUT} = $data; return parse_string($data);
$self->YYData->{LINE} = 0;
$self->YYData->{LAST_TOKEN} = "NONE";
my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error );
return CleanData($idl);
} }

View File

@ -2108,19 +2108,19 @@ sub new {
[#Rule 2 [#Rule 2
'idl', 2, 'idl', 2,
sub sub
#line 19 "pidl/idl.yp" #line 19 "idl.yp"
{ push(@{$_[1]}, $_[2]); $_[1] } { push(@{$_[1]}, $_[2]); $_[1] }
], ],
[#Rule 3 [#Rule 3
'idl', 2, 'idl', 2,
sub sub
#line 20 "pidl/idl.yp" #line 20 "idl.yp"
{ push(@{$_[1]}, $_[2]); $_[1] } { push(@{$_[1]}, $_[2]); $_[1] }
], ],
[#Rule 4 [#Rule 4
'coclass', 7, 'coclass', 7,
sub sub
#line 24 "pidl/idl.yp" #line 24 "idl.yp"
{$_[3] => { {$_[3] => {
"TYPE" => "COCLASS", "TYPE" => "COCLASS",
"PROPERTIES" => $_[1], "PROPERTIES" => $_[1],
@ -2136,13 +2136,13 @@ sub
[#Rule 6 [#Rule 6
'interface_names', 4, 'interface_names', 4,
sub sub
#line 36 "pidl/idl.yp" #line 36 "idl.yp"
{ push(@{$_[1]}, $_[2]); $_[1] } { push(@{$_[1]}, $_[2]); $_[1] }
], ],
[#Rule 7 [#Rule 7
'interface', 8, 'interface', 8,
sub sub
#line 40 "pidl/idl.yp" #line 40 "idl.yp"
{$_[3] => { {$_[3] => {
"TYPE" => "INTERFACE", "TYPE" => "INTERFACE",
"PROPERTIES" => $_[1], "PROPERTIES" => $_[1],
@ -2159,19 +2159,19 @@ sub
[#Rule 9 [#Rule 9
'base_interface', 2, 'base_interface', 2,
sub sub
#line 53 "pidl/idl.yp" #line 53 "idl.yp"
{ $_[2] } { $_[2] }
], ],
[#Rule 10 [#Rule 10
'definitions', 1, 'definitions', 1,
sub sub
#line 57 "pidl/idl.yp" #line 57 "idl.yp"
{ [ $_[1] ] } { [ $_[1] ] }
], ],
[#Rule 11 [#Rule 11
'definitions', 2, 'definitions', 2,
sub sub
#line 58 "pidl/idl.yp" #line 58 "idl.yp"
{ push(@{$_[1]}, $_[2]); $_[1] } { push(@{$_[1]}, $_[2]); $_[1] }
], ],
[#Rule 12 [#Rule 12
@ -2192,7 +2192,7 @@ sub
[#Rule 17 [#Rule 17
'const', 7, 'const', 7,
sub sub
#line 66 "pidl/idl.yp" #line 66 "idl.yp"
{{ {{
"TYPE" => "CONST", "TYPE" => "CONST",
"DTYPE" => $_[2], "DTYPE" => $_[2],
@ -2206,7 +2206,7 @@ sub
[#Rule 18 [#Rule 18
'const', 8, 'const', 8,
sub sub
#line 76 "pidl/idl.yp" #line 76 "idl.yp"
{{ {{
"TYPE" => "CONST", "TYPE" => "CONST",
"DTYPE" => $_[2], "DTYPE" => $_[2],
@ -2221,7 +2221,7 @@ sub
[#Rule 19 [#Rule 19
'function', 7, 'function', 7,
sub sub
#line 90 "pidl/idl.yp" #line 90 "idl.yp"
{{ {{
"TYPE" => "FUNCTION", "TYPE" => "FUNCTION",
"NAME" => $_[3], "NAME" => $_[3],
@ -2235,7 +2235,7 @@ sub
[#Rule 20 [#Rule 20
'declare', 5, 'declare', 5,
sub sub
#line 102 "pidl/idl.yp" #line 102 "idl.yp"
{{ {{
"TYPE" => "DECLARE", "TYPE" => "DECLARE",
"PROPERTIES" => $_[2], "PROPERTIES" => $_[2],
@ -2254,7 +2254,7 @@ sub
[#Rule 23 [#Rule 23
'decl_enum', 1, 'decl_enum', 1,
sub sub
#line 116 "pidl/idl.yp" #line 116 "idl.yp"
{{ {{
"TYPE" => "ENUM" "TYPE" => "ENUM"
}} }}
@ -2262,7 +2262,7 @@ sub
[#Rule 24 [#Rule 24
'decl_bitmap', 1, 'decl_bitmap', 1,
sub sub
#line 122 "pidl/idl.yp" #line 122 "idl.yp"
{{ {{
"TYPE" => "BITMAP" "TYPE" => "BITMAP"
}} }}
@ -2270,7 +2270,7 @@ sub
[#Rule 25 [#Rule 25
'typedef', 6, 'typedef', 6,
sub sub
#line 128 "pidl/idl.yp" #line 128 "idl.yp"
{{ {{
"TYPE" => "TYPEDEF", "TYPE" => "TYPEDEF",
"PROPERTIES" => $_[2], "PROPERTIES" => $_[2],
@ -2296,7 +2296,7 @@ sub
[#Rule 30 [#Rule 30
'typedecl', 2, 'typedecl', 2,
sub sub
#line 141 "pidl/idl.yp" #line 141 "idl.yp"
{ $_[1] } { $_[1] }
], ],
[#Rule 31 [#Rule 31
@ -2308,13 +2308,13 @@ sub
[#Rule 33 [#Rule 33
'type', 1, 'type', 1,
sub sub
#line 144 "pidl/idl.yp" #line 144 "idl.yp"
{ "void" } { "void" }
], ],
[#Rule 34 [#Rule 34
'enum', 5, 'enum', 5,
sub sub
#line 148 "pidl/idl.yp" #line 148 "idl.yp"
{{ {{
"TYPE" => "ENUM", "TYPE" => "ENUM",
"NAME" => $_[2], "NAME" => $_[2],
@ -2324,13 +2324,13 @@ sub
[#Rule 35 [#Rule 35
'enum_elements', 1, 'enum_elements', 1,
sub sub
#line 156 "pidl/idl.yp" #line 156 "idl.yp"
{ [ $_[1] ] } { [ $_[1] ] }
], ],
[#Rule 36 [#Rule 36
'enum_elements', 3, 'enum_elements', 3,
sub sub
#line 157 "pidl/idl.yp" #line 157 "idl.yp"
{ push(@{$_[1]}, $_[3]); $_[1] } { push(@{$_[1]}, $_[3]); $_[1] }
], ],
[#Rule 37 [#Rule 37
@ -2339,13 +2339,13 @@ sub
[#Rule 38 [#Rule 38
'enum_element', 3, 'enum_element', 3,
sub sub
#line 161 "pidl/idl.yp" #line 161 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 39 [#Rule 39
'bitmap', 5, 'bitmap', 5,
sub sub
#line 165 "pidl/idl.yp" #line 165 "idl.yp"
{{ {{
"TYPE" => "BITMAP", "TYPE" => "BITMAP",
"NAME" => $_[2], "NAME" => $_[2],
@ -2355,25 +2355,25 @@ sub
[#Rule 40 [#Rule 40
'bitmap_elements', 1, 'bitmap_elements', 1,
sub sub
#line 173 "pidl/idl.yp" #line 173 "idl.yp"
{ [ $_[1] ] } { [ $_[1] ] }
], ],
[#Rule 41 [#Rule 41
'bitmap_elements', 3, 'bitmap_elements', 3,
sub sub
#line 174 "pidl/idl.yp" #line 174 "idl.yp"
{ push(@{$_[1]}, $_[3]); $_[1] } { push(@{$_[1]}, $_[3]); $_[1] }
], ],
[#Rule 42 [#Rule 42
'bitmap_element', 3, 'bitmap_element', 3,
sub sub
#line 177 "pidl/idl.yp" #line 177 "idl.yp"
{ "$_[1] ( $_[3] )" } { "$_[1] ( $_[3] )" }
], ],
[#Rule 43 [#Rule 43
'struct', 5, 'struct', 5,
sub sub
#line 181 "pidl/idl.yp" #line 181 "idl.yp"
{{ {{
"TYPE" => "STRUCT", "TYPE" => "STRUCT",
"NAME" => $_[2], "NAME" => $_[2],
@ -2383,7 +2383,7 @@ sub
[#Rule 44 [#Rule 44
'empty_element', 2, 'empty_element', 2,
sub sub
#line 189 "pidl/idl.yp" #line 189 "idl.yp"
{{ {{
"NAME" => "", "NAME" => "",
"TYPE" => "EMPTY", "TYPE" => "EMPTY",
@ -2403,7 +2403,7 @@ sub
[#Rule 47 [#Rule 47
'optional_base_element', 2, 'optional_base_element', 2,
sub sub
#line 203 "pidl/idl.yp" #line 203 "idl.yp"
{ $_[2]->{PROPERTIES} = Parse::Pidl::Util::FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] } { $_[2]->{PROPERTIES} = Parse::Pidl::Util::FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] }
], ],
[#Rule 48 [#Rule 48
@ -2412,13 +2412,13 @@ sub
[#Rule 49 [#Rule 49
'union_elements', 2, 'union_elements', 2,
sub sub
#line 208 "pidl/idl.yp" #line 208 "idl.yp"
{ push(@{$_[1]}, $_[2]); $_[1] } { push(@{$_[1]}, $_[2]); $_[1] }
], ],
[#Rule 50 [#Rule 50
'union', 5, 'union', 5,
sub sub
#line 212 "pidl/idl.yp" #line 212 "idl.yp"
{{ {{
"TYPE" => "UNION", "TYPE" => "UNION",
"NAME" => $_[2], "NAME" => $_[2],
@ -2428,7 +2428,7 @@ sub
[#Rule 51 [#Rule 51
'base_element', 5, 'base_element', 5,
sub sub
#line 220 "pidl/idl.yp" #line 220 "idl.yp"
{{ {{
"NAME" => $_[4], "NAME" => $_[4],
"TYPE" => $_[2], "TYPE" => $_[2],
@ -2442,13 +2442,13 @@ sub
[#Rule 52 [#Rule 52
'pointers', 0, 'pointers', 0,
sub sub
#line 234 "pidl/idl.yp" #line 234 "idl.yp"
{ 0 } { 0 }
], ],
[#Rule 53 [#Rule 53
'pointers', 2, 'pointers', 2,
sub sub
#line 235 "pidl/idl.yp" #line 235 "idl.yp"
{ $_[1]+1 } { $_[1]+1 }
], ],
[#Rule 54 [#Rule 54
@ -2457,7 +2457,7 @@ sub
[#Rule 55 [#Rule 55
'element_list1', 3, 'element_list1', 3,
sub sub
#line 240 "pidl/idl.yp" #line 240 "idl.yp"
{ push(@{$_[1]}, $_[2]); $_[1] } { push(@{$_[1]}, $_[2]); $_[1] }
], ],
[#Rule 56 [#Rule 56
@ -2469,13 +2469,13 @@ sub
[#Rule 58 [#Rule 58
'element_list2', 1, 'element_list2', 1,
sub sub
#line 246 "pidl/idl.yp" #line 246 "idl.yp"
{ [ $_[1] ] } { [ $_[1] ] }
], ],
[#Rule 59 [#Rule 59
'element_list2', 3, 'element_list2', 3,
sub sub
#line 247 "pidl/idl.yp" #line 247 "idl.yp"
{ push(@{$_[1]}, $_[3]); $_[1] } { push(@{$_[1]}, $_[3]); $_[1] }
], ],
[#Rule 60 [#Rule 60
@ -2484,13 +2484,13 @@ sub
[#Rule 61 [#Rule 61
'array_len', 3, 'array_len', 3,
sub sub
#line 252 "pidl/idl.yp" #line 252 "idl.yp"
{ push(@{$_[3]}, "*"); $_[3] } { push(@{$_[3]}, "*"); $_[3] }
], ],
[#Rule 62 [#Rule 62
'array_len', 4, 'array_len', 4,
sub sub
#line 253 "pidl/idl.yp" #line 253 "idl.yp"
{ push(@{$_[4]}, "$_[2]"); $_[4] } { push(@{$_[4]}, "$_[2]"); $_[4] }
], ],
[#Rule 63 [#Rule 63
@ -2499,31 +2499,31 @@ sub
[#Rule 64 [#Rule 64
'property_list', 4, 'property_list', 4,
sub sub
#line 259 "pidl/idl.yp" #line 259 "idl.yp"
{ Parse::Pidl::Util::FlattenHash([$_[1],$_[3]]); } { Parse::Pidl::Util::FlattenHash([$_[1],$_[3]]); }
], ],
[#Rule 65 [#Rule 65
'properties', 1, 'properties', 1,
sub sub
#line 262 "pidl/idl.yp" #line 262 "idl.yp"
{ $_[1] } { $_[1] }
], ],
[#Rule 66 [#Rule 66
'properties', 3, 'properties', 3,
sub sub
#line 263 "pidl/idl.yp" #line 263 "idl.yp"
{ Parse::Pidl::Util::FlattenHash([$_[1], $_[3]]); } { Parse::Pidl::Util::FlattenHash([$_[1], $_[3]]); }
], ],
[#Rule 67 [#Rule 67
'property', 1, 'property', 1,
sub sub
#line 266 "pidl/idl.yp" #line 266 "idl.yp"
{{ "$_[1]" => "1" }} {{ "$_[1]" => "1" }}
], ],
[#Rule 68 [#Rule 68
'property', 4, 'property', 4,
sub sub
#line 267 "pidl/idl.yp" #line 267 "idl.yp"
{{ "$_[1]" => "$_[3]" }} {{ "$_[1]" => "$_[3]" }}
], ],
[#Rule 69 [#Rule 69
@ -2532,7 +2532,7 @@ sub
[#Rule 70 [#Rule 70
'listtext', 3, 'listtext', 3,
sub sub
#line 272 "pidl/idl.yp" #line 272 "idl.yp"
{ "$_[1] $_[3]" } { "$_[1] $_[3]" }
], ],
[#Rule 71 [#Rule 71
@ -2541,13 +2541,13 @@ sub
[#Rule 72 [#Rule 72
'commalisttext', 3, 'commalisttext', 3,
sub sub
#line 277 "pidl/idl.yp" #line 277 "idl.yp"
{ "$_[1],$_[3]" } { "$_[1],$_[3]" }
], ],
[#Rule 73 [#Rule 73
'anytext', 0, 'anytext', 0,
sub sub
#line 281 "pidl/idl.yp" #line 281 "idl.yp"
{ "" } { "" }
], ],
[#Rule 74 [#Rule 74
@ -2562,91 +2562,91 @@ sub
[#Rule 77 [#Rule 77
'anytext', 3, 'anytext', 3,
sub sub
#line 283 "pidl/idl.yp" #line 283 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 78 [#Rule 78
'anytext', 3, 'anytext', 3,
sub sub
#line 284 "pidl/idl.yp" #line 284 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 79 [#Rule 79
'anytext', 3, 'anytext', 3,
sub sub
#line 285 "pidl/idl.yp" #line 285 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 80 [#Rule 80
'anytext', 3, 'anytext', 3,
sub sub
#line 286 "pidl/idl.yp" #line 286 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 81 [#Rule 81
'anytext', 3, 'anytext', 3,
sub sub
#line 287 "pidl/idl.yp" #line 287 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 82 [#Rule 82
'anytext', 3, 'anytext', 3,
sub sub
#line 288 "pidl/idl.yp" #line 288 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 83 [#Rule 83
'anytext', 3, 'anytext', 3,
sub sub
#line 289 "pidl/idl.yp" #line 289 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 84 [#Rule 84
'anytext', 3, 'anytext', 3,
sub sub
#line 290 "pidl/idl.yp" #line 290 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 85 [#Rule 85
'anytext', 3, 'anytext', 3,
sub sub
#line 291 "pidl/idl.yp" #line 291 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 86 [#Rule 86
'anytext', 3, 'anytext', 3,
sub sub
#line 292 "pidl/idl.yp" #line 292 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 87 [#Rule 87
'anytext', 3, 'anytext', 3,
sub sub
#line 293 "pidl/idl.yp" #line 293 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 88 [#Rule 88
'anytext', 3, 'anytext', 3,
sub sub
#line 294 "pidl/idl.yp" #line 294 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 89 [#Rule 89
'anytext', 3, 'anytext', 3,
sub sub
#line 295 "pidl/idl.yp" #line 295 "idl.yp"
{ "$_[1]$_[2]$_[3]" } { "$_[1]$_[2]$_[3]" }
], ],
[#Rule 90 [#Rule 90
'anytext', 5, 'anytext', 5,
sub sub
#line 296 "pidl/idl.yp" #line 296 "idl.yp"
{ "$_[1]$_[2]$_[3]$_[4]$_[5]" } { "$_[1]$_[2]$_[3]$_[4]$_[5]" }
], ],
[#Rule 91 [#Rule 91
'anytext', 5, 'anytext', 5,
sub sub
#line 297 "pidl/idl.yp" #line 297 "idl.yp"
{ "$_[1]$_[2]$_[3]$_[4]$_[5]" } { "$_[1]$_[2]$_[3]$_[4]$_[5]" }
], ],
[#Rule 92 [#Rule 92
@ -2664,7 +2664,7 @@ sub
[#Rule 96 [#Rule 96
'text', 1, 'text', 1,
sub sub
#line 311 "pidl/idl.yp" #line 311 "idl.yp"
{ "\"$_[1]\"" } { "\"$_[1]\"" }
], ],
[#Rule 97 [#Rule 97
@ -2678,7 +2678,7 @@ sub
bless($self,$class); bless($self,$class);
} }
#line 322 "pidl/idl.yp" #line 322 "idl.yp"
use Parse::Pidl::Util; use Parse::Pidl::Util;
@ -2776,18 +2776,11 @@ again:
} }
} }
sub parse_idl($$) sub parse_string($)
{ {
my ($self,$filename) = @_; my ($data) = @_;
my $saved_delim = $/; my $self = new Parse::Pidl::IDL;
undef $/;
my $cpp = $ENV{CPP};
if (! defined $cpp) {
$cpp = "cpp";
}
my $data = `$cpp -D__PIDL__ -xc $filename`;
$/ = $saved_delim;
$self->YYData->{INPUT} = $data; $self->YYData->{INPUT} = $data;
$self->YYData->{LINE} = 0; $self->YYData->{LINE} = 0;
@ -2798,4 +2791,20 @@ sub parse_idl($$)
return CleanData($idl); return CleanData($idl);
} }
sub parse_file($)
{
my ($filename) = @_;
my $saved_delim = $/;
undef $/;
my $cpp = $ENV{CPP};
if (! defined $cpp) {
$cpp = "cpp";
}
my $data = `$cpp -D__PIDL__ -xc $filename`;
$/ = $saved_delim;
return parse_string($data);
}
1; 1;

View File

@ -587,9 +587,8 @@ sub process_file($)
defined $pidl || die "Failed to load $idl_file"; defined $pidl || die "Failed to load $idl_file";
} else { } else {
require Parse::Pidl::IDL; require Parse::Pidl::IDL;
my $idl_parser = new Parse::Pidl::IDL;
$pidl = $idl_parser->parse_idl($idl_file); $pidl = Parse::Pidl::IDL::parse_file($idl_file);
defined @$pidl || die "Failed to parse $idl_file"; defined @$pidl || die "Failed to parse $idl_file";
require Parse::Pidl::Typelist; require Parse::Pidl::Typelist;
Parse::Pidl::Typelist::LoadIdl($pidl); Parse::Pidl::Typelist::LoadIdl($pidl);